--- linuxsampler/trunk/src/network/lscpserver.cpp 2004/06/15 03:30:16 129 +++ linuxsampler/trunk/src/network/lscpserver.cpp 2004/06/20 23:18:24 138 @@ -132,7 +132,7 @@ /** * Will be called by the parser to load an instrument. */ -String LSCPServer::LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel) { +String LSCPServer::LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel, bool bBackground) { dmsg(2,("LSCPServer: LoadInstrument(Filename=%s,Instrument=%d,SamplerChannel=%d)\n", Filename.c_str(), uiInstrument, uiSamplerChannel)); LSCPResultSet result; try { @@ -140,7 +140,11 @@ if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); Engine* pEngine = pSamplerChannel->GetEngine(); if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); - pEngine->LoadInstrument(Filename.c_str(), uiInstrument); + if (bBackground) { + LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument); + pLoadInstrument->StartThread(); + } + else pEngine->LoadInstrument(Filename.c_str(), uiInstrument); } catch (LinuxSamplerException e) { result.Error(e); @@ -244,16 +248,16 @@ String EngineName = "NONE"; float Volume = 0; String InstrumentFileName = "NONE"; - int InstrumentIndex = 0; + int InstrumentIndex = -1; + int InstrumentStatus = -1; if (pEngine) { EngineName = pEngine->EngineName(); Volume = pEngine->Volume(); - int iIdx = pEngine->InstrumentIndex(); - if (iIdx != -1) { + InstrumentStatus = pEngine->InstrumentStatus(); + InstrumentIndex = pEngine->InstrumentIndex(); + if (InstrumentIndex != -1) InstrumentFileName = pEngine->InstrumentFileName(); - InstrumentIndex = iIdx; - } } result.Add("ENGINE_NAME", EngineName); @@ -266,6 +270,7 @@ result.Add("INSTRUMENT_FILE", InstrumentFileName); result.Add("INSTRUMENT_NR", InstrumentIndex); + result.Add("INSTRUMENT_STATUS", InstrumentStatus); //Some more hardcoded stuff for now to make GUI look good result.Add("MIDI_INPUT_DEVICE", "0"); @@ -415,7 +420,7 @@ LSCPResultSet result; try { uint count = pSampler->AudioOutputDevices(); - result = count; // success + result.Add(count); // success } catch (LinuxSamplerException e) { result.Error(e); @@ -580,7 +585,7 @@ SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); // FIXME: workaround until MIDI driver configuration is implemented (using a Factory class for the MIDI input drivers then, like its already done for audio output drivers) - if (MidiInputDriver != "ALSA") throw LinuxSamplerException("Unknown MIDI input driver '" + MidiInputDriver + "'."); + if (MidiInputDriver != "Alsa") throw LinuxSamplerException("Unknown MIDI input driver '" + MidiInputDriver + "'."); MidiInputDevice::type_t MidiInputType = MidiInputDevice::type_alsa; pSamplerChannel->SetMidiInputDevice(MidiInputType); } @@ -683,8 +688,8 @@ * Will be called by the parser to subscribe a client (frontend) on the * server for receiving event messages. */ -String LSCPServer::SubscribeNotification(uint UDPPort) { - dmsg(2,("LSCPServer: SubscribeNotification(UDPPort=%d)\n", UDPPort)); +String LSCPServer::SubscribeNotification(event_t Event) { + dmsg(2,("LSCPServer: SubscribeNotification(Event=%d)\n", Event)); return "ERR:0:Not implemented yet.\r\n"; } @@ -692,7 +697,35 @@ * Will be called by the parser to unsubscribe a client on the server * for not receiving further event messages. */ -String LSCPServer::UnsubscribeNotification(String SessionID) { - dmsg(2,("LSCPServer: UnsubscribeNotification(SessionID=%s)\n", SessionID.c_str())); +String LSCPServer::UnsubscribeNotification(event_t Event) { + dmsg(2,("LSCPServer: UnsubscribeNotification(Event=%d)\n", Event)); return "ERR:0:Not implemented yet.\r\n"; } + + +// 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; +}