33 |
#endif |
#endif |
34 |
|
|
35 |
#include "../engines/EngineFactory.h" |
#include "../engines/EngineFactory.h" |
36 |
|
#include "../engines/EngineChannelFactory.h" |
37 |
#include "../drivers/audio/AudioOutputDeviceFactory.h" |
#include "../drivers/audio/AudioOutputDeviceFactory.h" |
38 |
#include "../drivers/midi/MidiInputDeviceFactory.h" |
#include "../drivers/midi/MidiInputDeviceFactory.h" |
39 |
|
|
61 |
Mutex LSCPServer::SubscriptionMutex = Mutex(); |
Mutex LSCPServer::SubscriptionMutex = Mutex(); |
62 |
Mutex LSCPServer::RTNotifyMutex = Mutex(); |
Mutex LSCPServer::RTNotifyMutex = Mutex(); |
63 |
|
|
64 |
LSCPServer::LSCPServer(Sampler* pSampler) : Thread(true, false, 0, -4) { |
LSCPServer::LSCPServer(Sampler* pSampler, long int addr, short int port) : Thread(true, false, 0, -4) { |
65 |
|
SocketAddress.sin_family = AF_INET; |
66 |
|
SocketAddress.sin_addr.s_addr = addr; |
67 |
|
SocketAddress.sin_port = port; |
68 |
this->pSampler = pSampler; |
this->pSampler = pSampler; |
69 |
LSCPEvent::RegisterEvent(LSCPEvent::event_channels, "CHANNELS"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_channel_count, "CHANNEL_COUNT"); |
70 |
LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT"); |
71 |
LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT"); |
72 |
LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL"); |
73 |
LSCPEvent::RegisterEvent(LSCPEvent::event_info, "INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_channel_info, "CHANNEL_INFO"); |
74 |
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
75 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT"); |
76 |
hSocket = -1; |
hSocket = -1; |
77 |
} |
} |
78 |
|
|
102 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
103 |
} |
} |
104 |
|
|
|
SocketAddress.sin_family = AF_INET; |
|
|
SocketAddress.sin_port = htons(LSCP_PORT); |
|
|
SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY); |
|
|
|
|
105 |
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
106 |
std::cerr << "LSCPServer: Could not bind server socket, retrying for " << ToString(LSCP_SERVER_BIND_TIMEOUT) << " seconds..."; |
std::cerr << "LSCPServer: Could not bind server socket, retrying for " << ToString(LSCP_SERVER_BIND_TIMEOUT) << " seconds..."; |
107 |
for (int trial = 0; true; trial++) { // retry for LSCP_SERVER_BIND_TIMEOUT seconds |
for (int trial = 0; true; trial++) { // retry for LSCP_SERVER_BIND_TIMEOUT seconds |
128 |
FD_SET(hSocket, &fdSet); |
FD_SET(hSocket, &fdSet); |
129 |
int maxSessions = hSocket; |
int maxSessions = hSocket; |
130 |
|
|
131 |
|
timeval timeout; |
132 |
|
|
133 |
while (true) { |
while (true) { |
134 |
fd_set selectSet = fdSet; |
// check if some engine channel's parameter / status changed, if so notify the respective LSCP event subscribers |
135 |
int retval = select(maxSessions+1, &selectSet, NULL, NULL, NULL); |
{ |
136 |
|
std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances(); |
137 |
|
std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin(); |
138 |
|
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
139 |
|
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
140 |
|
if ((*itEngineChannel)->StatusChanged()) { |
141 |
|
SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex)); |
142 |
|
} |
143 |
|
} |
144 |
|
} |
145 |
|
|
146 |
|
//Now let's deliver late notifies (if any) |
147 |
|
NotifyBufferMutex.Lock(); |
148 |
|
for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) { |
149 |
|
#ifdef MSG_NOSIGNAL |
150 |
|
send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), MSG_NOSIGNAL); |
151 |
|
#else |
152 |
|
send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0); |
153 |
|
#endif |
154 |
|
} |
155 |
|
bufferedNotifies.clear(); |
156 |
|
NotifyBufferMutex.Unlock(); |
157 |
|
|
158 |
|
fd_set selectSet = fdSet; |
159 |
|
timeout.tv_sec = 0; |
160 |
|
timeout.tv_usec = 100000; |
161 |
|
|
162 |
|
int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout); |
163 |
|
|
164 |
if (retval == 0) |
if (retval == 0) |
165 |
continue; //Nothing try again |
continue; //Nothing try again |
166 |
if (retval == -1) { |
if (retval == -1) { |
220 |
break; |
break; |
221 |
} |
} |
222 |
} |
} |
|
|
|
|
//Now let's deliver late notifies (if any) |
|
|
NotifyBufferMutex.Lock(); |
|
|
for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) { |
|
|
send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0); |
|
|
bufferedNotifies.erase(iterNotify); |
|
|
} |
|
|
NotifyBufferMutex.Unlock(); |
|
223 |
} |
} |
224 |
} |
} |
225 |
|
|
266 |
while (true) { |
while (true) { |
267 |
if (NotifyMutex.Trylock()) { |
if (NotifyMutex.Trylock()) { |
268 |
for(;iter != end; iter++) |
for(;iter != end; iter++) |
269 |
|
#ifdef MSG_NOSIGNAL |
270 |
|
send(*iter, notify.c_str(), notify.size(), MSG_NOSIGNAL); |
271 |
|
#else |
272 |
send(*iter, notify.c_str(), notify.size(), 0); |
send(*iter, notify.c_str(), notify.size(), 0); |
273 |
|
#endif |
274 |
NotifyMutex.Unlock(); |
NotifyMutex.Unlock(); |
275 |
break; |
break; |
276 |
} else { |
} else { |
379 |
dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str())); |
dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str())); |
380 |
if (currentSocket != -1) { |
if (currentSocket != -1) { |
381 |
NotifyMutex.Lock(); |
NotifyMutex.Lock(); |
382 |
|
#ifdef MSG_NOSIGNAL |
383 |
|
send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), MSG_NOSIGNAL); |
384 |
|
#else |
385 |
send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0); |
send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0); |
386 |
|
#endif |
387 |
NotifyMutex.Unlock(); |
NotifyMutex.Unlock(); |
388 |
} |
} |
389 |
} |
} |
516 |
* sampler channel. |
* sampler channel. |
517 |
*/ |
*/ |
518 |
String LSCPServer::SetEngineType(String EngineName, uint uiSamplerChannel) { |
String LSCPServer::SetEngineType(String EngineName, uint uiSamplerChannel) { |
519 |
dmsg(2,("LSCPServer: LoadEngine(EngineName=%s,SamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetEngineType(EngineName=%s,uiSamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel)); |
520 |
LSCPResultSet result; |
LSCPResultSet result; |
521 |
try { |
try { |
522 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
523 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
524 |
LockRTNotify(); |
LockRTNotify(); |
525 |
pSamplerChannel->SetEngineType(EngineName); |
pSamplerChannel->SetEngineType(EngineName); |
526 |
|
if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1); |
527 |
UnlockRTNotify(); |
UnlockRTNotify(); |
528 |
} |
} |
529 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
564 |
*/ |
*/ |
565 |
String LSCPServer::AddChannel() { |
String LSCPServer::AddChannel() { |
566 |
dmsg(2,("LSCPServer: AddChannel()\n")); |
dmsg(2,("LSCPServer: AddChannel()\n")); |
567 |
|
LockRTNotify(); |
568 |
SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel(); |
SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel(); |
569 |
|
UnlockRTNotify(); |
570 |
LSCPResultSet result(pSamplerChannel->Index()); |
LSCPResultSet result(pSamplerChannel->Index()); |
571 |
return result.Produce(); |
return result.Produce(); |
572 |
} |
} |
584 |
} |
} |
585 |
|
|
586 |
/** |
/** |
587 |
* Will be called by the parser to get all available engines. |
* Will be called by the parser to get the amount of all available engines. |
588 |
*/ |
*/ |
589 |
String LSCPServer::GetAvailableEngines() { |
String LSCPServer::GetAvailableEngines() { |
590 |
dmsg(2,("LSCPServer: GetAvailableEngines()\n")); |
dmsg(2,("LSCPServer: GetAvailableEngines()\n")); |
591 |
LSCPResultSet result("GigEngine"); |
LSCPResultSet result("1"); |
592 |
|
return result.Produce(); |
593 |
|
} |
594 |
|
|
595 |
|
/** |
596 |
|
* Will be called by the parser to get a list of all available engines. |
597 |
|
*/ |
598 |
|
String LSCPServer::ListAvailableEngines() { |
599 |
|
dmsg(2,("LSCPServer: ListAvailableEngines()\n")); |
600 |
|
LSCPResultSet result("\'GIG\'"); |
601 |
return result.Produce(); |
return result.Produce(); |
602 |
} |
} |
603 |
|
|
608 |
String LSCPServer::GetEngineInfo(String EngineName) { |
String LSCPServer::GetEngineInfo(String EngineName) { |
609 |
dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str())); |
dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str())); |
610 |
LSCPResultSet result; |
LSCPResultSet result; |
611 |
|
LockRTNotify(); |
612 |
try { |
try { |
613 |
Engine* pEngine = EngineFactory::Create(EngineName); |
Engine* pEngine = EngineFactory::Create(EngineName); |
614 |
result.Add("DESCRIPTION", pEngine->Description()); |
result.Add("DESCRIPTION", pEngine->Description()); |
615 |
result.Add("VERSION", pEngine->Version()); |
result.Add("VERSION", pEngine->Version()); |
616 |
delete pEngine; |
EngineFactory::Destroy(pEngine); |
617 |
} |
} |
618 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
619 |
result.Error(e); |
result.Error(e); |
620 |
} |
} |
621 |
|
UnlockRTNotify(); |
622 |
return result.Produce(); |
return result.Produce(); |
623 |
} |
} |
624 |
|
|
643 |
int InstrumentStatus = -1; |
int InstrumentStatus = -1; |
644 |
int AudioOutputChannels = 0; |
int AudioOutputChannels = 0; |
645 |
String AudioRouting; |
String AudioRouting; |
646 |
|
int Mute = 0; |
647 |
|
bool Solo = false; |
648 |
|
|
649 |
if (pEngineChannel) { |
if (pEngineChannel) { |
650 |
EngineName = pEngineChannel->EngineName(); |
EngineName = pEngineChannel->EngineName(); |
660 |
if (AudioRouting != "") AudioRouting += ","; |
if (AudioRouting != "") AudioRouting += ","; |
661 |
AudioRouting += ToString(pEngineChannel->OutputChannel(chan)); |
AudioRouting += ToString(pEngineChannel->OutputChannel(chan)); |
662 |
} |
} |
663 |
|
Mute = pEngineChannel->GetMute(); |
664 |
|
Solo = pEngineChannel->GetSolo(); |
665 |
} |
} |
666 |
|
|
667 |
result.Add("ENGINE_NAME", EngineName); |
result.Add("ENGINE_NAME", EngineName); |
674 |
|
|
675 |
result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice())); |
result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice())); |
676 |
result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort()); |
result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort()); |
677 |
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"); |
678 |
else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); |
else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); |
679 |
|
|
680 |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
681 |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
682 |
result.Add("INSTRUMENT_NAME", InstrumentName); |
result.Add("INSTRUMENT_NAME", InstrumentName); |
683 |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
684 |
|
result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false")); |
685 |
|
result.Add("SOLO", Solo); |
686 |
} |
} |
687 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
688 |
result.Error(e); |
result.Error(e); |
702 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
703 |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
704 |
if (!pEngineChannel) throw LinuxSamplerException("No engine loaded on sampler channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine loaded on sampler channel"); |
705 |
|
if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel"); |
706 |
result.Add(pEngineChannel->GetEngine()->VoiceCount()); |
result.Add(pEngineChannel->GetEngine()->VoiceCount()); |
707 |
} |
} |
708 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
723 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
724 |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
725 |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
726 |
|
if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel"); |
727 |
result.Add(pEngineChannel->GetEngine()->DiskStreamCount()); |
result.Add(pEngineChannel->GetEngine()->DiskStreamCount()); |
728 |
} |
} |
729 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
744 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
745 |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
746 |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
747 |
|
if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel"); |
748 |
if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA"); |
if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA"); |
749 |
else { |
else { |
750 |
switch (ResponseType) { |
switch (ResponseType) { |
769 |
dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n")); |
dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n")); |
770 |
LSCPResultSet result; |
LSCPResultSet result; |
771 |
try { |
try { |
772 |
|
int n = AudioOutputDeviceFactory::AvailableDrivers().size(); |
773 |
|
result.Add(n); |
774 |
|
} |
775 |
|
catch (LinuxSamplerException e) { |
776 |
|
result.Error(e); |
777 |
|
} |
778 |
|
return result.Produce(); |
779 |
|
} |
780 |
|
|
781 |
|
String LSCPServer::ListAvailableAudioOutputDrivers() { |
782 |
|
dmsg(2,("LSCPServer: ListAvailableAudioOutputDrivers()\n")); |
783 |
|
LSCPResultSet result; |
784 |
|
try { |
785 |
String s = AudioOutputDeviceFactory::AvailableDriversAsString(); |
String s = AudioOutputDeviceFactory::AvailableDriversAsString(); |
786 |
result.Add(s); |
result.Add(s); |
787 |
} |
} |
795 |
dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n")); |
dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n")); |
796 |
LSCPResultSet result; |
LSCPResultSet result; |
797 |
try { |
try { |
798 |
|
int n = MidiInputDeviceFactory::AvailableDrivers().size(); |
799 |
|
result.Add(n); |
800 |
|
} |
801 |
|
catch (LinuxSamplerException e) { |
802 |
|
result.Error(e); |
803 |
|
} |
804 |
|
return result.Produce(); |
805 |
|
} |
806 |
|
|
807 |
|
String LSCPServer::ListAvailableMidiInputDrivers() { |
808 |
|
dmsg(2,("LSCPServer: ListAvailableMidiInputDrivers()\n")); |
809 |
|
LSCPResultSet result; |
810 |
|
try { |
811 |
String s = MidiInputDeviceFactory::AvailableDriversAsString(); |
String s = MidiInputDeviceFactory::AvailableDriversAsString(); |
812 |
result.Add(s); |
result.Add(s); |
813 |
} |
} |
1249 |
String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) { |
String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) { |
1250 |
dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel)); |
1251 |
LSCPResultSet result; |
LSCPResultSet result; |
1252 |
|
LockRTNotify(); |
1253 |
try { |
try { |
1254 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1255 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1261 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1262 |
result.Error(e); |
result.Error(e); |
1263 |
} |
} |
1264 |
|
UnlockRTNotify(); |
1265 |
return result.Produce(); |
return result.Produce(); |
1266 |
} |
} |
1267 |
|
|
1268 |
String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) { |
String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) { |
1269 |
dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel)); |
1270 |
LSCPResultSet result; |
LSCPResultSet result; |
1271 |
|
LockRTNotify(); |
1272 |
try { |
try { |
1273 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1274 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1300 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1301 |
result.Error(e); |
result.Error(e); |
1302 |
} |
} |
1303 |
|
UnlockRTNotify(); |
1304 |
return result.Produce(); |
return result.Produce(); |
1305 |
} |
} |
1306 |
|
|
1324 |
try { |
try { |
1325 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1326 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1327 |
pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel); |
pSamplerChannel->SetMidiInputChannel((midi_chan_t) MIDIChannel); |
1328 |
} |
} |
1329 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1330 |
result.Error(e); |
result.Error(e); |
1401 |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1402 |
if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
1403 |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
1404 |
pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (MidiInputPort::midi_chan_t) MIDIChannel); |
pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (midi_chan_t) MIDIChannel); |
1405 |
} |
} |
1406 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1407 |
result.Error(e); |
result.Error(e); |
1430 |
} |
} |
1431 |
|
|
1432 |
/** |
/** |
1433 |
|
* Will be called by the parser to mute/unmute particular sampler channel. |
1434 |
|
*/ |
1435 |
|
String LSCPServer::SetChannelMute(bool bMute, uint uiSamplerChannel) { |
1436 |
|
dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel)); |
1437 |
|
LSCPResultSet result; |
1438 |
|
try { |
1439 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1440 |
|
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1441 |
|
|
1442 |
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
1443 |
|
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
1444 |
|
|
1445 |
|
if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0); |
1446 |
|
else pEngineChannel->SetMute(1); |
1447 |
|
} catch (LinuxSamplerException e) { |
1448 |
|
result.Error(e); |
1449 |
|
} |
1450 |
|
return result.Produce(); |
1451 |
|
} |
1452 |
|
|
1453 |
|
/** |
1454 |
|
* Will be called by the parser to solo particular sampler channel. |
1455 |
|
*/ |
1456 |
|
String LSCPServer::SetChannelSolo(bool bSolo, uint uiSamplerChannel) { |
1457 |
|
dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel)); |
1458 |
|
LSCPResultSet result; |
1459 |
|
try { |
1460 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1461 |
|
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1462 |
|
|
1463 |
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
1464 |
|
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
1465 |
|
|
1466 |
|
bool oldSolo = pEngineChannel->GetSolo(); |
1467 |
|
bool hadSoloChannel = HasSoloChannel(); |
1468 |
|
|
1469 |
|
pEngineChannel->SetSolo(bSolo); |
1470 |
|
|
1471 |
|
if(!oldSolo && bSolo) { |
1472 |
|
if(pEngineChannel->GetMute() == -1) pEngineChannel->SetMute(0); |
1473 |
|
if(!hadSoloChannel) MuteNonSoloChannels(); |
1474 |
|
} |
1475 |
|
|
1476 |
|
if(oldSolo && !bSolo) { |
1477 |
|
if(!HasSoloChannel()) UnmuteChannels(); |
1478 |
|
else if(!pEngineChannel->GetMute()) pEngineChannel->SetMute(-1); |
1479 |
|
} |
1480 |
|
} catch (LinuxSamplerException e) { |
1481 |
|
result.Error(e); |
1482 |
|
} |
1483 |
|
return result.Produce(); |
1484 |
|
} |
1485 |
|
|
1486 |
|
/** |
1487 |
|
* Determines whether there is at least one solo channel in the channel list. |
1488 |
|
* |
1489 |
|
* @returns true if there is at least one solo channel in the channel list, |
1490 |
|
* false otherwise. |
1491 |
|
*/ |
1492 |
|
bool LSCPServer::HasSoloChannel() { |
1493 |
|
std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels(); |
1494 |
|
std::map<uint,SamplerChannel*>::iterator iter = channels.begin(); |
1495 |
|
for (; iter != channels.end(); iter++) { |
1496 |
|
EngineChannel* c = iter->second->GetEngineChannel(); |
1497 |
|
if(c && c->GetSolo()) return true; |
1498 |
|
} |
1499 |
|
|
1500 |
|
return false; |
1501 |
|
} |
1502 |
|
|
1503 |
|
/** |
1504 |
|
* Mutes all unmuted non-solo channels. Notice that the channels are muted |
1505 |
|
* with -1 which indicates that they are muted because of the presence |
1506 |
|
* of a solo channel(s). Channels muted with -1 will be automatically unmuted |
1507 |
|
* when there are no solo channels left. |
1508 |
|
*/ |
1509 |
|
void LSCPServer::MuteNonSoloChannels() { |
1510 |
|
dmsg(2,("LSCPServer: MuteNonSoloChannels()\n")); |
1511 |
|
std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels(); |
1512 |
|
std::map<uint,SamplerChannel*>::iterator iter = channels.begin(); |
1513 |
|
for (; iter != channels.end(); iter++) { |
1514 |
|
EngineChannel* c = iter->second->GetEngineChannel(); |
1515 |
|
if(c && !c->GetSolo() && !c->GetMute()) c->SetMute(-1); |
1516 |
|
} |
1517 |
|
} |
1518 |
|
|
1519 |
|
/** |
1520 |
|
* Unmutes all channels that are muted because of the presence |
1521 |
|
* of a solo channel(s). |
1522 |
|
*/ |
1523 |
|
void LSCPServer::UnmuteChannels() { |
1524 |
|
dmsg(2,("LSCPServer: UnmuteChannels()\n")); |
1525 |
|
std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels(); |
1526 |
|
std::map<uint,SamplerChannel*>::iterator iter = channels.begin(); |
1527 |
|
for (; iter != channels.end(); iter++) { |
1528 |
|
EngineChannel* c = iter->second->GetEngineChannel(); |
1529 |
|
if(c && c->GetMute() == -1) c->SetMute(0); |
1530 |
|
} |
1531 |
|
} |
1532 |
|
|
1533 |
|
/** |
1534 |
* Will be called by the parser to reset a particular sampler channel. |
* Will be called by the parser to reset a particular sampler channel. |
1535 |
*/ |
*/ |
1536 |
String LSCPServer::ResetChannel(uint uiSamplerChannel) { |
String LSCPServer::ResetChannel(uint uiSamplerChannel) { |
1541 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1542 |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
1543 |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
1544 |
pEngineChannel->GetEngine()->Reset(); |
pEngineChannel->Reset(); |
1545 |
} |
} |
1546 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1547 |
result.Error(e); |
result.Error(e); |
1559 |
return result.Produce(); |
return result.Produce(); |
1560 |
} |
} |
1561 |
|
|
1562 |
|
/** |
1563 |
|
* Will be called by the parser to return general informations about this |
1564 |
|
* sampler. |
1565 |
|
*/ |
1566 |
|
String LSCPServer::GetServerInfo() { |
1567 |
|
dmsg(2,("LSCPServer: GetServerInfo()\n")); |
1568 |
|
LSCPResultSet result; |
1569 |
|
result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler"); |
1570 |
|
result.Add("VERSION", VERSION); |
1571 |
|
result.Add("PROTOCOL_VERSION", "1.0"); |
1572 |
|
return result.Produce(); |
1573 |
|
} |
1574 |
|
|
1575 |
|
/** |
1576 |
|
* Will be called by the parser to return the current number of all active voices. |
1577 |
|
*/ |
1578 |
|
String LSCPServer::GetTotalVoiceCount() { |
1579 |
|
dmsg(2,("LSCPServer: GetTotalVoiceCount()\n")); |
1580 |
|
LSCPResultSet result; |
1581 |
|
result.Add(pSampler->GetVoiceCount()); |
1582 |
|
return result.Produce(); |
1583 |
|
} |
1584 |
|
|
1585 |
|
/** |
1586 |
|
* Will be called by the parser to return the maximum number of voices. |
1587 |
|
*/ |
1588 |
|
String LSCPServer::GetTotalVoiceCountMax() { |
1589 |
|
dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n")); |
1590 |
|
LSCPResultSet result; |
1591 |
|
result.Add(EngineFactory::EngineInstances().size() * CONFIG_MAX_VOICES); |
1592 |
|
return result.Produce(); |
1593 |
|
} |
1594 |
|
|
1595 |
/** |
/** |
1596 |
* Will be called by the parser to subscribe a client (frontend) on the |
* Will be called by the parser to subscribe a client (frontend) on the |
1597 |
* server for receiving event messages. |
* server for receiving event messages. |