[Ariamaestosa-commit] SF.net SVN: ariamaestosa:[2233] trunk/Src/Midi/Players/Alsa
Brought to you by:
mmg1
From: <aar...@us...> - 2013-01-03 13:18:59
|
Revision: 2233 http://ariamaestosa.svn.sourceforge.net/ariamaestosa/?rev=2233&view=rev Author: aarchambault Date: 2013-01-03 13:18:51 +0000 (Thu, 03 Jan 2013) Log Message: ----------- Added : handles better Fluidsynth MIDI port selection (especially when parameters attached to port have changed, which happens when Fluidsynth is stopped then restarted) Modified Paths: -------------- trunk/Src/Midi/Players/Alsa/AlsaPort.cpp trunk/Src/Midi/Players/Alsa/AlsaPort.h Modified: trunk/Src/Midi/Players/Alsa/AlsaPort.cpp =================================================================== --- trunk/Src/Midi/Players/Alsa/AlsaPort.cpp 2013-01-02 22:01:02 UTC (rev 2232) +++ trunk/Src/Midi/Players/Alsa/AlsaPort.cpp 2013-01-03 13:18:51 UTC (rev 2233) @@ -1,4 +1,4 @@ -#ifdef _ALSA +//#ifdef _ALSA #include <glib.h> #include "AriaCore.h" @@ -10,9 +10,9 @@ #include "Dialogs/WaitWindow.h" #include "PreferencesData.h" -static const wxString SOFT_SYNTH_COMMAND = wxT("fluidsynth"); -static const wxString SOFT_SYNTH_NAME = wxT("FluidSynth"); -static const wxString SOFT_SYNTH_PORT_MARKER = wxT("Synth"); +static const wxString FLUIDSYNTH_COMMAND = wxT("fluidsynth"); +static const wxString FLUIDSYNTH_NAME = wxT("FluidSynth"); +static const wxString FLUIDSYNTH_PORT_MARKER = wxT("Synth input"); static const wxString MIDI_THROUGH_PORT_MARKER = wxT("through"); static const int SOFT_SYNTH_BASIC_TIMER = 300; static const int SOFT_SYNTH_TIMER = 1000; // 1s @@ -103,13 +103,13 @@ soundBank = PreferencesData::getInstance()->getValue(SETTING_ID_SOUNDBANK); soundFontPath = (soundBank == SYSTEM_BANK ? DEFAULT_SOUNDFONT_PATH : soundBank); soundFontExists = wxFileExists(soundFontPath); - if (isExeRunning(SOFT_SYNTH_COMMAND)) + if (isExeRunning(FLUIDSYNTH_COMMAND)) { - std::cout << SOFT_SYNTH_NAME.mb_str() << " appears to be already running. " << std::endl; + std::cout << FLUIDSYNTH_NAME.mb_str() << " appears to be already running. " << std::endl; if (soundFontExists) { - wxString grepCommand = wxT("ps x --cols 255 | grep ") + SOFT_SYNTH_COMMAND; + wxString grepCommand = wxT("ps x --cols 255 | grep ") + FLUIDSYNTH_COMMAND; // @todo : compare current soundfont path (in params) with path in prefs @@ -145,9 +145,9 @@ { int filePartCount; - WaitWindow::show((wxWindow*)getMainFrame(), _("Loading ") + SOFT_SYNTH_NAME, true); + WaitWindow::show((wxWindow*)getMainFrame(), _("Loading ") + FLUIDSYNTH_NAME, true); - std::cout << "Launching " << SOFT_SYNTH_NAME.mb_str() << " ALSA deamon" << std::endl; + std::cout << "Launching " << FLUIDSYNTH_NAME.mb_str() << " ALSA deamon" << std::endl; runSoftSynth(soundFontPath); wxMilliSleep(SOFT_SYNTH_BASIC_TIMER); @@ -234,22 +234,23 @@ } else { - d = getDevice(a,b); + int n = -1; + d = getDevice(a, b, n); - // fail-over based upon "Synth" string - if (d==NULL && port.Find(SOFT_SYNTH_PORT_MARKER)!=wxNOT_FOUND) + // fail-over based upon Fluidsynth port string + if (d==NULL && port.Find(FLUIDSYNTH_PORT_MARKER)!=wxNOT_FOUND) { - bool found = false; - for (int n=0 ; n<(int)devices.size() && !found ; n++) - { - if (devices[n].name.Find(SOFT_SYNTH_PORT_MARKER)!=wxNOT_FOUND) - { - d = &devices[n]; - found = true; - setDevice(&d, n); - } - } + d = getDevice(FLUIDSYNTH_PORT_MARKER, n); } + + // Overwrites the setting SETTING_ID_MIDI_OUTPUT, so that output midi port menu selection + // happens correctly in MainFrame::initMenuBar + // => in expression "128:0 Synth input port (24071:0)", last params (here : 24071:0) + // change if Fluidsynth has been killed then restarted + if (d!=NULL) + { + setDevice(&d, n); + } } } @@ -273,23 +274,46 @@ } -MidiDevice* MidiContext::getDevice(int i) +MidiDevice* MidiContext::getDevice(int index) { - if(i<0 or i>(int)devices.size()) return NULL; - return &devices[i]; + if (index<0 or index>(int)devices.size()) return NULL; + return &devices[index]; } -MidiDevice* MidiContext::getDevice(int client, int port) +MidiDevice* MidiContext::getDevice(int client, int port, int& index) { for (int n=0; n<(int)devices.size(); n++) { - if(devices[n].client == client and devices[n].port == port) return &devices[n]; + if (devices[n].client == client and devices[n].port == port) + { + index = n; + return &devices[n]; + } + } return NULL; } +MidiDevice* MidiContext::getDevice(const wxString& marker, int& index) +{ + MidiDevice* d = NULL; + bool found = false; + for (int n=0 ; n<(int)devices.size() && !found ; n++) + { + if (devices[n].name.Find(marker)!=wxNOT_FOUND) + { + index = n; + d = &devices[n]; + found = true; + } + } + + return d; +} + + void MidiContext::findDevices() { devices.clearAndDeleteAll(); @@ -429,7 +453,7 @@ void MidiContext::runSoftSynth(const wxString& soundfontPath) { - wxString cmd(SOFT_SYNTH_COMMAND + wxString cmd(FLUIDSYNTH_COMMAND + wxT(" -a alsa -l --server -i ") + soundfontPath); wxExecute(cmd, wxEXEC_ASYNC); @@ -446,4 +470,4 @@ } -#endif +//#endif Modified: trunk/Src/Midi/Players/Alsa/AlsaPort.h =================================================================== --- trunk/Src/Midi/Players/Alsa/AlsaPort.h 2013-01-02 22:01:02 UTC (rev 2232) +++ trunk/Src/Midi/Players/Alsa/AlsaPort.h 2013-01-03 13:18:51 UTC (rev 2233) @@ -61,8 +61,9 @@ void findDevices (); int getDeviceAmount(); - MidiDevice* getDevice(int id); - MidiDevice* getDevice(int client, int port); + MidiDevice* getDevice(int index); + MidiDevice* getDevice(int client, int port, int& index); + MidiDevice* getDevice(const wxString& marker, int& index); }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |