Skip to content

Commit

Permalink
Fallback to default audio/MIDI backends if invalid one is set
Browse files Browse the repository at this point in the history
Also shows the setup dialog in case of invalid audio backends
  • Loading branch information
PhysSong committed Sep 13, 2018
1 parent 3064f03 commit 91ca660
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 1 deletion.
3 changes: 3 additions & 0 deletions include/Mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ class EXPORT Mixer : public QObject
void requestChangeInModel();
void doneChangeInModel();

static bool isAudioDevNameValid(QString name);
static bool isMidiDevNameValid(QString name);


signals:
void qualitySettingsChanged();
Expand Down
128 changes: 128 additions & 0 deletions src/core/Mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -829,14 +829,138 @@ void Mixer::runChangesInModel()
}
}

bool Mixer::isAudioDevNameValid(QString name)
{
#ifdef LMMS_HAVE_SDL
if (name == AudioSdl::name())
{
return true;
}
#endif


#ifdef LMMS_HAVE_ALSA
if (name == AudioAlsa::name())
{
return true;
}
#endif


#ifdef LMMS_HAVE_PULSEAUDIO
if (name == AudioPulseAudio::name())
{
return true;
}
#endif


#ifdef LMMS_HAVE_OSS
if (name == AudioOss::name())
{
return true;
}
#endif

#ifdef LMMS_HAVE_SNDIO
if (name == AudioSndio::name())
{
return true;
}
#endif

#ifdef LMMS_HAVE_JACK
if (name == AudioJack::name())
{
return true;
}
#endif


#ifdef LMMS_HAVE_PORTAUDIO
if (name == AudioPortAudio::name())
{
return true;
}
#endif


#ifdef LMMS_HAVE_SOUNDIO
if (name == AudioSoundIo::name())
{
return true;
}
#endif

if (name == AudioDummy::name())
{
return true;
}

return false;
}

bool Mixer::isMidiDevNameValid(QString name)
{
#ifdef LMMS_HAVE_ALSA
if (name == MidiAlsaSeq::name() || name == MidiAlsaRaw::name())
{
return true;
}
#endif

#ifdef LMMS_HAVE_JACK
if (name == MidiJack::name())
{
return true;
}
#endif

#ifdef LMMS_HAVE_OSS
if (name == MidiOss::name())
{
return true;
}
#endif

#ifdef LMMS_HAVE_SNDIO
if (name == MidiSndio::name())
{
return true;
}
#endif

#ifdef LMMS_BUILD_WIN32
if (name == MidiWinMM::name())
{
return true;
}
#endif

#ifdef LMMS_BUILD_APPLE
if (name == MidiApple::name())
{
return true;
}
#endif

if (name == MidiDummy::name())
{
return true;
}

return false;
}

AudioDevice * Mixer::tryAudioDevices()
{
bool success_ful = false;
AudioDevice * dev = NULL;
QString dev_name = ConfigManager::inst()->value( "mixer", "audiodev" );
if( !isAudioDevNameValid( dev_name ) )
{
dev_name = "";
}

m_audioDevStartFailed = false;

Expand Down Expand Up @@ -980,6 +1104,10 @@ MidiClient * Mixer::tryMidiClients()
{
QString client_name = ConfigManager::inst()->value( "mixer",
"mididev" );
if( !isMidiDevNameValid( client_name ) )
{
client_name = "";
}

#ifdef LMMS_HAVE_ALSA
if( client_name == MidiAlsaSeq::name() || client_name == "" )
Expand Down
4 changes: 3 additions & 1 deletion src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,9 @@ void MainWindow::finalize()
}
// look whether mixer failed to start the audio device selected by the
// user and is using AudioDummy as a fallback
else if( Engine::mixer()->audioDevStartFailed() )
// or the audio device is set to invalid one
else if( Engine::mixer()->audioDevStartFailed() || !Mixer::isAudioDevNameValid(
ConfigManager::inst()->value( "mixer", "audiodev" ) ) )
{
// if so, offer the audio settings section of the setup dialog
SetupDialog sd( SetupDialog::AudioSettings );
Expand Down

0 comments on commit 91ca660

Please sign in to comment.