--- linuxsampler/trunk/src/network/lscpserver.cpp 2004/10/09 00:46:18 274 +++ linuxsampler/trunk/src/network/lscpserver.cpp 2005/02/12 23:48:50 376 @@ -50,6 +50,7 @@ Mutex LSCPServer::NotifyMutex = Mutex(); Mutex LSCPServer::NotifyBufferMutex = Mutex(); Mutex LSCPServer::SubscriptionMutex = Mutex(); +Mutex LSCPServer::RTNotifyMutex = Mutex(); LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) { this->pSampler = pSampler; @@ -203,6 +204,18 @@ NotifyMutex.Unlock(); } +int LSCPServer::EventSubscribers( std::list events ) { + int subs = 0; + SubscriptionMutex.Lock(); + for( std::list::iterator iter = events.begin(); + iter != events.end(); iter++) + { + subs += eventSubscriptions.count(*iter); + } + SubscriptionMutex.Unlock(); + return subs; +} + void LSCPServer::SendLSCPNotify( LSCPEvent event ) { SubscriptionMutex.Lock(); if (eventSubscriptions.count(event.GetType()) == 0) { @@ -432,11 +445,11 @@ LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); + if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); Engine* pEngine = pSamplerChannel->GetEngine(); - if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); + if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); if (!pSamplerChannel->GetAudioOutputDevice()) - throw LinuxSamplerException("No audio output device on channel"); + throw LinuxSamplerException("No audio output device connected to sampler channel"); if (bBackground) { LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument); pLoadInstrument->StartThread(); @@ -460,8 +473,10 @@ 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"); + if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); + LockRTNotify(); pSamplerChannel->LoadEngine(type); + UnlockRTNotify(); } catch (LinuxSamplerException e) { result.Error(e); @@ -512,7 +527,9 @@ String LSCPServer::RemoveChannel(uint uiSamplerChannel) { dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel)); LSCPResultSet result; + LockRTNotify(); pSampler->RemoveSamplerChannel(uiSamplerChannel); + UnlockRTNotify(); return result.Produce(); } @@ -555,13 +572,14 @@ LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); + if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); Engine* pEngine = pSamplerChannel->GetEngine(); //Defaults values String EngineName = "NONE"; float Volume = 0.0f; String InstrumentFileName = "NONE"; + String InstrumentName = "NONE"; int InstrumentIndex = -1; int InstrumentStatus = -1; int AudioOutputChannels = 0; @@ -574,7 +592,10 @@ InstrumentStatus = pEngine->InstrumentStatus(); InstrumentIndex = pEngine->InstrumentIndex(); if (InstrumentIndex != -1) + { InstrumentFileName = pEngine->InstrumentFileName(); + InstrumentName = pEngine->InstrumentName(); + } for (int chan = 0; chan < pEngine->Channels(); chan++) { if (AudioRouting != "") AudioRouting += ","; AudioRouting += ToString(pEngine->OutputChannel(chan)); @@ -596,6 +617,7 @@ result.Add("INSTRUMENT_FILE", InstrumentFileName); result.Add("INSTRUMENT_NR", InstrumentIndex); + result.Add("INSTRUMENT_NAME", InstrumentName); result.Add("INSTRUMENT_STATUS", InstrumentStatus); } catch (LinuxSamplerException e) { @@ -613,9 +635,9 @@ LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); + if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); Engine* pEngine = pSamplerChannel->GetEngine(); - if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); + if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); result.Add(pEngine->VoiceCount()); } catch (LinuxSamplerException e) { @@ -633,9 +655,9 @@ LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); + if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); Engine* pEngine = pSamplerChannel->GetEngine(); - if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); + if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); result.Add(pEngine->DiskStreamCount()); } catch (LinuxSamplerException e) { @@ -653,9 +675,9 @@ LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); + if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); Engine* pEngine = pSamplerChannel->GetEngine(); - if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); + if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); if (!pEngine->DiskStreamSupported()) result.Add("NA"); else { @@ -945,7 +967,7 @@ // get audio channel AudioChannel* pChannel = pDevice->Channel(ChannelId); - if (!pChannel) throw LinuxSamplerException("Audio ouotput device does not have channel " + ToString(ChannelId) + "."); + if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + "."); // return the values of all audio channel parameters std::map parameters = pChannel->ChannelParameters(); @@ -1004,7 +1026,7 @@ // get audio channel AudioChannel* pChannel = pDevice->Channel(ChannelId); - if (!pChannel) throw LinuxSamplerException("Audio output device does not have channel " + ToString(ChannelId) + "."); + if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + "."); // get desired audio channel parameter std::map parameters = pChannel->ChannelParameters(); @@ -1037,7 +1059,7 @@ // get audio channel AudioChannel* pChannel = pDevice->Channel(ChannelId); - if (!pChannel) throw LinuxSamplerException("Audio output device does not have channel " + ToString(ChannelId) + "."); + if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + "."); // get desired audio channel parameter std::map parameters = pChannel->ChannelParameters(); @@ -1120,9 +1142,10 @@ LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); + if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); Engine* pEngine = pSamplerChannel->GetEngine(); if (!pEngine) throw LinuxSamplerException("No engine deployed on sampler channel " + ToString(uiSamplerChannel)); + if (!pSamplerChannel->GetAudioOutputDevice()) throw LinuxSamplerException("No audio output device connected to sampler channel " + ToString(uiSamplerChannel)); pEngine->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel); } catch (LinuxSamplerException e) { @@ -1136,7 +1159,7 @@ LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); + if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler 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]; @@ -1153,7 +1176,7 @@ LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); + if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); // Driver type name aliasing... if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA"; if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK"; @@ -1190,7 +1213,7 @@ LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); + if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); pSamplerChannel->SetMidiInputPort(MIDIPort); } catch (LinuxSamplerException e) { @@ -1204,7 +1227,7 @@ LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); + if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel); } catch (LinuxSamplerException e) { @@ -1218,7 +1241,7 @@ LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); + if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler 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]; @@ -1235,7 +1258,7 @@ LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); + if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); // Driver type name aliasing... if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA"; // Check if there's one MIDI input device already created @@ -1278,7 +1301,7 @@ LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); + if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler 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]; @@ -1299,9 +1322,9 @@ LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); + if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); Engine* pEngine = pSamplerChannel->GetEngine(); - if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); + if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); pEngine->Volume(dVolume); } catch (LinuxSamplerException e) { @@ -1318,9 +1341,9 @@ LSCPResultSet result; try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); - if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); + if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); Engine* pEngine = pSamplerChannel->GetEngine(); - if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); + if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); pEngine->Reset(); } catch (LinuxSamplerException e) {