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_channel_count, "CHANNEL_COUNT"); |
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"); |
101 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
102 |
} |
} |
103 |
|
|
|
SocketAddress.sin_family = AF_INET; |
|
|
SocketAddress.sin_port = htons(LSCP_PORT); |
|
|
SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY); |
|
|
|
|
104 |
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
105 |
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..."; |
106 |
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 |
190 |
} |
} |
191 |
} |
} |
192 |
|
|
193 |
|
// check if some engine channel's parameter / status changed, if so notify the respective LSCP event subscribers |
194 |
|
{ |
195 |
|
std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances(); |
196 |
|
std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin(); |
197 |
|
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
198 |
|
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
199 |
|
if ((*itEngineChannel)->StatusChanged()) { |
200 |
|
SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex)); |
201 |
|
} |
202 |
|
} |
203 |
|
} |
204 |
|
|
205 |
//Now let's deliver late notifies (if any) |
//Now let's deliver late notifies (if any) |
206 |
NotifyBufferMutex.Lock(); |
NotifyBufferMutex.Lock(); |
207 |
for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) { |
for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) { |
590 |
Engine* pEngine = EngineFactory::Create(EngineName); |
Engine* pEngine = EngineFactory::Create(EngineName); |
591 |
result.Add("DESCRIPTION", pEngine->Description()); |
result.Add("DESCRIPTION", pEngine->Description()); |
592 |
result.Add("VERSION", pEngine->Version()); |
result.Add("VERSION", pEngine->Version()); |
593 |
delete pEngine; |
EngineFactory::Destroy(pEngine); |
594 |
} |
} |
595 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
596 |
result.Error(e); |
result.Error(e); |
672 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
673 |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
674 |
if (!pEngineChannel) throw LinuxSamplerException("No engine loaded on sampler channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine loaded on sampler channel"); |
675 |
|
if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel"); |
676 |
result.Add(pEngineChannel->GetEngine()->VoiceCount()); |
result.Add(pEngineChannel->GetEngine()->VoiceCount()); |
677 |
} |
} |
678 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
693 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
694 |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
695 |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
696 |
|
if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel"); |
697 |
result.Add(pEngineChannel->GetEngine()->DiskStreamCount()); |
result.Add(pEngineChannel->GetEngine()->DiskStreamCount()); |
698 |
} |
} |
699 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
714 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
715 |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
716 |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
717 |
|
if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel"); |
718 |
if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA"); |
if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA"); |
719 |
else { |
else { |
720 |
switch (ResponseType) { |
switch (ResponseType) { |
1406 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1407 |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
1408 |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
1409 |
|
if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel"); |
1410 |
pEngineChannel->GetEngine()->Reset(); |
pEngineChannel->GetEngine()->Reset(); |
1411 |
} |
} |
1412 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1425 |
return result.Produce(); |
return result.Produce(); |
1426 |
} |
} |
1427 |
|
|
1428 |
|
/** |
1429 |
|
* Will be called by the parser to return general informations about this |
1430 |
|
* sampler. |
1431 |
|
*/ |
1432 |
|
String LSCPServer::GetServerInfo() { |
1433 |
|
dmsg(2,("LSCPServer: GetServerInfo()\n")); |
1434 |
|
LSCPResultSet result; |
1435 |
|
result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler"); |
1436 |
|
result.Add("VERSION", VERSION); |
1437 |
|
result.Add("PROTOCOL_VERSION", "1.0"); |
1438 |
|
return result.Produce(); |
1439 |
|
} |
1440 |
|
|
1441 |
/** |
/** |
1442 |
* 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 |
1443 |
* server for receiving event messages. |
* server for receiving event messages. |