50 |
Mutex LSCPServer::NotifyMutex = Mutex(); |
Mutex LSCPServer::NotifyMutex = Mutex(); |
51 |
Mutex LSCPServer::NotifyBufferMutex = Mutex(); |
Mutex LSCPServer::NotifyBufferMutex = Mutex(); |
52 |
Mutex LSCPServer::SubscriptionMutex = Mutex(); |
Mutex LSCPServer::SubscriptionMutex = Mutex(); |
53 |
|
Mutex LSCPServer::RTNotifyMutex = Mutex(); |
54 |
|
|
55 |
LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) { |
LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) { |
56 |
this->pSampler = pSampler; |
this->pSampler = pSampler; |
89 |
SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY); |
SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY); |
90 |
|
|
91 |
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
92 |
std::cerr << "LSCPServer: Could not bind server socket." << std::endl; |
std::cerr << "LSCPServer: Could not bind server socket, retrying for " << ToString(LSCP_SERVER_BIND_TIMEOUT) << " seconds..."; |
93 |
close(hSocket); |
for (int trial = 0; true; trial++) { // retry for LSCP_SERVER_BIND_TIMEOUT seconds |
94 |
//return -1; |
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
95 |
exit(EXIT_FAILURE); |
if (trial > LSCP_SERVER_BIND_TIMEOUT) { |
96 |
|
std::cerr << "gave up!" << std::endl; |
97 |
|
close(hSocket); |
98 |
|
//return -1; |
99 |
|
exit(EXIT_FAILURE); |
100 |
|
} |
101 |
|
else sleep(1); // sleep 1s |
102 |
|
} |
103 |
|
else break; // success |
104 |
|
} |
105 |
} |
} |
106 |
|
|
107 |
listen(hSocket, 1); |
listen(hSocket, 1); |
204 |
NotifyMutex.Unlock(); |
NotifyMutex.Unlock(); |
205 |
} |
} |
206 |
|
|
207 |
|
int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) { |
208 |
|
int subs = 0; |
209 |
|
SubscriptionMutex.Lock(); |
210 |
|
for( std::list<LSCPEvent::event_t>::iterator iter = events.begin(); |
211 |
|
iter != events.end(); iter++) |
212 |
|
{ |
213 |
|
subs += eventSubscriptions.count(*iter); |
214 |
|
} |
215 |
|
SubscriptionMutex.Unlock(); |
216 |
|
return subs; |
217 |
|
} |
218 |
|
|
219 |
void LSCPServer::SendLSCPNotify( LSCPEvent event ) { |
void LSCPServer::SendLSCPNotify( LSCPEvent event ) { |
220 |
SubscriptionMutex.Lock(); |
SubscriptionMutex.Lock(); |
221 |
if (eventSubscriptions.count(event.GetType()) == 0) { |
if (eventSubscriptions.count(event.GetType()) == 0) { |
474 |
else throw LinuxSamplerException("Unknown engine type"); |
else throw LinuxSamplerException("Unknown engine type"); |
475 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
476 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
477 |
|
LockRTNotify(); |
478 |
pSamplerChannel->LoadEngine(type); |
pSamplerChannel->LoadEngine(type); |
479 |
|
UnlockRTNotify(); |
480 |
} |
} |
481 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
482 |
result.Error(e); |
result.Error(e); |
527 |
String LSCPServer::RemoveChannel(uint uiSamplerChannel) { |
String LSCPServer::RemoveChannel(uint uiSamplerChannel) { |
528 |
dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
529 |
LSCPResultSet result; |
LSCPResultSet result; |
530 |
|
LockRTNotify(); |
531 |
pSampler->RemoveSamplerChannel(uiSamplerChannel); |
pSampler->RemoveSamplerChannel(uiSamplerChannel); |
532 |
|
UnlockRTNotify(); |
533 |
return result.Produce(); |
return result.Produce(); |
534 |
} |
} |
535 |
|
|
551 |
try { |
try { |
552 |
if ((EngineName == "GigEngine") || (EngineName == "gig")) { |
if ((EngineName == "GigEngine") || (EngineName == "gig")) { |
553 |
Engine* pEngine = new LinuxSampler::gig::Engine; |
Engine* pEngine = new LinuxSampler::gig::Engine; |
554 |
result.Add(pEngine->Description()); |
result.Add("DESCRIPTION", pEngine->Description()); |
555 |
result.Add(pEngine->Version()); |
result.Add("VERSION", pEngine->Version()); |
556 |
delete pEngine; |
delete pEngine; |
557 |
} |
} |
558 |
else throw LinuxSamplerException("Unknown engine type"); |
else throw LinuxSamplerException("Unknown engine type"); |
577 |
|
|
578 |
//Defaults values |
//Defaults values |
579 |
String EngineName = "NONE"; |
String EngineName = "NONE"; |
580 |
float Volume = 0; |
float Volume = 0.0f; |
581 |
String InstrumentFileName = "NONE"; |
String InstrumentFileName = "NONE"; |
582 |
int InstrumentIndex = -1; |
int InstrumentIndex = -1; |
583 |
int InstrumentStatus = -1; |
int InstrumentStatus = -1; |
584 |
|
int AudioOutputChannels = 0; |
585 |
|
String AudioRouting; |
586 |
|
|
587 |
if (pEngine) { |
if (pEngine) { |
588 |
EngineName = pEngine->EngineName(); |
EngineName = pEngine->EngineName(); |
589 |
|
AudioOutputChannels = pEngine->Channels(); |
590 |
Volume = pEngine->Volume(); |
Volume = pEngine->Volume(); |
591 |
InstrumentStatus = pEngine->InstrumentStatus(); |
InstrumentStatus = pEngine->InstrumentStatus(); |
592 |
InstrumentIndex = pEngine->InstrumentIndex(); |
InstrumentIndex = pEngine->InstrumentIndex(); |
593 |
if (InstrumentIndex != -1) |
if (InstrumentIndex != -1) |
594 |
InstrumentFileName = pEngine->InstrumentFileName(); |
InstrumentFileName = pEngine->InstrumentFileName(); |
595 |
|
for (int chan = 0; chan < pEngine->Channels(); chan++) { |
596 |
|
if (AudioRouting != "") AudioRouting += ","; |
597 |
|
AudioRouting += ToString(pEngine->OutputChannel(chan)); |
598 |
|
} |
599 |
} |
} |
600 |
|
|
601 |
result.Add("ENGINE_NAME", EngineName); |
result.Add("ENGINE_NAME", EngineName); |
603 |
|
|
604 |
//Some not-so-hardcoded stuff to make GUI look good |
//Some not-so-hardcoded stuff to make GUI look good |
605 |
result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice())); |
result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice())); |
606 |
result.Add("AUDIO_OUTPUT_CHANNELS", "2"); |
result.Add("AUDIO_OUTPUT_CHANNELS", AudioOutputChannels); |
607 |
result.Add("AUDIO_OUTPUT_ROUTING", "0,1"); |
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
608 |
|
|
609 |
result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice())); |
result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice())); |
610 |
result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort()); |
result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort()); |
611 |
result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); |
if (pSamplerChannel->GetMidiInputChannel() == MidiInputPort::midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL"); |
612 |
|
else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); |
613 |
|
|
614 |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
615 |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
769 |
} |
} |
770 |
|
|
771 |
String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) { |
String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) { |
772 |
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())); |
773 |
LSCPResultSet result; |
LSCPResultSet result; |
774 |
try { |
try { |
775 |
DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter); |
DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter); |
778 |
result.Add("MANDATORY", pParameter->Mandatory()); |
result.Add("MANDATORY", pParameter->Mandatory()); |
779 |
result.Add("FIX", pParameter->Fix()); |
result.Add("FIX", pParameter->Fix()); |
780 |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
781 |
if (pParameter->Depends()) result.Add("DEPENDS", *pParameter->Depends()); |
optional<String> oDepends = pParameter->Depends(); |
782 |
if (pParameter->Default()) result.Add("DEFAULT", *pParameter->Default()); |
optional<String> oDefault = pParameter->Default(DependencyList); |
783 |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", *pParameter->RangeMin()); |
optional<String> oRangeMin = pParameter->RangeMin(DependencyList); |
784 |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", *pParameter->RangeMax()); |
optional<String> oRangeMax = pParameter->RangeMax(DependencyList); |
785 |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities()); |
optional<String> oPossibilities = pParameter->Possibilities(DependencyList); |
786 |
|
if (oDepends) result.Add("DEPENDS", *oDepends); |
787 |
|
if (oDefault) result.Add("DEFAULT", *oDefault); |
788 |
|
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
789 |
|
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
790 |
|
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
791 |
} |
} |
792 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
793 |
result.Error(e); |
result.Error(e); |
796 |
} |
} |
797 |
|
|
798 |
String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) { |
String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) { |
799 |
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())); |
800 |
LSCPResultSet result; |
LSCPResultSet result; |
801 |
try { |
try { |
802 |
DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter); |
DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter); |
805 |
result.Add("MANDATORY", pParameter->Mandatory()); |
result.Add("MANDATORY", pParameter->Mandatory()); |
806 |
result.Add("FIX", pParameter->Fix()); |
result.Add("FIX", pParameter->Fix()); |
807 |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
808 |
if (pParameter->Depends()) result.Add("DEPENDS", *pParameter->Depends()); |
optional<String> oDepends = pParameter->Depends(); |
809 |
if (pParameter->Default()) result.Add("DEFAULT", *pParameter->Default()); |
optional<String> oDefault = pParameter->Default(DependencyList); |
810 |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", *pParameter->RangeMin()); |
optional<String> oRangeMin = pParameter->RangeMin(DependencyList); |
811 |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", *pParameter->RangeMax()); |
optional<String> oRangeMax = pParameter->RangeMax(DependencyList); |
812 |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities()); |
optional<String> oPossibilities = pParameter->Possibilities(DependencyList); |
813 |
|
if (oDepends) result.Add("DEPENDS", *oDepends); |
814 |
|
if (oDefault) result.Add("DEFAULT", *oDefault); |
815 |
|
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
816 |
|
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
817 |
|
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
818 |
} |
} |
819 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
820 |
result.Error(e); |
result.Error(e); |
1134 |
*/ |
*/ |
1135 |
String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) { |
String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) { |
1136 |
dmsg(2,("LSCPServer: SetAudioOutputChannel(ChannelAudioOutputChannel=%d, AudioOutputDeviceInputChannel=%d, SamplerChannel=%d)\n",ChannelAudioOutputChannel,AudioOutputDeviceInputChannel,uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetAudioOutputChannel(ChannelAudioOutputChannel=%d, AudioOutputDeviceInputChannel=%d, SamplerChannel=%d)\n",ChannelAudioOutputChannel,AudioOutputDeviceInputChannel,uiSamplerChannel)); |
1137 |
return "ERR:0:Not implemented yet.\r\n"; //FIXME: Add support for this in resultset class? |
LSCPResultSet result; |
1138 |
|
try { |
1139 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1140 |
|
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
1141 |
|
Engine* pEngine = pSamplerChannel->GetEngine(); |
1142 |
|
if (!pEngine) throw LinuxSamplerException("No engine deployed on sampler channel " + ToString(uiSamplerChannel)); |
1143 |
|
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1144 |
|
if (!devices.count(ChannelAudioOutputChannel)) throw LinuxSamplerException("There is no audio output device with index " + ToString(ChannelAudioOutputChannel)); |
1145 |
|
pEngine->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel); |
1146 |
|
} |
1147 |
|
catch (LinuxSamplerException e) { |
1148 |
|
result.Error(e); |
1149 |
|
} |
1150 |
|
return result.Produce(); |
1151 |
} |
} |
1152 |
|
|
1153 |
String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) { |
String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) { |
1174 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1175 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
1176 |
// Driver type name aliasing... |
// Driver type name aliasing... |
1177 |
if (AudioOutputDriver == "ALSA") AudioOutputDriver = "Alsa"; |
if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA"; |
1178 |
if (AudioOutputDriver == "JACK") AudioOutputDriver = "Jack"; |
if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK"; |
1179 |
// Check if there's one audio output device already created |
// Check if there's one audio output device already created |
1180 |
// for the intended audio driver type (AudioOutputDriver)... |
// for the intended audio driver type (AudioOutputDriver)... |
1181 |
AudioOutputDevice *pDevice = NULL; |
AudioOutputDevice *pDevice = NULL; |
1256 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1257 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
1258 |
// Driver type name aliasing... |
// Driver type name aliasing... |
1259 |
if (MidiInputDriver == "ALSA") MidiInputDriver = "Alsa"; |
if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA"; |
1260 |
// Check if there's one MIDI input device already created |
// Check if there's one MIDI input device already created |
1261 |
// for the intended MIDI driver type (MidiInputDriver)... |
// for the intended MIDI driver type (MidiInputDriver)... |
1262 |
MidiInputDevice *pDevice = NULL; |
MidiInputDevice *pDevice = NULL; |
1313 |
* Will be called by the parser to change the global volume factor on a |
* Will be called by the parser to change the global volume factor on a |
1314 |
* particular sampler channel. |
* particular sampler channel. |
1315 |
*/ |
*/ |
1316 |
String LSCPServer::SetVolume(double Volume, uint uiSamplerChannel) { |
String LSCPServer::SetVolume(double dVolume, uint uiSamplerChannel) { |
1317 |
dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel)); |
1318 |
LSCPResultSet result; |
LSCPResultSet result; |
1319 |
try { |
try { |
1320 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1321 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
1322 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
1323 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
1324 |
pEngine->Volume(Volume); |
pEngine->Volume(dVolume); |
1325 |
} |
} |
1326 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1327 |
result.Error(e); |
result.Error(e); |