--- linuxsampler/trunk/src/network/lscpserver.cpp 2004/07/25 23:27:41 211 +++ linuxsampler/trunk/src/network/lscpserver.cpp 2004/08/26 22:05:44 227 @@ -88,10 +88,19 @@ 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." << std::endl; - close(hSocket); - //return -1; - exit(EXIT_FAILURE); + 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 + if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { + if (trial > LSCP_SERVER_BIND_TIMEOUT) { + std::cerr << "gave up!" << std::endl; + close(hSocket); + //return -1; + exit(EXIT_FAILURE); + } + else sleep(1); // sleep 1s + } + else break; // success + } } listen(hSocket, 1); @@ -147,7 +156,8 @@ if (FD_ISSET((*iter).hSession, &selectSet)) { //Was it this socket? if (GetLSCPCommand(iter)) { //Have we read the entire command? dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket)); - yylex_init(&((*iter).pScanner)); //FIXME: should me moved out of this loop and initialized only when a new session is created + int dummy; // just a temporary hack to fulfill the restart() function prototype + restart(NULL, dummy); // restart the 'scanner' currentSocket = (*iter).hSession; //a hack if ((*iter).bVerbose) { // if echo mode enabled AnswerClient(bufferedCommands[currentSocket]); @@ -173,8 +183,6 @@ } NotifyBufferMutex.Unlock(); } - //It will never get here anyway - //yylex_destroy(yyparse_param.pScanner); } void LSCPServer::CloseConnection( std::vector::iterator iter ) { @@ -193,7 +201,6 @@ bufferedNotifies.erase(socket); close(socket); NotifyMutex.Unlock(); - //yylex_destroy((*iter).pScanner); } void LSCPServer::SendLSCPNotify( LSCPEvent event ) { @@ -392,7 +399,7 @@ LSCPResultSet result; try { std::map devices = pSampler->GetAudioOutputDevices(); - if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); + if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); AudioOutputDevice* pDevice = devices[DeviceIndex]; pSampler->DestroyAudioOutputDevice(pDevice); } @@ -407,8 +414,8 @@ LSCPResultSet result; try { std::map devices = pSampler->GetMidiInputDevices(); + if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); MidiInputDevice* pDevice = devices[DeviceIndex]; - if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); pSampler->DestroyMidiInputDevice(pDevice); } catch (LinuxSamplerException e) { @@ -428,7 +435,7 @@ if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); Engine* pEngine = pSamplerChannel->GetEngine(); if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); - if (pSamplerChannel->GetAudioOutputDevice() == NULL) + if (!pSamplerChannel->GetAudioOutputDevice()) throw LinuxSamplerException("No audio output device on channel"); if (bBackground) { LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument); @@ -527,8 +534,8 @@ try { if ((EngineName == "GigEngine") || (EngineName == "gig")) { Engine* pEngine = new LinuxSampler::gig::Engine; - result.Add(pEngine->Description()); - result.Add(pEngine->Version()); + result.Add("DESCRIPTION", pEngine->Description()); + result.Add("VERSION", pEngine->Version()); delete pEngine; } else throw LinuxSamplerException("Unknown engine type"); @@ -553,18 +560,25 @@ //Defaults values String EngineName = "NONE"; - float Volume = 0; + float Volume = 0.0f; String InstrumentFileName = "NONE"; int InstrumentIndex = -1; int InstrumentStatus = -1; + 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(); + for (int chan = 0; chan < pEngine->Channels(); chan++) { + if (AudioRouting != "") AudioRouting += ","; + AudioRouting += ToString(pEngine->OutputChannel(chan)); + } } result.Add("ENGINE_NAME", EngineName); @@ -572,12 +586,13 @@ //Some not-so-hardcoded stuff to make GUI look good result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice())); - result.Add("AUDIO_OUTPUT_CHANNELS", "2"); - result.Add("AUDIO_OUTPUT_ROUTING", "0,1"); + result.Add("AUDIO_OUTPUT_CHANNELS", AudioOutputChannels); + result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice())); result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort()); - result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); + if (pSamplerChannel->GetMidiInputChannel()) result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); + else result.Add("MIDI_INPUT_CHANNEL", "ALL"); result.Add("INSTRUMENT_FILE", InstrumentFileName); result.Add("INSTRUMENT_NR", InstrumentIndex); @@ -737,7 +752,7 @@ } String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map DependencyList) { - dmsg(2,("LSCPServer: GetMidiInputDriverParameterInfo(Driver=%s,Parameter=%s)\n",Driver.c_str(),Parameter.c_str())); + dmsg(2,("LSCPServer: GetMidiInputDriverParameterInfo(Driver=%s,Parameter=%s,DependencyListSize=%d)\n",Driver.c_str(),Parameter.c_str(),DependencyList.size())); LSCPResultSet result; try { DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter); @@ -746,11 +761,16 @@ 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()); + optional oDepends = pParameter->Depends(); + optional oDefault = pParameter->Default(DependencyList); + optional oRangeMin = pParameter->RangeMin(DependencyList); + optional oRangeMax = pParameter->RangeMax(DependencyList); + optional oPossibilities = pParameter->Possibilities(DependencyList); + if (oDepends) result.Add("DEPENDS", *oDepends); + if (oDefault) result.Add("DEFAULT", *oDefault); + if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); + if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); + if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); } catch (LinuxSamplerException e) { result.Error(e); @@ -759,7 +779,7 @@ } 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())); + dmsg(2,("LSCPServer: GetAudioOutputDriverParameterInfo(Driver=%s,Parameter=%s,DependencyListSize=%d)\n",Driver.c_str(),Parameter.c_str(),DependencyList.size())); LSCPResultSet result; try { DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter); @@ -768,11 +788,16 @@ 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()); + optional oDepends = pParameter->Depends(); + optional oDefault = pParameter->Default(DependencyList); + optional oRangeMin = pParameter->RangeMin(DependencyList); + optional oRangeMax = pParameter->RangeMax(DependencyList); + optional oPossibilities = pParameter->Possibilities(DependencyList); + if (oDepends) result.Add("DEPENDS", *oDepends); + if (oDefault) result.Add("DEFAULT", *oDefault); + if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); + if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); + if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); } catch (LinuxSamplerException e) { result.Error(e); @@ -849,9 +874,9 @@ LSCPResultSet result; try { std::map devices = pSampler->GetAudioOutputDevices(); - if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); + if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); AudioOutputDevice* pDevice = devices[DeviceIndex]; - result.Add("driver", pDevice->Driver()); + result.Add("DRIVER", pDevice->Driver()); std::map parameters = pDevice->DeviceParameters(); std::map::iterator iter = parameters.begin(); for (; iter != parameters.end(); iter++) { @@ -869,9 +894,9 @@ LSCPResultSet result; try { std::map devices = pSampler->GetMidiInputDevices(); + if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); MidiInputDevice* pDevice = devices[DeviceIndex]; - if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); - result.Add("driver", pDevice->Driver()); + result.Add("DRIVER", pDevice->Driver()); std::map parameters = pDevice->DeviceParameters(); std::map::iterator iter = parameters.begin(); for (; iter != parameters.end(); iter++) { @@ -887,13 +912,18 @@ dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex)); LSCPResultSet result; try { + // get MIDI input device std::map devices = pSampler->GetMidiInputDevices(); + if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); MidiInputDevice* pDevice = devices[DeviceIndex]; - if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); - MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); - if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); - std::map parameters = pMidiInputPort->DeviceParameters(); - std::map::iterator iter = parameters.begin(); + + // get MIDI port + MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); + if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); + + // return the values of all MIDI port parameters + std::map parameters = pMidiInputPort->PortParameters(); + std::map::iterator iter = parameters.begin(); for (; iter != parameters.end(); iter++) { result.Add(iter->first, iter->second->Value()); } @@ -910,7 +940,7 @@ 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) + "."); + if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + "."); AudioOutputDevice* pDevice = devices[DeviceId]; // get audio channel @@ -934,28 +964,28 @@ dmsg(2,("LSCPServer: GetMidiInputPortParameterInfo(DeviceId=%d,PortId=%d,ParameterName=%s)\n",DeviceId,PortId,ParameterName.c_str())); LSCPResultSet result; try { - // get audio output device - std::map devices = pSampler->GetMidiInputDevices(); - if (!devices[DeviceId]) throw LinuxSamplerException("There is no midi input device with index " + ToString(DeviceId) + "."); - MidiInputDevice* pDevice = devices[DeviceId]; - - // get midi port - MidiInputDevice::MidiInputPort* pPort = pDevice->GetPort(PortId); - if (!pPort) throw LinuxSamplerException("Midi input device does not have port " + ToString(PortId) + "."); - - // get desired port parameter - std::map parameters = pPort->DeviceParameters(); - if (!parameters[ParameterName]) throw LinuxSamplerException("Midi port does not provice a parameters '" + ParameterName + "'."); - DeviceCreationParameter* pParameter = parameters[ParameterName]; + // get MIDI input device + std::map devices = pSampler->GetMidiInputDevices(); + if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no midi input device with index " + ToString(DeviceId) + "."); + MidiInputDevice* pDevice = devices[DeviceId]; + + // get midi port + MidiInputPort* pPort = pDevice->GetPort(PortId); + if (!pPort) throw LinuxSamplerException("Midi input device does not have port " + ToString(PortId) + "."); + + // get desired port parameter + std::map parameters = pPort->PortParameters(); + if (!parameters.count(ParameterName)) throw LinuxSamplerException("Midi port 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()); + 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); @@ -969,7 +999,7 @@ 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) + "."); + if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + "."); AudioOutputDevice* pDevice = devices[DeviceId]; // get audio channel @@ -978,7 +1008,7 @@ // get desired audio channel parameter std::map parameters = pChannel->ChannelParameters(); - if (!parameters[ParameterName]) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParameterName + "'."); + if (!parameters.count(ParameterName)) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParameterName + "'."); DeviceRuntimeParameter* pParameter = parameters[ParameterName]; // return all fields of this audio channel parameter @@ -986,9 +1016,9 @@ 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()); + 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); @@ -1002,7 +1032,7 @@ 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) + "."); + if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + "."); AudioOutputDevice* pDevice = devices[DeviceId]; // get audio channel @@ -1011,7 +1041,7 @@ // get desired audio channel parameter std::map parameters = pChannel->ChannelParameters(); - if (!parameters[ParamKey]) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParamKey + "'."); + if (!parameters.count(ParamKey)) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParamKey + "'."); DeviceRuntimeParameter* pParameter = parameters[ParamKey]; // set new channel parameter value @@ -1028,10 +1058,10 @@ LSCPResultSet result; try { std::map devices = pSampler->GetAudioOutputDevices(); - if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); + if (!devices.count(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 + "'"); + if (!parameters.count(ParamKey)) throw LinuxSamplerException("Audio output device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'"); parameters[ParamKey]->SetValue(ParamVal); } catch (LinuxSamplerException e) { @@ -1045,10 +1075,10 @@ LSCPResultSet result; try { std::map devices = pSampler->GetMidiInputDevices(); - if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); + if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); MidiInputDevice* pDevice = devices[DeviceIndex]; std::map parameters = pDevice->DeviceParameters(); - if (!parameters[ParamKey]) throw LinuxSamplerException("MIDI input device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'"); + if (!parameters.count(ParamKey)) throw LinuxSamplerException("MIDI input device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'"); parameters[ParamKey]->SetValue(ParamVal); } catch (LinuxSamplerException e) { @@ -1061,13 +1091,18 @@ dmsg(2,("LSCPServer: SetMidiOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str())); LSCPResultSet result; try { + // get MIDI input device std::map devices = pSampler->GetMidiInputDevices(); + if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); MidiInputDevice* pDevice = devices[DeviceIndex]; - if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); - MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); - if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); - std::map parameters = pMidiInputPort->DeviceParameters(); - if (!parameters[ParamKey]) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'"); + + // get MIDI port + MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); + if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); + + // set port parameter value + std::map parameters = pMidiInputPort->PortParameters(); + if (!parameters.count(ParamKey)) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'"); parameters[ParamKey]->SetValue(ParamVal); } catch (LinuxSamplerException e) { @@ -1082,7 +1117,18 @@ */ 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? + LSCPResultSet result; + try { + SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); + if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); + Engine* pEngine = pSamplerChannel->GetEngine(); + if (!pEngine) throw LinuxSamplerException("No engine deployed on sampler channel " + ToString(uiSamplerChannel)); + pEngine->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel); + } + catch (LinuxSamplerException e) { + result.Error(e); + } + return result.Produce(); } String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) { @@ -1092,8 +1138,8 @@ SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); std::map devices = pSampler->GetAudioOutputDevices(); + if (!devices.count(AudioDeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId)); AudioOutputDevice* pDevice = devices[AudioDeviceId]; - if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId)); pSamplerChannel->SetAudioOutputDevice(pDevice); } catch (LinuxSamplerException e) { @@ -1109,8 +1155,8 @@ SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); // Driver type name aliasing... - if (AudioOutputDriver == "ALSA") AudioOutputDriver = "Alsa"; - if (AudioOutputDriver == "JACK") AudioOutputDriver = "Jack"; + if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA"; + if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK"; // Check if there's one audio output device already created // for the intended audio driver type (AudioOutputDriver)... AudioOutputDevice *pDevice = NULL; @@ -1159,7 +1205,7 @@ try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); - pSamplerChannel->SetMidiInputChannel((MidiInputDevice::MidiInputPort::midi_chan_t) MIDIChannel); + pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel); } catch (LinuxSamplerException e) { result.Error(e); @@ -1174,8 +1220,8 @@ SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); 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]; - if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); pSamplerChannel->SetMidiInputDevice(pDevice); } catch (LinuxSamplerException e) { @@ -1191,7 +1237,7 @@ SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); // Driver type name aliasing... - if (MidiInputDriver == "ALSA") MidiInputDriver = "Alsa"; + if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA"; // Check if there's one MIDI input device already created // for the intended MIDI driver type (MidiInputDriver)... MidiInputDevice *pDevice = NULL; @@ -1209,7 +1255,7 @@ pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params); // Make it with at least one initial port. std::map parameters = pDevice->DeviceParameters(); - parameters["ports"]->SetValue("1"); + parameters["PORTS"]->SetValue("1"); } // Must have a device... if (pDevice == NULL) @@ -1234,9 +1280,9 @@ SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); 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]; - if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); - pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (MidiInputDevice::MidiInputPort::midi_chan_t) MIDIChannel); + pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (MidiInputPort::midi_chan_t) MIDIChannel); } catch (LinuxSamplerException e) { result.Error(e); @@ -1248,15 +1294,15 @@ * Will be called by the parser to change the global volume factor on a * particular sampler channel. */ -String LSCPServer::SetVolume(double Volume, uint uiSamplerChannel) { - dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, uiSamplerChannel)); +String LSCPServer::SetVolume(double dVolume, uint uiSamplerChannel) { + dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel)); 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); + pEngine->Volume(dVolume); } catch (LinuxSamplerException e) { result.Error(e); @@ -1283,6 +1329,16 @@ return result.Produce(); } +/** + * Will be called by the parser to reset the whole sampler. + */ +String LSCPServer::ResetSampler() { + dmsg(2,("LSCPServer: ResetSampler()\n")); + pSampler->Reset(); + LSCPResultSet result; + return result.Produce(); +} + /** * Will be called by the parser to subscribe a client (frontend) on the * server for receiving event messages.