Enable configuration of input device for SDL
Up to now the SDL audio driver attempted to use the default recording device. This might not be what users want or expect, especially since the actually used device is not visible anywhere. So if recording does not work for the users they have no way to find out what's wrong. Extend the settings screen of the SDL driver with a combo box that allows to select the input device to be used. Store the selected device name in a new attribute called "inputdevice" in the "audiosdl" section of the configuration file. Use the information from the configuration when attempting to inialize the input device. Fall back to the default device if that does not work.
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
#include "AudioDeviceSetupWidget.h"
|
||||
|
||||
class QLineEdit;
|
||||
class QComboBox;
|
||||
|
||||
namespace lmms
|
||||
{
|
||||
@@ -67,7 +68,7 @@ public:
|
||||
|
||||
private:
|
||||
QLineEdit * m_device;
|
||||
|
||||
QComboBox* m_inputDeviceComboBox = nullptr;
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
#include <QFormLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QComboBox>
|
||||
#include <SDL.h>
|
||||
|
||||
#include "AudioEngine.h"
|
||||
@@ -107,11 +108,18 @@ AudioSdl::AudioSdl( bool & _success_ful, AudioEngine* _audioEngine ) :
|
||||
m_inputAudioHandle = m_audioHandle;
|
||||
m_inputAudioHandle.callback = sdlInputAudioCallback;
|
||||
|
||||
m_inputDevice = SDL_OpenAudioDevice (nullptr,
|
||||
1,
|
||||
&m_inputAudioHandle,
|
||||
&actual,
|
||||
0);
|
||||
const QString inputDevice = ConfigManager::inst()->value("audiosdl", "inputdevice");
|
||||
|
||||
// Try with the configured device
|
||||
const auto inputDeviceCStr = inputDevice.toLocal8Bit().data();
|
||||
m_inputDevice = SDL_OpenAudioDevice (inputDeviceCStr, 1, &m_inputAudioHandle, &actual, 0);
|
||||
|
||||
// If we did not get a device ID try again with the default device
|
||||
if (m_inputDevice == 0)
|
||||
{
|
||||
m_inputDevice = SDL_OpenAudioDevice(nullptr, 1, &m_inputAudioHandle, &actual, 0);
|
||||
}
|
||||
|
||||
if (m_inputDevice != 0) {
|
||||
m_supportsCapture = true;
|
||||
} else {
|
||||
@@ -291,6 +299,23 @@ AudioSdl::setupWidget::setupWidget( QWidget * _parent ) :
|
||||
m_device = new QLineEdit( dev, this );
|
||||
|
||||
form->addRow(tr("Device"), m_device);
|
||||
|
||||
m_inputDeviceComboBox = new QComboBox(this);
|
||||
|
||||
#ifdef LMMS_HAVE_SDL2
|
||||
const int numberOfInputDevices = SDL_GetNumAudioDevices(1);
|
||||
for (int i = 0; i < numberOfInputDevices; ++i)
|
||||
{
|
||||
const QString deviceName = SDL_GetAudioDeviceName(i, 1);
|
||||
m_inputDeviceComboBox->addItem(deviceName);
|
||||
}
|
||||
|
||||
// Set the current device to the one in the configuration
|
||||
const auto inputDevice = ConfigManager::inst()->value("audiosdl", "inputdevice");
|
||||
m_inputDeviceComboBox->setCurrentText(inputDevice);
|
||||
#endif
|
||||
|
||||
form->addRow(tr("Input device"), m_inputDeviceComboBox);
|
||||
}
|
||||
|
||||
|
||||
@@ -300,6 +325,12 @@ void AudioSdl::setupWidget::saveSettings()
|
||||
{
|
||||
ConfigManager::inst()->setValue( "audiosdl", "device",
|
||||
m_device->text() );
|
||||
|
||||
const auto currentInputDevice = m_inputDeviceComboBox->currentText();
|
||||
if (!currentInputDevice.isEmpty())
|
||||
{
|
||||
ConfigManager::inst()->setValue("audiosdl", "inputdevice", currentInputDevice);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user