--- linuxsampler/trunk/src/network/lscpserver.cpp 2005/02/19 02:40:24 392 +++ linuxsampler/trunk/src/network/lscpserver.cpp 2005/07/21 08:38:15 707 @@ -24,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" @@ -53,14 +61,22 @@ Mutex LSCPServer::SubscriptionMutex = Mutex(); Mutex LSCPServer::RTNotifyMutex = Mutex(); -LSCPServer::LSCPServer(Sampler* pSampler) : Thread(true, 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_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_misc, "MISCELLANEOUS"); + hSocket = -1; +} + +LSCPServer::~LSCPServer() { + if (hSocket >= 0) close(hSocket); } /** @@ -78,17 +94,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 @@ -161,6 +173,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]); } @@ -177,10 +190,22 @@ } } + // 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++) { - send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0); + send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), MSG_NOSIGNAL); bufferedNotifies.erase(iterNotify); } NotifyBufferMutex.Unlock(); @@ -230,7 +255,7 @@ while (true) { if (NotifyMutex.Trylock()) { for(;iter != end; iter++) - send(*iter, notify.c_str(), notify.size(), 0); + send(*iter, notify.c_str(), notify.size(), MSG_NOSIGNAL); NotifyMutex.Unlock(); break; } else { @@ -339,7 +364,7 @@ dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str())); if (currentSocket != -1) { NotifyMutex.Lock(); - send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0); + send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), MSG_NOSIGNAL); NotifyMutex.Unlock(); } } @@ -447,18 +472,18 @@ 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"); + EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); + if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel yet"); if (!pSamplerChannel->GetAudioOutputDevice()) throw LinuxSamplerException("No audio output device connected to sampler channel"); if (bBackground) { - InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngine); + InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngineChannel); } else { - // tell the engine which instrument to load - pEngine->PrepareLoadInstrument(Filename.c_str(), uiInstrument); + // tell the engine channel which instrument to load + pEngineChannel->PrepareLoadInstrument(Filename.c_str(), uiInstrument); // actually start to load the instrument (blocks until completed) - pEngine->LoadInstrument(); + pEngineChannel->LoadInstrument(); } } catch (LinuxSamplerException e) { @@ -468,19 +493,18 @@ } /** - * 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)); LockRTNotify(); - pSamplerChannel->LoadEngine(type); + pSamplerChannel->SetEngineType(EngineName); + if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1); UnlockRTNotify(); } catch (LinuxSamplerException e) { @@ -539,28 +563,35 @@ } /** - * 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("1"); + 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("\'GIG\'"); 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; 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) { result.Error(e); @@ -578,7 +609,7 @@ try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); - Engine* pEngine = pSamplerChannel->GetEngine(); + EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); //Defaults values String EngineName = "NONE"; @@ -589,22 +620,25 @@ int InstrumentStatus = -1; int AudioOutputChannels = 0; String AudioRouting; + int Mute = 0; + bool Solo = false; - if (pEngine) { - EngineName = pEngine->EngineName(); - AudioOutputChannels = pEngine->Channels(); - Volume = pEngine->Volume(); - InstrumentStatus = pEngine->InstrumentStatus(); - InstrumentIndex = pEngine->InstrumentIndex(); - if (InstrumentIndex != -1) - { - InstrumentFileName = pEngine->InstrumentFileName(); - InstrumentName = pEngine->InstrumentName(); - } - for (int chan = 0; chan < pEngine->Channels(); chan++) { + 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(); } result.Add("ENGINE_NAME", EngineName); @@ -617,13 +651,15 @@ 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); } catch (LinuxSamplerException e) { result.Error(e); @@ -641,9 +677,10 @@ 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()); + EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); + if (!pEngineChannel) throw LinuxSamplerException("No engine loaded on sampler channel"); + if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel"); + result.Add(pEngineChannel->GetEngine()->VoiceCount()); } catch (LinuxSamplerException e) { result.Error(e); @@ -661,9 +698,10 @@ 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()); + EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); + if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); + if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel"); + result.Add(pEngineChannel->GetEngine()->DiskStreamCount()); } catch (LinuxSamplerException e) { result.Error(e); @@ -681,18 +719,18 @@ 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"); + EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); + if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); + if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("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"); } @@ -708,6 +746,19 @@ dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n")); LSCPResultSet result; try { + int n = AudioOutputDeviceFactory::AvailableDrivers().size(); + result.Add(n); + } + catch (LinuxSamplerException 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); } @@ -721,6 +772,19 @@ dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n")); LSCPResultSet result; try { + int n = MidiInputDeviceFactory::AvailableDrivers().size(); + result.Add(n); + } + catch (LinuxSamplerException 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); } @@ -1148,10 +1212,10 @@ 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)); + EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); + if (!pEngineChannel) throw LinuxSamplerException("No engine type yet assigned to sampler channel " + ToString(uiSamplerChannel)); if (!pSamplerChannel->GetAudioOutputDevice()) throw LinuxSamplerException("No audio output device connected to sampler channel " + ToString(uiSamplerChannel)); - pEngine->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel); + pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel); } catch (LinuxSamplerException e) { result.Error(e); @@ -1233,7 +1297,7 @@ try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); - pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel); + pSamplerChannel->SetMidiInputChannel((midi_chan_t) MIDIChannel); } catch (LinuxSamplerException e) { result.Error(e); @@ -1310,7 +1374,7 @@ std::map devices = pSampler->GetMidiInputDevices(); if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("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) { result.Error(e); @@ -1328,9 +1392,9 @@ 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); + EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); + if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); + pEngineChannel->Volume(dVolume); } catch (LinuxSamplerException e) { result.Error(e); @@ -1339,6 +1403,107 @@ } /** + * 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 LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); + + EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); + if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); + + if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0); + else pEngineChannel->SetMute(1); + } catch (LinuxSamplerException 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 LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); + + EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); + if (!pEngineChannel) throw LinuxSamplerException("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 (LinuxSamplerException 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); + } +} + +/** * Will be called by the parser to reset a particular sampler channel. */ String LSCPServer::ResetChannel(uint uiSamplerChannel) { @@ -1347,9 +1512,9 @@ 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(); + EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); + if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); + pEngineChannel->Reset(); } catch (LinuxSamplerException e) { result.Error(e); @@ -1368,6 +1533,19 @@ } /** + * 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", "1.0"); + return result.Produce(); +} + +/** * Will be called by the parser to subscribe a client (frontend) on the * server for receiving event messages. */ @@ -1393,6 +1571,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