--- linuxsampler/trunk/src/network/lscpserver.cpp 2005/05/22 20:43:32 563 +++ linuxsampler/trunk/src/network/lscpserver.cpp 2005/06/22 22:09:28 675 @@ -33,6 +33,7 @@ #endif #include "../engines/EngineFactory.h" +#include "../engines/EngineChannelFactory.h" #include "../drivers/audio/AudioOutputDeviceFactory.h" #include "../drivers/midi/MidiInputDeviceFactory.h" @@ -60,7 +61,10 @@ Mutex LSCPServer::SubscriptionMutex = Mutex(); Mutex LSCPServer::RTNotifyMutex = Mutex(); -LSCPServer::LSCPServer(Sampler* pSampler) : Thread(true, false, 0, -4) { +LSCPServer::LSCPServer(Sampler* pSampler, long int addr, short int port) : Thread(true, false, 0, -4) { + SocketAddress.sin_family = AF_INET; + SocketAddress.sin_addr.s_addr = addr; + SocketAddress.sin_port = port; this->pSampler = pSampler; LSCPEvent::RegisterEvent(LSCPEvent::event_channel_count, "CHANNEL_COUNT"); LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT"); @@ -97,10 +101,6 @@ exit(EXIT_FAILURE); } - SocketAddress.sin_family = AF_INET; - SocketAddress.sin_port = htons(LSCP_PORT); - 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, retrying for " << ToString(LSCP_SERVER_BIND_TIMEOUT) << " seconds..."; for (int trial = 0; true; trial++) { // retry for LSCP_SERVER_BIND_TIMEOUT seconds @@ -190,6 +190,18 @@ } } + // check if some engine channel's parameter / status changed, if so notify the respective LSCP event subscribers + { + std::set engineChannels = EngineChannelFactory::EngineChannelInstances(); + std::set::iterator itEngineChannel = engineChannels.begin(); + std::set::iterator itEnd = engineChannels.end(); + for (; itEngineChannel != itEnd; ++itEngineChannel) { + if ((*itEngineChannel)->StatusChanged()) { + SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex)); + } + } + } + //Now let's deliver late notifies (if any) NotifyBufferMutex.Lock(); for (std::map::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) { @@ -578,7 +590,7 @@ Engine* pEngine = EngineFactory::Create(EngineName); result.Add("DESCRIPTION", pEngine->Description()); result.Add("VERSION", pEngine->Version()); - delete pEngine; + EngineFactory::Destroy(pEngine); } catch (LinuxSamplerException e) { result.Error(e); @@ -634,7 +646,7 @@ result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice())); result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort()); - if (pSamplerChannel->GetMidiInputChannel() == MidiInputPort::midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL"); + if (pSamplerChannel->GetMidiInputChannel() == midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL"); else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); result.Add("INSTRUMENT_FILE", InstrumentFileName); @@ -660,6 +672,7 @@ if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); if (!pEngineChannel) throw LinuxSamplerException("No engine loaded on sampler channel"); + if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel"); result.Add(pEngineChannel->GetEngine()->VoiceCount()); } catch (LinuxSamplerException e) { @@ -680,6 +693,7 @@ if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); + if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel"); result.Add(pEngineChannel->GetEngine()->DiskStreamCount()); } catch (LinuxSamplerException e) { @@ -700,6 +714,7 @@ if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); + if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel"); if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA"); else { switch (ResponseType) { @@ -1275,7 +1290,7 @@ try { SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); - pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel); + pSamplerChannel->SetMidiInputChannel((midi_chan_t) MIDIChannel); } catch (LinuxSamplerException e) { result.Error(e); @@ -1352,7 +1367,7 @@ 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]; - pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (MidiInputPort::midi_chan_t) MIDIChannel); + pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (midi_chan_t) MIDIChannel); } catch (LinuxSamplerException e) { result.Error(e); @@ -1391,7 +1406,7 @@ if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); - pEngineChannel->GetEngine()->Reset(); + pEngineChannel->Reset(); } catch (LinuxSamplerException e) { result.Error(e); @@ -1417,7 +1432,8 @@ dmsg(2,("LSCPServer: GetServerInfo()\n")); LSCPResultSet result; result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler"); - result.Add("VERSION", VERSION); + result.Add("VERSION", VERSION); + result.Add("PROTOCOL_VERSION", "1.0"); return result.Produce(); }