3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005 - 2008 Christian Schoenebeck * |
* Copyright (C) 2005 - 2013 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This library is free software; you can redistribute it and/or modify * |
* This library is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
24 |
#include <algorithm> |
#include <algorithm> |
25 |
#include <string> |
#include <string> |
26 |
|
|
27 |
|
#include "../common/File.h" |
28 |
#include "lscpserver.h" |
#include "lscpserver.h" |
29 |
#include "lscpresultset.h" |
#include "lscpresultset.h" |
30 |
#include "lscpevent.h" |
#include "lscpevent.h" |
43 |
#include "../engines/EngineChannelFactory.h" |
#include "../engines/EngineChannelFactory.h" |
44 |
#include "../drivers/audio/AudioOutputDeviceFactory.h" |
#include "../drivers/audio/AudioOutputDeviceFactory.h" |
45 |
#include "../drivers/midi/MidiInputDeviceFactory.h" |
#include "../drivers/midi/MidiInputDeviceFactory.h" |
46 |
|
#include "../effects/EffectFactory.h" |
47 |
|
|
48 |
namespace LinuxSampler { |
namespace LinuxSampler { |
49 |
|
|
97 |
*/ |
*/ |
98 |
fd_set LSCPServer::fdSet; |
fd_set LSCPServer::fdSet; |
99 |
int LSCPServer::currentSocket = -1; |
int LSCPServer::currentSocket = -1; |
100 |
std::vector<yyparse_param_t> LSCPServer::Sessions = std::vector<yyparse_param_t>(); |
std::vector<yyparse_param_t> LSCPServer::Sessions; |
101 |
std::vector<yyparse_param_t>::iterator itCurrentSession = std::vector<yyparse_param_t>::iterator(); |
std::vector<yyparse_param_t>::iterator itCurrentSession; |
102 |
std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>(); |
std::map<int,String> LSCPServer::bufferedNotifies; |
103 |
std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>(); |
std::map<int,String> LSCPServer::bufferedCommands; |
104 |
std::map< LSCPEvent::event_t, std::list<int> > LSCPServer::eventSubscriptions = std::map< LSCPEvent::event_t, std::list<int> >(); |
std::map< LSCPEvent::event_t, std::list<int> > LSCPServer::eventSubscriptions; |
105 |
Mutex LSCPServer::NotifyMutex = Mutex(); |
Mutex LSCPServer::NotifyMutex; |
106 |
Mutex LSCPServer::NotifyBufferMutex = Mutex(); |
Mutex LSCPServer::NotifyBufferMutex; |
107 |
Mutex LSCPServer::SubscriptionMutex = Mutex(); |
Mutex LSCPServer::SubscriptionMutex; |
108 |
Mutex LSCPServer::RTNotifyMutex = Mutex(); |
Mutex LSCPServer::RTNotifyMutex; |
109 |
|
|
110 |
LSCPServer::LSCPServer(Sampler* pSampler, long int addr, short int port) : Thread(true, false, 0, -4), eventHandler(this) { |
LSCPServer::LSCPServer(Sampler* pSampler, long int addr, short int port) : Thread(true, false, 0, -4), eventHandler(this) { |
111 |
SocketAddress.sin_family = AF_INET; |
SocketAddress.sin_family = AF_INET; |
138 |
LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); |
139 |
LSCPEvent::RegisterEvent(LSCPEvent::event_channel_midi, "CHANNEL_MIDI"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_channel_midi, "CHANNEL_MIDI"); |
140 |
LSCPEvent::RegisterEvent(LSCPEvent::event_device_midi, "DEVICE_MIDI"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_device_midi, "DEVICE_MIDI"); |
141 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_fx_instance_count, "EFFECT_INSTANCE_COUNT"); |
142 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_fx_instance_info, "EFFECT_INSTANCE_INFO"); |
143 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_send_fx_chain_count, "SEND_EFFECT_CHAIN_COUNT"); |
144 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_send_fx_chain_info, "SEND_EFFECT_CHAIN_INFO"); |
145 |
hSocket = -1; |
hSocket = -1; |
146 |
} |
} |
147 |
|
|
148 |
LSCPServer::~LSCPServer() { |
LSCPServer::~LSCPServer() { |
149 |
|
CloseAllConnections(); |
150 |
|
InstrumentManager::StopBackgroundThread(); |
151 |
#if defined(WIN32) |
#if defined(WIN32) |
152 |
if (hSocket >= 0) closesocket(hSocket); |
if (hSocket >= 0) closesocket(hSocket); |
153 |
#else |
#else |
342 |
} |
} |
343 |
#endif // HAVE_SQLITE3 |
#endif // HAVE_SQLITE3 |
344 |
|
|
345 |
|
void LSCPServer::RemoveListeners() { |
346 |
|
pSampler->RemoveChannelCountListener(&eventHandler); |
347 |
|
pSampler->RemoveAudioDeviceCountListener(&eventHandler); |
348 |
|
pSampler->RemoveMidiDeviceCountListener(&eventHandler); |
349 |
|
pSampler->RemoveVoiceCountListener(&eventHandler); |
350 |
|
pSampler->RemoveStreamCountListener(&eventHandler); |
351 |
|
pSampler->RemoveBufferFillListener(&eventHandler); |
352 |
|
pSampler->RemoveTotalStreamCountListener(&eventHandler); |
353 |
|
pSampler->RemoveTotalVoiceCountListener(&eventHandler); |
354 |
|
pSampler->RemoveFxSendCountListener(&eventHandler); |
355 |
|
MidiInstrumentMapper::RemoveMidiInstrumentCountListener(&eventHandler); |
356 |
|
MidiInstrumentMapper::RemoveMidiInstrumentInfoListener(&eventHandler); |
357 |
|
MidiInstrumentMapper::RemoveMidiInstrumentMapCountListener(&eventHandler); |
358 |
|
MidiInstrumentMapper::RemoveMidiInstrumentMapInfoListener(&eventHandler); |
359 |
|
#if HAVE_SQLITE3 |
360 |
|
InstrumentsDb::GetInstrumentsDb()->RemoveInstrumentsDbListener(&dbInstrumentsEventHandler); |
361 |
|
#endif |
362 |
|
} |
363 |
|
|
364 |
/** |
/** |
365 |
* Blocks the calling thread until the LSCP Server is initialized and |
* Blocks the calling thread until the LSCP Server is initialized and |
447 |
#endif |
#endif |
448 |
// check if some engine channel's parameter / status changed, if so notify the respective LSCP event subscribers |
// check if some engine channel's parameter / status changed, if so notify the respective LSCP event subscribers |
449 |
{ |
{ |
450 |
|
LockGuard lock(EngineChannelFactory::EngineChannelsMutex); |
451 |
std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances(); |
std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances(); |
452 |
std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin(); |
std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin(); |
453 |
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
516 |
} |
} |
517 |
} |
} |
518 |
|
|
519 |
//Now let's deliver late notifies (if any) |
//Now let's deliver late notifies (if any) |
520 |
NotifyBufferMutex.Lock(); |
{ |
521 |
for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) { |
LockGuard lock(NotifyBufferMutex); |
522 |
|
for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) { |
523 |
#ifdef MSG_NOSIGNAL |
#ifdef MSG_NOSIGNAL |
524 |
send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), MSG_NOSIGNAL); |
send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), MSG_NOSIGNAL); |
525 |
#else |
#else |
526 |
send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0); |
send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0); |
527 |
#endif |
#endif |
528 |
} |
} |
529 |
bufferedNotifies.clear(); |
bufferedNotifies.clear(); |
530 |
NotifyBufferMutex.Unlock(); |
} |
531 |
|
|
532 |
fd_set selectSet = fdSet; |
fd_set selectSet = fdSet; |
533 |
timeout.tv_sec = 0; |
timeout.tv_sec = 0; |
535 |
|
|
536 |
int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout); |
int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout); |
537 |
|
|
538 |
if (retval == 0) |
if (retval == 0 || (retval == -1 && errno == EINTR)) |
539 |
continue; //Nothing try again |
continue; //Nothing try again |
540 |
if (retval == -1) { |
if (retval == -1) { |
541 |
std::cerr << "LSCPServer: Socket select error." << std::endl; |
std::cerr << "LSCPServer: Socket select error." << std::endl; |
562 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
563 |
} |
} |
564 |
#else |
#else |
565 |
|
struct linger linger; |
566 |
|
linger.l_onoff = 1; |
567 |
|
linger.l_linger = 0; |
568 |
|
if(setsockopt(socket, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger))) { |
569 |
|
std::cerr << "LSCPServer: Failed to set SO_LINGER\n"; |
570 |
|
} |
571 |
|
|
572 |
if (fcntl(socket, F_SETFL, O_NONBLOCK)) { |
if (fcntl(socket, F_SETFL, O_NONBLOCK)) { |
573 |
std::cerr << "LSCPServer: F_SETFL O_NONBLOCK failed." << std::endl; |
std::cerr << "LSCPServer: F_SETFL O_NONBLOCK failed." << std::endl; |
574 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
624 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection terminated on socket", socket)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection terminated on socket", socket)); |
625 |
Sessions.erase(iter); |
Sessions.erase(iter); |
626 |
FD_CLR(socket, &fdSet); |
FD_CLR(socket, &fdSet); |
627 |
SubscriptionMutex.Lock(); //Must unsubscribe this socket from all events (if any) |
{ |
628 |
for (std::map< LSCPEvent::event_t, std::list<int> >::iterator iter = eventSubscriptions.begin(); iter != eventSubscriptions.end(); iter++) { |
LockGuard lock(SubscriptionMutex); |
629 |
iter->second.remove(socket); |
// Must unsubscribe this socket from all events (if any) |
630 |
} |
for (std::map< LSCPEvent::event_t, std::list<int> >::iterator iter = eventSubscriptions.begin(); iter != eventSubscriptions.end(); iter++) { |
631 |
SubscriptionMutex.Unlock(); |
iter->second.remove(socket); |
632 |
NotifyMutex.Lock(); |
} |
633 |
|
} |
634 |
|
LockGuard lock(NotifyMutex); |
635 |
bufferedCommands.erase(socket); |
bufferedCommands.erase(socket); |
636 |
bufferedNotifies.erase(socket); |
bufferedNotifies.erase(socket); |
637 |
#if defined(WIN32) |
#if defined(WIN32) |
639 |
#else |
#else |
640 |
close(socket); |
close(socket); |
641 |
#endif |
#endif |
|
NotifyMutex.Unlock(); |
|
642 |
} |
} |
643 |
|
|
644 |
void LSCPServer::LockRTNotify() { |
void LSCPServer::CloseAllConnections() { |
645 |
RTNotifyMutex.Lock(); |
std::vector<yyparse_param_t>::iterator iter = Sessions.begin(); |
646 |
} |
while(iter != Sessions.end()) { |
647 |
|
CloseConnection(iter); |
648 |
void LSCPServer::UnlockRTNotify() { |
iter = Sessions.begin(); |
649 |
RTNotifyMutex.Unlock(); |
} |
650 |
} |
} |
651 |
|
|
652 |
int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) { |
int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) { |
653 |
int subs = 0; |
int subs = 0; |
654 |
SubscriptionMutex.Lock(); |
LockGuard lock(SubscriptionMutex); |
655 |
for( std::list<LSCPEvent::event_t>::iterator iter = events.begin(); |
for( std::list<LSCPEvent::event_t>::iterator iter = events.begin(); |
656 |
iter != events.end(); iter++) |
iter != events.end(); iter++) |
657 |
{ |
{ |
658 |
subs += eventSubscriptions.count(*iter); |
subs += eventSubscriptions.count(*iter); |
659 |
} |
} |
|
SubscriptionMutex.Unlock(); |
|
660 |
return subs; |
return subs; |
661 |
} |
} |
662 |
|
|
663 |
void LSCPServer::SendLSCPNotify( LSCPEvent event ) { |
void LSCPServer::SendLSCPNotify( LSCPEvent event ) { |
664 |
SubscriptionMutex.Lock(); |
LockGuard lock(SubscriptionMutex); |
665 |
if (eventSubscriptions.count(event.GetType()) == 0) { |
if (eventSubscriptions.count(event.GetType()) == 0) { |
666 |
SubscriptionMutex.Unlock(); //Nobody is subscribed to this event |
// Nobody is subscribed to this event |
667 |
return; |
return; |
668 |
} |
} |
669 |
std::list<int>::iterator iter = eventSubscriptions[event.GetType()].begin(); |
std::list<int>::iterator iter = eventSubscriptions[event.GetType()].begin(); |
689 |
} |
} |
690 |
} |
} |
691 |
} |
} |
|
SubscriptionMutex.Unlock(); |
|
692 |
} |
} |
693 |
|
|
694 |
extern int GetLSCPCommand( void *buf, int max_size ) { |
extern int GetLSCPCommand( void *buf, int max_size ) { |
803 |
void LSCPServer::AnswerClient(String ReturnMessage) { |
void LSCPServer::AnswerClient(String ReturnMessage) { |
804 |
dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str())); |
dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str())); |
805 |
if (currentSocket != -1) { |
if (currentSocket != -1) { |
806 |
NotifyMutex.Lock(); |
LockGuard lock(NotifyMutex); |
807 |
#ifdef MSG_NOSIGNAL |
#ifdef MSG_NOSIGNAL |
808 |
send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), MSG_NOSIGNAL); |
send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), MSG_NOSIGNAL); |
809 |
#else |
#else |
810 |
send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0); |
send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0); |
811 |
#endif |
#endif |
|
NotifyMutex.Unlock(); |
|
812 |
} |
} |
813 |
} |
} |
814 |
|
|
958 |
try { |
try { |
959 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
960 |
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
961 |
LockRTNotify(); |
LockGuard lock(RTNotifyMutex); |
962 |
pSamplerChannel->SetEngineType(EngineName); |
pSamplerChannel->SetEngineType(EngineName); |
963 |
if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1); |
if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1); |
|
UnlockRTNotify(); |
|
964 |
} |
} |
965 |
catch (Exception e) { |
catch (Exception e) { |
966 |
result.Error(e); |
result.Error(e); |
1000 |
*/ |
*/ |
1001 |
String LSCPServer::AddChannel() { |
String LSCPServer::AddChannel() { |
1002 |
dmsg(2,("LSCPServer: AddChannel()\n")); |
dmsg(2,("LSCPServer: AddChannel()\n")); |
1003 |
LockRTNotify(); |
SamplerChannel* pSamplerChannel; |
1004 |
SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel(); |
{ |
1005 |
UnlockRTNotify(); |
LockGuard lock(RTNotifyMutex); |
1006 |
|
pSamplerChannel = pSampler->AddSamplerChannel(); |
1007 |
|
} |
1008 |
LSCPResultSet result(pSamplerChannel->Index()); |
LSCPResultSet result(pSamplerChannel->Index()); |
1009 |
return result.Produce(); |
return result.Produce(); |
1010 |
} |
} |
1015 |
String LSCPServer::RemoveChannel(uint uiSamplerChannel) { |
String LSCPServer::RemoveChannel(uint uiSamplerChannel) { |
1016 |
dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
1017 |
LSCPResultSet result; |
LSCPResultSet result; |
1018 |
LockRTNotify(); |
{ |
1019 |
pSampler->RemoveSamplerChannel(uiSamplerChannel); |
LockGuard lock(RTNotifyMutex); |
1020 |
UnlockRTNotify(); |
pSampler->RemoveSamplerChannel(uiSamplerChannel); |
1021 |
|
} |
1022 |
return result.Produce(); |
return result.Produce(); |
1023 |
} |
} |
1024 |
|
|
1061 |
String LSCPServer::GetEngineInfo(String EngineName) { |
String LSCPServer::GetEngineInfo(String EngineName) { |
1062 |
dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str())); |
dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str())); |
1063 |
LSCPResultSet result; |
LSCPResultSet result; |
1064 |
LockRTNotify(); |
{ |
1065 |
try { |
LockGuard lock(RTNotifyMutex); |
1066 |
Engine* pEngine = EngineFactory::Create(EngineName); |
try { |
1067 |
result.Add("DESCRIPTION", _escapeLscpResponse(pEngine->Description())); |
Engine* pEngine = EngineFactory::Create(EngineName); |
1068 |
result.Add("VERSION", pEngine->Version()); |
result.Add("DESCRIPTION", _escapeLscpResponse(pEngine->Description())); |
1069 |
EngineFactory::Destroy(pEngine); |
result.Add("VERSION", pEngine->Version()); |
1070 |
} |
EngineFactory::Destroy(pEngine); |
1071 |
catch (Exception e) { |
} |
1072 |
result.Error(e); |
catch (Exception e) { |
1073 |
|
result.Error(e); |
1074 |
|
} |
1075 |
} |
} |
|
UnlockRTNotify(); |
|
1076 |
return result.Produce(); |
return result.Produce(); |
1077 |
} |
} |
1078 |
|
|
1295 |
for (;iter != parameters.end(); iter++) { |
for (;iter != parameters.end(); iter++) { |
1296 |
if (s != "") s += ","; |
if (s != "") s += ","; |
1297 |
s += iter->first; |
s += iter->first; |
1298 |
|
delete iter->second; |
1299 |
} |
} |
1300 |
result.Add("PARAMETERS", s); |
result.Add("PARAMETERS", s); |
1301 |
} |
} |
1320 |
for (;iter != parameters.end(); iter++) { |
for (;iter != parameters.end(); iter++) { |
1321 |
if (s != "") s += ","; |
if (s != "") s += ","; |
1322 |
s += iter->first; |
s += iter->first; |
1323 |
|
delete iter->second; |
1324 |
} |
} |
1325 |
result.Add("PARAMETERS", s); |
result.Add("PARAMETERS", s); |
1326 |
} |
} |
1351 |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
1352 |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
1353 |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
1354 |
|
delete pParameter; |
1355 |
} |
} |
1356 |
catch (Exception e) { |
catch (Exception e) { |
1357 |
result.Error(e); |
result.Error(e); |
1379 |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
1380 |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
1381 |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
1382 |
|
delete pParameter; |
1383 |
} |
} |
1384 |
catch (Exception e) { |
catch (Exception e) { |
1385 |
result.Error(e); |
result.Error(e); |
1721 |
String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) { |
String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) { |
1722 |
dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel)); |
1723 |
LSCPResultSet result; |
LSCPResultSet result; |
1724 |
LockRTNotify(); |
{ |
1725 |
try { |
LockGuard lock(RTNotifyMutex); |
1726 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
try { |
1727 |
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1728 |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1729 |
if (!devices.count(AudioDeviceId)) throw Exception("There is no audio output device with index " + ToString(AudioDeviceId)); |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1730 |
AudioOutputDevice* pDevice = devices[AudioDeviceId]; |
if (!devices.count(AudioDeviceId)) throw Exception("There is no audio output device with index " + ToString(AudioDeviceId)); |
1731 |
pSamplerChannel->SetAudioOutputDevice(pDevice); |
AudioOutputDevice* pDevice = devices[AudioDeviceId]; |
1732 |
} |
pSamplerChannel->SetAudioOutputDevice(pDevice); |
1733 |
catch (Exception e) { |
} |
1734 |
result.Error(e); |
catch (Exception e) { |
1735 |
|
result.Error(e); |
1736 |
|
} |
1737 |
} |
} |
|
UnlockRTNotify(); |
|
1738 |
return result.Produce(); |
return result.Produce(); |
1739 |
} |
} |
1740 |
|
|
1741 |
String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) { |
String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) { |
1742 |
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)); |
1743 |
LSCPResultSet result; |
LSCPResultSet result; |
1744 |
LockRTNotify(); |
{ |
1745 |
try { |
LockGuard lock(RTNotifyMutex); |
1746 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
try { |
1747 |
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1748 |
// Driver type name aliasing... |
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1749 |
if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA"; |
// Driver type name aliasing... |
1750 |
if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK"; |
if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA"; |
1751 |
// Check if there's one audio output device already created |
if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK"; |
1752 |
// for the intended audio driver type (AudioOutputDriver)... |
// Check if there's one audio output device already created |
1753 |
AudioOutputDevice *pDevice = NULL; |
// for the intended audio driver type (AudioOutputDriver)... |
1754 |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
AudioOutputDevice *pDevice = NULL; |
1755 |
std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin(); |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1756 |
for (; iter != devices.end(); iter++) { |
std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin(); |
1757 |
if ((iter->second)->Driver() == AudioOutputDriver) { |
for (; iter != devices.end(); iter++) { |
1758 |
pDevice = iter->second; |
if ((iter->second)->Driver() == AudioOutputDriver) { |
1759 |
break; |
pDevice = iter->second; |
1760 |
|
break; |
1761 |
|
} |
1762 |
} |
} |
1763 |
|
// If it doesn't exist, create a new one with default parameters... |
1764 |
|
if (pDevice == NULL) { |
1765 |
|
std::map<String,String> params; |
1766 |
|
pDevice = pSampler->CreateAudioOutputDevice(AudioOutputDriver, params); |
1767 |
|
} |
1768 |
|
// Must have a device... |
1769 |
|
if (pDevice == NULL) |
1770 |
|
throw Exception("Internal error: could not create audio output device."); |
1771 |
|
// Set it as the current channel device... |
1772 |
|
pSamplerChannel->SetAudioOutputDevice(pDevice); |
1773 |
} |
} |
1774 |
// If it doesn't exist, create a new one with default parameters... |
catch (Exception e) { |
1775 |
if (pDevice == NULL) { |
result.Error(e); |
|
std::map<String,String> params; |
|
|
pDevice = pSampler->CreateAudioOutputDevice(AudioOutputDriver, params); |
|
1776 |
} |
} |
|
// Must have a device... |
|
|
if (pDevice == NULL) |
|
|
throw Exception("Internal error: could not create audio output device."); |
|
|
// Set it as the current channel device... |
|
|
pSamplerChannel->SetAudioOutputDevice(pDevice); |
|
|
} |
|
|
catch (Exception e) { |
|
|
result.Error(e); |
|
1777 |
} |
} |
|
UnlockRTNotify(); |
|
1778 |
return result.Produce(); |
return result.Produce(); |
1779 |
} |
} |
1780 |
|
|
1848 |
pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params); |
pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params); |
1849 |
// Make it with at least one initial port. |
// Make it with at least one initial port. |
1850 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
|
parameters["PORTS"]->SetValue("1"); |
|
1851 |
} |
} |
1852 |
// Must have a device... |
// Must have a device... |
1853 |
if (pDevice == NULL) |
if (pDevice == NULL) |
2384 |
AudioRouting += ToString(pFxSend->DestinationChannel(chan)); |
AudioRouting += ToString(pFxSend->DestinationChannel(chan)); |
2385 |
} |
} |
2386 |
|
|
2387 |
|
const String sEffectRouting = |
2388 |
|
(pFxSend->DestinationEffectChain() >= 0 && pFxSend->DestinationEffectChainPosition() >= 0) |
2389 |
|
? ToString(pFxSend->DestinationEffectChain()) + "," + ToString(pFxSend->DestinationEffectChainPosition()) |
2390 |
|
: "NONE"; |
2391 |
|
|
2392 |
// success |
// success |
2393 |
result.Add("NAME", _escapeLscpResponse(pFxSend->Name())); |
result.Add("NAME", _escapeLscpResponse(pFxSend->Name())); |
2394 |
result.Add("MIDI_CONTROLLER", pFxSend->MidiController()); |
result.Add("MIDI_CONTROLLER", pFxSend->MidiController()); |
2395 |
result.Add("LEVEL", ToString(pFxSend->Level())); |
result.Add("LEVEL", ToString(pFxSend->Level())); |
2396 |
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
2397 |
|
result.Add("EFFECT", sEffectRouting); |
2398 |
} catch (Exception e) { |
} catch (Exception e) { |
2399 |
result.Error(e); |
result.Error(e); |
2400 |
} |
} |
2457 |
return result.Produce(); |
return result.Produce(); |
2458 |
} |
} |
2459 |
|
|
2460 |
|
String LSCPServer::SetFxSendEffect(uint uiSamplerChannel, uint FxSendID, int iSendEffectChain, int iEffectChainPosition) { |
2461 |
|
dmsg(2,("LSCPServer: SetFxSendEffect(%d,%d)\n", iSendEffectChain, iEffectChainPosition)); |
2462 |
|
LSCPResultSet result; |
2463 |
|
try { |
2464 |
|
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
2465 |
|
|
2466 |
|
pFxSend->SetDestinationEffect(iSendEffectChain, iEffectChainPosition); |
2467 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
2468 |
|
} catch (Exception e) { |
2469 |
|
result.Error(e); |
2470 |
|
} |
2471 |
|
return result.Produce(); |
2472 |
|
} |
2473 |
|
|
2474 |
|
String LSCPServer::GetAvailableEffects() { |
2475 |
|
dmsg(2,("LSCPServer: GetAvailableEffects()\n")); |
2476 |
|
LSCPResultSet result; |
2477 |
|
try { |
2478 |
|
int n = EffectFactory::AvailableEffectsCount(); |
2479 |
|
result.Add(n); |
2480 |
|
} |
2481 |
|
catch (Exception e) { |
2482 |
|
result.Error(e); |
2483 |
|
} |
2484 |
|
return result.Produce(); |
2485 |
|
} |
2486 |
|
|
2487 |
|
String LSCPServer::ListAvailableEffects() { |
2488 |
|
dmsg(2,("LSCPServer: ListAvailableEffects()\n")); |
2489 |
|
LSCPResultSet result; |
2490 |
|
String list; |
2491 |
|
try { |
2492 |
|
//FIXME: for now we simply enumerate from 0 .. EffectFactory::AvailableEffectsCount() here, in future we should use unique IDs for effects during the whole sampler session. This issue comes into game when the user forces a reload of available effect plugins |
2493 |
|
int n = EffectFactory::AvailableEffectsCount(); |
2494 |
|
for (int i = 0; i < n; i++) { |
2495 |
|
if (i) list += ","; |
2496 |
|
list += ToString(i); |
2497 |
|
} |
2498 |
|
} |
2499 |
|
catch (Exception e) { |
2500 |
|
result.Error(e); |
2501 |
|
} |
2502 |
|
result.Add(list); |
2503 |
|
return result.Produce(); |
2504 |
|
} |
2505 |
|
|
2506 |
|
String LSCPServer::GetEffectInfo(int iEffectIndex) { |
2507 |
|
dmsg(2,("LSCPServer: GetEffectInfo(%d)\n", iEffectIndex)); |
2508 |
|
LSCPResultSet result; |
2509 |
|
try { |
2510 |
|
EffectInfo* pEffectInfo = EffectFactory::GetEffectInfo(iEffectIndex); |
2511 |
|
if (!pEffectInfo) |
2512 |
|
throw Exception("There is no effect with index " + ToString(iEffectIndex)); |
2513 |
|
|
2514 |
|
// convert the filename into the correct encoding as defined for LSCP |
2515 |
|
// (especially in terms of special characters -> escape sequences) |
2516 |
|
#if WIN32 |
2517 |
|
const String dllFileName = Path::fromWindows(pEffectInfo->Module()).toLscp(); |
2518 |
|
#else |
2519 |
|
// assuming POSIX |
2520 |
|
const String dllFileName = Path::fromPosix(pEffectInfo->Module()).toLscp(); |
2521 |
|
#endif |
2522 |
|
|
2523 |
|
result.Add("SYSTEM", pEffectInfo->EffectSystem()); |
2524 |
|
result.Add("MODULE", dllFileName); |
2525 |
|
result.Add("NAME", _escapeLscpResponse(pEffectInfo->Name())); |
2526 |
|
result.Add("DESCRIPTION", _escapeLscpResponse(pEffectInfo->Description())); |
2527 |
|
} |
2528 |
|
catch (Exception e) { |
2529 |
|
result.Error(e); |
2530 |
|
} |
2531 |
|
return result.Produce(); |
2532 |
|
} |
2533 |
|
|
2534 |
|
String LSCPServer::GetEffectInstanceInfo(int iEffectInstance) { |
2535 |
|
dmsg(2,("LSCPServer: GetEffectInstanceInfo(%d)\n", iEffectInstance)); |
2536 |
|
LSCPResultSet result; |
2537 |
|
try { |
2538 |
|
Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance); |
2539 |
|
if (!pEffect) |
2540 |
|
throw Exception("There is no effect instance with ID " + ToString(iEffectInstance)); |
2541 |
|
|
2542 |
|
EffectInfo* pEffectInfo = pEffect->GetEffectInfo(); |
2543 |
|
|
2544 |
|
// convert the filename into the correct encoding as defined for LSCP |
2545 |
|
// (especially in terms of special characters -> escape sequences) |
2546 |
|
#if WIN32 |
2547 |
|
const String dllFileName = Path::fromWindows(pEffectInfo->Module()).toLscp(); |
2548 |
|
#else |
2549 |
|
// assuming POSIX |
2550 |
|
const String dllFileName = Path::fromPosix(pEffectInfo->Module()).toLscp(); |
2551 |
|
#endif |
2552 |
|
|
2553 |
|
result.Add("SYSTEM", pEffectInfo->EffectSystem()); |
2554 |
|
result.Add("MODULE", dllFileName); |
2555 |
|
result.Add("NAME", _escapeLscpResponse(pEffectInfo->Name())); |
2556 |
|
result.Add("DESCRIPTION", _escapeLscpResponse(pEffectInfo->Description())); |
2557 |
|
result.Add("INPUT_CONTROLS", ToString(pEffect->InputControlCount())); |
2558 |
|
} |
2559 |
|
catch (Exception e) { |
2560 |
|
result.Error(e); |
2561 |
|
} |
2562 |
|
return result.Produce(); |
2563 |
|
} |
2564 |
|
|
2565 |
|
String LSCPServer::GetEffectInstanceInputControlInfo(int iEffectInstance, int iInputControlIndex) { |
2566 |
|
dmsg(2,("LSCPServer: GetEffectInstanceInputControlInfo(%d,%d)\n", iEffectInstance, iInputControlIndex)); |
2567 |
|
LSCPResultSet result; |
2568 |
|
try { |
2569 |
|
Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance); |
2570 |
|
if (!pEffect) |
2571 |
|
throw Exception("There is no effect instance with ID " + ToString(iEffectInstance)); |
2572 |
|
|
2573 |
|
EffectControl* pEffectControl = pEffect->InputControl(iInputControlIndex); |
2574 |
|
if (!pEffectControl) |
2575 |
|
throw Exception( |
2576 |
|
"Effect instance " + ToString(iEffectInstance) + |
2577 |
|
" does not have an input control with index " + |
2578 |
|
ToString(iInputControlIndex) |
2579 |
|
); |
2580 |
|
|
2581 |
|
result.Add("DESCRIPTION", _escapeLscpResponse(pEffectControl->Description())); |
2582 |
|
result.Add("VALUE", pEffectControl->Value()); |
2583 |
|
if (pEffectControl->MinValue()) |
2584 |
|
result.Add("RANGE_MIN", *pEffectControl->MinValue()); |
2585 |
|
if (pEffectControl->MaxValue()) |
2586 |
|
result.Add("RANGE_MAX", *pEffectControl->MaxValue()); |
2587 |
|
if (!pEffectControl->Possibilities().empty()) |
2588 |
|
result.Add("POSSIBILITIES", pEffectControl->Possibilities()); |
2589 |
|
if (pEffectControl->DefaultValue()) |
2590 |
|
result.Add("DEFAULT", *pEffectControl->DefaultValue()); |
2591 |
|
} catch (Exception e) { |
2592 |
|
result.Error(e); |
2593 |
|
} |
2594 |
|
return result.Produce(); |
2595 |
|
} |
2596 |
|
|
2597 |
|
String LSCPServer::SetEffectInstanceInputControlValue(int iEffectInstance, int iInputControlIndex, double dValue) { |
2598 |
|
dmsg(2,("LSCPServer: SetEffectInstanceInputControlValue(%d,%d,%f)\n", iEffectInstance, iInputControlIndex, dValue)); |
2599 |
|
LSCPResultSet result; |
2600 |
|
try { |
2601 |
|
Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance); |
2602 |
|
if (!pEffect) |
2603 |
|
throw Exception("There is no effect instance with ID " + ToString(iEffectInstance)); |
2604 |
|
|
2605 |
|
EffectControl* pEffectControl = pEffect->InputControl(iInputControlIndex); |
2606 |
|
if (!pEffectControl) |
2607 |
|
throw Exception( |
2608 |
|
"Effect instance " + ToString(iEffectInstance) + |
2609 |
|
" does not have an input control with index " + |
2610 |
|
ToString(iInputControlIndex) |
2611 |
|
); |
2612 |
|
|
2613 |
|
pEffectControl->SetValue(dValue); |
2614 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_info, iEffectInstance)); |
2615 |
|
} catch (Exception e) { |
2616 |
|
result.Error(e); |
2617 |
|
} |
2618 |
|
return result.Produce(); |
2619 |
|
} |
2620 |
|
|
2621 |
|
String LSCPServer::CreateEffectInstance(int iEffectIndex) { |
2622 |
|
dmsg(2,("LSCPServer: CreateEffectInstance(%d)\n", iEffectIndex)); |
2623 |
|
LSCPResultSet result; |
2624 |
|
try { |
2625 |
|
EffectInfo* pEffectInfo = EffectFactory::GetEffectInfo(iEffectIndex); |
2626 |
|
if (!pEffectInfo) |
2627 |
|
throw Exception("There is no effect with index " + ToString(iEffectIndex)); |
2628 |
|
Effect* pEffect = EffectFactory::Create(pEffectInfo); |
2629 |
|
result = pEffect->ID(); // success |
2630 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_count, EffectFactory::EffectInstancesCount())); |
2631 |
|
} catch (Exception e) { |
2632 |
|
result.Error(e); |
2633 |
|
} |
2634 |
|
return result.Produce(); |
2635 |
|
} |
2636 |
|
|
2637 |
|
String LSCPServer::CreateEffectInstance(String effectSystem, String module, String effectName) { |
2638 |
|
dmsg(2,("LSCPServer: CreateEffectInstance('%s','%s','%s')\n", effectSystem.c_str(), module.c_str(), effectName.c_str())); |
2639 |
|
LSCPResultSet result; |
2640 |
|
try { |
2641 |
|
// to allow loading the same LSCP session file on different systems |
2642 |
|
// successfully, probably with different effect plugin DLL paths or even |
2643 |
|
// running completely different operating systems, we do the following |
2644 |
|
// for finding the right effect: |
2645 |
|
// |
2646 |
|
// first try to search for an exact match of the effect plugin DLL |
2647 |
|
// (a.k.a 'module'), to avoid picking the wrong DLL with the same |
2648 |
|
// effect name ... |
2649 |
|
EffectInfo* pEffectInfo = EffectFactory::GetEffectInfo(effectSystem, module, effectName, EffectFactory::MODULE_MATCH_EXACTLY); |
2650 |
|
// ... if no effect with exactly matchin DLL filename was found, then |
2651 |
|
// try to lower the restrictions of matching the effect plugin DLL |
2652 |
|
// filename and try again and again ... |
2653 |
|
if (!pEffectInfo) { |
2654 |
|
dmsg(2,("no exact module match, trying MODULE_IGNORE_PATH\n")); |
2655 |
|
pEffectInfo = EffectFactory::GetEffectInfo(effectSystem, module, effectName, EffectFactory::MODULE_IGNORE_PATH); |
2656 |
|
} |
2657 |
|
if (!pEffectInfo) { |
2658 |
|
dmsg(2,("no module match, trying MODULE_IGNORE_PATH | MODULE_IGNORE_CASE\n")); |
2659 |
|
pEffectInfo = EffectFactory::GetEffectInfo(effectSystem, module, effectName, EffectFactory::MODULE_IGNORE_PATH | EffectFactory::MODULE_IGNORE_CASE); |
2660 |
|
} |
2661 |
|
if (!pEffectInfo) { |
2662 |
|
dmsg(2,("no module match, trying MODULE_IGNORE_PATH | MODULE_IGNORE_CASE | MODULE_IGNORE_EXTENSION\n")); |
2663 |
|
pEffectInfo = EffectFactory::GetEffectInfo(effectSystem, module, effectName, EffectFactory::MODULE_IGNORE_PATH | EffectFactory::MODULE_IGNORE_CASE | EffectFactory::MODULE_IGNORE_EXTENSION); |
2664 |
|
} |
2665 |
|
// ... if there was still no effect found, then completely ignore the |
2666 |
|
// DLL plugin filename argument and just search for the matching effect |
2667 |
|
// system type and effect name |
2668 |
|
if (!pEffectInfo) { |
2669 |
|
dmsg(2,("no module match, trying MODULE_IGNORE_ALL\n")); |
2670 |
|
pEffectInfo = EffectFactory::GetEffectInfo(effectSystem, module, effectName, EffectFactory::MODULE_IGNORE_ALL); |
2671 |
|
} |
2672 |
|
if (!pEffectInfo) |
2673 |
|
throw Exception("There is no such effect '" + effectSystem + "' '" + module + "' '" + effectName + "'"); |
2674 |
|
|
2675 |
|
Effect* pEffect = EffectFactory::Create(pEffectInfo); |
2676 |
|
result = LSCPResultSet(pEffect->ID()); |
2677 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_count, EffectFactory::EffectInstancesCount())); |
2678 |
|
} catch (Exception e) { |
2679 |
|
result.Error(e); |
2680 |
|
} |
2681 |
|
return result.Produce(); |
2682 |
|
} |
2683 |
|
|
2684 |
|
String LSCPServer::DestroyEffectInstance(int iEffectInstance) { |
2685 |
|
dmsg(2,("LSCPServer: DestroyEffectInstance(%d)\n", iEffectInstance)); |
2686 |
|
LSCPResultSet result; |
2687 |
|
try { |
2688 |
|
Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance); |
2689 |
|
if (!pEffect) |
2690 |
|
throw Exception("There is no effect instance with ID " + ToString(iEffectInstance)); |
2691 |
|
EffectFactory::Destroy(pEffect); |
2692 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_count, EffectFactory::EffectInstancesCount())); |
2693 |
|
} catch (Exception e) { |
2694 |
|
result.Error(e); |
2695 |
|
} |
2696 |
|
return result.Produce(); |
2697 |
|
} |
2698 |
|
|
2699 |
|
String LSCPServer::GetEffectInstances() { |
2700 |
|
dmsg(2,("LSCPServer: GetEffectInstances()\n")); |
2701 |
|
LSCPResultSet result; |
2702 |
|
try { |
2703 |
|
int n = EffectFactory::EffectInstancesCount(); |
2704 |
|
result.Add(n); |
2705 |
|
} catch (Exception e) { |
2706 |
|
result.Error(e); |
2707 |
|
} |
2708 |
|
return result.Produce(); |
2709 |
|
} |
2710 |
|
|
2711 |
|
String LSCPServer::ListEffectInstances() { |
2712 |
|
dmsg(2,("LSCPServer: ListEffectInstances()\n")); |
2713 |
|
LSCPResultSet result; |
2714 |
|
String list; |
2715 |
|
try { |
2716 |
|
int n = EffectFactory::EffectInstancesCount(); |
2717 |
|
for (int i = 0; i < n; i++) { |
2718 |
|
Effect* pEffect = EffectFactory::GetEffectInstance(i); |
2719 |
|
if (i) list += ","; |
2720 |
|
list += ToString(pEffect->ID()); |
2721 |
|
} |
2722 |
|
} catch (Exception e) { |
2723 |
|
result.Error(e); |
2724 |
|
} |
2725 |
|
result.Add(list); |
2726 |
|
return result.Produce(); |
2727 |
|
} |
2728 |
|
|
2729 |
|
String LSCPServer::GetSendEffectChains(int iAudioOutputDevice) { |
2730 |
|
dmsg(2,("LSCPServer: GetSendEffectChains(%d)\n", iAudioOutputDevice)); |
2731 |
|
LSCPResultSet result; |
2732 |
|
try { |
2733 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
2734 |
|
if (!devices.count(iAudioOutputDevice)) |
2735 |
|
throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + "."); |
2736 |
|
AudioOutputDevice* pDevice = devices[iAudioOutputDevice]; |
2737 |
|
int n = pDevice->SendEffectChainCount(); |
2738 |
|
result.Add(n); |
2739 |
|
} catch (Exception e) { |
2740 |
|
result.Error(e); |
2741 |
|
} |
2742 |
|
return result.Produce(); |
2743 |
|
} |
2744 |
|
|
2745 |
|
String LSCPServer::ListSendEffectChains(int iAudioOutputDevice) { |
2746 |
|
dmsg(2,("LSCPServer: ListSendEffectChains(%d)\n", iAudioOutputDevice)); |
2747 |
|
LSCPResultSet result; |
2748 |
|
String list; |
2749 |
|
try { |
2750 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
2751 |
|
if (!devices.count(iAudioOutputDevice)) |
2752 |
|
throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + "."); |
2753 |
|
AudioOutputDevice* pDevice = devices[iAudioOutputDevice]; |
2754 |
|
int n = pDevice->SendEffectChainCount(); |
2755 |
|
for (int i = 0; i < n; i++) { |
2756 |
|
EffectChain* pEffectChain = pDevice->SendEffectChain(i); |
2757 |
|
if (i) list += ","; |
2758 |
|
list += ToString(pEffectChain->ID()); |
2759 |
|
} |
2760 |
|
} catch (Exception e) { |
2761 |
|
result.Error(e); |
2762 |
|
} |
2763 |
|
result.Add(list); |
2764 |
|
return result.Produce(); |
2765 |
|
} |
2766 |
|
|
2767 |
|
String LSCPServer::AddSendEffectChain(int iAudioOutputDevice) { |
2768 |
|
dmsg(2,("LSCPServer: AddSendEffectChain(%d)\n", iAudioOutputDevice)); |
2769 |
|
LSCPResultSet result; |
2770 |
|
try { |
2771 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
2772 |
|
if (!devices.count(iAudioOutputDevice)) |
2773 |
|
throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + "."); |
2774 |
|
AudioOutputDevice* pDevice = devices[iAudioOutputDevice]; |
2775 |
|
EffectChain* pEffectChain = pDevice->AddSendEffectChain(); |
2776 |
|
result = pEffectChain->ID(); |
2777 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_count, iAudioOutputDevice, pDevice->SendEffectChainCount())); |
2778 |
|
} catch (Exception e) { |
2779 |
|
result.Error(e); |
2780 |
|
} |
2781 |
|
return result.Produce(); |
2782 |
|
} |
2783 |
|
|
2784 |
|
String LSCPServer::RemoveSendEffectChain(int iAudioOutputDevice, int iSendEffectChain) { |
2785 |
|
dmsg(2,("LSCPServer: RemoveSendEffectChain(%d,%d)\n", iAudioOutputDevice, iSendEffectChain)); |
2786 |
|
LSCPResultSet result; |
2787 |
|
try { |
2788 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
2789 |
|
if (!devices.count(iAudioOutputDevice)) |
2790 |
|
throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + "."); |
2791 |
|
|
2792 |
|
std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances(); |
2793 |
|
std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin(); |
2794 |
|
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
2795 |
|
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
2796 |
|
AudioOutputDevice* pDev = (*itEngineChannel)->GetAudioOutputDevice(); |
2797 |
|
if (pDev != NULL && pDev->deviceId() == iAudioOutputDevice) { |
2798 |
|
for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) { |
2799 |
|
FxSend* fxs = (*itEngineChannel)->GetFxSend(i); |
2800 |
|
if(fxs != NULL && fxs->DestinationEffectChain() == iSendEffectChain) { |
2801 |
|
throw Exception("The effect chain is still in use by channel " + ToString((*itEngineChannel)->GetSamplerChannel()->Index())); |
2802 |
|
} |
2803 |
|
} |
2804 |
|
} |
2805 |
|
} |
2806 |
|
|
2807 |
|
AudioOutputDevice* pDevice = devices[iAudioOutputDevice]; |
2808 |
|
for (int i = 0; i < pDevice->SendEffectChainCount(); i++) { |
2809 |
|
EffectChain* pEffectChain = pDevice->SendEffectChain(i); |
2810 |
|
if (pEffectChain->ID() == iSendEffectChain) { |
2811 |
|
pDevice->RemoveSendEffectChain(i); |
2812 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_count, iAudioOutputDevice, pDevice->SendEffectChainCount())); |
2813 |
|
return result.Produce(); |
2814 |
|
} |
2815 |
|
} |
2816 |
|
throw Exception( |
2817 |
|
"There is no send effect chain with ID " + |
2818 |
|
ToString(iSendEffectChain) + " for audio output device " + |
2819 |
|
ToString(iAudioOutputDevice) + "." |
2820 |
|
); |
2821 |
|
} catch (Exception e) { |
2822 |
|
result.Error(e); |
2823 |
|
} |
2824 |
|
return result.Produce(); |
2825 |
|
} |
2826 |
|
|
2827 |
|
static EffectChain* _getSendEffectChain(Sampler* pSampler, int iAudioOutputDevice, int iSendEffectChain) throw (Exception) { |
2828 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
2829 |
|
if (!devices.count(iAudioOutputDevice)) |
2830 |
|
throw Exception( |
2831 |
|
"There is no audio output device with index " + |
2832 |
|
ToString(iAudioOutputDevice) + "." |
2833 |
|
); |
2834 |
|
AudioOutputDevice* pDevice = devices[iAudioOutputDevice]; |
2835 |
|
EffectChain* pEffectChain = pDevice->SendEffectChainByID(iSendEffectChain); |
2836 |
|
if(pEffectChain != NULL) return pEffectChain; |
2837 |
|
throw Exception( |
2838 |
|
"There is no send effect chain with ID " + |
2839 |
|
ToString(iSendEffectChain) + " for audio output device " + |
2840 |
|
ToString(iAudioOutputDevice) + "." |
2841 |
|
); |
2842 |
|
} |
2843 |
|
|
2844 |
|
String LSCPServer::GetSendEffectChainInfo(int iAudioOutputDevice, int iSendEffectChain) { |
2845 |
|
dmsg(2,("LSCPServer: GetSendEffectChainInfo(%d,%d)\n", iAudioOutputDevice, iSendEffectChain)); |
2846 |
|
LSCPResultSet result; |
2847 |
|
try { |
2848 |
|
EffectChain* pEffectChain = |
2849 |
|
_getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain); |
2850 |
|
String sEffectSequence; |
2851 |
|
for (int i = 0; i < pEffectChain->EffectCount(); i++) { |
2852 |
|
if (i) sEffectSequence += ","; |
2853 |
|
sEffectSequence += ToString(pEffectChain->GetEffect(i)->ID()); |
2854 |
|
} |
2855 |
|
result.Add("EFFECT_COUNT", pEffectChain->EffectCount()); |
2856 |
|
result.Add("EFFECT_SEQUENCE", sEffectSequence); |
2857 |
|
} catch (Exception e) { |
2858 |
|
result.Error(e); |
2859 |
|
} |
2860 |
|
return result.Produce(); |
2861 |
|
} |
2862 |
|
|
2863 |
|
String LSCPServer::AppendSendEffectChainEffect(int iAudioOutputDevice, int iSendEffectChain, int iEffectInstance) { |
2864 |
|
dmsg(2,("LSCPServer: AppendSendEffectChainEffect(%d,%d,%d)\n", iAudioOutputDevice, iSendEffectChain, iEffectInstance)); |
2865 |
|
LSCPResultSet result; |
2866 |
|
try { |
2867 |
|
EffectChain* pEffectChain = |
2868 |
|
_getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain); |
2869 |
|
Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance); |
2870 |
|
if (!pEffect) |
2871 |
|
throw Exception("There is no effect instance with ID " + ToString(iEffectInstance)); |
2872 |
|
pEffectChain->AppendEffect(pEffect); |
2873 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_info, iAudioOutputDevice, iSendEffectChain, pEffectChain->EffectCount())); |
2874 |
|
} catch (Exception e) { |
2875 |
|
result.Error(e); |
2876 |
|
} |
2877 |
|
return result.Produce(); |
2878 |
|
} |
2879 |
|
|
2880 |
|
String LSCPServer::InsertSendEffectChainEffect(int iAudioOutputDevice, int iSendEffectChain, int iEffectChainPosition, int iEffectInstance) { |
2881 |
|
dmsg(2,("LSCPServer: InsertSendEffectChainEffect(%d,%d,%d,%d)\n", iAudioOutputDevice, iSendEffectChain, iEffectChainPosition, iEffectInstance)); |
2882 |
|
LSCPResultSet result; |
2883 |
|
try { |
2884 |
|
EffectChain* pEffectChain = |
2885 |
|
_getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain); |
2886 |
|
Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance); |
2887 |
|
if (!pEffect) |
2888 |
|
throw Exception("There is no effect instance with index " + ToString(iEffectInstance)); |
2889 |
|
pEffectChain->InsertEffect(pEffect, iEffectChainPosition); |
2890 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_info, iAudioOutputDevice, iSendEffectChain, pEffectChain->EffectCount())); |
2891 |
|
} catch (Exception e) { |
2892 |
|
result.Error(e); |
2893 |
|
} |
2894 |
|
return result.Produce(); |
2895 |
|
} |
2896 |
|
|
2897 |
|
String LSCPServer::RemoveSendEffectChainEffect(int iAudioOutputDevice, int iSendEffectChain, int iEffectChainPosition) { |
2898 |
|
dmsg(2,("LSCPServer: RemoveSendEffectChainEffect(%d,%d,%d)\n", iAudioOutputDevice, iSendEffectChain, iEffectChainPosition)); |
2899 |
|
LSCPResultSet result; |
2900 |
|
try { |
2901 |
|
EffectChain* pEffectChain = |
2902 |
|
_getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain); |
2903 |
|
|
2904 |
|
std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances(); |
2905 |
|
std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin(); |
2906 |
|
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
2907 |
|
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
2908 |
|
AudioOutputDevice* pDev = (*itEngineChannel)->GetAudioOutputDevice(); |
2909 |
|
if (pDev != NULL && pDev->deviceId() == iAudioOutputDevice) { |
2910 |
|
for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) { |
2911 |
|
FxSend* fxs = (*itEngineChannel)->GetFxSend(i); |
2912 |
|
if(fxs != NULL && fxs->DestinationEffectChain() == iSendEffectChain && fxs->DestinationEffectChainPosition() == iEffectChainPosition) { |
2913 |
|
throw Exception("The effect instance is still in use by channel " + ToString((*itEngineChannel)->GetSamplerChannel()->Index())); |
2914 |
|
} |
2915 |
|
} |
2916 |
|
} |
2917 |
|
} |
2918 |
|
|
2919 |
|
pEffectChain->RemoveEffect(iEffectChainPosition); |
2920 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_info, iAudioOutputDevice, iSendEffectChain, pEffectChain->EffectCount())); |
2921 |
|
} catch (Exception e) { |
2922 |
|
result.Error(e); |
2923 |
|
} |
2924 |
|
return result.Produce(); |
2925 |
|
} |
2926 |
|
|
2927 |
String LSCPServer::EditSamplerChannelInstrument(uint uiSamplerChannel) { |
String LSCPServer::EditSamplerChannelInstrument(uint uiSamplerChannel) { |
2928 |
dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel)); |
2929 |
LSCPResultSet result; |
LSCPResultSet result; |
2972 |
pMidiDevice->SendNoteOffToDevice(Arg1, Arg2); |
pMidiDevice->SendNoteOffToDevice(Arg1, Arg2); |
2973 |
bool b = pMidiDevice->SendNoteOffToSampler(Arg1, Arg2); |
bool b = pMidiDevice->SendNoteOffToSampler(Arg1, Arg2); |
2974 |
if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2)); |
if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2)); |
2975 |
|
} else if (MidiMsg == "CC") { |
2976 |
|
pMidiDevice->SendCCToDevice(Arg1, Arg2); |
2977 |
|
bool b = pMidiDevice->SendCCToSampler(Arg1, Arg2); |
2978 |
|
if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2)); |
2979 |
} else { |
} else { |
2980 |
throw Exception("Unknown MIDI message type: " + MidiMsg); |
throw Exception("Unknown MIDI message type: " + MidiMsg); |
2981 |
} |
} |
3058 |
String LSCPServer::GetTotalVoiceCountMax() { |
String LSCPServer::GetTotalVoiceCountMax() { |
3059 |
dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n")); |
dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n")); |
3060 |
LSCPResultSet result; |
LSCPResultSet result; |
3061 |
result.Add(EngineFactory::EngineInstances().size() * CONFIG_MAX_VOICES); |
result.Add(EngineFactory::EngineInstances().size() * pSampler->GetGlobalMaxVoices()); |
3062 |
|
return result.Produce(); |
3063 |
|
} |
3064 |
|
|
3065 |
|
/** |
3066 |
|
* Will be called by the parser to return the sampler global maximum |
3067 |
|
* allowed number of voices. |
3068 |
|
*/ |
3069 |
|
String LSCPServer::GetGlobalMaxVoices() { |
3070 |
|
dmsg(2,("LSCPServer: GetGlobalMaxVoices()\n")); |
3071 |
|
LSCPResultSet result; |
3072 |
|
result.Add(pSampler->GetGlobalMaxVoices()); |
3073 |
|
return result.Produce(); |
3074 |
|
} |
3075 |
|
|
3076 |
|
/** |
3077 |
|
* Will be called by the parser to set the sampler global maximum number of |
3078 |
|
* voices. |
3079 |
|
*/ |
3080 |
|
String LSCPServer::SetGlobalMaxVoices(int iVoices) { |
3081 |
|
dmsg(2,("LSCPServer: SetGlobalMaxVoices(%d)\n", iVoices)); |
3082 |
|
LSCPResultSet result; |
3083 |
|
try { |
3084 |
|
pSampler->SetGlobalMaxVoices(iVoices); |
3085 |
|
LSCPServer::SendLSCPNotify( |
3086 |
|
LSCPEvent(LSCPEvent::event_global_info, "VOICES", pSampler->GetGlobalMaxVoices()) |
3087 |
|
); |
3088 |
|
} catch (Exception e) { |
3089 |
|
result.Error(e); |
3090 |
|
} |
3091 |
|
return result.Produce(); |
3092 |
|
} |
3093 |
|
|
3094 |
|
/** |
3095 |
|
* Will be called by the parser to return the sampler global maximum |
3096 |
|
* allowed number of disk streams. |
3097 |
|
*/ |
3098 |
|
String LSCPServer::GetGlobalMaxStreams() { |
3099 |
|
dmsg(2,("LSCPServer: GetGlobalMaxStreams()\n")); |
3100 |
|
LSCPResultSet result; |
3101 |
|
result.Add(pSampler->GetGlobalMaxStreams()); |
3102 |
|
return result.Produce(); |
3103 |
|
} |
3104 |
|
|
3105 |
|
/** |
3106 |
|
* Will be called by the parser to set the sampler global maximum number of |
3107 |
|
* disk streams. |
3108 |
|
*/ |
3109 |
|
String LSCPServer::SetGlobalMaxStreams(int iStreams) { |
3110 |
|
dmsg(2,("LSCPServer: SetGlobalMaxStreams(%d)\n", iStreams)); |
3111 |
|
LSCPResultSet result; |
3112 |
|
try { |
3113 |
|
pSampler->SetGlobalMaxStreams(iStreams); |
3114 |
|
LSCPServer::SendLSCPNotify( |
3115 |
|
LSCPEvent(LSCPEvent::event_global_info, "STREAMS", pSampler->GetGlobalMaxStreams()) |
3116 |
|
); |
3117 |
|
} catch (Exception e) { |
3118 |
|
result.Error(e); |
3119 |
|
} |
3120 |
return result.Produce(); |
return result.Produce(); |
3121 |
} |
} |
3122 |
|
|
3304 |
throw Exception("Directory is specified"); |
throw Exception("Directory is specified"); |
3305 |
} |
} |
3306 |
#else |
#else |
3307 |
struct stat statBuf; |
File f(Filename); |
3308 |
int res = stat(Filename.c_str(), &statBuf); |
if(!f.Exist()) throw Exception(f.GetErrorMsg()); |
3309 |
if (res) { |
if (f.IsDirectory()) throw Exception("Directory is specified"); |
|
std::stringstream ss; |
|
|
ss << "Fail to stat `" << Filename << "`: " << strerror(errno); |
|
|
throw Exception(ss.str()); |
|
|
} |
|
|
|
|
|
if (S_ISDIR(statBuf.st_mode)) { |
|
|
throw Exception("Directory is specified"); |
|
|
} |
|
3310 |
#endif |
#endif |
3311 |
} |
} |
3312 |
|
|
3317 |
String LSCPServer::SubscribeNotification(LSCPEvent::event_t type) { |
String LSCPServer::SubscribeNotification(LSCPEvent::event_t type) { |
3318 |
dmsg(2,("LSCPServer: SubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str())); |
dmsg(2,("LSCPServer: SubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str())); |
3319 |
LSCPResultSet result; |
LSCPResultSet result; |
3320 |
SubscriptionMutex.Lock(); |
{ |
3321 |
eventSubscriptions[type].push_back(currentSocket); |
LockGuard lock(SubscriptionMutex); |
3322 |
SubscriptionMutex.Unlock(); |
eventSubscriptions[type].push_back(currentSocket); |
3323 |
|
} |
3324 |
return result.Produce(); |
return result.Produce(); |
3325 |
} |
} |
3326 |
|
|
3331 |
String LSCPServer::UnsubscribeNotification(LSCPEvent::event_t type) { |
String LSCPServer::UnsubscribeNotification(LSCPEvent::event_t type) { |
3332 |
dmsg(2,("LSCPServer: UnsubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str())); |
dmsg(2,("LSCPServer: UnsubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str())); |
3333 |
LSCPResultSet result; |
LSCPResultSet result; |
3334 |
SubscriptionMutex.Lock(); |
{ |
3335 |
eventSubscriptions[type].remove(currentSocket); |
LockGuard lock(SubscriptionMutex); |
3336 |
SubscriptionMutex.Unlock(); |
eventSubscriptions[type].remove(currentSocket); |
3337 |
|
} |
3338 |
return result.Produce(); |
return result.Produce(); |
3339 |
} |
} |
3340 |
|
|