--- linuxsampler/trunk/src/network/lscpserver.cpp 2005/02/21 04:35:31 398 +++ linuxsampler/trunk/src/network/lscpserver.cpp 2005/05/09 11:59:58 527 @@ -26,11 +26,13 @@ #include "lscpevent.h" //#include "../common/global.h" -#ifdef HAVE_SQLITE3 -#include "sqlite3.h" +#include + +#if HAVE_SQLITE3 +# include "sqlite3.h" #endif -#include "../engines/gig/Engine.h" +#include "../engines/EngineFactory.h" #include "../drivers/audio/AudioOutputDeviceFactory.h" #include "../drivers/midi/MidiInputDeviceFactory.h" @@ -66,6 +68,11 @@ LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL"); LSCPEvent::RegisterEvent(LSCPEvent::event_info, "INFO"); LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); + hSocket = -1; +} + +LSCPServer::~LSCPServer() { + if (hSocket >= 0) close(hSocket); } /** @@ -83,7 +90,7 @@ } 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; @@ -166,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]); } @@ -452,18 +460,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) { @@ -473,19 +481,17 @@ } /** - * 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) { +String LSCPServer::SetEngineType(String EngineName, uint uiSamplerChannel) { dmsg(2,("LSCPServer: LoadEngine(EngineName=%s,SamplerChannel=%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); UnlockRTNotify(); } catch (LinuxSamplerException e) { @@ -544,28 +550,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 descriptions for a particular engine. + * 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 + * 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()); + delete pEngine; } catch (LinuxSamplerException e) { result.Error(e); @@ -583,7 +596,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"; @@ -595,20 +608,19 @@ 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(); - 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)); } } @@ -646,9 +658,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"); - result.Add(pEngine->VoiceCount()); + EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); + if (!pEngineChannel) throw LinuxSamplerException("No engine loaded on sampler channel"); + result.Add(pEngineChannel->GetEngine()->VoiceCount()); } catch (LinuxSamplerException e) { result.Error(e); @@ -666,9 +678,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"); - result.Add(pEngine->DiskStreamCount()); + EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); + if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); + result.Add(pEngineChannel->GetEngine()->DiskStreamCount()); } catch (LinuxSamplerException e) { result.Error(e); @@ -686,18 +698,17 @@ 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()->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"); } @@ -713,6 +724,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); } @@ -726,6 +750,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); } @@ -1153,10 +1190,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); @@ -1333,9 +1370,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); @@ -1352,9 +1389,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->GetEngine()->Reset(); } catch (LinuxSamplerException e) { result.Error(e); @@ -1408,7 +1445,7 @@ String LSCPServer::QueryDatabase(String query) { LSCPResultSet result; -#ifdef HAVE_SQLITE3 +#if HAVE_SQLITE3 char* zErrMsg = NULL; sqlite3 *db; String selectStr = "SELECT " + query;