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 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program 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 * |
10 |
* the Free Software Foundation; either version 2 of the License, or * |
* the Free Software Foundation; either version 2 of the License, or * |
11 |
* (at your option) any later version. * |
* (at your option) any later version. * |
12 |
* * |
* * |
13 |
* This program is distributed in the hope that it will be useful, * |
* This library is distributed in the hope that it will be useful, * |
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
16 |
* GNU General Public License for more details. * |
* GNU General Public License for more details. * |
17 |
* * |
* * |
18 |
* You should have received a copy of the GNU General Public License * |
* You should have received a copy of the GNU General Public License * |
19 |
* along with this program; if not, write to the Free Software * |
* along with this library; if not, write to the Free Software * |
20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
21 |
* MA 02111-1307 USA * |
* MA 02111-1307 USA * |
22 |
***************************************************************************/ |
***************************************************************************/ |
24 |
#include "lscpserver.h" |
#include "lscpserver.h" |
25 |
#include "lscpresultset.h" |
#include "lscpresultset.h" |
26 |
#include "lscpevent.h" |
#include "lscpevent.h" |
27 |
|
//#include "../common/global.h" |
28 |
|
|
29 |
#include "../engines/gig/Engine.h" |
#include <fcntl.h> |
30 |
|
|
31 |
|
#if HAVE_SQLITE3 |
32 |
|
# include "sqlite3.h" |
33 |
|
#endif |
34 |
|
|
35 |
|
#include "../engines/EngineFactory.h" |
36 |
|
#include "../engines/EngineChannelFactory.h" |
37 |
#include "../drivers/audio/AudioOutputDeviceFactory.h" |
#include "../drivers/audio/AudioOutputDeviceFactory.h" |
38 |
#include "../drivers/midi/MidiInputDeviceFactory.h" |
#include "../drivers/midi/MidiInputDeviceFactory.h" |
39 |
|
|
59 |
Mutex LSCPServer::NotifyMutex = Mutex(); |
Mutex LSCPServer::NotifyMutex = Mutex(); |
60 |
Mutex LSCPServer::NotifyBufferMutex = Mutex(); |
Mutex LSCPServer::NotifyBufferMutex = Mutex(); |
61 |
Mutex LSCPServer::SubscriptionMutex = Mutex(); |
Mutex LSCPServer::SubscriptionMutex = Mutex(); |
62 |
|
Mutex LSCPServer::RTNotifyMutex = Mutex(); |
63 |
|
|
64 |
LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) { |
LSCPServer::LSCPServer(Sampler* pSampler, long int addr, short int port) : Thread(true, false, 0, -4) { |
65 |
|
SocketAddress.sin_family = AF_INET; |
66 |
|
SocketAddress.sin_addr.s_addr = addr; |
67 |
|
SocketAddress.sin_port = port; |
68 |
this->pSampler = pSampler; |
this->pSampler = pSampler; |
69 |
LSCPEvent::RegisterEvent(LSCPEvent::event_channels, "CHANNELS"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_channel_count, "CHANNEL_COUNT"); |
70 |
LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT"); |
71 |
LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT"); |
72 |
LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL"); |
73 |
LSCPEvent::RegisterEvent(LSCPEvent::event_info, "INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_channel_info, "CHANNEL_INFO"); |
74 |
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
75 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT"); |
76 |
|
hSocket = -1; |
77 |
|
} |
78 |
|
|
79 |
|
LSCPServer::~LSCPServer() { |
80 |
|
if (hSocket >= 0) close(hSocket); |
81 |
} |
} |
82 |
|
|
83 |
/** |
/** |
95 |
} |
} |
96 |
|
|
97 |
int LSCPServer::Main() { |
int LSCPServer::Main() { |
98 |
int hSocket = socket(AF_INET, SOCK_STREAM, 0); |
hSocket = socket(AF_INET, SOCK_STREAM, 0); |
99 |
if (hSocket < 0) { |
if (hSocket < 0) { |
100 |
std::cerr << "LSCPServer: Could not create server socket." << std::endl; |
std::cerr << "LSCPServer: Could not create server socket." << std::endl; |
101 |
//return -1; |
//return -1; |
102 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
103 |
} |
} |
104 |
|
|
|
SocketAddress.sin_family = AF_INET; |
|
|
SocketAddress.sin_port = htons(LSCP_PORT); |
|
|
SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY); |
|
|
|
|
105 |
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
106 |
std::cerr << "LSCPServer: Could not bind server socket, retrying for " << ToString(LSCP_SERVER_BIND_TIMEOUT) << " seconds..."; |
std::cerr << "LSCPServer: Could not bind server socket, retrying for " << ToString(LSCP_SERVER_BIND_TIMEOUT) << " seconds..."; |
107 |
for (int trial = 0; true; trial++) { // retry for LSCP_SERVER_BIND_TIMEOUT seconds |
for (int trial = 0; true; trial++) { // retry for LSCP_SERVER_BIND_TIMEOUT seconds |
128 |
FD_SET(hSocket, &fdSet); |
FD_SET(hSocket, &fdSet); |
129 |
int maxSessions = hSocket; |
int maxSessions = hSocket; |
130 |
|
|
131 |
|
timeval timeout; |
132 |
|
|
133 |
while (true) { |
while (true) { |
134 |
fd_set selectSet = fdSet; |
// check if some engine channel's parameter / status changed, if so notify the respective LSCP event subscribers |
135 |
int retval = select(maxSessions+1, &selectSet, NULL, NULL, NULL); |
{ |
136 |
|
std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances(); |
137 |
|
std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin(); |
138 |
|
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
139 |
|
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
140 |
|
if ((*itEngineChannel)->StatusChanged()) { |
141 |
|
SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex)); |
142 |
|
} |
143 |
|
} |
144 |
|
} |
145 |
|
|
146 |
|
//Now let's deliver late notifies (if any) |
147 |
|
NotifyBufferMutex.Lock(); |
148 |
|
for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) { |
149 |
|
send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), MSG_NOSIGNAL); |
150 |
|
bufferedNotifies.erase(iterNotify); |
151 |
|
} |
152 |
|
NotifyBufferMutex.Unlock(); |
153 |
|
|
154 |
|
fd_set selectSet = fdSet; |
155 |
|
timeout.tv_sec = 0; |
156 |
|
timeout.tv_usec = 100000; |
157 |
|
|
158 |
|
int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout); |
159 |
|
|
160 |
if (retval == 0) |
if (retval == 0) |
161 |
continue; //Nothing try again |
continue; //Nothing try again |
162 |
if (retval == -1) { |
if (retval == -1) { |
200 |
int dummy; // just a temporary hack to fulfill the restart() function prototype |
int dummy; // just a temporary hack to fulfill the restart() function prototype |
201 |
restart(NULL, dummy); // restart the 'scanner' |
restart(NULL, dummy); // restart the 'scanner' |
202 |
currentSocket = (*iter).hSession; //a hack |
currentSocket = (*iter).hSession; //a hack |
203 |
|
dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str())); |
204 |
if ((*iter).bVerbose) { // if echo mode enabled |
if ((*iter).bVerbose) { // if echo mode enabled |
205 |
AnswerClient(bufferedCommands[currentSocket]); |
AnswerClient(bufferedCommands[currentSocket]); |
206 |
} |
} |
216 |
break; |
break; |
217 |
} |
} |
218 |
} |
} |
|
|
|
|
//Now let's deliver late notifies (if any) |
|
|
NotifyBufferMutex.Lock(); |
|
|
for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) { |
|
|
send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0); |
|
|
bufferedNotifies.erase(iterNotify); |
|
|
} |
|
|
NotifyBufferMutex.Unlock(); |
|
219 |
} |
} |
220 |
} |
} |
221 |
|
|
237 |
NotifyMutex.Unlock(); |
NotifyMutex.Unlock(); |
238 |
} |
} |
239 |
|
|
240 |
|
int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) { |
241 |
|
int subs = 0; |
242 |
|
SubscriptionMutex.Lock(); |
243 |
|
for( std::list<LSCPEvent::event_t>::iterator iter = events.begin(); |
244 |
|
iter != events.end(); iter++) |
245 |
|
{ |
246 |
|
subs += eventSubscriptions.count(*iter); |
247 |
|
} |
248 |
|
SubscriptionMutex.Unlock(); |
249 |
|
return subs; |
250 |
|
} |
251 |
|
|
252 |
void LSCPServer::SendLSCPNotify( LSCPEvent event ) { |
void LSCPServer::SendLSCPNotify( LSCPEvent event ) { |
253 |
SubscriptionMutex.Lock(); |
SubscriptionMutex.Lock(); |
254 |
if (eventSubscriptions.count(event.GetType()) == 0) { |
if (eventSubscriptions.count(event.GetType()) == 0) { |
262 |
while (true) { |
while (true) { |
263 |
if (NotifyMutex.Trylock()) { |
if (NotifyMutex.Trylock()) { |
264 |
for(;iter != end; iter++) |
for(;iter != end; iter++) |
265 |
send(*iter, notify.c_str(), notify.size(), 0); |
send(*iter, notify.c_str(), notify.size(), MSG_NOSIGNAL); |
266 |
NotifyMutex.Unlock(); |
NotifyMutex.Unlock(); |
267 |
break; |
break; |
268 |
} else { |
} else { |
371 |
dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str())); |
dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str())); |
372 |
if (currentSocket != -1) { |
if (currentSocket != -1) { |
373 |
NotifyMutex.Lock(); |
NotifyMutex.Lock(); |
374 |
send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0); |
send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), MSG_NOSIGNAL); |
375 |
NotifyMutex.Unlock(); |
NotifyMutex.Unlock(); |
376 |
} |
} |
377 |
} |
} |
478 |
LSCPResultSet result; |
LSCPResultSet result; |
479 |
try { |
try { |
480 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
481 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
482 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
483 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel yet"); |
484 |
if (!pSamplerChannel->GetAudioOutputDevice()) |
if (!pSamplerChannel->GetAudioOutputDevice()) |
485 |
throw LinuxSamplerException("No audio output device on channel"); |
throw LinuxSamplerException("No audio output device connected to sampler channel"); |
486 |
if (bBackground) { |
if (bBackground) { |
487 |
LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument); |
InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngineChannel); |
488 |
pLoadInstrument->StartThread(); |
} |
489 |
|
else { |
490 |
|
// tell the engine channel which instrument to load |
491 |
|
pEngineChannel->PrepareLoadInstrument(Filename.c_str(), uiInstrument); |
492 |
|
// actually start to load the instrument (blocks until completed) |
493 |
|
pEngineChannel->LoadInstrument(); |
494 |
} |
} |
|
else pEngine->LoadInstrument(Filename.c_str(), uiInstrument); |
|
495 |
} |
} |
496 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
497 |
result.Error(e); |
result.Error(e); |
500 |
} |
} |
501 |
|
|
502 |
/** |
/** |
503 |
* Will be called by the parser to load and deploy an engine. |
* Will be called by the parser to assign a sampler engine type to a |
504 |
|
* sampler channel. |
505 |
*/ |
*/ |
506 |
String LSCPServer::LoadEngine(String EngineName, uint uiSamplerChannel) { |
String LSCPServer::SetEngineType(String EngineName, uint uiSamplerChannel) { |
507 |
dmsg(2,("LSCPServer: LoadEngine(EngineName=%s,SamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetEngineType(EngineName=%s,uiSamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel)); |
508 |
LSCPResultSet result; |
LSCPResultSet result; |
509 |
try { |
try { |
|
Engine::type_t type; |
|
|
if ((EngineName == "GigEngine") || (EngineName == "gig")) type = Engine::type_gig; |
|
|
else throw LinuxSamplerException("Unknown engine type"); |
|
510 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
511 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
512 |
pSamplerChannel->LoadEngine(type); |
LockRTNotify(); |
513 |
|
pSamplerChannel->SetEngineType(EngineName); |
514 |
|
if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1); |
515 |
|
UnlockRTNotify(); |
516 |
} |
} |
517 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
518 |
result.Error(e); |
result.Error(e); |
563 |
String LSCPServer::RemoveChannel(uint uiSamplerChannel) { |
String LSCPServer::RemoveChannel(uint uiSamplerChannel) { |
564 |
dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
565 |
LSCPResultSet result; |
LSCPResultSet result; |
566 |
|
LockRTNotify(); |
567 |
pSampler->RemoveSamplerChannel(uiSamplerChannel); |
pSampler->RemoveSamplerChannel(uiSamplerChannel); |
568 |
|
UnlockRTNotify(); |
569 |
return result.Produce(); |
return result.Produce(); |
570 |
} |
} |
571 |
|
|
572 |
/** |
/** |
573 |
* Will be called by the parser to get all available engines. |
* Will be called by the parser to get the amount of all available engines. |
574 |
*/ |
*/ |
575 |
String LSCPServer::GetAvailableEngines() { |
String LSCPServer::GetAvailableEngines() { |
576 |
dmsg(2,("LSCPServer: GetAvailableEngines()\n")); |
dmsg(2,("LSCPServer: GetAvailableEngines()\n")); |
577 |
LSCPResultSet result("GigEngine"); |
LSCPResultSet result("1"); |
578 |
|
return result.Produce(); |
579 |
|
} |
580 |
|
|
581 |
|
/** |
582 |
|
* Will be called by the parser to get a list of all available engines. |
583 |
|
*/ |
584 |
|
String LSCPServer::ListAvailableEngines() { |
585 |
|
dmsg(2,("LSCPServer: ListAvailableEngines()\n")); |
586 |
|
LSCPResultSet result("\'GIG\'"); |
587 |
return result.Produce(); |
return result.Produce(); |
588 |
} |
} |
589 |
|
|
590 |
/** |
/** |
591 |
* Will be called by the parser to get descriptions for a particular engine. |
* Will be called by the parser to get descriptions for a particular |
592 |
|
* sampler engine. |
593 |
*/ |
*/ |
594 |
String LSCPServer::GetEngineInfo(String EngineName) { |
String LSCPServer::GetEngineInfo(String EngineName) { |
595 |
dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str())); |
dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str())); |
596 |
LSCPResultSet result; |
LSCPResultSet result; |
597 |
try { |
try { |
598 |
if ((EngineName == "GigEngine") || (EngineName == "gig")) { |
Engine* pEngine = EngineFactory::Create(EngineName); |
599 |
Engine* pEngine = new LinuxSampler::gig::Engine; |
result.Add("DESCRIPTION", pEngine->Description()); |
600 |
result.Add("DESCRIPTION", pEngine->Description()); |
result.Add("VERSION", pEngine->Version()); |
601 |
result.Add("VERSION", pEngine->Version()); |
EngineFactory::Destroy(pEngine); |
|
delete pEngine; |
|
|
} |
|
|
else throw LinuxSamplerException("Unknown engine type"); |
|
602 |
} |
} |
603 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
604 |
result.Error(e); |
result.Error(e); |
615 |
LSCPResultSet result; |
LSCPResultSet result; |
616 |
try { |
try { |
617 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
618 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
619 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
620 |
|
|
621 |
//Defaults values |
//Defaults values |
622 |
String EngineName = "NONE"; |
String EngineName = "NONE"; |
623 |
float Volume = 0.0f; |
float Volume = 0.0f; |
624 |
String InstrumentFileName = "NONE"; |
String InstrumentFileName = "NONE"; |
625 |
|
String InstrumentName = "NONE"; |
626 |
int InstrumentIndex = -1; |
int InstrumentIndex = -1; |
627 |
int InstrumentStatus = -1; |
int InstrumentStatus = -1; |
628 |
int AudioOutputChannels = 0; |
int AudioOutputChannels = 0; |
629 |
String AudioRouting; |
String AudioRouting; |
630 |
|
int Mute = 0; |
631 |
|
bool Solo = false; |
632 |
|
|
633 |
if (pEngine) { |
if (pEngineChannel) { |
634 |
EngineName = pEngine->EngineName(); |
EngineName = pEngineChannel->EngineName(); |
635 |
AudioOutputChannels = pEngine->Channels(); |
AudioOutputChannels = pEngineChannel->Channels(); |
636 |
Volume = pEngine->Volume(); |
Volume = pEngineChannel->Volume(); |
637 |
InstrumentStatus = pEngine->InstrumentStatus(); |
InstrumentStatus = pEngineChannel->InstrumentStatus(); |
638 |
InstrumentIndex = pEngine->InstrumentIndex(); |
InstrumentIndex = pEngineChannel->InstrumentIndex(); |
639 |
if (InstrumentIndex != -1) |
if (InstrumentIndex != -1) { |
640 |
InstrumentFileName = pEngine->InstrumentFileName(); |
InstrumentFileName = pEngineChannel->InstrumentFileName(); |
641 |
for (int chan = 0; chan < pEngine->Channels(); chan++) { |
InstrumentName = pEngineChannel->InstrumentName(); |
642 |
|
} |
643 |
|
for (int chan = 0; chan < pEngineChannel->Channels(); chan++) { |
644 |
if (AudioRouting != "") AudioRouting += ","; |
if (AudioRouting != "") AudioRouting += ","; |
645 |
AudioRouting += ToString(pEngine->OutputChannel(chan)); |
AudioRouting += ToString(pEngineChannel->OutputChannel(chan)); |
646 |
} |
} |
647 |
|
Mute = pEngineChannel->GetMute(); |
648 |
|
Solo = pEngineChannel->GetSolo(); |
649 |
} |
} |
650 |
|
|
651 |
result.Add("ENGINE_NAME", EngineName); |
result.Add("ENGINE_NAME", EngineName); |
658 |
|
|
659 |
result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice())); |
result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice())); |
660 |
result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort()); |
result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort()); |
661 |
if (pSamplerChannel->GetMidiInputChannel()) result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); |
if (pSamplerChannel->GetMidiInputChannel() == midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL"); |
662 |
else result.Add("MIDI_INPUT_CHANNEL", "ALL"); |
else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); |
663 |
|
|
664 |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
665 |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
666 |
|
result.Add("INSTRUMENT_NAME", InstrumentName); |
667 |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
668 |
|
result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false")); |
669 |
|
result.Add("SOLO", Solo); |
670 |
} |
} |
671 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
672 |
result.Error(e); |
result.Error(e); |
683 |
LSCPResultSet result; |
LSCPResultSet result; |
684 |
try { |
try { |
685 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
686 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
687 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
688 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine loaded on sampler channel"); |
689 |
result.Add(pEngine->VoiceCount()); |
if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel"); |
690 |
|
result.Add(pEngineChannel->GetEngine()->VoiceCount()); |
691 |
} |
} |
692 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
693 |
result.Error(e); |
result.Error(e); |
704 |
LSCPResultSet result; |
LSCPResultSet result; |
705 |
try { |
try { |
706 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
707 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
708 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
709 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
710 |
result.Add(pEngine->DiskStreamCount()); |
if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel"); |
711 |
|
result.Add(pEngineChannel->GetEngine()->DiskStreamCount()); |
712 |
} |
} |
713 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
714 |
result.Error(e); |
result.Error(e); |
725 |
LSCPResultSet result; |
LSCPResultSet result; |
726 |
try { |
try { |
727 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
728 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
729 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
730 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
731 |
if (!pEngine->DiskStreamSupported()) |
if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel"); |
732 |
result.Add("NA"); |
if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA"); |
733 |
else { |
else { |
734 |
switch (ResponseType) { |
switch (ResponseType) { |
735 |
case fill_response_bytes: |
case fill_response_bytes: |
736 |
result.Add(pEngine->DiskStreamBufferFillBytes()); |
result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillBytes()); |
737 |
break; |
break; |
738 |
case fill_response_percentage: |
case fill_response_percentage: |
739 |
result.Add(pEngine->DiskStreamBufferFillPercentage()); |
result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage()); |
740 |
break; |
break; |
741 |
default: |
default: |
742 |
throw LinuxSamplerException("Unknown fill response type"); |
throw LinuxSamplerException("Unknown fill response type"); |
743 |
} |
} |
753 |
dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n")); |
dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n")); |
754 |
LSCPResultSet result; |
LSCPResultSet result; |
755 |
try { |
try { |
756 |
|
int n = AudioOutputDeviceFactory::AvailableDrivers().size(); |
757 |
|
result.Add(n); |
758 |
|
} |
759 |
|
catch (LinuxSamplerException e) { |
760 |
|
result.Error(e); |
761 |
|
} |
762 |
|
return result.Produce(); |
763 |
|
} |
764 |
|
|
765 |
|
String LSCPServer::ListAvailableAudioOutputDrivers() { |
766 |
|
dmsg(2,("LSCPServer: ListAvailableAudioOutputDrivers()\n")); |
767 |
|
LSCPResultSet result; |
768 |
|
try { |
769 |
String s = AudioOutputDeviceFactory::AvailableDriversAsString(); |
String s = AudioOutputDeviceFactory::AvailableDriversAsString(); |
770 |
result.Add(s); |
result.Add(s); |
771 |
} |
} |
779 |
dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n")); |
dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n")); |
780 |
LSCPResultSet result; |
LSCPResultSet result; |
781 |
try { |
try { |
782 |
|
int n = MidiInputDeviceFactory::AvailableDrivers().size(); |
783 |
|
result.Add(n); |
784 |
|
} |
785 |
|
catch (LinuxSamplerException e) { |
786 |
|
result.Error(e); |
787 |
|
} |
788 |
|
return result.Produce(); |
789 |
|
} |
790 |
|
|
791 |
|
String LSCPServer::ListAvailableMidiInputDrivers() { |
792 |
|
dmsg(2,("LSCPServer: ListAvailableMidiInputDrivers()\n")); |
793 |
|
LSCPResultSet result; |
794 |
|
try { |
795 |
String s = MidiInputDeviceFactory::AvailableDriversAsString(); |
String s = MidiInputDeviceFactory::AvailableDriversAsString(); |
796 |
result.Add(s); |
result.Add(s); |
797 |
} |
} |
1043 |
|
|
1044 |
// get audio channel |
// get audio channel |
1045 |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
1046 |
if (!pChannel) throw LinuxSamplerException("Audio ouotput device does not have channel " + ToString(ChannelId) + "."); |
if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + "."); |
1047 |
|
|
1048 |
// return the values of all audio channel parameters |
// return the values of all audio channel parameters |
1049 |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
1102 |
|
|
1103 |
// get audio channel |
// get audio channel |
1104 |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
1105 |
if (!pChannel) throw LinuxSamplerException("Audio output device does not have channel " + ToString(ChannelId) + "."); |
if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + "."); |
1106 |
|
|
1107 |
// get desired audio channel parameter |
// get desired audio channel parameter |
1108 |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
1135 |
|
|
1136 |
// get audio channel |
// get audio channel |
1137 |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
1138 |
if (!pChannel) throw LinuxSamplerException("Audio output device does not have channel " + ToString(ChannelId) + "."); |
if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + "."); |
1139 |
|
|
1140 |
// get desired audio channel parameter |
// get desired audio channel parameter |
1141 |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
1218 |
LSCPResultSet result; |
LSCPResultSet result; |
1219 |
try { |
try { |
1220 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1221 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1222 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
1223 |
if (!pEngine) throw LinuxSamplerException("No engine deployed on sampler channel " + ToString(uiSamplerChannel)); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type yet assigned to sampler channel " + ToString(uiSamplerChannel)); |
1224 |
pEngine->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel); |
if (!pSamplerChannel->GetAudioOutputDevice()) throw LinuxSamplerException("No audio output device connected to sampler channel " + ToString(uiSamplerChannel)); |
1225 |
|
pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel); |
1226 |
} |
} |
1227 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1228 |
result.Error(e); |
result.Error(e); |
1235 |
LSCPResultSet result; |
LSCPResultSet result; |
1236 |
try { |
try { |
1237 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1238 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1239 |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1240 |
if (!devices.count(AudioDeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId)); |
if (!devices.count(AudioDeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId)); |
1241 |
AudioOutputDevice* pDevice = devices[AudioDeviceId]; |
AudioOutputDevice* pDevice = devices[AudioDeviceId]; |
1252 |
LSCPResultSet result; |
LSCPResultSet result; |
1253 |
try { |
try { |
1254 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1255 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1256 |
// Driver type name aliasing... |
// Driver type name aliasing... |
1257 |
if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA"; |
if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA"; |
1258 |
if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK"; |
if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK"; |
1289 |
LSCPResultSet result; |
LSCPResultSet result; |
1290 |
try { |
try { |
1291 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1292 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1293 |
pSamplerChannel->SetMidiInputPort(MIDIPort); |
pSamplerChannel->SetMidiInputPort(MIDIPort); |
1294 |
} |
} |
1295 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1303 |
LSCPResultSet result; |
LSCPResultSet result; |
1304 |
try { |
try { |
1305 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1306 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1307 |
pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel); |
pSamplerChannel->SetMidiInputChannel((midi_chan_t) MIDIChannel); |
1308 |
} |
} |
1309 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1310 |
result.Error(e); |
result.Error(e); |
1317 |
LSCPResultSet result; |
LSCPResultSet result; |
1318 |
try { |
try { |
1319 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1320 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1321 |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1322 |
if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
1323 |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
1334 |
LSCPResultSet result; |
LSCPResultSet result; |
1335 |
try { |
try { |
1336 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1337 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1338 |
// Driver type name aliasing... |
// Driver type name aliasing... |
1339 |
if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA"; |
if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA"; |
1340 |
// Check if there's one MIDI input device already created |
// Check if there's one MIDI input device already created |
1377 |
LSCPResultSet result; |
LSCPResultSet result; |
1378 |
try { |
try { |
1379 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1380 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1381 |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1382 |
if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
1383 |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
1384 |
pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (MidiInputPort::midi_chan_t) MIDIChannel); |
pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (midi_chan_t) MIDIChannel); |
1385 |
} |
} |
1386 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1387 |
result.Error(e); |
result.Error(e); |
1398 |
LSCPResultSet result; |
LSCPResultSet result; |
1399 |
try { |
try { |
1400 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1401 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1402 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
1403 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
1404 |
pEngine->Volume(dVolume); |
pEngineChannel->Volume(dVolume); |
1405 |
} |
} |
1406 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1407 |
result.Error(e); |
result.Error(e); |
1410 |
} |
} |
1411 |
|
|
1412 |
/** |
/** |
1413 |
|
* Will be called by the parser to mute/unmute particular sampler channel. |
1414 |
|
*/ |
1415 |
|
String LSCPServer::SetChannelMute(bool bMute, uint uiSamplerChannel) { |
1416 |
|
dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel)); |
1417 |
|
LSCPResultSet result; |
1418 |
|
try { |
1419 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1420 |
|
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1421 |
|
|
1422 |
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
1423 |
|
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
1424 |
|
|
1425 |
|
if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0); |
1426 |
|
else pEngineChannel->SetMute(1); |
1427 |
|
} catch (LinuxSamplerException e) { |
1428 |
|
result.Error(e); |
1429 |
|
} |
1430 |
|
return result.Produce(); |
1431 |
|
} |
1432 |
|
|
1433 |
|
/** |
1434 |
|
* Will be called by the parser to solo particular sampler channel. |
1435 |
|
*/ |
1436 |
|
String LSCPServer::SetChannelSolo(bool bSolo, uint uiSamplerChannel) { |
1437 |
|
dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel)); |
1438 |
|
LSCPResultSet result; |
1439 |
|
try { |
1440 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1441 |
|
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1442 |
|
|
1443 |
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
1444 |
|
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
1445 |
|
|
1446 |
|
bool oldSolo = pEngineChannel->GetSolo(); |
1447 |
|
bool hadSoloChannel = HasSoloChannel(); |
1448 |
|
|
1449 |
|
pEngineChannel->SetSolo(bSolo); |
1450 |
|
|
1451 |
|
if(!oldSolo && bSolo) { |
1452 |
|
if(pEngineChannel->GetMute() == -1) pEngineChannel->SetMute(0); |
1453 |
|
if(!hadSoloChannel) MuteNonSoloChannels(); |
1454 |
|
} |
1455 |
|
|
1456 |
|
if(oldSolo && !bSolo) { |
1457 |
|
if(!HasSoloChannel()) UnmuteChannels(); |
1458 |
|
else if(!pEngineChannel->GetMute()) pEngineChannel->SetMute(-1); |
1459 |
|
} |
1460 |
|
} catch (LinuxSamplerException e) { |
1461 |
|
result.Error(e); |
1462 |
|
} |
1463 |
|
return result.Produce(); |
1464 |
|
} |
1465 |
|
|
1466 |
|
/** |
1467 |
|
* Determines whether there is at least one solo channel in the channel list. |
1468 |
|
* |
1469 |
|
* @returns true if there is at least one solo channel in the channel list, |
1470 |
|
* false otherwise. |
1471 |
|
*/ |
1472 |
|
bool LSCPServer::HasSoloChannel() { |
1473 |
|
std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels(); |
1474 |
|
std::map<uint,SamplerChannel*>::iterator iter = channels.begin(); |
1475 |
|
for (; iter != channels.end(); iter++) { |
1476 |
|
EngineChannel* c = iter->second->GetEngineChannel(); |
1477 |
|
if(c && c->GetSolo()) return true; |
1478 |
|
} |
1479 |
|
|
1480 |
|
return false; |
1481 |
|
} |
1482 |
|
|
1483 |
|
/** |
1484 |
|
* Mutes all unmuted non-solo channels. Notice that the channels are muted |
1485 |
|
* with -1 which indicates that they are muted because of the presence |
1486 |
|
* of a solo channel(s). Channels muted with -1 will be automatically unmuted |
1487 |
|
* when there are no solo channels left. |
1488 |
|
*/ |
1489 |
|
void LSCPServer::MuteNonSoloChannels() { |
1490 |
|
dmsg(2,("LSCPServer: MuteNonSoloChannels()\n")); |
1491 |
|
std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels(); |
1492 |
|
std::map<uint,SamplerChannel*>::iterator iter = channels.begin(); |
1493 |
|
for (; iter != channels.end(); iter++) { |
1494 |
|
EngineChannel* c = iter->second->GetEngineChannel(); |
1495 |
|
if(c && !c->GetSolo() && !c->GetMute()) c->SetMute(-1); |
1496 |
|
} |
1497 |
|
} |
1498 |
|
|
1499 |
|
/** |
1500 |
|
* Unmutes all channels that are muted because of the presence |
1501 |
|
* of a solo channel(s). |
1502 |
|
*/ |
1503 |
|
void LSCPServer::UnmuteChannels() { |
1504 |
|
dmsg(2,("LSCPServer: UnmuteChannels()\n")); |
1505 |
|
std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels(); |
1506 |
|
std::map<uint,SamplerChannel*>::iterator iter = channels.begin(); |
1507 |
|
for (; iter != channels.end(); iter++) { |
1508 |
|
EngineChannel* c = iter->second->GetEngineChannel(); |
1509 |
|
if(c && c->GetMute() == -1) c->SetMute(0); |
1510 |
|
} |
1511 |
|
} |
1512 |
|
|
1513 |
|
/** |
1514 |
* Will be called by the parser to reset a particular sampler channel. |
* Will be called by the parser to reset a particular sampler channel. |
1515 |
*/ |
*/ |
1516 |
String LSCPServer::ResetChannel(uint uiSamplerChannel) { |
String LSCPServer::ResetChannel(uint uiSamplerChannel) { |
1518 |
LSCPResultSet result; |
LSCPResultSet result; |
1519 |
try { |
try { |
1520 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1521 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1522 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
1523 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
1524 |
pEngine->Reset(); |
pEngineChannel->Reset(); |
1525 |
} |
} |
1526 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1527 |
result.Error(e); |
result.Error(e); |
1540 |
} |
} |
1541 |
|
|
1542 |
/** |
/** |
1543 |
|
* Will be called by the parser to return general informations about this |
1544 |
|
* sampler. |
1545 |
|
*/ |
1546 |
|
String LSCPServer::GetServerInfo() { |
1547 |
|
dmsg(2,("LSCPServer: GetServerInfo()\n")); |
1548 |
|
LSCPResultSet result; |
1549 |
|
result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler"); |
1550 |
|
result.Add("VERSION", VERSION); |
1551 |
|
result.Add("PROTOCOL_VERSION", "1.0"); |
1552 |
|
return result.Produce(); |
1553 |
|
} |
1554 |
|
|
1555 |
|
/** |
1556 |
|
* Will be called by the parser to return the current number of all active voices. |
1557 |
|
*/ |
1558 |
|
String LSCPServer::GetTotalVoiceCount() { |
1559 |
|
dmsg(2,("LSCPServer: GetTotalVoiceCount()\n")); |
1560 |
|
LSCPResultSet result; |
1561 |
|
result.Add(pSampler->GetVoiceCount()); |
1562 |
|
return result.Produce(); |
1563 |
|
} |
1564 |
|
|
1565 |
|
/** |
1566 |
|
* Will be called by the parser to return the maximum number of voices. |
1567 |
|
*/ |
1568 |
|
String LSCPServer::GetTotalVoiceCountMax() { |
1569 |
|
dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n")); |
1570 |
|
LSCPResultSet result; |
1571 |
|
result.Add(EngineFactory::EngineInstances().size() * CONFIG_MAX_VOICES); |
1572 |
|
return result.Produce(); |
1573 |
|
} |
1574 |
|
|
1575 |
|
/** |
1576 |
* Will be called by the parser to subscribe a client (frontend) on the |
* Will be called by the parser to subscribe a client (frontend) on the |
1577 |
* server for receiving event messages. |
* server for receiving event messages. |
1578 |
*/ |
*/ |
1598 |
return result.Produce(); |
return result.Produce(); |
1599 |
} |
} |
1600 |
|
|
1601 |
|
static int select_callback(void * lscpResultSet, int argc, |
1602 |
|
char **argv, char **azColName) |
1603 |
|
{ |
1604 |
|
LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet; |
1605 |
|
resultSet->Add(argc, argv); |
1606 |
|
return 0; |
1607 |
|
} |
1608 |
|
|
1609 |
|
String LSCPServer::QueryDatabase(String query) { |
1610 |
|
LSCPResultSet result; |
1611 |
|
#if HAVE_SQLITE3 |
1612 |
|
char* zErrMsg = NULL; |
1613 |
|
sqlite3 *db; |
1614 |
|
String selectStr = "SELECT " + query; |
1615 |
|
|
1616 |
|
int rc = sqlite3_open("linuxsampler.db", &db); |
1617 |
|
if (rc == SQLITE_OK) |
1618 |
|
{ |
1619 |
|
rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg); |
1620 |
|
} |
1621 |
|
if ( rc != SQLITE_OK ) |
1622 |
|
{ |
1623 |
|
result.Error(String(zErrMsg), rc); |
1624 |
|
} |
1625 |
|
sqlite3_close(db); |
1626 |
|
#else |
1627 |
|
result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0); |
1628 |
|
#endif |
1629 |
|
return result.Produce(); |
1630 |
|
} |
1631 |
|
|
1632 |
/** |
/** |
1633 |
* Will be called by the parser to enable or disable echo mode; if echo |
* Will be called by the parser to enable or disable echo mode; if echo |
1634 |
* mode is enabled, all commands from the client will (immediately) be |
* mode is enabled, all commands from the client will (immediately) be |
1647 |
} |
} |
1648 |
return result.Produce(); |
return result.Produce(); |
1649 |
} |
} |
|
|
|
|
// Instrument loader constructor. |
|
|
LSCPLoadInstrument::LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument) |
|
|
: Thread(false, 0, -4) |
|
|
{ |
|
|
this->pEngine = pEngine; |
|
|
this->Filename = Filename; |
|
|
this->uiInstrument = uiInstrument; |
|
|
} |
|
|
|
|
|
// Instrument loader process. |
|
|
int LSCPLoadInstrument::Main() |
|
|
{ |
|
|
try { |
|
|
pEngine->LoadInstrument(Filename.c_str(), uiInstrument); |
|
|
} |
|
|
|
|
|
catch (LinuxSamplerException e) { |
|
|
e.PrintMessage(); |
|
|
} |
|
|
|
|
|
// Always re-enable the engine. |
|
|
pEngine->Enable(); |
|
|
|
|
|
// FIXME: Shoot ourselves on the foot? |
|
|
delete this; |
|
|
} |
|