--- linuxsampler/trunk/src/network/lscpserver.cpp 2004/08/21 11:35:50 222 +++ linuxsampler/trunk/src/network/lscpserver.cpp 2004/08/21 11:43:53 223 @@ -390,7 +390,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); } @@ -405,8 +405,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) { @@ -426,7 +426,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); @@ -741,9 +741,9 @@ DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter); result.Add("TYPE", pParameter->Type()); result.Add("DESCRIPTION", pParameter->Description()); - result.Add("MANDATORY", (pParameter->Mandatory()) ? "true" : "false"); - result.Add("FIX", (pParameter->Fix()) ? "true" : "false"); - result.Add("MULTIPLICITY", (pParameter->Multiplicity()) ? "true" : "false"); + 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()); @@ -763,9 +763,9 @@ DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter); result.Add("TYPE", pParameter->Type()); result.Add("DESCRIPTION", pParameter->Description()); - result.Add("MANDATORY", (pParameter->Mandatory()) ? "true" : "false"); - result.Add("FIX", (pParameter->Fix()) ? "true" : "false"); - result.Add("MULTIPLICITY", (pParameter->Multiplicity()) ? "true" : "false"); + 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()); @@ -847,7 +847,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]; result.Add("DRIVER", pDevice->Driver()); std::map parameters = pDevice->DeviceParameters(); @@ -867,8 +867,8 @@ 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()); std::map parameters = pDevice->DeviceParameters(); std::map::iterator iter = parameters.begin(); @@ -885,11 +885,16 @@ 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) + "."); + + // 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++) { @@ -908,7 +913,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 @@ -932,28 +937,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 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[ParameterName]) throw LinuxSamplerException("Midi port does not provice a parameters '" + ParameterName + "'."); - DeviceRuntimeParameter* pParameter = parameters[ParameterName]; + // 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); @@ -967,7 +972,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 @@ -976,7 +981,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 @@ -984,9 +989,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); @@ -1000,7 +1005,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 @@ -1009,7 +1014,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 @@ -1026,10 +1031,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) { @@ -1043,10 +1048,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) { @@ -1059,13 +1064,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) + "."); + + // 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[ParamKey]) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'"); + if (!parameters.count(ParamKey)) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'"); parameters[ParamKey]->SetValue(ParamVal); } catch (LinuxSamplerException e) { @@ -1090,8 +1100,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) { @@ -1172,8 +1182,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) { @@ -1232,8 +1242,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->SetMidiInput(pDevice, MIDIPort, (MidiInputPort::midi_chan_t) MIDIChannel); } catch (LinuxSamplerException e) {