--- linuxsampler/trunk/src/network/lscpserver.cpp 2004/05/22 06:33:55 79 +++ linuxsampler/trunk/src/network/lscpserver.cpp 2004/06/18 14:29:02 133 @@ -21,8 +21,10 @@ ***************************************************************************/ #include "lscpserver.h" +#include "lscpresultset.h" #include "../engines/gig/Engine.h" +#include "../audiodriver/AudioOutputDeviceFactory.h" LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) { this->pSampler = pSampler; @@ -88,27 +90,63 @@ send(hSession, ReturnMessage.c_str(), ReturnMessage.size(), 0); } +String LSCPServer::CreateAudioOutputDevice(String Driver, std::map Parameters) { + dmsg(2,("LSCPServer: CreateAudioOutputDevice(Driver=%s)\n", Driver.c_str())); + LSCPResultSet result; + try { + AudioOutputDevice* pDevice = pSampler->CreateAudioOutputDevice(Driver, Parameters); + std::map devices = pSampler->GetAudioOutputDevices(); + // search for the created device to get its index + int index = -1; + std::map::iterator iter = devices.begin(); + for (; iter != devices.end(); iter++) { + if (iter->second == pDevice) { + index = iter->first; + break; + } + } + if (index == -1) throw LinuxSamplerException("Internal error: could not find created audio output device."); + result = index; // success + } + catch (LinuxSamplerException e) { + result.Error(e); + } + return result.Produce(); +} + +String LSCPServer::DestroyAudioOutputDevice(uint DeviceIndex) { + dmsg(2,("LSCPServer: DestroyAudioOutputDevice(DeviceIndex=%d)\n", DeviceIndex)); + LSCPResultSet result; + try { + std::map devices = pSampler->GetAudioOutputDevices(); + if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); + AudioOutputDevice* pDevice = devices[DeviceIndex]; + pSampler->DestroyAudioOutputDevice(pDevice); + } + catch (LinuxSamplerException e) { + result.Error(e); + } + return result.Produce(); +} + /** * Will be called by the parser to load an instrument. */ String LSCPServer::LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel) { dmsg(2,("LSCPServer: LoadInstrument(Filename=%s,Instrument=%d,SamplerChannel=%d)\n", Filename.c_str(), uiInstrument, uiSamplerChannel)); - result_t result; + LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); 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); - result.type = result_type_success; + LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument); + pLoadInstrument->StartThread(); } catch (LinuxSamplerException e) { - e.PrintMessage(); - result.type = result_type_error; - result.code = LSCP_ERR_UNKNOWN; - result.message = e.Message(); + result.Error(e); } - return ConvertResult(result); + return result.Produce(); } /** @@ -116,23 +154,19 @@ */ String LSCPServer::LoadEngine(String EngineName, uint uiSamplerChannel) { dmsg(2,("LSCPServer: LoadEngine(EngineName=%s,SamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel)); - result_t result; + LSCPResultSet result; try { Engine::type_t type; - if (EngineName == "gig") type = Engine::type_gig; + if ((EngineName == "GigEngine") || (EngineName == "gig")) type = Engine::type_gig; else throw LinuxSamplerException("Unknown engine type"); SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); pSamplerChannel->LoadEngine(type); - result.type = result_type_success; } catch (LinuxSamplerException e) { - e.PrintMessage(); - result.type = result_type_error; - result.code = LSCP_ERR_UNKNOWN; - result.message = e.Message(); + result.Error(e); } - return ConvertResult(result); + return result.Produce(); } /** @@ -140,7 +174,9 @@ */ String LSCPServer::GetChannels() { dmsg(2,("LSCPServer: GetChannels()\n")); - return ToString(pSampler->SamplerChannels()) + "\r\n"; + LSCPResultSet result; + result.Add(pSampler->SamplerChannels()); + return result.Produce(); } /** @@ -149,7 +185,8 @@ String LSCPServer::AddChannel() { dmsg(2,("LSCPServer: AddChannel()\n")); SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel(); - return "OK[" + ToString(pSamplerChannel->Index()) + "]\r\n"; + LSCPResultSet result(pSamplerChannel->Index()); + return result.Produce(); } /** @@ -157,8 +194,9 @@ */ String LSCPServer::RemoveChannel(uint uiSamplerChannel) { dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel)); + LSCPResultSet result; pSampler->RemoveSamplerChannel(uiSamplerChannel); - return "OK\r\n"; + return result.Produce(); } /** @@ -166,7 +204,8 @@ */ String LSCPServer::GetAvailableEngines() { dmsg(2,("LSCPServer: GetAvailableEngines()\n")); - return "gig\r\n"; + LSCPResultSet result("GigEngine"); + return result.Produce(); } /** @@ -174,23 +213,20 @@ */ String LSCPServer::GetEngineInfo(String EngineName) { dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str())); - result_t result; + LSCPResultSet result; try { - if (EngineName == "gig") { + if ((EngineName == "GigEngine") || (EngineName == "gig")) { Engine* pEngine = new LinuxSampler::gig::Engine; - String info = pEngine->Description() + "\r\n"; + result.Add(pEngine->Description()); + result.Add(pEngine->Version()); delete pEngine; - return info; // success } else throw LinuxSamplerException("Unknown engine type"); } catch (LinuxSamplerException e) { - e.PrintMessage(); - result.type = result_type_error; - result.code = LSCP_ERR_UNKNOWN; - result.message = e.Message(); + result.Error(e); } - return ConvertResult(result); + return result.Produce(); } /** @@ -199,7 +235,49 @@ */ String LSCPServer::GetChannelInfo(uint uiSamplerChannel) { dmsg(2,("LSCPServer: GetChannelInfo(SamplerChannel=%d)\n", uiSamplerChannel)); - return "ERR:0:Not implemented yet.\r\n"; + LSCPResultSet result; + try { + SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); + if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); + Engine* pEngine = pSamplerChannel->GetEngine(); + + //Defaults values + String EngineName = "NONE"; + float Volume = 0; + String InstrumentFileName = "NONE"; + int InstrumentIndex = -1; + int InstrumentStatus = -1; + + if (pEngine) { + EngineName = pEngine->EngineName(); + Volume = pEngine->Volume(); + InstrumentStatus = pEngine->InstrumentStatus(); + InstrumentIndex = pEngine->InstrumentIndex(); + if (InstrumentIndex != -1) + InstrumentFileName = pEngine->InstrumentFileName(); + } + + result.Add("ENGINE_NAME", EngineName); + result.Add("VOLUME", Volume); + + //Some hardcoded stuff for now to make GUI look good + result.Add("AUDIO_OUTPUT_DEVICE", "0"); + result.Add("AUDIO_OUTPUT_CHANNELS", "2"); + result.Add("AUDIO_OUTPUT_ROUTING", "0,1"); + + 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"); + result.Add("MIDI_INPUT_PORT", "0"); + result.Add("MIDI_INPUT_CHANNEL", "1"); + } + catch (LinuxSamplerException e) { + result.Error(e); + } + return result.Produce(); } /** @@ -208,21 +286,18 @@ */ String LSCPServer::GetVoiceCount(uint uiSamplerChannel) { dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel)); - result_t result; + LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); Engine* pEngine = pSamplerChannel->GetEngine(); if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); - return ToString(pEngine->VoiceCount()) + "\r\n"; // success + result.Add(pEngine->VoiceCount()); } catch (LinuxSamplerException e) { - e.PrintMessage(); - result.type = result_type_error; - result.code = LSCP_ERR_UNKNOWN; - result.message = e.Message(); + result.Error(e); } - return ConvertResult(result); + return result.Produce(); } /** @@ -231,21 +306,18 @@ */ String LSCPServer::GetStreamCount(uint uiSamplerChannel) { dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel)); - result_t result; + LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); Engine* pEngine = pSamplerChannel->GetEngine(); if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); - return ToString(pEngine->DiskStreamCount()) + "\r\n"; // success + result.Add(pEngine->DiskStreamCount()); } catch (LinuxSamplerException e) { - e.PrintMessage(); - result.type = result_type_error; - result.code = LSCP_ERR_UNKNOWN; - result.message = e.Message(); + result.Error(e); } - return ConvertResult(result); + return result.Produce(); } /** @@ -254,78 +326,270 @@ */ String LSCPServer::GetBufferFill(fill_response_t ResponseType, uint uiSamplerChannel) { dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel)); - result_t result; + LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); 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"; - switch (ResponseType) { - case fill_response_bytes: - return ToString(pEngine->DiskStreamBufferFillBytes()) + "\r\n"; // success - case fill_response_percentage: - return ToString(pEngine->DiskStreamBufferFillPercentage()) + "\r\n"; // success - 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); + } + return result.Produce(); +} + +String LSCPServer::GetAvailableAudioOutputDrivers() { + dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n")); + LSCPResultSet result; + try { + String s = AudioOutputDeviceFactory::AvailableDriversAsString(); + result.Add(s); + } + catch (LinuxSamplerException e) { + result.Error(e); + } + return result.Produce(); +} + +String LSCPServer::GetAudioOutputDriverInfo(String Driver) { + dmsg(2,("LSCPServer: GetAudioOutputDriverInfo(Driver=%s)\n",Driver.c_str())); + LSCPResultSet result; + try { + result.Add("DESCRIPTION", AudioOutputDeviceFactory::GetDriverDescription(Driver)); + result.Add("VERSION", AudioOutputDeviceFactory::GetDriverVersion(Driver)); + + std::map parameters = AudioOutputDeviceFactory::GetAvailableDriverParameters(Driver); + if (parameters.size()) { // if there are parameters defined for this driver + String s; + std::map::iterator iter = parameters.begin(); + for (;iter != parameters.end(); iter++) { + if (s != "") s += ","; + s += iter->first; + } + result.Add("PARAMETERS", s); } } catch (LinuxSamplerException e) { - e.PrintMessage(); - result.type = result_type_error; - result.code = LSCP_ERR_UNKNOWN; - result.message = e.Message(); + result.Error(e); } - return ConvertResult(result); + return result.Produce(); } -/** - * Will be called by the parser to change the audio output type on a - * particular sampler channel. - */ -String LSCPServer::SetAudioOutputType(AudioOutputDevice::type_t AudioOutputType, uint uiSamplerChannel) { - dmsg(2,("LSCPServer: SetAudioOutputType(AudioOutputType=%d, SamplerChannel=%d)\n", AudioOutputType, uiSamplerChannel)); - result_t result; +String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map DependencyList) { + dmsg(2,("LSCPServer: GetAudioOutputDriverParameterInfo(Driver=%s,Parameter=%s)\n",Driver.c_str(),Parameter.c_str())); + LSCPResultSet result; try { - SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); - pSamplerChannel->SetAudioOutputDevice(AudioOutputType); - result.type = result_type_success; + DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter); + result.Add("TYPE", pParameter->Type()); + result.Add("DESCRIPTION", pParameter->Description()); + result.Add("MANDATORY", pParameter->Mandatory()); + result.Add("FIX", pParameter->Fix()); + result.Add("MULTIPLICITY", pParameter->Multiplicity()); + if (pParameter->Depends()) result.Add("DEPENDS", pParameter->Depends()); + if (pParameter->Default()) result.Add("DEFAULT", pParameter->Default()); + if (pParameter->RangeMin()) result.Add("RANGE_MIN", pParameter->RangeMin()); + if (pParameter->RangeMax()) result.Add("RANGE_MAX", pParameter->RangeMax()); + if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities()); + } + catch (LinuxSamplerException e) { + result.Error(e); + } + return result.Produce(); +} + +String LSCPServer::GetAudioOutputDeviceCount() { + dmsg(2,("LSCPServer: GetAudioOutputDeviceCount()\n")); + LSCPResultSet result; + try { + uint count = pSampler->AudioOutputDevices(); + result = count; // success + } + catch (LinuxSamplerException e) { + result.Error(e); + } + return result.Produce(); +} + +String LSCPServer::GetAudioOutputDevices() { + dmsg(2,("LSCPServer: GetAudioOutputDevices()\n")); + LSCPResultSet result; + try { + String s; + std::map devices = pSampler->GetAudioOutputDevices(); + std::map::iterator iter = devices.begin(); + for (; iter != devices.end(); iter++) { + if (s != "") s += ","; + s += ToString(iter->first); + } + result.Add(s); + } + catch (LinuxSamplerException e) { + result.Error(e); + } + return result.Produce(); +} + +String LSCPServer::GetAudioOutputDeviceInfo(uint DeviceIndex) { + dmsg(2,("LSCPServer: GetAudioOutputDeviceInfo(DeviceIndex=%d)\n",DeviceIndex)); + LSCPResultSet result; + try { + std::map devices = pSampler->GetAudioOutputDevices(); + if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); + AudioOutputDevice* pDevice = devices[DeviceIndex]; + std::map parameters = pDevice->DeviceParameters(); + std::map::iterator iter = parameters.begin(); + for (; iter != parameters.end(); iter++) { + result.Add(iter->first, iter->second->Value()); + } + } + catch (LinuxSamplerException e) { + result.Error(e); + } + return result.Produce(); +} + +String LSCPServer::GetAudioOutputChannelInfo(uint DeviceId, uint ChannelId) { + dmsg(2,("LSCPServer: GetAudioOutputChannelInfo(DeviceId=%d,ChannelId)\n",DeviceId,ChannelId)); + LSCPResultSet result; + try { + // get audio output device + std::map devices = pSampler->GetAudioOutputDevices(); + if (!devices[DeviceId]) throw LinuxSamplerException("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 ouotput device does not have channel " + ToString(ChannelId) + "."); + + // return the values of all audio channel parameters + std::map parameters = pChannel->ChannelParameters(); + std::map::iterator iter = parameters.begin(); + for (; iter != parameters.end(); iter++) { + result.Add(iter->first, iter->second->Value()); + } + } + catch (LinuxSamplerException e) { + result.Error(e); + } + return result.Produce(); +} + +String LSCPServer::GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName) { + dmsg(2,("LSCPServer: GetAudioOutputChannelParameterInfo(DeviceId=%d,ChannelId=%d,ParameterName=%s)\n",DeviceId,ChannelId,ParameterName.c_str())); + LSCPResultSet result; + try { + // get audio output device + std::map devices = pSampler->GetAudioOutputDevices(); + if (!devices[DeviceId]) throw LinuxSamplerException("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 channel " + ToString(ChannelId) + "."); + + // get desired audio channel parameter + std::map parameters = pChannel->ChannelParameters(); + if (!parameters[ParameterName]) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParameterName + "'."); + DeviceRuntimeParameter* pParameter = parameters[ParameterName]; + + // return all fields of this audio channel parameter + result.Add("TYPE", pParameter->Type()); + result.Add("DESCRIPTION", pParameter->Description()); + result.Add("FIX", pParameter->Fix()); + result.Add("MULTIPLICITY", pParameter->Multiplicity()); + if (pParameter->RangeMin()) result.Add("RANGE_MIN", pParameter->RangeMin()); + if (pParameter->RangeMax()) result.Add("RANGE_MAX", pParameter->RangeMax()); + if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities()); + } + catch (LinuxSamplerException e) { + result.Error(e); + } + return result.Produce(); +} + +String LSCPServer::SetAudioOutputChannelParameter(uint DeviceId, uint ChannelId, String ParamKey, String ParamVal) { + dmsg(2,("LSCPServer: SetAudioOutputChannelParameter(DeviceId=%d,ChannelId=%d,ParamKey=%s,ParamVal=%s)\n",DeviceId,ChannelId,ParamKey.c_str(),ParamVal.c_str())); + LSCPResultSet result; + try { + // get audio output device + std::map devices = pSampler->GetAudioOutputDevices(); + if (!devices[DeviceId]) throw LinuxSamplerException("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 channel " + ToString(ChannelId) + "."); + + // get desired audio channel parameter + std::map parameters = pChannel->ChannelParameters(); + if (!parameters[ParamKey]) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParamKey + "'."); + DeviceRuntimeParameter* pParameter = parameters[ParamKey]; + + // set new channel parameter value + pParameter->SetValue(ParamVal); + } + catch (LinuxSamplerException e) { + result.Error(e); + } + return result.Produce(); +} + +String LSCPServer::SetAudioOutputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal) { + dmsg(2,("LSCPServer: SetAudioOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str())); + LSCPResultSet result; + try { + std::map devices = pSampler->GetAudioOutputDevices(); + if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); + AudioOutputDevice* pDevice = devices[DeviceIndex]; + std::map parameters = pDevice->DeviceParameters(); + if (!parameters[ParamKey]) throw LinuxSamplerException("Audio output device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'"); + parameters[ParamKey]->SetValue(ParamVal); } catch (LinuxSamplerException e) { - e.PrintMessage(); - result.type = result_type_error; - result.code = LSCP_ERR_UNKNOWN; - result.message = e.Message(); + result.Error(e); } - return ConvertResult(result); + return result.Produce(); } /** * Will be called by the parser to change the audio output channel for * playback on a particular sampler channel. */ -String LSCPServer::SetAudioOutputChannel(uint AudioOutputChannel, uint uiSamplerChannel) { - dmsg(2,("LSCPServer: SetAudioOutputChannel(AudioOutputChannel=%d, SamplerChannel=%d)\n", AudioOutputChannel, uiSamplerChannel)); - return "ERR:0:Not implemented yet.\r\n"; +String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) { + dmsg(2,("LSCPServer: SetAudioOutputChannel(ChannelAudioOutputChannel=%d, AudioOutputDeviceInputChannel=%d, SamplerChannel=%d)\n",ChannelAudioOutputChannel,AudioOutputDeviceInputChannel,uiSamplerChannel)); + return "ERR:0:Not implemented yet.\r\n"; //FIXME: Add support for this in resultset class? } -String LSCPServer::SetMIDIInputType(MidiInputDevice::type_t MidiInputType, uint uiSamplerChannel) { - dmsg(2,("LSCPServer: SetMIDIInputType(MidiInputType=%d, SamplerChannel=%d)\n", MidiInputType, uiSamplerChannel)); - result_t result; +String LSCPServer::SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel) { + dmsg(2,("LSCPServer: SetMIDIInputType(String MidiInputDriver=%s, SamplerChannel=%d)\n",MidiInputDriver.c_str(),uiSamplerChannel)); + LSCPResultSet result; try { 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 + "'."); + MidiInputDevice::type_t MidiInputType = MidiInputDevice::type_alsa; pSamplerChannel->SetMidiInputDevice(MidiInputType); - result.type = result_type_success; } catch (LinuxSamplerException e) { - e.PrintMessage(); - result.type = result_type_error; - result.code = LSCP_ERR_UNKNOWN; - result.message = e.Message(); + result.Error(e); } - return ConvertResult(result); + return result.Produce(); } /** @@ -334,21 +598,17 @@ */ String LSCPServer::SetMIDIInputPort(String MIDIInputPort, uint uiSamplerChannel) { dmsg(2,("LSCPServer: SetMIDIInputPort(MIDIInputPort=%s, Samplerchannel=%d)\n", MIDIInputPort.c_str(), uiSamplerChannel)); - result_t result; + LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); if (!pSamplerChannel->GetMidiInputDevice()) throw LinuxSamplerException("No MIDI input device connected yet"); pSamplerChannel->GetMidiInputDevice()->SetInputPort(MIDIInputPort.c_str()); - result.type = result_type_success; } catch (LinuxSamplerException e) { - e.PrintMessage(); - result.type = result_type_error; - result.code = LSCP_ERR_UNKNOWN; - result.message = e.Message(); + result.Error(e); } - return ConvertResult(result); + return result.Produce(); } /** @@ -357,23 +617,29 @@ */ String LSCPServer::SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel) { dmsg(2,("LSCPServer: SetMIDIInputChannel(MIDIChannel=%d, SamplerChannel=%d)\n", MIDIChannel, uiSamplerChannel)); - result_t result; + LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); if (!pSamplerChannel->GetMidiInputDevice()) throw LinuxSamplerException("No MIDI input device connected yet"); MidiInputDevice::type_t oldtype = pSamplerChannel->GetMidiInputDevice()->Type(); pSamplerChannel->SetMidiInputDevice(oldtype, (MidiInputDevice::midi_chan_t) MIDIChannel); + } + catch (LinuxSamplerException e) { + result.Error(e); + } + return result.Produce(); +} - result.type = result_type_success; +String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint SamplerChannel) { + LSCPResultSet result; + try { + throw LinuxSamplerException("Command not yet implemented"); } catch (LinuxSamplerException e) { - e.PrintMessage(); - result.type = result_type_error; - result.code = LSCP_ERR_UNKNOWN; - result.message = e.Message(); + result.Error(e); } - return ConvertResult(result); + return result.Produce(); } /** @@ -382,22 +648,18 @@ */ String LSCPServer::SetVolume(double Volume, uint uiSamplerChannel) { dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, uiSamplerChannel)); - result_t result; + LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); Engine* pEngine = pSamplerChannel->GetEngine(); if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); pEngine->Volume(Volume); - result.type = result_type_success; } catch (LinuxSamplerException e) { - e.PrintMessage(); - result.type = result_type_error; - result.code = LSCP_ERR_UNKNOWN; - result.message = e.Message(); + result.Error(e); } - return ConvertResult(result); + return result.Produce(); } /** @@ -405,22 +667,18 @@ */ String LSCPServer::ResetChannel(uint uiSamplerChannel) { dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel)); - result_t result; + LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); Engine* pEngine = pSamplerChannel->GetEngine(); if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); pEngine->Reset(); - result.type = result_type_success; } catch (LinuxSamplerException e) { - e.PrintMessage(); - result.type = result_type_error; - result.code = LSCP_ERR_UNKNOWN; - result.message = e.Message(); + result.Error(e); } - return ConvertResult(result); + return result.Produce(); } /** @@ -440,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; +}