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 - 2014 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 * |
22 |
***************************************************************************/ |
***************************************************************************/ |
23 |
|
|
24 |
#include <algorithm> |
#include <algorithm> |
25 |
|
#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 |
|
|
50 |
|
String lscpParserProcessShellInteraction(String& line, yyparse_param_t* param); |
51 |
|
|
52 |
/** |
/** |
53 |
* Returns a copy of the given string where all special characters are |
* Returns a copy of the given string where all special characters are |
54 |
* replaced by LSCP escape sequences ("\xHH"). This function shall be used |
* replaced by LSCP escape sequences ("\xHH"). This function shall be used |
99 |
*/ |
*/ |
100 |
fd_set LSCPServer::fdSet; |
fd_set LSCPServer::fdSet; |
101 |
int LSCPServer::currentSocket = -1; |
int LSCPServer::currentSocket = -1; |
102 |
std::vector<yyparse_param_t> LSCPServer::Sessions = std::vector<yyparse_param_t>(); |
std::vector<yyparse_param_t> LSCPServer::Sessions; |
103 |
std::vector<yyparse_param_t>::iterator itCurrentSession = std::vector<yyparse_param_t>::iterator(); |
std::vector<yyparse_param_t>::iterator itCurrentSession; |
104 |
std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>(); |
std::map<int,String> LSCPServer::bufferedNotifies; |
105 |
std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>(); |
std::map<int,String> LSCPServer::bufferedCommands; |
106 |
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; |
107 |
Mutex LSCPServer::NotifyMutex = Mutex(); |
Mutex LSCPServer::NotifyMutex; |
108 |
Mutex LSCPServer::NotifyBufferMutex = Mutex(); |
Mutex LSCPServer::NotifyBufferMutex; |
109 |
Mutex LSCPServer::SubscriptionMutex = Mutex(); |
Mutex LSCPServer::SubscriptionMutex; |
110 |
Mutex LSCPServer::RTNotifyMutex = Mutex(); |
Mutex LSCPServer::RTNotifyMutex; |
111 |
|
|
112 |
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) { |
113 |
SocketAddress.sin_family = AF_INET; |
SocketAddress.sin_family = AF_INET; |
140 |
LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); |
141 |
LSCPEvent::RegisterEvent(LSCPEvent::event_channel_midi, "CHANNEL_MIDI"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_channel_midi, "CHANNEL_MIDI"); |
142 |
LSCPEvent::RegisterEvent(LSCPEvent::event_device_midi, "DEVICE_MIDI"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_device_midi, "DEVICE_MIDI"); |
143 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_fx_instance_count, "EFFECT_INSTANCE_COUNT"); |
144 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_fx_instance_info, "EFFECT_INSTANCE_INFO"); |
145 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_send_fx_chain_count, "SEND_EFFECT_CHAIN_COUNT"); |
146 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_send_fx_chain_info, "SEND_EFFECT_CHAIN_INFO"); |
147 |
hSocket = -1; |
hSocket = -1; |
148 |
} |
} |
149 |
|
|
150 |
LSCPServer::~LSCPServer() { |
LSCPServer::~LSCPServer() { |
151 |
|
CloseAllConnections(); |
152 |
|
InstrumentManager::StopBackgroundThread(); |
153 |
#if defined(WIN32) |
#if defined(WIN32) |
154 |
if (hSocket >= 0) closesocket(hSocket); |
if (hSocket >= 0) closesocket(hSocket); |
155 |
#else |
#else |
344 |
} |
} |
345 |
#endif // HAVE_SQLITE3 |
#endif // HAVE_SQLITE3 |
346 |
|
|
347 |
|
void LSCPServer::RemoveListeners() { |
348 |
|
pSampler->RemoveChannelCountListener(&eventHandler); |
349 |
|
pSampler->RemoveAudioDeviceCountListener(&eventHandler); |
350 |
|
pSampler->RemoveMidiDeviceCountListener(&eventHandler); |
351 |
|
pSampler->RemoveVoiceCountListener(&eventHandler); |
352 |
|
pSampler->RemoveStreamCountListener(&eventHandler); |
353 |
|
pSampler->RemoveBufferFillListener(&eventHandler); |
354 |
|
pSampler->RemoveTotalStreamCountListener(&eventHandler); |
355 |
|
pSampler->RemoveTotalVoiceCountListener(&eventHandler); |
356 |
|
pSampler->RemoveFxSendCountListener(&eventHandler); |
357 |
|
MidiInstrumentMapper::RemoveMidiInstrumentCountListener(&eventHandler); |
358 |
|
MidiInstrumentMapper::RemoveMidiInstrumentInfoListener(&eventHandler); |
359 |
|
MidiInstrumentMapper::RemoveMidiInstrumentMapCountListener(&eventHandler); |
360 |
|
MidiInstrumentMapper::RemoveMidiInstrumentMapInfoListener(&eventHandler); |
361 |
|
#if HAVE_SQLITE3 |
362 |
|
InstrumentsDb::GetInstrumentsDb()->RemoveInstrumentsDbListener(&dbInstrumentsEventHandler); |
363 |
|
#endif |
364 |
|
} |
365 |
|
|
366 |
/** |
/** |
367 |
* Blocks the calling thread until the LSCP Server is initialized and |
* Blocks the calling thread until the LSCP Server is initialized and |
449 |
#endif |
#endif |
450 |
// 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 |
451 |
{ |
{ |
452 |
|
LockGuard lock(EngineChannelFactory::EngineChannelsMutex); |
453 |
std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances(); |
std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances(); |
454 |
std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin(); |
std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin(); |
455 |
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
518 |
} |
} |
519 |
} |
} |
520 |
|
|
521 |
//Now let's deliver late notifies (if any) |
//Now let's deliver late notifies (if any) |
522 |
NotifyBufferMutex.Lock(); |
{ |
523 |
for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) { |
LockGuard lock(NotifyBufferMutex); |
524 |
|
for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) { |
525 |
#ifdef MSG_NOSIGNAL |
#ifdef MSG_NOSIGNAL |
526 |
send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), MSG_NOSIGNAL); |
send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), MSG_NOSIGNAL); |
527 |
#else |
#else |
528 |
send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0); |
send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0); |
529 |
#endif |
#endif |
530 |
} |
} |
531 |
bufferedNotifies.clear(); |
bufferedNotifies.clear(); |
532 |
NotifyBufferMutex.Unlock(); |
} |
533 |
|
|
534 |
fd_set selectSet = fdSet; |
fd_set selectSet = fdSet; |
535 |
timeout.tv_sec = 0; |
timeout.tv_sec = 0; |
537 |
|
|
538 |
int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout); |
int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout); |
539 |
|
|
540 |
if (retval == 0) |
if (retval == 0 || (retval == -1 && errno == EINTR)) |
541 |
continue; //Nothing try again |
continue; //Nothing try again |
542 |
if (retval == -1) { |
if (retval == -1) { |
543 |
std::cerr << "LSCPServer: Socket select error." << std::endl; |
std::cerr << "LSCPServer: Socket select error." << std::endl; |
564 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
565 |
} |
} |
566 |
#else |
#else |
567 |
|
struct linger linger; |
568 |
|
linger.l_onoff = 1; |
569 |
|
linger.l_linger = 0; |
570 |
|
if(setsockopt(socket, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger))) { |
571 |
|
std::cerr << "LSCPServer: Failed to set SO_LINGER\n"; |
572 |
|
} |
573 |
|
|
574 |
if (fcntl(socket, F_SETFL, O_NONBLOCK)) { |
if (fcntl(socket, F_SETFL, O_NONBLOCK)) { |
575 |
std::cerr << "LSCPServer: F_SETFL O_NONBLOCK failed." << std::endl; |
std::cerr << "LSCPServer: F_SETFL O_NONBLOCK failed." << std::endl; |
576 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
594 |
//Something was selected and it was not the hSocket, so it must be some command(s) coming. |
//Something was selected and it was not the hSocket, so it must be some command(s) coming. |
595 |
for (std::vector<yyparse_param_t>::iterator iter = Sessions.begin(); iter != Sessions.end(); iter++) { |
for (std::vector<yyparse_param_t>::iterator iter = Sessions.begin(); iter != Sessions.end(); iter++) { |
596 |
if (FD_ISSET((*iter).hSession, &selectSet)) { //Was it this socket? |
if (FD_ISSET((*iter).hSession, &selectSet)) { //Was it this socket? |
597 |
|
currentSocket = (*iter).hSession; //a hack |
598 |
if (GetLSCPCommand(iter)) { //Have we read the entire command? |
if (GetLSCPCommand(iter)) { //Have we read the entire command? |
599 |
dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket)); |
dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket)); |
600 |
int dummy; // just a temporary hack to fulfill the restart() function prototype |
int dummy; // just a temporary hack to fulfill the restart() function prototype |
601 |
restart(NULL, dummy); // restart the 'scanner' |
restart(NULL, dummy); // restart the 'scanner' |
|
currentSocket = (*iter).hSession; //a hack |
|
602 |
itCurrentSession = iter; // another hack |
itCurrentSession = iter; // another hack |
603 |
dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str())); |
dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str())); |
604 |
if ((*iter).bVerbose) { // if echo mode enabled |
if ((*iter).bVerbose) { // if echo mode enabled |
612 |
CloseConnection(iter); |
CloseConnection(iter); |
613 |
} |
} |
614 |
} |
} |
615 |
|
currentSocket = -1; //continuation of a hack |
616 |
//socket may have been closed, iter may be invalid, get out of the loop for now. |
//socket may have been closed, iter may be invalid, get out of the loop for now. |
617 |
//we'll be back if there is data. |
//we'll be back if there is data. |
618 |
break; |
break; |
627 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection terminated on socket", socket)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection terminated on socket", socket)); |
628 |
Sessions.erase(iter); |
Sessions.erase(iter); |
629 |
FD_CLR(socket, &fdSet); |
FD_CLR(socket, &fdSet); |
630 |
SubscriptionMutex.Lock(); //Must unsubscribe this socket from all events (if any) |
{ |
631 |
for (std::map< LSCPEvent::event_t, std::list<int> >::iterator iter = eventSubscriptions.begin(); iter != eventSubscriptions.end(); iter++) { |
LockGuard lock(SubscriptionMutex); |
632 |
iter->second.remove(socket); |
// Must unsubscribe this socket from all events (if any) |
633 |
} |
for (std::map< LSCPEvent::event_t, std::list<int> >::iterator iter = eventSubscriptions.begin(); iter != eventSubscriptions.end(); iter++) { |
634 |
SubscriptionMutex.Unlock(); |
iter->second.remove(socket); |
635 |
NotifyMutex.Lock(); |
} |
636 |
|
} |
637 |
|
LockGuard lock(NotifyMutex); |
638 |
bufferedCommands.erase(socket); |
bufferedCommands.erase(socket); |
639 |
bufferedNotifies.erase(socket); |
bufferedNotifies.erase(socket); |
640 |
#if defined(WIN32) |
#if defined(WIN32) |
642 |
#else |
#else |
643 |
close(socket); |
close(socket); |
644 |
#endif |
#endif |
|
NotifyMutex.Unlock(); |
|
|
} |
|
|
|
|
|
void LSCPServer::LockRTNotify() { |
|
|
RTNotifyMutex.Lock(); |
|
645 |
} |
} |
646 |
|
|
647 |
void LSCPServer::UnlockRTNotify() { |
void LSCPServer::CloseAllConnections() { |
648 |
RTNotifyMutex.Unlock(); |
std::vector<yyparse_param_t>::iterator iter = Sessions.begin(); |
649 |
|
while(iter != Sessions.end()) { |
650 |
|
CloseConnection(iter); |
651 |
|
iter = Sessions.begin(); |
652 |
|
} |
653 |
} |
} |
654 |
|
|
655 |
int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) { |
int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) { |
656 |
int subs = 0; |
int subs = 0; |
657 |
SubscriptionMutex.Lock(); |
LockGuard lock(SubscriptionMutex); |
658 |
for( std::list<LSCPEvent::event_t>::iterator iter = events.begin(); |
for( std::list<LSCPEvent::event_t>::iterator iter = events.begin(); |
659 |
iter != events.end(); iter++) |
iter != events.end(); iter++) |
660 |
{ |
{ |
661 |
subs += eventSubscriptions.count(*iter); |
subs += eventSubscriptions.count(*iter); |
662 |
} |
} |
|
SubscriptionMutex.Unlock(); |
|
663 |
return subs; |
return subs; |
664 |
} |
} |
665 |
|
|
666 |
void LSCPServer::SendLSCPNotify( LSCPEvent event ) { |
void LSCPServer::SendLSCPNotify( LSCPEvent event ) { |
667 |
SubscriptionMutex.Lock(); |
LockGuard lock(SubscriptionMutex); |
668 |
if (eventSubscriptions.count(event.GetType()) == 0) { |
if (eventSubscriptions.count(event.GetType()) == 0) { |
669 |
SubscriptionMutex.Unlock(); //Nobody is subscribed to this event |
// Nobody is subscribed to this event |
670 |
return; |
return; |
671 |
} |
} |
672 |
std::list<int>::iterator iter = eventSubscriptions[event.GetType()].begin(); |
std::list<int>::iterator iter = eventSubscriptions[event.GetType()].begin(); |
692 |
} |
} |
693 |
} |
} |
694 |
} |
} |
|
SubscriptionMutex.Unlock(); |
|
695 |
} |
} |
696 |
|
|
697 |
extern int GetLSCPCommand( void *buf, int max_size ) { |
extern int GetLSCPCommand( void *buf, int max_size ) { |
742 |
bufferedCommands[socket] += "\r\n"; |
bufferedCommands[socket] += "\r\n"; |
743 |
return true; //Complete command was read |
return true; //Complete command was read |
744 |
} |
} |
745 |
bufferedCommands[socket] += c; |
// backspace character - should only happen with shell |
746 |
|
if (c == '\b') { |
747 |
|
if (!bufferedCommands[socket].empty()) { |
748 |
|
bufferedCommands[socket] = bufferedCommands[socket].substr( |
749 |
|
0, bufferedCommands[socket].length() - 1 |
750 |
|
); |
751 |
|
} |
752 |
|
} else bufferedCommands[socket] += c; |
753 |
|
// only if the other side is the LSCP shell application: |
754 |
|
// check the current (incomplete) command line for syntax errors, |
755 |
|
// possible completions and report everything back to the shell |
756 |
|
if ((*iter).bShellInteract || (*iter).bShellAutoCorrect) { |
757 |
|
String s = lscpParserProcessShellInteraction(bufferedCommands[socket], &(*iter)); |
758 |
|
if (!s.empty() && (*iter).bShellInteract) AnswerClient(s + "\n"); |
759 |
|
} |
760 |
} |
} |
761 |
#if defined(WIN32) |
#if defined(WIN32) |
762 |
if (result == SOCKET_ERROR) { |
if (result == SOCKET_ERROR) { |
818 |
* @param ReturnMessage - message that will be send to the client |
* @param ReturnMessage - message that will be send to the client |
819 |
*/ |
*/ |
820 |
void LSCPServer::AnswerClient(String ReturnMessage) { |
void LSCPServer::AnswerClient(String ReturnMessage) { |
821 |
dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str())); |
dmsg(2,("LSCPServer::AnswerClient(ReturnMessage='%s')", ReturnMessage.c_str())); |
822 |
if (currentSocket != -1) { |
if (currentSocket != -1) { |
823 |
NotifyMutex.Lock(); |
LockGuard lock(NotifyMutex); |
824 |
|
|
825 |
|
// just if other side is LSCP shell: in case respose is a multi-line |
826 |
|
// one, then inform client about it before sending the actual mult-line |
827 |
|
// response |
828 |
|
if (GetCurrentYaccSession()->bShellInteract) { |
829 |
|
// check if this is a multi-line response |
830 |
|
int n = 0; |
831 |
|
for (int i = 0; i < ReturnMessage.size(); ++i) |
832 |
|
if (ReturnMessage[i] == '\n') ++n; |
833 |
|
if (n >= 2) { |
834 |
|
dmsg(2,("LSCP Shell <- expect mult-line response\n")); |
835 |
|
String s = LSCP_SHK_EXPECT_MULTI_LINE "\r\n"; |
836 |
|
#ifdef MSG_NOSIGNAL |
837 |
|
send(currentSocket, s.c_str(), s.size(), MSG_NOSIGNAL); |
838 |
|
#else |
839 |
|
send(currentSocket, s.c_str(), s.size(), 0); |
840 |
|
#endif |
841 |
|
} |
842 |
|
} |
843 |
|
|
844 |
#ifdef MSG_NOSIGNAL |
#ifdef MSG_NOSIGNAL |
845 |
send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), MSG_NOSIGNAL); |
send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), MSG_NOSIGNAL); |
846 |
#else |
#else |
847 |
send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0); |
send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0); |
848 |
#endif |
#endif |
|
NotifyMutex.Unlock(); |
|
849 |
} |
} |
850 |
} |
} |
851 |
|
|
995 |
try { |
try { |
996 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
997 |
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
998 |
LockRTNotify(); |
LockGuard lock(RTNotifyMutex); |
999 |
pSamplerChannel->SetEngineType(EngineName); |
pSamplerChannel->SetEngineType(EngineName); |
1000 |
if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1); |
if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1); |
|
UnlockRTNotify(); |
|
1001 |
} |
} |
1002 |
catch (Exception e) { |
catch (Exception e) { |
1003 |
result.Error(e); |
result.Error(e); |
1037 |
*/ |
*/ |
1038 |
String LSCPServer::AddChannel() { |
String LSCPServer::AddChannel() { |
1039 |
dmsg(2,("LSCPServer: AddChannel()\n")); |
dmsg(2,("LSCPServer: AddChannel()\n")); |
1040 |
LockRTNotify(); |
SamplerChannel* pSamplerChannel; |
1041 |
SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel(); |
{ |
1042 |
UnlockRTNotify(); |
LockGuard lock(RTNotifyMutex); |
1043 |
|
pSamplerChannel = pSampler->AddSamplerChannel(); |
1044 |
|
} |
1045 |
LSCPResultSet result(pSamplerChannel->Index()); |
LSCPResultSet result(pSamplerChannel->Index()); |
1046 |
return result.Produce(); |
return result.Produce(); |
1047 |
} |
} |
1052 |
String LSCPServer::RemoveChannel(uint uiSamplerChannel) { |
String LSCPServer::RemoveChannel(uint uiSamplerChannel) { |
1053 |
dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
1054 |
LSCPResultSet result; |
LSCPResultSet result; |
1055 |
LockRTNotify(); |
{ |
1056 |
pSampler->RemoveSamplerChannel(uiSamplerChannel); |
LockGuard lock(RTNotifyMutex); |
1057 |
UnlockRTNotify(); |
pSampler->RemoveSamplerChannel(uiSamplerChannel); |
1058 |
|
} |
1059 |
return result.Produce(); |
return result.Produce(); |
1060 |
} |
} |
1061 |
|
|
1098 |
String LSCPServer::GetEngineInfo(String EngineName) { |
String LSCPServer::GetEngineInfo(String EngineName) { |
1099 |
dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str())); |
dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str())); |
1100 |
LSCPResultSet result; |
LSCPResultSet result; |
1101 |
LockRTNotify(); |
{ |
1102 |
try { |
LockGuard lock(RTNotifyMutex); |
1103 |
Engine* pEngine = EngineFactory::Create(EngineName); |
try { |
1104 |
result.Add("DESCRIPTION", _escapeLscpResponse(pEngine->Description())); |
Engine* pEngine = EngineFactory::Create(EngineName); |
1105 |
result.Add("VERSION", pEngine->Version()); |
result.Add("DESCRIPTION", _escapeLscpResponse(pEngine->Description())); |
1106 |
EngineFactory::Destroy(pEngine); |
result.Add("VERSION", pEngine->Version()); |
1107 |
} |
EngineFactory::Destroy(pEngine); |
1108 |
catch (Exception e) { |
} |
1109 |
result.Error(e); |
catch (Exception e) { |
1110 |
|
result.Error(e); |
1111 |
|
} |
1112 |
} |
} |
|
UnlockRTNotify(); |
|
1113 |
return result.Produce(); |
return result.Produce(); |
1114 |
} |
} |
1115 |
|
|
1208 |
dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
1209 |
LSCPResultSet result; |
LSCPResultSet result; |
1210 |
try { |
try { |
1211 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine loaded on sampler channel"); |
|
1212 |
if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel"); |
if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel"); |
1213 |
result.Add(pEngineChannel->GetEngine()->VoiceCount()); |
result.Add(pEngineChannel->GetEngine()->VoiceCount()); |
1214 |
} |
} |
1226 |
dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
1227 |
LSCPResultSet result; |
LSCPResultSet result; |
1228 |
try { |
try { |
1229 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
|
1230 |
if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel"); |
if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel"); |
1231 |
result.Add(pEngineChannel->GetEngine()->DiskStreamCount()); |
result.Add(pEngineChannel->GetEngine()->DiskStreamCount()); |
1232 |
} |
} |
1244 |
dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel)); |
dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel)); |
1245 |
LSCPResultSet result; |
LSCPResultSet result; |
1246 |
try { |
try { |
1247 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
|
1248 |
if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel"); |
if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel"); |
1249 |
if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA"); |
if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA"); |
1250 |
else { |
else { |
1332 |
for (;iter != parameters.end(); iter++) { |
for (;iter != parameters.end(); iter++) { |
1333 |
if (s != "") s += ","; |
if (s != "") s += ","; |
1334 |
s += iter->first; |
s += iter->first; |
1335 |
|
delete iter->second; |
1336 |
} |
} |
1337 |
result.Add("PARAMETERS", s); |
result.Add("PARAMETERS", s); |
1338 |
} |
} |
1357 |
for (;iter != parameters.end(); iter++) { |
for (;iter != parameters.end(); iter++) { |
1358 |
if (s != "") s += ","; |
if (s != "") s += ","; |
1359 |
s += iter->first; |
s += iter->first; |
1360 |
|
delete iter->second; |
1361 |
} |
} |
1362 |
result.Add("PARAMETERS", s); |
result.Add("PARAMETERS", s); |
1363 |
} |
} |
1388 |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
1389 |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
1390 |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
1391 |
|
delete pParameter; |
1392 |
} |
} |
1393 |
catch (Exception e) { |
catch (Exception e) { |
1394 |
result.Error(e); |
result.Error(e); |
1416 |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
1417 |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
1418 |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
1419 |
|
delete pParameter; |
1420 |
} |
} |
1421 |
catch (Exception e) { |
catch (Exception e) { |
1422 |
result.Error(e); |
result.Error(e); |
1758 |
String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) { |
String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) { |
1759 |
dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel)); |
1760 |
LSCPResultSet result; |
LSCPResultSet result; |
1761 |
LockRTNotify(); |
{ |
1762 |
|
LockGuard lock(RTNotifyMutex); |
1763 |
|
try { |
1764 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1765 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1766 |
|
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1767 |
|
if (!devices.count(AudioDeviceId)) throw Exception("There is no audio output device with index " + ToString(AudioDeviceId)); |
1768 |
|
AudioOutputDevice* pDevice = devices[AudioDeviceId]; |
1769 |
|
pSamplerChannel->SetAudioOutputDevice(pDevice); |
1770 |
|
} |
1771 |
|
catch (Exception e) { |
1772 |
|
result.Error(e); |
1773 |
|
} |
1774 |
|
} |
1775 |
|
return result.Produce(); |
1776 |
|
} |
1777 |
|
|
1778 |
|
String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) { |
1779 |
|
dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel)); |
1780 |
|
LSCPResultSet result; |
1781 |
|
{ |
1782 |
|
LockGuard lock(RTNotifyMutex); |
1783 |
|
try { |
1784 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1785 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1786 |
|
// Driver type name aliasing... |
1787 |
|
if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA"; |
1788 |
|
if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK"; |
1789 |
|
// Check if there's one audio output device already created |
1790 |
|
// for the intended audio driver type (AudioOutputDriver)... |
1791 |
|
AudioOutputDevice *pDevice = NULL; |
1792 |
|
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1793 |
|
std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin(); |
1794 |
|
for (; iter != devices.end(); iter++) { |
1795 |
|
if ((iter->second)->Driver() == AudioOutputDriver) { |
1796 |
|
pDevice = iter->second; |
1797 |
|
break; |
1798 |
|
} |
1799 |
|
} |
1800 |
|
// If it doesn't exist, create a new one with default parameters... |
1801 |
|
if (pDevice == NULL) { |
1802 |
|
std::map<String,String> params; |
1803 |
|
pDevice = pSampler->CreateAudioOutputDevice(AudioOutputDriver, params); |
1804 |
|
} |
1805 |
|
// Must have a device... |
1806 |
|
if (pDevice == NULL) |
1807 |
|
throw Exception("Internal error: could not create audio output device."); |
1808 |
|
// Set it as the current channel device... |
1809 |
|
pSamplerChannel->SetAudioOutputDevice(pDevice); |
1810 |
|
} |
1811 |
|
catch (Exception e) { |
1812 |
|
result.Error(e); |
1813 |
|
} |
1814 |
|
} |
1815 |
|
return result.Produce(); |
1816 |
|
} |
1817 |
|
|
1818 |
|
String LSCPServer::AddChannelMidiInput(uint uiSamplerChannel, uint MIDIDeviceId, uint MIDIPort) { |
1819 |
|
dmsg(2,("LSCPServer: AddChannelMidiInput(uiSamplerChannel=%d, MIDIDeviceId=%d, MIDIPort=%d)\n",uiSamplerChannel,MIDIDeviceId,MIDIPort)); |
1820 |
|
LSCPResultSet result; |
1821 |
try { |
try { |
1822 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1823 |
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1824 |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
|
1825 |
if (!devices.count(AudioDeviceId)) throw Exception("There is no audio output device with index " + ToString(AudioDeviceId)); |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1826 |
AudioOutputDevice* pDevice = devices[AudioDeviceId]; |
if (!devices.count(MIDIDeviceId)) throw Exception("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
1827 |
pSamplerChannel->SetAudioOutputDevice(pDevice); |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
1828 |
|
|
1829 |
|
MidiInputPort* pPort = pDevice->GetPort(MIDIPort); |
1830 |
|
if (!pPort) throw Exception("There is no MIDI input port with index " + ToString(MIDIPort) + " on MIDI input device with index " + ToString(MIDIDeviceId)); |
1831 |
|
|
1832 |
|
pSamplerChannel->Connect(pPort); |
1833 |
|
} catch (Exception e) { |
1834 |
|
result.Error(e); |
1835 |
} |
} |
1836 |
catch (Exception e) { |
return result.Produce(); |
1837 |
result.Error(e); |
} |
1838 |
|
|
1839 |
|
String LSCPServer::RemoveChannelMidiInput(uint uiSamplerChannel) { |
1840 |
|
dmsg(2,("LSCPServer: RemoveChannelMidiInput(uiSamplerChannel=%d)\n",uiSamplerChannel)); |
1841 |
|
LSCPResultSet result; |
1842 |
|
try { |
1843 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1844 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1845 |
|
pSamplerChannel->DisconnectAllMidiInputPorts(); |
1846 |
|
} catch (Exception e) { |
1847 |
|
result.Error(e); |
1848 |
} |
} |
|
UnlockRTNotify(); |
|
1849 |
return result.Produce(); |
return result.Produce(); |
1850 |
} |
} |
1851 |
|
|
1852 |
String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) { |
String LSCPServer::RemoveChannelMidiInput(uint uiSamplerChannel, uint MIDIDeviceId) { |
1853 |
dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel)); |
dmsg(2,("LSCPServer: RemoveChannelMidiInput(uiSamplerChannel=%d, MIDIDeviceId=%d)\n",uiSamplerChannel,MIDIDeviceId)); |
1854 |
LSCPResultSet result; |
LSCPResultSet result; |
|
LockRTNotify(); |
|
1855 |
try { |
try { |
1856 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1857 |
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1858 |
// Driver type name aliasing... |
|
1859 |
if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA"; |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1860 |
if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK"; |
if (!devices.count(MIDIDeviceId)) throw Exception("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
1861 |
// Check if there's one audio output device already created |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
1862 |
// for the intended audio driver type (AudioOutputDriver)... |
|
1863 |
AudioOutputDevice *pDevice = NULL; |
std::vector<MidiInputPort*> vPorts = pSamplerChannel->GetMidiInputPorts(); |
1864 |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
for (int i = 0; i < vPorts.size(); ++i) |
1865 |
std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin(); |
if (vPorts[i]->GetDevice() == pDevice) |
1866 |
for (; iter != devices.end(); iter++) { |
pSamplerChannel->Disconnect(vPorts[i]); |
1867 |
if ((iter->second)->Driver() == AudioOutputDriver) { |
|
1868 |
pDevice = iter->second; |
} catch (Exception e) { |
1869 |
break; |
result.Error(e); |
|
} |
|
|
} |
|
|
// If it doesn't exist, create a new one with default parameters... |
|
|
if (pDevice == NULL) { |
|
|
std::map<String,String> params; |
|
|
pDevice = pSampler->CreateAudioOutputDevice(AudioOutputDriver, params); |
|
|
} |
|
|
// 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); |
|
1870 |
} |
} |
1871 |
catch (Exception e) { |
return result.Produce(); |
1872 |
result.Error(e); |
} |
1873 |
|
|
1874 |
|
String LSCPServer::RemoveChannelMidiInput(uint uiSamplerChannel, uint MIDIDeviceId, uint MIDIPort) { |
1875 |
|
dmsg(2,("LSCPServer: RemoveChannelMidiInput(uiSamplerChannel=%d, MIDIDeviceId=%d, MIDIPort=%d)\n",uiSamplerChannel,MIDIDeviceId,MIDIPort)); |
1876 |
|
LSCPResultSet result; |
1877 |
|
try { |
1878 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1879 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1880 |
|
|
1881 |
|
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1882 |
|
if (!devices.count(MIDIDeviceId)) throw Exception("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
1883 |
|
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
1884 |
|
|
1885 |
|
MidiInputPort* pPort = pDevice->GetPort(MIDIPort); |
1886 |
|
if (!pPort) throw Exception("There is no MIDI input port with index " + ToString(MIDIPort) + " on MIDI input device with index " + ToString(MIDIDeviceId)); |
1887 |
|
|
1888 |
|
pSamplerChannel->Disconnect(pPort); |
1889 |
|
} catch (Exception e) { |
1890 |
|
result.Error(e); |
1891 |
|
} |
1892 |
|
return result.Produce(); |
1893 |
|
} |
1894 |
|
|
1895 |
|
String LSCPServer::ListChannelMidiInputs(uint uiSamplerChannel) { |
1896 |
|
dmsg(2,("LSCPServer: ListChannelMidiInputs(uiSamplerChannel=%d)\n",uiSamplerChannel)); |
1897 |
|
LSCPResultSet result; |
1898 |
|
try { |
1899 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1900 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1901 |
|
std::vector<MidiInputPort*> vPorts = pSamplerChannel->GetMidiInputPorts(); |
1902 |
|
|
1903 |
|
String s; |
1904 |
|
for (int i = 0; i < vPorts.size(); ++i) { |
1905 |
|
const int iDeviceID = vPorts[i]->GetDevice()->MidiInputDeviceID(); |
1906 |
|
const int iPortNr = vPorts[i]->GetPortNumber(); |
1907 |
|
if (s.size()) s += ","; |
1908 |
|
s += "{" + ToString(iDeviceID) + "," |
1909 |
|
+ ToString(iPortNr) + "}"; |
1910 |
|
} |
1911 |
|
result.Add(s); |
1912 |
|
} catch (Exception e) { |
1913 |
|
result.Error(e); |
1914 |
} |
} |
|
UnlockRTNotify(); |
|
1915 |
return result.Produce(); |
return result.Produce(); |
1916 |
} |
} |
1917 |
|
|
1985 |
pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params); |
pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params); |
1986 |
// Make it with at least one initial port. |
// Make it with at least one initial port. |
1987 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
|
parameters["PORTS"]->SetValue("1"); |
|
1988 |
} |
} |
1989 |
// Must have a device... |
// Must have a device... |
1990 |
if (pDevice == NULL) |
if (pDevice == NULL) |
2027 |
dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel)); |
2028 |
LSCPResultSet result; |
LSCPResultSet result; |
2029 |
try { |
try { |
2030 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
|
2031 |
pEngineChannel->Volume(dVolume); |
pEngineChannel->Volume(dVolume); |
2032 |
} |
} |
2033 |
catch (Exception e) { |
catch (Exception e) { |
2043 |
dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel)); |
2044 |
LSCPResultSet result; |
LSCPResultSet result; |
2045 |
try { |
try { |
2046 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
|
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
|
2047 |
|
|
2048 |
if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0); |
if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0); |
2049 |
else pEngineChannel->SetMute(1); |
else pEngineChannel->SetMute(1); |
2060 |
dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel)); |
2061 |
LSCPResultSet result; |
LSCPResultSet result; |
2062 |
try { |
try { |
2063 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
|
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
|
2064 |
|
|
2065 |
bool oldSolo = pEngineChannel->GetSolo(); |
bool oldSolo = pEngineChannel->GetSolo(); |
2066 |
bool hadSoloChannel = HasSoloChannel(); |
bool hadSoloChannel = HasSoloChannel(); |
2413 |
dmsg(2,("LSCPServer: SetChannelMap()\n")); |
dmsg(2,("LSCPServer: SetChannelMap()\n")); |
2414 |
LSCPResultSet result; |
LSCPResultSet result; |
2415 |
try { |
try { |
2416 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
|
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet"); |
|
2417 |
|
|
2418 |
if (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone(); |
if (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone(); |
2419 |
else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault(); |
else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault(); |
2521 |
AudioRouting += ToString(pFxSend->DestinationChannel(chan)); |
AudioRouting += ToString(pFxSend->DestinationChannel(chan)); |
2522 |
} |
} |
2523 |
|
|
2524 |
|
const String sEffectRouting = |
2525 |
|
(pFxSend->DestinationEffectChain() >= 0 && pFxSend->DestinationEffectChainPosition() >= 0) |
2526 |
|
? ToString(pFxSend->DestinationEffectChain()) + "," + ToString(pFxSend->DestinationEffectChainPosition()) |
2527 |
|
: "NONE"; |
2528 |
|
|
2529 |
// success |
// success |
2530 |
result.Add("NAME", _escapeLscpResponse(pFxSend->Name())); |
result.Add("NAME", _escapeLscpResponse(pFxSend->Name())); |
2531 |
result.Add("MIDI_CONTROLLER", pFxSend->MidiController()); |
result.Add("MIDI_CONTROLLER", pFxSend->MidiController()); |
2532 |
result.Add("LEVEL", ToString(pFxSend->Level())); |
result.Add("LEVEL", ToString(pFxSend->Level())); |
2533 |
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
2534 |
|
result.Add("EFFECT", sEffectRouting); |
2535 |
} catch (Exception e) { |
} catch (Exception e) { |
2536 |
result.Error(e); |
result.Error(e); |
2537 |
} |
} |
2594 |
return result.Produce(); |
return result.Produce(); |
2595 |
} |
} |
2596 |
|
|
2597 |
|
String LSCPServer::SetFxSendEffect(uint uiSamplerChannel, uint FxSendID, int iSendEffectChain, int iEffectChainPosition) { |
2598 |
|
dmsg(2,("LSCPServer: SetFxSendEffect(%d,%d)\n", iSendEffectChain, iEffectChainPosition)); |
2599 |
|
LSCPResultSet result; |
2600 |
|
try { |
2601 |
|
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
2602 |
|
|
2603 |
|
pFxSend->SetDestinationEffect(iSendEffectChain, iEffectChainPosition); |
2604 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
2605 |
|
} catch (Exception e) { |
2606 |
|
result.Error(e); |
2607 |
|
} |
2608 |
|
return result.Produce(); |
2609 |
|
} |
2610 |
|
|
2611 |
|
String LSCPServer::GetAvailableEffects() { |
2612 |
|
dmsg(2,("LSCPServer: GetAvailableEffects()\n")); |
2613 |
|
LSCPResultSet result; |
2614 |
|
try { |
2615 |
|
int n = EffectFactory::AvailableEffectsCount(); |
2616 |
|
result.Add(n); |
2617 |
|
} |
2618 |
|
catch (Exception e) { |
2619 |
|
result.Error(e); |
2620 |
|
} |
2621 |
|
return result.Produce(); |
2622 |
|
} |
2623 |
|
|
2624 |
|
String LSCPServer::ListAvailableEffects() { |
2625 |
|
dmsg(2,("LSCPServer: ListAvailableEffects()\n")); |
2626 |
|
LSCPResultSet result; |
2627 |
|
String list; |
2628 |
|
try { |
2629 |
|
//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 |
2630 |
|
int n = EffectFactory::AvailableEffectsCount(); |
2631 |
|
for (int i = 0; i < n; i++) { |
2632 |
|
if (i) list += ","; |
2633 |
|
list += ToString(i); |
2634 |
|
} |
2635 |
|
} |
2636 |
|
catch (Exception e) { |
2637 |
|
result.Error(e); |
2638 |
|
} |
2639 |
|
result.Add(list); |
2640 |
|
return result.Produce(); |
2641 |
|
} |
2642 |
|
|
2643 |
|
String LSCPServer::GetEffectInfo(int iEffectIndex) { |
2644 |
|
dmsg(2,("LSCPServer: GetEffectInfo(%d)\n", iEffectIndex)); |
2645 |
|
LSCPResultSet result; |
2646 |
|
try { |
2647 |
|
EffectInfo* pEffectInfo = EffectFactory::GetEffectInfo(iEffectIndex); |
2648 |
|
if (!pEffectInfo) |
2649 |
|
throw Exception("There is no effect with index " + ToString(iEffectIndex)); |
2650 |
|
|
2651 |
|
// convert the filename into the correct encoding as defined for LSCP |
2652 |
|
// (especially in terms of special characters -> escape sequences) |
2653 |
|
#if WIN32 |
2654 |
|
const String dllFileName = Path::fromWindows(pEffectInfo->Module()).toLscp(); |
2655 |
|
#else |
2656 |
|
// assuming POSIX |
2657 |
|
const String dllFileName = Path::fromPosix(pEffectInfo->Module()).toLscp(); |
2658 |
|
#endif |
2659 |
|
|
2660 |
|
result.Add("SYSTEM", pEffectInfo->EffectSystem()); |
2661 |
|
result.Add("MODULE", dllFileName); |
2662 |
|
result.Add("NAME", _escapeLscpResponse(pEffectInfo->Name())); |
2663 |
|
result.Add("DESCRIPTION", _escapeLscpResponse(pEffectInfo->Description())); |
2664 |
|
} |
2665 |
|
catch (Exception e) { |
2666 |
|
result.Error(e); |
2667 |
|
} |
2668 |
|
return result.Produce(); |
2669 |
|
} |
2670 |
|
|
2671 |
|
String LSCPServer::GetEffectInstanceInfo(int iEffectInstance) { |
2672 |
|
dmsg(2,("LSCPServer: GetEffectInstanceInfo(%d)\n", iEffectInstance)); |
2673 |
|
LSCPResultSet result; |
2674 |
|
try { |
2675 |
|
Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance); |
2676 |
|
if (!pEffect) |
2677 |
|
throw Exception("There is no effect instance with ID " + ToString(iEffectInstance)); |
2678 |
|
|
2679 |
|
EffectInfo* pEffectInfo = pEffect->GetEffectInfo(); |
2680 |
|
|
2681 |
|
// convert the filename into the correct encoding as defined for LSCP |
2682 |
|
// (especially in terms of special characters -> escape sequences) |
2683 |
|
#if WIN32 |
2684 |
|
const String dllFileName = Path::fromWindows(pEffectInfo->Module()).toLscp(); |
2685 |
|
#else |
2686 |
|
// assuming POSIX |
2687 |
|
const String dllFileName = Path::fromPosix(pEffectInfo->Module()).toLscp(); |
2688 |
|
#endif |
2689 |
|
|
2690 |
|
result.Add("SYSTEM", pEffectInfo->EffectSystem()); |
2691 |
|
result.Add("MODULE", dllFileName); |
2692 |
|
result.Add("NAME", _escapeLscpResponse(pEffectInfo->Name())); |
2693 |
|
result.Add("DESCRIPTION", _escapeLscpResponse(pEffectInfo->Description())); |
2694 |
|
result.Add("INPUT_CONTROLS", ToString(pEffect->InputControlCount())); |
2695 |
|
} |
2696 |
|
catch (Exception e) { |
2697 |
|
result.Error(e); |
2698 |
|
} |
2699 |
|
return result.Produce(); |
2700 |
|
} |
2701 |
|
|
2702 |
|
String LSCPServer::GetEffectInstanceInputControlInfo(int iEffectInstance, int iInputControlIndex) { |
2703 |
|
dmsg(2,("LSCPServer: GetEffectInstanceInputControlInfo(%d,%d)\n", iEffectInstance, iInputControlIndex)); |
2704 |
|
LSCPResultSet result; |
2705 |
|
try { |
2706 |
|
Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance); |
2707 |
|
if (!pEffect) |
2708 |
|
throw Exception("There is no effect instance with ID " + ToString(iEffectInstance)); |
2709 |
|
|
2710 |
|
EffectControl* pEffectControl = pEffect->InputControl(iInputControlIndex); |
2711 |
|
if (!pEffectControl) |
2712 |
|
throw Exception( |
2713 |
|
"Effect instance " + ToString(iEffectInstance) + |
2714 |
|
" does not have an input control with index " + |
2715 |
|
ToString(iInputControlIndex) |
2716 |
|
); |
2717 |
|
|
2718 |
|
result.Add("DESCRIPTION", _escapeLscpResponse(pEffectControl->Description())); |
2719 |
|
result.Add("VALUE", pEffectControl->Value()); |
2720 |
|
if (pEffectControl->MinValue()) |
2721 |
|
result.Add("RANGE_MIN", *pEffectControl->MinValue()); |
2722 |
|
if (pEffectControl->MaxValue()) |
2723 |
|
result.Add("RANGE_MAX", *pEffectControl->MaxValue()); |
2724 |
|
if (!pEffectControl->Possibilities().empty()) |
2725 |
|
result.Add("POSSIBILITIES", pEffectControl->Possibilities()); |
2726 |
|
if (pEffectControl->DefaultValue()) |
2727 |
|
result.Add("DEFAULT", *pEffectControl->DefaultValue()); |
2728 |
|
} catch (Exception e) { |
2729 |
|
result.Error(e); |
2730 |
|
} |
2731 |
|
return result.Produce(); |
2732 |
|
} |
2733 |
|
|
2734 |
|
String LSCPServer::SetEffectInstanceInputControlValue(int iEffectInstance, int iInputControlIndex, double dValue) { |
2735 |
|
dmsg(2,("LSCPServer: SetEffectInstanceInputControlValue(%d,%d,%f)\n", iEffectInstance, iInputControlIndex, dValue)); |
2736 |
|
LSCPResultSet result; |
2737 |
|
try { |
2738 |
|
Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance); |
2739 |
|
if (!pEffect) |
2740 |
|
throw Exception("There is no effect instance with ID " + ToString(iEffectInstance)); |
2741 |
|
|
2742 |
|
EffectControl* pEffectControl = pEffect->InputControl(iInputControlIndex); |
2743 |
|
if (!pEffectControl) |
2744 |
|
throw Exception( |
2745 |
|
"Effect instance " + ToString(iEffectInstance) + |
2746 |
|
" does not have an input control with index " + |
2747 |
|
ToString(iInputControlIndex) |
2748 |
|
); |
2749 |
|
|
2750 |
|
pEffectControl->SetValue(dValue); |
2751 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_info, iEffectInstance)); |
2752 |
|
} catch (Exception e) { |
2753 |
|
result.Error(e); |
2754 |
|
} |
2755 |
|
return result.Produce(); |
2756 |
|
} |
2757 |
|
|
2758 |
|
String LSCPServer::CreateEffectInstance(int iEffectIndex) { |
2759 |
|
dmsg(2,("LSCPServer: CreateEffectInstance(%d)\n", iEffectIndex)); |
2760 |
|
LSCPResultSet result; |
2761 |
|
try { |
2762 |
|
EffectInfo* pEffectInfo = EffectFactory::GetEffectInfo(iEffectIndex); |
2763 |
|
if (!pEffectInfo) |
2764 |
|
throw Exception("There is no effect with index " + ToString(iEffectIndex)); |
2765 |
|
Effect* pEffect = EffectFactory::Create(pEffectInfo); |
2766 |
|
result = pEffect->ID(); // success |
2767 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_count, EffectFactory::EffectInstancesCount())); |
2768 |
|
} catch (Exception e) { |
2769 |
|
result.Error(e); |
2770 |
|
} |
2771 |
|
return result.Produce(); |
2772 |
|
} |
2773 |
|
|
2774 |
|
String LSCPServer::CreateEffectInstance(String effectSystem, String module, String effectName) { |
2775 |
|
dmsg(2,("LSCPServer: CreateEffectInstance('%s','%s','%s')\n", effectSystem.c_str(), module.c_str(), effectName.c_str())); |
2776 |
|
LSCPResultSet result; |
2777 |
|
try { |
2778 |
|
// to allow loading the same LSCP session file on different systems |
2779 |
|
// successfully, probably with different effect plugin DLL paths or even |
2780 |
|
// running completely different operating systems, we do the following |
2781 |
|
// for finding the right effect: |
2782 |
|
// |
2783 |
|
// first try to search for an exact match of the effect plugin DLL |
2784 |
|
// (a.k.a 'module'), to avoid picking the wrong DLL with the same |
2785 |
|
// effect name ... |
2786 |
|
EffectInfo* pEffectInfo = EffectFactory::GetEffectInfo(effectSystem, module, effectName, EffectFactory::MODULE_MATCH_EXACTLY); |
2787 |
|
// ... if no effect with exactly matchin DLL filename was found, then |
2788 |
|
// try to lower the restrictions of matching the effect plugin DLL |
2789 |
|
// filename and try again and again ... |
2790 |
|
if (!pEffectInfo) { |
2791 |
|
dmsg(2,("no exact module match, trying MODULE_IGNORE_PATH\n")); |
2792 |
|
pEffectInfo = EffectFactory::GetEffectInfo(effectSystem, module, effectName, EffectFactory::MODULE_IGNORE_PATH); |
2793 |
|
} |
2794 |
|
if (!pEffectInfo) { |
2795 |
|
dmsg(2,("no module match, trying MODULE_IGNORE_PATH | MODULE_IGNORE_CASE\n")); |
2796 |
|
pEffectInfo = EffectFactory::GetEffectInfo(effectSystem, module, effectName, EffectFactory::MODULE_IGNORE_PATH | EffectFactory::MODULE_IGNORE_CASE); |
2797 |
|
} |
2798 |
|
if (!pEffectInfo) { |
2799 |
|
dmsg(2,("no module match, trying MODULE_IGNORE_PATH | MODULE_IGNORE_CASE | MODULE_IGNORE_EXTENSION\n")); |
2800 |
|
pEffectInfo = EffectFactory::GetEffectInfo(effectSystem, module, effectName, EffectFactory::MODULE_IGNORE_PATH | EffectFactory::MODULE_IGNORE_CASE | EffectFactory::MODULE_IGNORE_EXTENSION); |
2801 |
|
} |
2802 |
|
// ... if there was still no effect found, then completely ignore the |
2803 |
|
// DLL plugin filename argument and just search for the matching effect |
2804 |
|
// system type and effect name |
2805 |
|
if (!pEffectInfo) { |
2806 |
|
dmsg(2,("no module match, trying MODULE_IGNORE_ALL\n")); |
2807 |
|
pEffectInfo = EffectFactory::GetEffectInfo(effectSystem, module, effectName, EffectFactory::MODULE_IGNORE_ALL); |
2808 |
|
} |
2809 |
|
if (!pEffectInfo) |
2810 |
|
throw Exception("There is no such effect '" + effectSystem + "' '" + module + "' '" + effectName + "'"); |
2811 |
|
|
2812 |
|
Effect* pEffect = EffectFactory::Create(pEffectInfo); |
2813 |
|
result = LSCPResultSet(pEffect->ID()); |
2814 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_count, EffectFactory::EffectInstancesCount())); |
2815 |
|
} catch (Exception e) { |
2816 |
|
result.Error(e); |
2817 |
|
} |
2818 |
|
return result.Produce(); |
2819 |
|
} |
2820 |
|
|
2821 |
|
String LSCPServer::DestroyEffectInstance(int iEffectInstance) { |
2822 |
|
dmsg(2,("LSCPServer: DestroyEffectInstance(%d)\n", iEffectInstance)); |
2823 |
|
LSCPResultSet result; |
2824 |
|
try { |
2825 |
|
Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance); |
2826 |
|
if (!pEffect) |
2827 |
|
throw Exception("There is no effect instance with ID " + ToString(iEffectInstance)); |
2828 |
|
EffectFactory::Destroy(pEffect); |
2829 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_count, EffectFactory::EffectInstancesCount())); |
2830 |
|
} catch (Exception e) { |
2831 |
|
result.Error(e); |
2832 |
|
} |
2833 |
|
return result.Produce(); |
2834 |
|
} |
2835 |
|
|
2836 |
|
String LSCPServer::GetEffectInstances() { |
2837 |
|
dmsg(2,("LSCPServer: GetEffectInstances()\n")); |
2838 |
|
LSCPResultSet result; |
2839 |
|
try { |
2840 |
|
int n = EffectFactory::EffectInstancesCount(); |
2841 |
|
result.Add(n); |
2842 |
|
} catch (Exception e) { |
2843 |
|
result.Error(e); |
2844 |
|
} |
2845 |
|
return result.Produce(); |
2846 |
|
} |
2847 |
|
|
2848 |
|
String LSCPServer::ListEffectInstances() { |
2849 |
|
dmsg(2,("LSCPServer: ListEffectInstances()\n")); |
2850 |
|
LSCPResultSet result; |
2851 |
|
String list; |
2852 |
|
try { |
2853 |
|
int n = EffectFactory::EffectInstancesCount(); |
2854 |
|
for (int i = 0; i < n; i++) { |
2855 |
|
Effect* pEffect = EffectFactory::GetEffectInstance(i); |
2856 |
|
if (i) list += ","; |
2857 |
|
list += ToString(pEffect->ID()); |
2858 |
|
} |
2859 |
|
} catch (Exception e) { |
2860 |
|
result.Error(e); |
2861 |
|
} |
2862 |
|
result.Add(list); |
2863 |
|
return result.Produce(); |
2864 |
|
} |
2865 |
|
|
2866 |
|
String LSCPServer::GetSendEffectChains(int iAudioOutputDevice) { |
2867 |
|
dmsg(2,("LSCPServer: GetSendEffectChains(%d)\n", iAudioOutputDevice)); |
2868 |
|
LSCPResultSet result; |
2869 |
|
try { |
2870 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
2871 |
|
if (!devices.count(iAudioOutputDevice)) |
2872 |
|
throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + "."); |
2873 |
|
AudioOutputDevice* pDevice = devices[iAudioOutputDevice]; |
2874 |
|
int n = pDevice->SendEffectChainCount(); |
2875 |
|
result.Add(n); |
2876 |
|
} catch (Exception e) { |
2877 |
|
result.Error(e); |
2878 |
|
} |
2879 |
|
return result.Produce(); |
2880 |
|
} |
2881 |
|
|
2882 |
|
String LSCPServer::ListSendEffectChains(int iAudioOutputDevice) { |
2883 |
|
dmsg(2,("LSCPServer: ListSendEffectChains(%d)\n", iAudioOutputDevice)); |
2884 |
|
LSCPResultSet result; |
2885 |
|
String list; |
2886 |
|
try { |
2887 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
2888 |
|
if (!devices.count(iAudioOutputDevice)) |
2889 |
|
throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + "."); |
2890 |
|
AudioOutputDevice* pDevice = devices[iAudioOutputDevice]; |
2891 |
|
int n = pDevice->SendEffectChainCount(); |
2892 |
|
for (int i = 0; i < n; i++) { |
2893 |
|
EffectChain* pEffectChain = pDevice->SendEffectChain(i); |
2894 |
|
if (i) list += ","; |
2895 |
|
list += ToString(pEffectChain->ID()); |
2896 |
|
} |
2897 |
|
} catch (Exception e) { |
2898 |
|
result.Error(e); |
2899 |
|
} |
2900 |
|
result.Add(list); |
2901 |
|
return result.Produce(); |
2902 |
|
} |
2903 |
|
|
2904 |
|
String LSCPServer::AddSendEffectChain(int iAudioOutputDevice) { |
2905 |
|
dmsg(2,("LSCPServer: AddSendEffectChain(%d)\n", iAudioOutputDevice)); |
2906 |
|
LSCPResultSet result; |
2907 |
|
try { |
2908 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
2909 |
|
if (!devices.count(iAudioOutputDevice)) |
2910 |
|
throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + "."); |
2911 |
|
AudioOutputDevice* pDevice = devices[iAudioOutputDevice]; |
2912 |
|
EffectChain* pEffectChain = pDevice->AddSendEffectChain(); |
2913 |
|
result = pEffectChain->ID(); |
2914 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_count, iAudioOutputDevice, pDevice->SendEffectChainCount())); |
2915 |
|
} catch (Exception e) { |
2916 |
|
result.Error(e); |
2917 |
|
} |
2918 |
|
return result.Produce(); |
2919 |
|
} |
2920 |
|
|
2921 |
|
String LSCPServer::RemoveSendEffectChain(int iAudioOutputDevice, int iSendEffectChain) { |
2922 |
|
dmsg(2,("LSCPServer: RemoveSendEffectChain(%d,%d)\n", iAudioOutputDevice, iSendEffectChain)); |
2923 |
|
LSCPResultSet result; |
2924 |
|
try { |
2925 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
2926 |
|
if (!devices.count(iAudioOutputDevice)) |
2927 |
|
throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + "."); |
2928 |
|
|
2929 |
|
std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances(); |
2930 |
|
std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin(); |
2931 |
|
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
2932 |
|
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
2933 |
|
AudioOutputDevice* pDev = (*itEngineChannel)->GetAudioOutputDevice(); |
2934 |
|
if (pDev != NULL && pDev->deviceId() == iAudioOutputDevice) { |
2935 |
|
for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) { |
2936 |
|
FxSend* fxs = (*itEngineChannel)->GetFxSend(i); |
2937 |
|
if(fxs != NULL && fxs->DestinationEffectChain() == iSendEffectChain) { |
2938 |
|
throw Exception("The effect chain is still in use by channel " + ToString((*itEngineChannel)->GetSamplerChannel()->Index())); |
2939 |
|
} |
2940 |
|
} |
2941 |
|
} |
2942 |
|
} |
2943 |
|
|
2944 |
|
AudioOutputDevice* pDevice = devices[iAudioOutputDevice]; |
2945 |
|
for (int i = 0; i < pDevice->SendEffectChainCount(); i++) { |
2946 |
|
EffectChain* pEffectChain = pDevice->SendEffectChain(i); |
2947 |
|
if (pEffectChain->ID() == iSendEffectChain) { |
2948 |
|
pDevice->RemoveSendEffectChain(i); |
2949 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_count, iAudioOutputDevice, pDevice->SendEffectChainCount())); |
2950 |
|
return result.Produce(); |
2951 |
|
} |
2952 |
|
} |
2953 |
|
throw Exception( |
2954 |
|
"There is no send effect chain with ID " + |
2955 |
|
ToString(iSendEffectChain) + " for audio output device " + |
2956 |
|
ToString(iAudioOutputDevice) + "." |
2957 |
|
); |
2958 |
|
} catch (Exception e) { |
2959 |
|
result.Error(e); |
2960 |
|
} |
2961 |
|
return result.Produce(); |
2962 |
|
} |
2963 |
|
|
2964 |
|
static EffectChain* _getSendEffectChain(Sampler* pSampler, int iAudioOutputDevice, int iSendEffectChain) throw (Exception) { |
2965 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
2966 |
|
if (!devices.count(iAudioOutputDevice)) |
2967 |
|
throw Exception( |
2968 |
|
"There is no audio output device with index " + |
2969 |
|
ToString(iAudioOutputDevice) + "." |
2970 |
|
); |
2971 |
|
AudioOutputDevice* pDevice = devices[iAudioOutputDevice]; |
2972 |
|
EffectChain* pEffectChain = pDevice->SendEffectChainByID(iSendEffectChain); |
2973 |
|
if(pEffectChain != NULL) return pEffectChain; |
2974 |
|
throw Exception( |
2975 |
|
"There is no send effect chain with ID " + |
2976 |
|
ToString(iSendEffectChain) + " for audio output device " + |
2977 |
|
ToString(iAudioOutputDevice) + "." |
2978 |
|
); |
2979 |
|
} |
2980 |
|
|
2981 |
|
String LSCPServer::GetSendEffectChainInfo(int iAudioOutputDevice, int iSendEffectChain) { |
2982 |
|
dmsg(2,("LSCPServer: GetSendEffectChainInfo(%d,%d)\n", iAudioOutputDevice, iSendEffectChain)); |
2983 |
|
LSCPResultSet result; |
2984 |
|
try { |
2985 |
|
EffectChain* pEffectChain = |
2986 |
|
_getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain); |
2987 |
|
String sEffectSequence; |
2988 |
|
for (int i = 0; i < pEffectChain->EffectCount(); i++) { |
2989 |
|
if (i) sEffectSequence += ","; |
2990 |
|
sEffectSequence += ToString(pEffectChain->GetEffect(i)->ID()); |
2991 |
|
} |
2992 |
|
result.Add("EFFECT_COUNT", pEffectChain->EffectCount()); |
2993 |
|
result.Add("EFFECT_SEQUENCE", sEffectSequence); |
2994 |
|
} catch (Exception e) { |
2995 |
|
result.Error(e); |
2996 |
|
} |
2997 |
|
return result.Produce(); |
2998 |
|
} |
2999 |
|
|
3000 |
|
String LSCPServer::AppendSendEffectChainEffect(int iAudioOutputDevice, int iSendEffectChain, int iEffectInstance) { |
3001 |
|
dmsg(2,("LSCPServer: AppendSendEffectChainEffect(%d,%d,%d)\n", iAudioOutputDevice, iSendEffectChain, iEffectInstance)); |
3002 |
|
LSCPResultSet result; |
3003 |
|
try { |
3004 |
|
EffectChain* pEffectChain = |
3005 |
|
_getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain); |
3006 |
|
Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance); |
3007 |
|
if (!pEffect) |
3008 |
|
throw Exception("There is no effect instance with ID " + ToString(iEffectInstance)); |
3009 |
|
pEffectChain->AppendEffect(pEffect); |
3010 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_info, iAudioOutputDevice, iSendEffectChain, pEffectChain->EffectCount())); |
3011 |
|
} catch (Exception e) { |
3012 |
|
result.Error(e); |
3013 |
|
} |
3014 |
|
return result.Produce(); |
3015 |
|
} |
3016 |
|
|
3017 |
|
String LSCPServer::InsertSendEffectChainEffect(int iAudioOutputDevice, int iSendEffectChain, int iEffectChainPosition, int iEffectInstance) { |
3018 |
|
dmsg(2,("LSCPServer: InsertSendEffectChainEffect(%d,%d,%d,%d)\n", iAudioOutputDevice, iSendEffectChain, iEffectChainPosition, iEffectInstance)); |
3019 |
|
LSCPResultSet result; |
3020 |
|
try { |
3021 |
|
EffectChain* pEffectChain = |
3022 |
|
_getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain); |
3023 |
|
Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance); |
3024 |
|
if (!pEffect) |
3025 |
|
throw Exception("There is no effect instance with index " + ToString(iEffectInstance)); |
3026 |
|
pEffectChain->InsertEffect(pEffect, iEffectChainPosition); |
3027 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_info, iAudioOutputDevice, iSendEffectChain, pEffectChain->EffectCount())); |
3028 |
|
} catch (Exception e) { |
3029 |
|
result.Error(e); |
3030 |
|
} |
3031 |
|
return result.Produce(); |
3032 |
|
} |
3033 |
|
|
3034 |
|
String LSCPServer::RemoveSendEffectChainEffect(int iAudioOutputDevice, int iSendEffectChain, int iEffectChainPosition) { |
3035 |
|
dmsg(2,("LSCPServer: RemoveSendEffectChainEffect(%d,%d,%d)\n", iAudioOutputDevice, iSendEffectChain, iEffectChainPosition)); |
3036 |
|
LSCPResultSet result; |
3037 |
|
try { |
3038 |
|
EffectChain* pEffectChain = |
3039 |
|
_getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain); |
3040 |
|
|
3041 |
|
std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances(); |
3042 |
|
std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin(); |
3043 |
|
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
3044 |
|
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
3045 |
|
AudioOutputDevice* pDev = (*itEngineChannel)->GetAudioOutputDevice(); |
3046 |
|
if (pDev != NULL && pDev->deviceId() == iAudioOutputDevice) { |
3047 |
|
for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) { |
3048 |
|
FxSend* fxs = (*itEngineChannel)->GetFxSend(i); |
3049 |
|
if(fxs != NULL && fxs->DestinationEffectChain() == iSendEffectChain && fxs->DestinationEffectChainPosition() == iEffectChainPosition) { |
3050 |
|
throw Exception("The effect instance is still in use by channel " + ToString((*itEngineChannel)->GetSamplerChannel()->Index())); |
3051 |
|
} |
3052 |
|
} |
3053 |
|
} |
3054 |
|
} |
3055 |
|
|
3056 |
|
pEffectChain->RemoveEffect(iEffectChainPosition); |
3057 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_info, iAudioOutputDevice, iSendEffectChain, pEffectChain->EffectCount())); |
3058 |
|
} catch (Exception e) { |
3059 |
|
result.Error(e); |
3060 |
|
} |
3061 |
|
return result.Produce(); |
3062 |
|
} |
3063 |
|
|
3064 |
String LSCPServer::EditSamplerChannelInstrument(uint uiSamplerChannel) { |
String LSCPServer::EditSamplerChannelInstrument(uint uiSamplerChannel) { |
3065 |
dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel)); |
3066 |
LSCPResultSet result; |
LSCPResultSet result; |
3067 |
try { |
try { |
3068 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
|
3069 |
if (pEngineChannel->InstrumentStatus() < 0) throw Exception("No instrument loaded to sampler channel"); |
if (pEngineChannel->InstrumentStatus() < 0) throw Exception("No instrument loaded to sampler channel"); |
3070 |
Engine* pEngine = pEngineChannel->GetEngine(); |
Engine* pEngine = pEngineChannel->GetEngine(); |
3071 |
InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager(); |
InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager(); |
3080 |
return result.Produce(); |
return result.Produce(); |
3081 |
} |
} |
3082 |
|
|
3083 |
|
String LSCPServer::SendChannelMidiData(String MidiMsg, uint uiSamplerChannel, uint Arg1, uint Arg2) { |
3084 |
|
dmsg(2,("LSCPServer: SendChannelMidiData(MidiMsg=%s,uiSamplerChannel=%d,Arg1=%d,Arg2=%d)\n", MidiMsg.c_str(), uiSamplerChannel, Arg1, Arg2)); |
3085 |
|
LSCPResultSet result; |
3086 |
|
try { |
3087 |
|
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
3088 |
|
|
3089 |
|
if (Arg1 > 127 || Arg2 > 127) { |
3090 |
|
throw Exception("Invalid MIDI message"); |
3091 |
|
} |
3092 |
|
|
3093 |
|
VirtualMidiDevice* pMidiDevice = NULL; |
3094 |
|
std::vector<EventHandler::midi_listener_entry>::iterator iter = eventHandler.channelMidiListeners.begin(); |
3095 |
|
for (; iter != eventHandler.channelMidiListeners.end(); ++iter) { |
3096 |
|
if ((*iter).pEngineChannel == pEngineChannel) { |
3097 |
|
pMidiDevice = (*iter).pMidiListener; |
3098 |
|
break; |
3099 |
|
} |
3100 |
|
} |
3101 |
|
|
3102 |
|
if(pMidiDevice == NULL) throw Exception("Couldn't find virtual MIDI device"); |
3103 |
|
|
3104 |
|
if (MidiMsg == "NOTE_ON") { |
3105 |
|
pMidiDevice->SendNoteOnToDevice(Arg1, Arg2); |
3106 |
|
bool b = pMidiDevice->SendNoteOnToSampler(Arg1, Arg2); |
3107 |
|
if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2)); |
3108 |
|
} else if (MidiMsg == "NOTE_OFF") { |
3109 |
|
pMidiDevice->SendNoteOffToDevice(Arg1, Arg2); |
3110 |
|
bool b = pMidiDevice->SendNoteOffToSampler(Arg1, Arg2); |
3111 |
|
if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2)); |
3112 |
|
} else if (MidiMsg == "CC") { |
3113 |
|
pMidiDevice->SendCCToDevice(Arg1, Arg2); |
3114 |
|
bool b = pMidiDevice->SendCCToSampler(Arg1, Arg2); |
3115 |
|
if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2)); |
3116 |
|
} else { |
3117 |
|
throw Exception("Unknown MIDI message type: " + MidiMsg); |
3118 |
|
} |
3119 |
|
} catch (Exception e) { |
3120 |
|
result.Error(e); |
3121 |
|
} |
3122 |
|
return result.Produce(); |
3123 |
|
} |
3124 |
|
|
3125 |
/** |
/** |
3126 |
* Will be called by the parser to reset a particular sampler channel. |
* Will be called by the parser to reset a particular sampler channel. |
3127 |
*/ |
*/ |
3129 |
dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
3130 |
LSCPResultSet result; |
LSCPResultSet result; |
3131 |
try { |
try { |
3132 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
|
3133 |
pEngineChannel->Reset(); |
pEngineChannel->Reset(); |
3134 |
} |
} |
3135 |
catch (Exception e) { |
catch (Exception e) { |
3195 |
String LSCPServer::GetTotalVoiceCountMax() { |
String LSCPServer::GetTotalVoiceCountMax() { |
3196 |
dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n")); |
dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n")); |
3197 |
LSCPResultSet result; |
LSCPResultSet result; |
3198 |
result.Add(EngineFactory::EngineInstances().size() * CONFIG_MAX_VOICES); |
result.Add(EngineFactory::EngineInstances().size() * pSampler->GetGlobalMaxVoices()); |
3199 |
|
return result.Produce(); |
3200 |
|
} |
3201 |
|
|
3202 |
|
/** |
3203 |
|
* Will be called by the parser to return the sampler global maximum |
3204 |
|
* allowed number of voices. |
3205 |
|
*/ |
3206 |
|
String LSCPServer::GetGlobalMaxVoices() { |
3207 |
|
dmsg(2,("LSCPServer: GetGlobalMaxVoices()\n")); |
3208 |
|
LSCPResultSet result; |
3209 |
|
result.Add(pSampler->GetGlobalMaxVoices()); |
3210 |
|
return result.Produce(); |
3211 |
|
} |
3212 |
|
|
3213 |
|
/** |
3214 |
|
* Will be called by the parser to set the sampler global maximum number of |
3215 |
|
* voices. |
3216 |
|
*/ |
3217 |
|
String LSCPServer::SetGlobalMaxVoices(int iVoices) { |
3218 |
|
dmsg(2,("LSCPServer: SetGlobalMaxVoices(%d)\n", iVoices)); |
3219 |
|
LSCPResultSet result; |
3220 |
|
try { |
3221 |
|
pSampler->SetGlobalMaxVoices(iVoices); |
3222 |
|
LSCPServer::SendLSCPNotify( |
3223 |
|
LSCPEvent(LSCPEvent::event_global_info, "VOICES", pSampler->GetGlobalMaxVoices()) |
3224 |
|
); |
3225 |
|
} catch (Exception e) { |
3226 |
|
result.Error(e); |
3227 |
|
} |
3228 |
|
return result.Produce(); |
3229 |
|
} |
3230 |
|
|
3231 |
|
/** |
3232 |
|
* Will be called by the parser to return the sampler global maximum |
3233 |
|
* allowed number of disk streams. |
3234 |
|
*/ |
3235 |
|
String LSCPServer::GetGlobalMaxStreams() { |
3236 |
|
dmsg(2,("LSCPServer: GetGlobalMaxStreams()\n")); |
3237 |
|
LSCPResultSet result; |
3238 |
|
result.Add(pSampler->GetGlobalMaxStreams()); |
3239 |
|
return result.Produce(); |
3240 |
|
} |
3241 |
|
|
3242 |
|
/** |
3243 |
|
* Will be called by the parser to set the sampler global maximum number of |
3244 |
|
* disk streams. |
3245 |
|
*/ |
3246 |
|
String LSCPServer::SetGlobalMaxStreams(int iStreams) { |
3247 |
|
dmsg(2,("LSCPServer: SetGlobalMaxStreams(%d)\n", iStreams)); |
3248 |
|
LSCPResultSet result; |
3249 |
|
try { |
3250 |
|
pSampler->SetGlobalMaxStreams(iStreams); |
3251 |
|
LSCPServer::SendLSCPNotify( |
3252 |
|
LSCPEvent(LSCPEvent::event_global_info, "STREAMS", pSampler->GetGlobalMaxStreams()) |
3253 |
|
); |
3254 |
|
} catch (Exception e) { |
3255 |
|
result.Error(e); |
3256 |
|
} |
3257 |
return result.Produce(); |
return result.Produce(); |
3258 |
} |
} |
3259 |
|
|
3394 |
result.Add("FORMAT_VERSION", info.FormatVersion); |
result.Add("FORMAT_VERSION", info.FormatVersion); |
3395 |
result.Add("PRODUCT", info.Product); |
result.Add("PRODUCT", info.Product); |
3396 |
result.Add("ARTISTS", info.Artists); |
result.Add("ARTISTS", info.Artists); |
3397 |
|
|
3398 |
|
std::stringstream ss; |
3399 |
|
bool b = false; |
3400 |
|
for (int i = 0; i < 128; i++) { |
3401 |
|
if (info.KeyBindings[i]) { |
3402 |
|
if (b) ss << ','; |
3403 |
|
ss << i; b = true; |
3404 |
|
} |
3405 |
|
} |
3406 |
|
result.Add("KEY_BINDINGS", ss.str()); |
3407 |
|
|
3408 |
|
b = false; |
3409 |
|
std::stringstream ss2; |
3410 |
|
for (int i = 0; i < 128; i++) { |
3411 |
|
if (info.KeySwitchBindings[i]) { |
3412 |
|
if (b) ss2 << ','; |
3413 |
|
ss2 << i; b = true; |
3414 |
|
} |
3415 |
|
} |
3416 |
|
result.Add("KEYSWITCH_BINDINGS", ss2.str()); |
3417 |
// no more need to ask other engine types |
// no more need to ask other engine types |
3418 |
bFound = true; |
bFound = true; |
3419 |
} else dmsg(1,("Warning: engine '%s' does not provide an instrument manager\n", engineTypes[i].c_str())); |
} else dmsg(1,("Warning: engine '%s' does not provide an instrument manager\n", engineTypes[i].c_str())); |
3441 |
throw Exception("Directory is specified"); |
throw Exception("Directory is specified"); |
3442 |
} |
} |
3443 |
#else |
#else |
3444 |
struct stat statBuf; |
File f(Filename); |
3445 |
int res = stat(Filename.c_str(), &statBuf); |
if(!f.Exist()) throw Exception(f.GetErrorMsg()); |
3446 |
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"); |
|
|
} |
|
3447 |
#endif |
#endif |
3448 |
} |
} |
3449 |
|
|
3454 |
String LSCPServer::SubscribeNotification(LSCPEvent::event_t type) { |
String LSCPServer::SubscribeNotification(LSCPEvent::event_t type) { |
3455 |
dmsg(2,("LSCPServer: SubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str())); |
dmsg(2,("LSCPServer: SubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str())); |
3456 |
LSCPResultSet result; |
LSCPResultSet result; |
3457 |
SubscriptionMutex.Lock(); |
{ |
3458 |
eventSubscriptions[type].push_back(currentSocket); |
LockGuard lock(SubscriptionMutex); |
3459 |
SubscriptionMutex.Unlock(); |
eventSubscriptions[type].push_back(currentSocket); |
3460 |
|
} |
3461 |
return result.Produce(); |
return result.Produce(); |
3462 |
} |
} |
3463 |
|
|
3468 |
String LSCPServer::UnsubscribeNotification(LSCPEvent::event_t type) { |
String LSCPServer::UnsubscribeNotification(LSCPEvent::event_t type) { |
3469 |
dmsg(2,("LSCPServer: UnsubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str())); |
dmsg(2,("LSCPServer: UnsubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str())); |
3470 |
LSCPResultSet result; |
LSCPResultSet result; |
3471 |
SubscriptionMutex.Lock(); |
{ |
3472 |
eventSubscriptions[type].remove(currentSocket); |
LockGuard lock(SubscriptionMutex); |
3473 |
SubscriptionMutex.Unlock(); |
eventSubscriptions[type].remove(currentSocket); |
3474 |
|
} |
3475 |
return result.Produce(); |
return result.Produce(); |
3476 |
} |
} |
3477 |
|
|
3640 |
return result.Produce(); |
return result.Produce(); |
3641 |
} |
} |
3642 |
|
|
3643 |
String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground) { |
String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground, bool insDir) { |
3644 |
dmsg(2,("LSCPServer: AddDbInstruments(ScanMode=%s,DbDir=%s,FsDir=%s,bBackground=%d)\n", ScanMode.c_str(), DbDir.c_str(), FsDir.c_str(), bBackground)); |
dmsg(2,("LSCPServer: AddDbInstruments(ScanMode=%s,DbDir=%s,FsDir=%s,bBackground=%d,insDir=%d)\n", ScanMode.c_str(), DbDir.c_str(), FsDir.c_str(), bBackground, insDir)); |
3645 |
LSCPResultSet result; |
LSCPResultSet result; |
3646 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
3647 |
try { |
try { |
3648 |
int id; |
int id; |
3649 |
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
3650 |
if (ScanMode.compare("RECURSIVE") == 0) { |
if (ScanMode.compare("RECURSIVE") == 0) { |
3651 |
id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground); |
id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground, insDir); |
3652 |
} else if (ScanMode.compare("NON_RECURSIVE") == 0) { |
} else if (ScanMode.compare("NON_RECURSIVE") == 0) { |
3653 |
id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground); |
id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground, insDir); |
3654 |
} else if (ScanMode.compare("FLAT") == 0) { |
} else if (ScanMode.compare("FLAT") == 0) { |
3655 |
id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground); |
id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground, insDir); |
3656 |
} else { |
} else { |
3657 |
throw Exception("Unknown scan mode: " + ScanMode); |
throw Exception("Unknown scan mode: " + ScanMode); |
3658 |
} |
} |
3996 |
} |
} |
3997 |
return result.Produce(); |
return result.Produce(); |
3998 |
} |
} |
3999 |
|
|
4000 |
|
String LSCPServer::SetShellInteract(yyparse_param_t* pSession, double boolean_value) { |
4001 |
|
dmsg(2,("LSCPServer: SetShellInteract(val=%f)\n", boolean_value)); |
4002 |
|
LSCPResultSet result; |
4003 |
|
try { |
4004 |
|
if (boolean_value == 0) pSession->bShellInteract = false; |
4005 |
|
else if (boolean_value == 1) pSession->bShellInteract = true; |
4006 |
|
else throw Exception("Not a boolean value, must either be 0 or 1"); |
4007 |
|
} catch (Exception e) { |
4008 |
|
result.Error(e); |
4009 |
|
} |
4010 |
|
return result.Produce(); |
4011 |
|
} |
4012 |
|
|
4013 |
|
String LSCPServer::SetShellAutoCorrect(yyparse_param_t* pSession, double boolean_value) { |
4014 |
|
dmsg(2,("LSCPServer: SetShellAutoCorrect(val=%f)\n", boolean_value)); |
4015 |
|
LSCPResultSet result; |
4016 |
|
try { |
4017 |
|
if (boolean_value == 0) pSession->bShellAutoCorrect = false; |
4018 |
|
else if (boolean_value == 1) pSession->bShellAutoCorrect = true; |
4019 |
|
else throw Exception("Not a boolean value, must either be 0 or 1"); |
4020 |
|
} catch (Exception e) { |
4021 |
|
result.Error(e); |
4022 |
|
} |
4023 |
|
return result.Produce(); |
4024 |
|
} |
4025 |
|
|
4026 |
} |
} |