--- linuxsampler/trunk/src/network/lscpserver.cpp 2005/02/12 00:36:08 374 +++ linuxsampler/trunk/src/network/lscpserver.cpp 2006/12/29 20:06:14 1005 @@ -3,19 +3,20 @@ * LinuxSampler - modular, streaming capable sampler * * * * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * + * Copyright (C) 2005, 2006 Christian Schoenebeck * * * - * This program is free software; you can redistribute it and/or modify * + * This library is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * - * This program is distributed in the hope that it will be useful, * + * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software * + * along with this library; if not, write to the Free Software * * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * * MA 02111-1307 USA * ***************************************************************************/ @@ -23,8 +24,16 @@ #include "lscpserver.h" #include "lscpresultset.h" #include "lscpevent.h" +#include "../common/global.h" -#include "../engines/gig/Engine.h" +#include + +#if HAVE_SQLITE3 +# include "sqlite3.h" +#endif + +#include "../engines/EngineFactory.h" +#include "../engines/EngineChannelFactory.h" #include "../drivers/audio/AudioOutputDeviceFactory.h" #include "../drivers/midi/MidiInputDeviceFactory.h" @@ -52,14 +61,31 @@ Mutex LSCPServer::SubscriptionMutex = Mutex(); Mutex LSCPServer::RTNotifyMutex = Mutex(); -LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) { +LSCPServer::LSCPServer(Sampler* pSampler, long int addr, short int port) : Thread(true, false, 0, -4) { + SocketAddress.sin_family = AF_INET; + SocketAddress.sin_addr.s_addr = addr; + SocketAddress.sin_port = port; this->pSampler = pSampler; - LSCPEvent::RegisterEvent(LSCPEvent::event_channels, "CHANNELS"); + LSCPEvent::RegisterEvent(LSCPEvent::event_audio_device_count, "AUDIO_OUTPUT_DEVICE_COUNT"); + LSCPEvent::RegisterEvent(LSCPEvent::event_audio_device_info, "AUDIO_OUTPUT_DEVICE_INFO"); + LSCPEvent::RegisterEvent(LSCPEvent::event_midi_device_count, "MIDI_INPUT_DEVICE_COUNT"); + LSCPEvent::RegisterEvent(LSCPEvent::event_midi_device_info, "MIDI_INPUT_DEVICE_INFO"); + LSCPEvent::RegisterEvent(LSCPEvent::event_channel_count, "CHANNEL_COUNT"); LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT"); LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT"); LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL"); - LSCPEvent::RegisterEvent(LSCPEvent::event_info, "INFO"); + LSCPEvent::RegisterEvent(LSCPEvent::event_channel_info, "CHANNEL_INFO"); + LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_count, "MIDI_INSTRUMENT_MAP_COUNT"); + LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_info, "MIDI_INSTRUMENT_MAP_INFO"); + LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_count, "MIDI_INSTRUMENT_COUNT"); + LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_info, "MIDI_INSTRUMENT_INFO"); LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); + LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT"); + hSocket = -1; +} + +LSCPServer::~LSCPServer() { + if (hSocket >= 0) close(hSocket); } /** @@ -77,17 +103,13 @@ } int LSCPServer::Main() { - int hSocket = socket(AF_INET, SOCK_STREAM, 0); + hSocket = socket(AF_INET, SOCK_STREAM, 0); if (hSocket < 0) { std::cerr << "LSCPServer: Could not create server socket." << std::endl; //return -1; exit(EXIT_FAILURE); } - SocketAddress.sin_family = AF_INET; - SocketAddress.sin_port = htons(LSCP_PORT); - SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY); - if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { std::cerr << "LSCPServer: Could not bind server socket, retrying for " << ToString(LSCP_SERVER_BIND_TIMEOUT) << " seconds..."; for (int trial = 0; true; trial++) { // retry for LSCP_SERVER_BIND_TIMEOUT seconds @@ -114,9 +136,39 @@ FD_SET(hSocket, &fdSet); int maxSessions = hSocket; + timeval timeout; + while (true) { - fd_set selectSet = fdSet; - int retval = select(maxSessions+1, &selectSet, NULL, NULL, NULL); + // check if some engine channel's parameter / status changed, if so notify the respective LSCP event subscribers + { + std::set engineChannels = EngineChannelFactory::EngineChannelInstances(); + std::set::iterator itEngineChannel = engineChannels.begin(); + std::set::iterator itEnd = engineChannels.end(); + for (; itEngineChannel != itEnd; ++itEngineChannel) { + if ((*itEngineChannel)->StatusChanged()) { + SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex)); + } + } + } + + //Now let's deliver late notifies (if any) + NotifyBufferMutex.Lock(); + for (std::map::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) { +#ifdef MSG_NOSIGNAL + send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), MSG_NOSIGNAL); +#else + send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0); +#endif + } + bufferedNotifies.clear(); + NotifyBufferMutex.Unlock(); + + fd_set selectSet = fdSet; + timeout.tv_sec = 0; + timeout.tv_usec = 100000; + + int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout); + if (retval == 0) continue; //Nothing try again if (retval == -1) { @@ -160,6 +212,7 @@ int dummy; // just a temporary hack to fulfill the restart() function prototype restart(NULL, dummy); // restart the 'scanner' currentSocket = (*iter).hSession; //a hack + dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str())); if ((*iter).bVerbose) { // if echo mode enabled AnswerClient(bufferedCommands[currentSocket]); } @@ -175,14 +228,6 @@ break; } } - - //Now let's deliver late notifies (if any) - NotifyBufferMutex.Lock(); - for (std::map::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) { - send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0); - bufferedNotifies.erase(iterNotify); - } - NotifyBufferMutex.Unlock(); } } @@ -229,7 +274,11 @@ while (true) { if (NotifyMutex.Trylock()) { for(;iter != end; iter++) +#ifdef MSG_NOSIGNAL + send(*iter, notify.c_str(), notify.size(), MSG_NOSIGNAL); +#else send(*iter, notify.c_str(), notify.size(), 0); +#endif NotifyMutex.Unlock(); break; } else { @@ -281,7 +330,7 @@ continue; //Ignore CR if (c == '\n') { LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket)); - bufferedCommands[socket] += "\n"; + bufferedCommands[socket] += "\r\n"; return true; //Complete command was read } bufferedCommands[socket] += c; @@ -338,7 +387,11 @@ dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str())); if (currentSocket != -1) { NotifyMutex.Lock(); +#ifdef MSG_NOSIGNAL + send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), MSG_NOSIGNAL); +#else send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0); +#endif NotifyMutex.Unlock(); } } @@ -382,10 +435,10 @@ AudioOutputDevice* pDevice = pSampler->CreateAudioOutputDevice(Driver, Parameters); // search for the created device to get its index int index = GetAudioOutputDeviceIndex(pDevice); - if (index == -1) throw LinuxSamplerException("Internal error: could not find created audio output device."); + if (index == -1) throw Exception("Internal error: could not find created audio output device."); result = index; // success } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -398,10 +451,10 @@ MidiInputDevice* pDevice = pSampler->CreateMidiInputDevice(Driver, Parameters); // search for the created device to get its index int index = GetMidiInputDeviceIndex(pDevice); - if (index == -1) throw LinuxSamplerException("Internal error: could not find created midi input device."); + if (index == -1) throw Exception("Internal error: could not find created midi input device."); result = index; // success } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -412,11 +465,11 @@ LSCPResultSet result; try { std::map devices = pSampler->GetAudioOutputDevices(); - if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); + if (!devices.count(DeviceIndex)) throw Exception("There is no audio output device with index " + ToString(DeviceIndex) + "."); AudioOutputDevice* pDevice = devices[DeviceIndex]; pSampler->DestroyAudioOutputDevice(pDevice); } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -427,11 +480,11 @@ LSCPResultSet result; try { std::map devices = pSampler->GetMidiInputDevices(); - if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); + if (!devices.count(DeviceIndex)) throw Exception("There is no audio output device with index " + ToString(DeviceIndex) + "."); MidiInputDevice* pDevice = devices[DeviceIndex]; pSampler->DestroyMidiInputDevice(pDevice); } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -445,40 +498,46 @@ LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); - Engine* pEngine = pSamplerChannel->GetEngine(); - if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); + if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); + EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); + if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel yet"); if (!pSamplerChannel->GetAudioOutputDevice()) - throw LinuxSamplerException("No audio output device connected to sampler channel"); + throw Exception("No audio output device connected to sampler channel"); if (bBackground) { - LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument); - pLoadInstrument->StartThread(); + InstrumentManager::instrument_id_t id; + id.FileName = Filename; + id.Index = uiInstrument; + InstrumentManager::LoadInstrumentInBackground(id, pEngineChannel); + } + else { + // tell the engine channel which instrument to load + pEngineChannel->PrepareLoadInstrument(Filename.c_str(), uiInstrument); + // actually start to load the instrument (blocks until completed) + pEngineChannel->LoadInstrument(); } - else pEngine->LoadInstrument(Filename.c_str(), uiInstrument); } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); } /** - * Will be called by the parser to load and deploy an engine. + * Will be called by the parser to assign a sampler engine type to a + * sampler channel. */ -String LSCPServer::LoadEngine(String EngineName, uint uiSamplerChannel) { - dmsg(2,("LSCPServer: LoadEngine(EngineName=%s,SamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel)); +String LSCPServer::SetEngineType(String EngineName, uint uiSamplerChannel) { + dmsg(2,("LSCPServer: SetEngineType(EngineName=%s,uiSamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel)); LSCPResultSet result; try { - Engine::type_t type; - if ((EngineName == "GigEngine") || (EngineName == "gig")) type = Engine::type_gig; - else throw LinuxSamplerException("Unknown engine type"); SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); + if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); LockRTNotify(); - pSamplerChannel->LoadEngine(type); + pSamplerChannel->SetEngineType(EngineName); + if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1); UnlockRTNotify(); } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -516,7 +575,9 @@ */ String LSCPServer::AddChannel() { dmsg(2,("LSCPServer: AddChannel()\n")); + LockRTNotify(); SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel(); + UnlockRTNotify(); LSCPResultSet result(pSamplerChannel->Index()); return result.Produce(); } @@ -534,32 +595,55 @@ } /** - * Will be called by the parser to get all available engines. + * Will be called by the parser to get the amount of all available engines. */ String LSCPServer::GetAvailableEngines() { dmsg(2,("LSCPServer: GetAvailableEngines()\n")); - LSCPResultSet result("GigEngine"); + LSCPResultSet result; + try { + int n = EngineFactory::AvailableEngineTypes().size(); + result.Add(n); + } + catch (Exception e) { + result.Error(e); + } + return result.Produce(); +} + +/** + * Will be called by the parser to get a list of all available engines. + */ +String LSCPServer::ListAvailableEngines() { + dmsg(2,("LSCPServer: ListAvailableEngines()\n")); + LSCPResultSet result; + try { + String s = EngineFactory::AvailableEngineTypesAsString(); + result.Add(s); + } + catch (Exception e) { + result.Error(e); + } return result.Produce(); } /** - * Will be called by the parser to get descriptions for a particular engine. + * Will be called by the parser to get descriptions for a particular + * sampler engine. */ String LSCPServer::GetEngineInfo(String EngineName) { dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str())); LSCPResultSet result; + LockRTNotify(); try { - if ((EngineName == "GigEngine") || (EngineName == "gig")) { - Engine* pEngine = new LinuxSampler::gig::Engine; - result.Add("DESCRIPTION", pEngine->Description()); - result.Add("VERSION", pEngine->Version()); - delete pEngine; - } - else throw LinuxSamplerException("Unknown engine type"); + Engine* pEngine = EngineFactory::Create(EngineName); + result.Add("DESCRIPTION", pEngine->Description()); + result.Add("VERSION", pEngine->Version()); + EngineFactory::Destroy(pEngine); } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } + UnlockRTNotify(); return result.Produce(); } @@ -572,30 +656,44 @@ LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); - Engine* pEngine = pSamplerChannel->GetEngine(); + if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); + EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); //Defaults values String EngineName = "NONE"; float Volume = 0.0f; String InstrumentFileName = "NONE"; + String InstrumentName = "NONE"; int InstrumentIndex = -1; int InstrumentStatus = -1; int AudioOutputChannels = 0; String AudioRouting; - - if (pEngine) { - EngineName = pEngine->EngineName(); - AudioOutputChannels = pEngine->Channels(); - Volume = pEngine->Volume(); - InstrumentStatus = pEngine->InstrumentStatus(); - InstrumentIndex = pEngine->InstrumentIndex(); - if (InstrumentIndex != -1) - InstrumentFileName = pEngine->InstrumentFileName(); - for (int chan = 0; chan < pEngine->Channels(); chan++) { + int Mute = 0; + bool Solo = false; + String MidiInstrumentMap; + + if (pEngineChannel) { + EngineName = pEngineChannel->EngineName(); + AudioOutputChannels = pEngineChannel->Channels(); + Volume = pEngineChannel->Volume(); + InstrumentStatus = pEngineChannel->InstrumentStatus(); + InstrumentIndex = pEngineChannel->InstrumentIndex(); + if (InstrumentIndex != -1) { + InstrumentFileName = pEngineChannel->InstrumentFileName(); + InstrumentName = pEngineChannel->InstrumentName(); + } + for (int chan = 0; chan < pEngineChannel->Channels(); chan++) { if (AudioRouting != "") AudioRouting += ","; - AudioRouting += ToString(pEngine->OutputChannel(chan)); + AudioRouting += ToString(pEngineChannel->OutputChannel(chan)); } + Mute = pEngineChannel->GetMute(); + Solo = pEngineChannel->GetSolo(); + if (pEngineChannel->UsesNoMidiInstrumentMap()) + MidiInstrumentMap = "NONE"; + else if (pEngineChannel->UsesDefaultMidiInstrumentMap()) + MidiInstrumentMap = "DEFAULT"; + else + MidiInstrumentMap = ToString(pEngineChannel->GetMidiInstrumentMap()); } result.Add("ENGINE_NAME", EngineName); @@ -608,14 +706,18 @@ result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice())); result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort()); - if (pSamplerChannel->GetMidiInputChannel() == MidiInputPort::midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL"); + if (pSamplerChannel->GetMidiInputChannel() == midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL"); else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); result.Add("INSTRUMENT_FILE", InstrumentFileName); result.Add("INSTRUMENT_NR", InstrumentIndex); + result.Add("INSTRUMENT_NAME", InstrumentName); result.Add("INSTRUMENT_STATUS", InstrumentStatus); + result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false")); + result.Add("SOLO", Solo); + result.Add("MIDI_INSTRUMENT_MAP", MidiInstrumentMap); } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -630,12 +732,13 @@ LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); - Engine* pEngine = pSamplerChannel->GetEngine(); - if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); - result.Add(pEngine->VoiceCount()); + if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); + EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); + if (!pEngineChannel) throw Exception("No engine loaded on sampler channel"); + if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel"); + result.Add(pEngineChannel->GetEngine()->VoiceCount()); } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -650,12 +753,13 @@ LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); - Engine* pEngine = pSamplerChannel->GetEngine(); - if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); - result.Add(pEngine->DiskStreamCount()); + if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); + EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); + if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); + if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel"); + result.Add(pEngineChannel->GetEngine()->DiskStreamCount()); } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -670,25 +774,25 @@ LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); - Engine* pEngine = pSamplerChannel->GetEngine(); - if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); - if (!pEngine->DiskStreamSupported()) - result.Add("NA"); + if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); + EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); + if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); + if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel"); + if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA"); else { switch (ResponseType) { case fill_response_bytes: - result.Add(pEngine->DiskStreamBufferFillBytes()); - break; + result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillBytes()); + break; case fill_response_percentage: - result.Add(pEngine->DiskStreamBufferFillPercentage()); - break; + result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage()); + break; default: - throw LinuxSamplerException("Unknown fill response type"); + throw Exception("Unknown fill response type"); } } } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -698,10 +802,23 @@ dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n")); LSCPResultSet result; try { + int n = AudioOutputDeviceFactory::AvailableDrivers().size(); + result.Add(n); + } + catch (Exception e) { + result.Error(e); + } + return result.Produce(); +} + +String LSCPServer::ListAvailableAudioOutputDrivers() { + dmsg(2,("LSCPServer: ListAvailableAudioOutputDrivers()\n")); + LSCPResultSet result; + try { String s = AudioOutputDeviceFactory::AvailableDriversAsString(); result.Add(s); } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -711,10 +828,23 @@ dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n")); LSCPResultSet result; try { + int n = MidiInputDeviceFactory::AvailableDrivers().size(); + result.Add(n); + } + catch (Exception e) { + result.Error(e); + } + return result.Produce(); +} + +String LSCPServer::ListAvailableMidiInputDrivers() { + dmsg(2,("LSCPServer: ListAvailableMidiInputDrivers()\n")); + LSCPResultSet result; + try { String s = MidiInputDeviceFactory::AvailableDriversAsString(); result.Add(s); } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -738,7 +868,7 @@ result.Add("PARAMETERS", s); } } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -762,7 +892,7 @@ result.Add("PARAMETERS", s); } } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -789,7 +919,7 @@ if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -816,7 +946,7 @@ if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -829,7 +959,7 @@ uint count = pSampler->AudioOutputDevices(); result.Add(count); // success } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -842,7 +972,7 @@ uint count = pSampler->MidiInputDevices(); result.Add(count); // success } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -861,7 +991,7 @@ } result.Add(s); } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -880,7 +1010,7 @@ } result.Add(s); } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -891,7 +1021,7 @@ LSCPResultSet result; try { std::map devices = pSampler->GetAudioOutputDevices(); - if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); + if (!devices.count(DeviceIndex)) throw Exception("There is no audio output device with index " + ToString(DeviceIndex) + "."); AudioOutputDevice* pDevice = devices[DeviceIndex]; result.Add("DRIVER", pDevice->Driver()); std::map parameters = pDevice->DeviceParameters(); @@ -900,7 +1030,7 @@ result.Add(iter->first, iter->second->Value()); } } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -911,7 +1041,7 @@ LSCPResultSet result; try { std::map devices = pSampler->GetMidiInputDevices(); - if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); + if (!devices.count(DeviceIndex)) throw Exception("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); MidiInputDevice* pDevice = devices[DeviceIndex]; result.Add("DRIVER", pDevice->Driver()); std::map parameters = pDevice->DeviceParameters(); @@ -920,7 +1050,7 @@ result.Add(iter->first, iter->second->Value()); } } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -931,12 +1061,12 @@ try { // get MIDI input device std::map devices = pSampler->GetMidiInputDevices(); - if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); + if (!devices.count(DeviceIndex)) throw Exception("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); MidiInputDevice* pDevice = devices[DeviceIndex]; // get MIDI port MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); - if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); + if (!pMidiInputPort) throw Exception("There is no MIDI input port with index " + ToString(PortIndex) + "."); // return the values of all MIDI port parameters std::map parameters = pMidiInputPort->PortParameters(); @@ -945,7 +1075,7 @@ result.Add(iter->first, iter->second->Value()); } } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -957,12 +1087,12 @@ try { // get audio output device std::map devices = pSampler->GetAudioOutputDevices(); - if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + "."); + if (!devices.count(DeviceId)) throw Exception("There is no audio output device with index " + ToString(DeviceId) + "."); AudioOutputDevice* pDevice = devices[DeviceId]; // get audio channel AudioChannel* pChannel = pDevice->Channel(ChannelId); - if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + "."); + if (!pChannel) throw Exception("Audio output device does not have audio channel " + ToString(ChannelId) + "."); // return the values of all audio channel parameters std::map parameters = pChannel->ChannelParameters(); @@ -971,7 +1101,7 @@ result.Add(iter->first, iter->second->Value()); } } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -983,16 +1113,16 @@ try { // get MIDI input device std::map devices = pSampler->GetMidiInputDevices(); - if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no midi input device with index " + ToString(DeviceId) + "."); + if (!devices.count(DeviceId)) throw Exception("There is no midi input device with index " + ToString(DeviceId) + "."); MidiInputDevice* pDevice = devices[DeviceId]; // get midi port MidiInputPort* pPort = pDevice->GetPort(PortId); - if (!pPort) throw LinuxSamplerException("Midi input device does not have port " + ToString(PortId) + "."); + if (!pPort) throw Exception("Midi input device does not have port " + ToString(PortId) + "."); // get desired port parameter std::map parameters = pPort->PortParameters(); - if (!parameters.count(ParameterName)) throw LinuxSamplerException("Midi port does not provide a parameter '" + ParameterName + "'."); + if (!parameters.count(ParameterName)) throw Exception("Midi port does not provide a parameter '" + ParameterName + "'."); DeviceRuntimeParameter* pParameter = parameters[ParameterName]; // return all fields of this audio channel parameter @@ -1004,7 +1134,7 @@ if (pParameter->RangeMax()) result.Add("RANGE_MAX", *pParameter->RangeMax()); if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities()); } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -1016,16 +1146,16 @@ try { // get audio output device std::map devices = pSampler->GetAudioOutputDevices(); - if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + "."); + if (!devices.count(DeviceId)) throw Exception("There is no audio output device with index " + ToString(DeviceId) + "."); AudioOutputDevice* pDevice = devices[DeviceId]; // get audio channel AudioChannel* pChannel = pDevice->Channel(ChannelId); - if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + "."); + if (!pChannel) throw Exception("Audio output device does not have audio channel " + ToString(ChannelId) + "."); // get desired audio channel parameter std::map parameters = pChannel->ChannelParameters(); - if (!parameters.count(ParameterName)) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParameterName + "'."); + if (!parameters.count(ParameterName)) throw Exception("Audio channel does not provide a parameter '" + ParameterName + "'."); DeviceRuntimeParameter* pParameter = parameters[ParameterName]; // return all fields of this audio channel parameter @@ -1037,7 +1167,7 @@ if (pParameter->RangeMax()) result.Add("RANGE_MAX", *pParameter->RangeMax()); if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities()); } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -1049,22 +1179,23 @@ try { // get audio output device std::map devices = pSampler->GetAudioOutputDevices(); - if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + "."); + if (!devices.count(DeviceId)) throw Exception("There is no audio output device with index " + ToString(DeviceId) + "."); AudioOutputDevice* pDevice = devices[DeviceId]; // get audio channel AudioChannel* pChannel = pDevice->Channel(ChannelId); - if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + "."); + if (!pChannel) throw Exception("Audio output device does not have audio channel " + ToString(ChannelId) + "."); // get desired audio channel parameter std::map parameters = pChannel->ChannelParameters(); - if (!parameters.count(ParamKey)) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParamKey + "'."); + if (!parameters.count(ParamKey)) throw Exception("Audio channel does not provide a parameter '" + ParamKey + "'."); DeviceRuntimeParameter* pParameter = parameters[ParamKey]; // set new channel parameter value pParameter->SetValue(ParamVal); + LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_info, DeviceId)); } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -1075,13 +1206,14 @@ LSCPResultSet result; try { std::map devices = pSampler->GetAudioOutputDevices(); - if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); + if (!devices.count(DeviceIndex)) throw Exception("There is no audio output device with index " + ToString(DeviceIndex) + "."); AudioOutputDevice* pDevice = devices[DeviceIndex]; std::map parameters = pDevice->DeviceParameters(); - if (!parameters.count(ParamKey)) throw LinuxSamplerException("Audio output device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'"); + if (!parameters.count(ParamKey)) throw Exception("Audio output device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'"); parameters[ParamKey]->SetValue(ParamVal); + LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_info, DeviceIndex)); } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -1092,13 +1224,14 @@ LSCPResultSet result; try { std::map devices = pSampler->GetMidiInputDevices(); - if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); + if (!devices.count(DeviceIndex)) throw Exception("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); MidiInputDevice* pDevice = devices[DeviceIndex]; std::map parameters = pDevice->DeviceParameters(); - if (!parameters.count(ParamKey)) throw LinuxSamplerException("MIDI input device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'"); + if (!parameters.count(ParamKey)) throw Exception("MIDI input device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'"); parameters[ParamKey]->SetValue(ParamVal); + LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_info, DeviceIndex)); } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -1110,19 +1243,20 @@ try { // get MIDI input device std::map devices = pSampler->GetMidiInputDevices(); - if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); + if (!devices.count(DeviceIndex)) throw Exception("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); MidiInputDevice* pDevice = devices[DeviceIndex]; // get MIDI port MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); - if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); + if (!pMidiInputPort) throw Exception("There is no MIDI input port with index " + ToString(PortIndex) + "."); // set port parameter value std::map parameters = pMidiInputPort->PortParameters(); - if (!parameters.count(ParamKey)) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'"); + if (!parameters.count(ParamKey)) throw Exception("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'"); parameters[ParamKey]->SetValue(ParamVal); + LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_info, DeviceIndex)); } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -1137,13 +1271,13 @@ LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); - Engine* pEngine = pSamplerChannel->GetEngine(); - if (!pEngine) throw LinuxSamplerException("No engine deployed on sampler channel " + ToString(uiSamplerChannel)); - if (!pSamplerChannel->GetAudioOutputDevice()) throw LinuxSamplerException("No audio output device connected to sampler channel " + ToString(uiSamplerChannel)); - pEngine->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel); + if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); + EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); + if (!pEngineChannel) throw Exception("No engine type yet assigned to sampler channel " + ToString(uiSamplerChannel)); + if (!pSamplerChannel->GetAudioOutputDevice()) throw Exception("No audio output device connected to sampler channel " + ToString(uiSamplerChannel)); + pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel); } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -1152,26 +1286,29 @@ String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) { dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel)); LSCPResultSet result; + LockRTNotify(); try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); + if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); std::map devices = pSampler->GetAudioOutputDevices(); - if (!devices.count(AudioDeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId)); + if (!devices.count(AudioDeviceId)) throw Exception("There is no audio output device with index " + ToString(AudioDeviceId)); AudioOutputDevice* pDevice = devices[AudioDeviceId]; pSamplerChannel->SetAudioOutputDevice(pDevice); } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } + UnlockRTNotify(); return result.Produce(); } String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) { dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel)); LSCPResultSet result; + LockRTNotify(); try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); + if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); // Driver type name aliasing... if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA"; if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK"; @@ -1193,13 +1330,14 @@ } // Must have a device... if (pDevice == NULL) - throw LinuxSamplerException("Internal error: could not create audio output device."); + throw Exception("Internal error: could not create audio output device."); // Set it as the current channel device... pSamplerChannel->SetAudioOutputDevice(pDevice); } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } + UnlockRTNotify(); return result.Produce(); } @@ -1208,10 +1346,10 @@ LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); + if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); pSamplerChannel->SetMidiInputPort(MIDIPort); } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -1222,10 +1360,10 @@ LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); - pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel); + if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); + pSamplerChannel->SetMidiInputChannel((midi_chan_t) MIDIChannel); } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -1236,13 +1374,13 @@ LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); + if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); std::map devices = pSampler->GetMidiInputDevices(); - if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); + if (!devices.count(MIDIDeviceId)) throw Exception("There is no MIDI input device with index " + ToString(MIDIDeviceId)); MidiInputDevice* pDevice = devices[MIDIDeviceId]; pSamplerChannel->SetMidiInputDevice(pDevice); } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -1253,7 +1391,7 @@ LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); + if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); // Driver type name aliasing... if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA"; // Check if there's one MIDI input device already created @@ -1277,11 +1415,11 @@ } // Must have a device... if (pDevice == NULL) - throw LinuxSamplerException("Internal error: could not create MIDI input device."); + throw Exception("Internal error: could not create MIDI input device."); // Set it as the current channel device... pSamplerChannel->SetMidiInputDevice(pDevice); } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -1296,13 +1434,13 @@ LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); + if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); std::map devices = pSampler->GetMidiInputDevices(); - if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); + if (!devices.count(MIDIDeviceId)) throw Exception("There is no MIDI input device with index " + ToString(MIDIDeviceId)); MidiInputDevice* pDevice = devices[MIDIDeviceId]; - pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (MidiInputPort::midi_chan_t) MIDIChannel); + pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (midi_chan_t) MIDIChannel); } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -1317,18 +1455,564 @@ LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); - Engine* pEngine = pSamplerChannel->GetEngine(); - if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); - pEngine->Volume(dVolume); + if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); + EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); + if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); + pEngineChannel->Volume(dVolume); } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); } /** + * Will be called by the parser to mute/unmute particular sampler channel. + */ +String LSCPServer::SetChannelMute(bool bMute, uint uiSamplerChannel) { + dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel)); + LSCPResultSet result; + try { + SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); + if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); + + EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); + if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); + + if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0); + else pEngineChannel->SetMute(1); + } catch (Exception e) { + result.Error(e); + } + return result.Produce(); +} + +/** + * Will be called by the parser to solo particular sampler channel. + */ +String LSCPServer::SetChannelSolo(bool bSolo, uint uiSamplerChannel) { + dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel)); + LSCPResultSet result; + try { + SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); + if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); + + EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); + if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); + + bool oldSolo = pEngineChannel->GetSolo(); + bool hadSoloChannel = HasSoloChannel(); + + pEngineChannel->SetSolo(bSolo); + + if(!oldSolo && bSolo) { + if(pEngineChannel->GetMute() == -1) pEngineChannel->SetMute(0); + if(!hadSoloChannel) MuteNonSoloChannels(); + } + + if(oldSolo && !bSolo) { + if(!HasSoloChannel()) UnmuteChannels(); + else if(!pEngineChannel->GetMute()) pEngineChannel->SetMute(-1); + } + } catch (Exception e) { + result.Error(e); + } + return result.Produce(); +} + +/** + * Determines whether there is at least one solo channel in the channel list. + * + * @returns true if there is at least one solo channel in the channel list, + * false otherwise. + */ +bool LSCPServer::HasSoloChannel() { + std::map channels = pSampler->GetSamplerChannels(); + std::map::iterator iter = channels.begin(); + for (; iter != channels.end(); iter++) { + EngineChannel* c = iter->second->GetEngineChannel(); + if(c && c->GetSolo()) return true; + } + + return false; +} + +/** + * Mutes all unmuted non-solo channels. Notice that the channels are muted + * with -1 which indicates that they are muted because of the presence + * of a solo channel(s). Channels muted with -1 will be automatically unmuted + * when there are no solo channels left. + */ +void LSCPServer::MuteNonSoloChannels() { + dmsg(2,("LSCPServer: MuteNonSoloChannels()\n")); + std::map channels = pSampler->GetSamplerChannels(); + std::map::iterator iter = channels.begin(); + for (; iter != channels.end(); iter++) { + EngineChannel* c = iter->second->GetEngineChannel(); + if(c && !c->GetSolo() && !c->GetMute()) c->SetMute(-1); + } +} + +/** + * Unmutes all channels that are muted because of the presence + * of a solo channel(s). + */ +void LSCPServer::UnmuteChannels() { + dmsg(2,("LSCPServer: UnmuteChannels()\n")); + std::map channels = pSampler->GetSamplerChannels(); + std::map::iterator iter = channels.begin(); + for (; iter != channels.end(); iter++) { + EngineChannel* c = iter->second->GetEngineChannel(); + if(c && c->GetMute() == -1) c->SetMute(0); + } +} + +String LSCPServer::AddOrReplaceMIDIInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg, String EngineType, String InstrumentFile, uint InstrumentIndex, float Volume, MidiInstrumentMapper::mode_t LoadMode, String Name) { + dmsg(2,("LSCPServer: AddOrReplaceMIDIInstrumentMapping()\n")); + + midi_prog_index_t idx; + idx.midi_bank_msb = (MidiBank >> 7) & 0x7f; + idx.midi_bank_lsb = MidiBank & 0x7f; + idx.midi_prog = MidiProg; + + MidiInstrumentMapper::entry_t entry; + entry.EngineName = EngineType; + entry.InstrumentFile = InstrumentFile; + entry.InstrumentIndex = InstrumentIndex; + entry.LoadMode = LoadMode; + entry.Volume = Volume; + entry.Name = Name; + + LSCPResultSet result; + try { + // PERSISTENT mapping commands might bloock for a long time, so in + // that case we add/replace the mapping in another thread + bool bInBackground = (entry.LoadMode == MidiInstrumentMapper::PERSISTENT); + MidiInstrumentMapper::AddOrReplaceEntry(MidiMapID, idx, entry, bInBackground); + } catch (Exception e) { + result.Error(e); + } + return result.Produce(); +} + +String LSCPServer::RemoveMIDIInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg) { + dmsg(2,("LSCPServer: RemoveMIDIInstrumentMapping()\n")); + + midi_prog_index_t idx; + idx.midi_bank_msb = (MidiBank >> 7) & 0x7f; + idx.midi_bank_lsb = MidiBank & 0x7f; + idx.midi_prog = MidiProg; + + LSCPResultSet result; + try { + MidiInstrumentMapper::RemoveEntry(MidiMapID, idx); + } catch (Exception e) { + result.Error(e); + } + return result.Produce(); +} + +String LSCPServer::GetMidiInstrumentMappings(uint MidiMapID) { + dmsg(2,("LSCPServer: GetMidiInstrumentMappings()\n")); + LSCPResultSet result; + try { + result.Add(MidiInstrumentMapper::Entries(MidiMapID).size()); + } catch (Exception e) { + result.Error(e); + } + return result.Produce(); +} + + +String LSCPServer::GetAllMidiInstrumentMappings() { + dmsg(2,("LSCPServer: GetAllMidiInstrumentMappings()\n")); + LSCPResultSet result; + std::vector maps = MidiInstrumentMapper::Maps(); + int totalMappings = 0; + for (int i = 0; i < maps.size(); i++) { + try { + totalMappings += MidiInstrumentMapper::Entries(maps[i]).size(); + } catch (Exception e) { /*NOOP*/ } + } + result.Add(totalMappings); + return result.Produce(); +} + +String LSCPServer::GetMidiInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg) { + dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n")); + LSCPResultSet result; + try { + midi_prog_index_t idx; + idx.midi_bank_msb = (MidiBank >> 7) & 0x7f; + idx.midi_bank_lsb = MidiBank & 0x7f; + idx.midi_prog = MidiProg; + + std::map mappings = MidiInstrumentMapper::Entries(MidiMapID); + std::map::iterator iter = mappings.find(idx); + if (iter == mappings.end()) result.Error("there is no map entry with that index"); + else { // found + result.Add("NAME", iter->second.Name); + result.Add("ENGINE_NAME", iter->second.EngineName); + result.Add("INSTRUMENT_FILE", iter->second.InstrumentFile); + result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex); + String instrumentName; + Engine* pEngine = EngineFactory::Create(iter->second.EngineName); + if (pEngine) { + if (pEngine->GetInstrumentManager()) { + InstrumentManager::instrument_id_t instrID; + instrID.FileName = iter->second.InstrumentFile; + instrID.Index = iter->second.InstrumentIndex; + instrumentName = pEngine->GetInstrumentManager()->GetInstrumentName(instrID); + } + EngineFactory::Destroy(pEngine); + } + result.Add("INSTRUMENT_NAME", instrumentName); + switch (iter->second.LoadMode) { + case MidiInstrumentMapper::ON_DEMAND: + result.Add("LOAD_MODE", "ON_DEMAND"); + break; + case MidiInstrumentMapper::ON_DEMAND_HOLD: + result.Add("LOAD_MODE", "ON_DEMAND_HOLD"); + break; + case MidiInstrumentMapper::PERSISTENT: + result.Add("LOAD_MODE", "PERSISTENT"); + break; + default: + throw Exception("entry reflects invalid LOAD_MODE, consider this as a bug!"); + } + result.Add("VOLUME", iter->second.Volume); + } + } catch (Exception e) { + result.Error(e); + } + return result.Produce(); +} + +String LSCPServer::ListMidiInstrumentMappings(uint MidiMapID) { + dmsg(2,("LSCPServer: ListMidiInstrumentMappings()\n")); + LSCPResultSet result; + try { + String s; + std::map mappings = MidiInstrumentMapper::Entries(MidiMapID); + std::map::iterator iter = mappings.begin(); + for (; iter != mappings.end(); iter++) { + if (s.size()) s += ","; + s += "{" + ToString(MidiMapID) + "," + + ToString((int(iter->first.midi_bank_msb) << 7) & int(iter->first.midi_bank_lsb)) + "," + + ToString(int(iter->first.midi_prog)) + "}"; + } + result.Add(s); + } catch (Exception e) { + result.Error(e); + } + return result.Produce(); +} + +String LSCPServer::ListAllMidiInstrumentMappings() { + dmsg(2,("LSCPServer: ListAllMidiInstrumentMappings()\n")); + LSCPResultSet result; + try { + std::vector maps = MidiInstrumentMapper::Maps(); + String s; + for (int i = 0; i < maps.size(); i++) { + std::map mappings = MidiInstrumentMapper::Entries(maps[i]); + std::map::iterator iter = mappings.begin(); + for (; iter != mappings.end(); iter++) { + if (s.size()) s += ","; + s += "{" + ToString(maps[i]) + "," + + ToString((int(iter->first.midi_bank_msb) << 7) & int(iter->first.midi_bank_lsb)) + "," + + ToString(int(iter->first.midi_prog)) + "}"; + } + } + result.Add(s); + } catch (Exception e) { + result.Error(e); + } + return result.Produce(); +} + +String LSCPServer::ClearMidiInstrumentMappings(uint MidiMapID) { + dmsg(2,("LSCPServer: ClearMidiInstrumentMappings()\n")); + LSCPResultSet result; + try { + MidiInstrumentMapper::RemoveAllEntries(MidiMapID); + } catch (Exception e) { + result.Error(e); + } + return result.Produce(); +} + +String LSCPServer::ClearAllMidiInstrumentMappings() { + dmsg(2,("LSCPServer: ClearAllMidiInstrumentMappings()\n")); + LSCPResultSet result; + try { + std::vector maps = MidiInstrumentMapper::Maps(); + for (int i = 0; i < maps.size(); i++) + MidiInstrumentMapper::RemoveAllEntries(maps[i]); + } catch (Exception e) { + result.Error(e); + } + return result.Produce(); +} + +String LSCPServer::AddMidiInstrumentMap(String MapName) { + dmsg(2,("LSCPServer: AddMidiInstrumentMap()\n")); + LSCPResultSet result; + try { + int MapID = MidiInstrumentMapper::AddMap(MapName); + result = LSCPResultSet(MapID); + } catch (Exception e) { + result.Error(e); + } + return result.Produce(); +} + +String LSCPServer::RemoveMidiInstrumentMap(uint MidiMapID) { + dmsg(2,("LSCPServer: RemoveMidiInstrumentMap()\n")); + LSCPResultSet result; + try { + MidiInstrumentMapper::RemoveMap(MidiMapID); + } catch (Exception e) { + result.Error(e); + } + return result.Produce(); +} + +String LSCPServer::RemoveAllMidiInstrumentMaps() { + dmsg(2,("LSCPServer: RemoveAllMidiInstrumentMaps()\n")); + LSCPResultSet result; + try { + MidiInstrumentMapper::RemoveAllMaps(); + } catch (Exception e) { + result.Error(e); + } + return result.Produce(); +} + +String LSCPServer::GetMidiInstrumentMaps() { + dmsg(2,("LSCPServer: GetMidiInstrumentMaps()\n")); + LSCPResultSet result; + try { + result.Add(MidiInstrumentMapper::Maps().size()); + } catch (Exception e) { + result.Error(e); + } + return result.Produce(); +} + +String LSCPServer::ListMidiInstrumentMaps() { + dmsg(2,("LSCPServer: ListMidiInstrumentMaps()\n")); + LSCPResultSet result; + try { + std::vector maps = MidiInstrumentMapper::Maps(); + String sList; + for (int i = 0; i < maps.size(); i++) { + if (sList != "") sList += ","; + sList += ToString(maps[i]); + } + result.Add(sList); + } catch (Exception e) { + result.Error(e); + } + return result.Produce(); +} + +String LSCPServer::GetMidiInstrumentMap(uint MidiMapID) { + dmsg(2,("LSCPServer: GetMidiInstrumentMap()\n")); + LSCPResultSet result; + try { + result.Add("NAME", MidiInstrumentMapper::MapName(MidiMapID)); + } catch (Exception e) { + result.Error(e); + } + return result.Produce(); +} + +String LSCPServer::SetMidiInstrumentMapName(uint MidiMapID, String NewName) { + dmsg(2,("LSCPServer: SetMidiInstrumentMapName()\n")); + LSCPResultSet result; + try { + MidiInstrumentMapper::RenameMap(MidiMapID, NewName); + } catch (Exception e) { + result.Error(e); + } + return result.Produce(); +} + +/** + * Set the MIDI instrument map the given sampler channel shall use for + * handling MIDI program change messages. There are the following two + * special (negative) values: + * + * - (-1) : set to NONE (ignore program changes) + * - (-2) : set to DEFAULT map + */ +String LSCPServer::SetChannelMap(uint uiSamplerChannel, int MidiMapID) { + dmsg(2,("LSCPServer: SetChannelMap()\n")); + LSCPResultSet result; + try { + SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); + if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); + + EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); + if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet"); + + if (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone(); + else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault(); + else pEngineChannel->SetMidiInstrumentMap(MidiMapID); + } catch (Exception e) { + result.Error(e); + } + return result.Produce(); +} + +String LSCPServer::CreateFxSend(uint uiSamplerChannel, uint MidiCtrl, String Name) { + dmsg(2,("LSCPServer: CreateFxSend()\n")); + LSCPResultSet result; + try { + SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); + if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); + + EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); + if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet"); + + FxSend* pFxSend = pEngineChannel->AddFxSend(MidiCtrl, Name); + if (!pFxSend) throw Exception("Could not add FxSend, don't ask, I don't know why (probably a bug)"); + + result = LSCPResultSet(pFxSend->Id()); // success + } catch (Exception e) { + result.Error(e); + } + return result.Produce(); +} + +String LSCPServer::DestroyFxSend(uint uiSamplerChannel, uint FxSendID) { + dmsg(2,("LSCPServer: DestroyFxSend()\n")); + LSCPResultSet result; + try { + SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); + if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); + + EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); + if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet"); + + FxSend* pFxSend = NULL; + for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) { + if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) { + pFxSend = pEngineChannel->GetFxSend(i); + break; + } + } + if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel"); + pEngineChannel->RemoveFxSend(pFxSend); + } catch (Exception e) { + result.Error(e); + } + return result.Produce(); +} + +String LSCPServer::GetFxSends(uint uiSamplerChannel) { + dmsg(2,("LSCPServer: GetFxSends()\n")); + LSCPResultSet result; + try { + SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); + if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); + + EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); + if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet"); + + result.Add(pEngineChannel->GetFxSendCount()); + } catch (Exception e) { + result.Error(e); + } + return result.Produce(); +} + +String LSCPServer::ListFxSends(uint uiSamplerChannel) { + dmsg(2,("LSCPServer: ListFxSends()\n")); + LSCPResultSet result; + String list; + try { + SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); + if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); + + EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); + if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet"); + + for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) { + FxSend* pFxSend = pEngineChannel->GetFxSend(i); + if (list != "") list += ","; + list += ToString(pFxSend->Id()); + } + result.Add(list); + } catch (Exception e) { + result.Error(e); + } + return result.Produce(); +} + +String LSCPServer::GetFxSendInfo(uint uiSamplerChannel, uint FxSendID) { + dmsg(2,("LSCPServer: GetFxSendInfo()\n")); + LSCPResultSet result; + try { + SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); + if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); + + EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); + if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet"); + + FxSend* pFxSend = NULL; + for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) { + if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) { + pFxSend = pEngineChannel->GetFxSend(i); + break; + } + } + if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel"); + + // gather audio routing informations + String AudioRouting; + for (int chan = 0; chan < pEngineChannel->Channels(); chan++) { + if (AudioRouting != "") AudioRouting += ","; + AudioRouting += ToString(pFxSend->DestinationChannel(chan)); + } + + // success + result.Add("NAME", pFxSend->Name()); + result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); + } catch (Exception e) { + result.Error(e); + } + return result.Produce(); +} + +String LSCPServer::SetFxSendAudioOutputChannel(uint uiSamplerChannel, uint FxSendID, uint FxSendChannel, uint DeviceChannel) { + dmsg(2,("LSCPServer: SetFxSendAudioOutputChannel()\n")); + LSCPResultSet result; + try { + SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); + if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); + + EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); + if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet"); + + FxSend* pFxSend = NULL; + for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) { + if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) { + pFxSend = pEngineChannel->GetFxSend(i); + break; + } + } + if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel"); + + pFxSend->SetDestinationChannel(FxSendChannel, DeviceChannel); + } catch (Exception e) { + result.Error(e); + } + return result.Produce(); +} + +/** * Will be called by the parser to reset a particular sampler channel. */ String LSCPServer::ResetChannel(uint uiSamplerChannel) { @@ -1336,12 +2020,12 @@ LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); - Engine* pEngine = pSamplerChannel->GetEngine(); - if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); - pEngine->Reset(); + if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); + EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); + if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); + pEngineChannel->Reset(); } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); @@ -1358,6 +2042,56 @@ } /** + * Will be called by the parser to return general informations about this + * sampler. + */ +String LSCPServer::GetServerInfo() { + dmsg(2,("LSCPServer: GetServerInfo()\n")); + LSCPResultSet result; + result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler"); + result.Add("VERSION", VERSION); + result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR)); + return result.Produce(); +} + +/** + * Will be called by the parser to return the current number of all active voices. + */ +String LSCPServer::GetTotalVoiceCount() { + dmsg(2,("LSCPServer: GetTotalVoiceCount()\n")); + LSCPResultSet result; + result.Add(pSampler->GetVoiceCount()); + return result.Produce(); +} + +/** + * Will be called by the parser to return the maximum number of voices. + */ +String LSCPServer::GetTotalVoiceCountMax() { + dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n")); + LSCPResultSet result; + result.Add(EngineFactory::EngineInstances().size() * CONFIG_MAX_VOICES); + return result.Produce(); +} + +String LSCPServer::GetGlobalVolume() { + LSCPResultSet result; + result.Add(ToString(GLOBAL_VOLUME)); // see common/global.cpp + return result.Produce(); +} + +String LSCPServer::SetGlobalVolume(double dVolume) { + LSCPResultSet result; + try { + if (dVolume < 0) throw Exception("Volume may not be negative"); + GLOBAL_VOLUME = dVolume; // see common/global.cpp + } catch (Exception e) { + result.Error(e); + } + return result.Produce(); +} + +/** * Will be called by the parser to subscribe a client (frontend) on the * server for receiving event messages. */ @@ -1383,6 +2117,37 @@ return result.Produce(); } +static int select_callback(void * lscpResultSet, int argc, + char **argv, char **azColName) +{ + LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet; + resultSet->Add(argc, argv); + return 0; +} + +String LSCPServer::QueryDatabase(String query) { + LSCPResultSet result; +#if HAVE_SQLITE3 + char* zErrMsg = NULL; + sqlite3 *db; + String selectStr = "SELECT " + query; + + int rc = sqlite3_open("linuxsampler.db", &db); + if (rc == SQLITE_OK) + { + rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg); + } + if ( rc != SQLITE_OK ) + { + result.Error(String(zErrMsg), rc); + } + sqlite3_close(db); +#else + result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0); +#endif + return result.Produce(); +} + /** * Will be called by the parser to enable or disable echo mode; if echo * mode is enabled, all commands from the client will (immediately) be @@ -1394,37 +2159,10 @@ try { if (boolean_value == 0) pSession->bVerbose = false; else if (boolean_value == 1) pSession->bVerbose = true; - else throw LinuxSamplerException("Not a boolean value, must either be 0 or 1"); + else throw Exception("Not a boolean value, must either be 0 or 1"); } - catch (LinuxSamplerException e) { + catch (Exception e) { result.Error(e); } return result.Produce(); } - -// Instrument loader constructor. -LSCPLoadInstrument::LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument) - : Thread(false, 0, -4) -{ - this->pEngine = pEngine; - this->Filename = Filename; - this->uiInstrument = uiInstrument; -} - -// Instrument loader process. -int LSCPLoadInstrument::Main() -{ - try { - pEngine->LoadInstrument(Filename.c_str(), uiInstrument); - } - - catch (LinuxSamplerException e) { - e.PrintMessage(); - } - - // Always re-enable the engine. - pEngine->Enable(); - - // FIXME: Shoot ourselves on the foot? - delete this; -}