--- linuxsampler/trunk/src/network/lscpserver.cpp 2004/06/14 19:33:16 123 +++ linuxsampler/trunk/src/network/lscpserver.cpp 2004/06/18 14:29:02 133 @@ -140,7 +140,8 @@ 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); + LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument); + pLoadInstrument->StartThread(); } catch (LinuxSamplerException e) { result.Error(e); @@ -244,16 +245,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 +267,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"); @@ -330,17 +332,20 @@ if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); Engine* pEngine = pSamplerChannel->GetEngine(); if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); - if (!pEngine->DiskStreamSupported()) return "NA\r\n"; //FIXME: Update resultset class to support "NA" - switch (ResponseType) { - case fill_response_bytes: - result.Add(pEngine->DiskStreamBufferFillBytes()); - break; - case fill_response_percentage: - result.Add(pEngine->DiskStreamBufferFillPercentage()); - break; - default: - throw LinuxSamplerException("Unknown fill response type"); - } + if (!pEngine->DiskStreamSupported()) + result.Add("NA"); + else { + switch (ResponseType) { + case fill_response_bytes: + result.Add(pEngine->DiskStreamBufferFillBytes()); + break; + case fill_response_percentage: + result.Add(pEngine->DiskStreamBufferFillPercentage()); + break; + default: + throw LinuxSamplerException("Unknown fill response type"); + } + } } catch (LinuxSamplerException e) { result.Error(e); @@ -693,3 +698,31 @@ dmsg(2,("LSCPServer: UnsubscribeNotification(SessionID=%s)\n", SessionID.c_str())); 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; +}