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 |
174 |
int dummy; // just a temporary hack to fulfill the restart() function prototype |
int dummy; // just a temporary hack to fulfill the restart() function prototype |
175 |
restart(NULL, dummy); // restart the 'scanner' |
restart(NULL, dummy); // restart the 'scanner' |
176 |
currentSocket = (*iter).hSession; //a hack |
currentSocket = (*iter).hSession; //a hack |
177 |
|
dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str())); |
178 |
if ((*iter).bVerbose) { // if echo mode enabled |
if ((*iter).bVerbose) { // if echo mode enabled |
179 |
AnswerClient(bufferedCommands[currentSocket]); |
AnswerClient(bufferedCommands[currentSocket]); |
180 |
} |
} |
191 |
} |
} |
192 |
} |
} |
193 |
|
|
194 |
|
// check if some engine channel's parameter / status changed, if so notify the respective LSCP event subscribers |
195 |
|
{ |
196 |
|
std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances(); |
197 |
|
std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin(); |
198 |
|
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
199 |
|
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
200 |
|
if ((*itEngineChannel)->StatusChanged()) { |
201 |
|
SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex)); |
202 |
|
} |
203 |
|
} |
204 |
|
} |
205 |
|
|
206 |
//Now let's deliver late notifies (if any) |
//Now let's deliver late notifies (if any) |
207 |
NotifyBufferMutex.Lock(); |
NotifyBufferMutex.Lock(); |
208 |
for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) { |
for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) { |
209 |
send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0); |
send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), MSG_NOSIGNAL); |
210 |
bufferedNotifies.erase(iterNotify); |
bufferedNotifies.erase(iterNotify); |
211 |
} |
} |
212 |
NotifyBufferMutex.Unlock(); |
NotifyBufferMutex.Unlock(); |
231 |
NotifyMutex.Unlock(); |
NotifyMutex.Unlock(); |
232 |
} |
} |
233 |
|
|
234 |
|
int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) { |
235 |
|
int subs = 0; |
236 |
|
SubscriptionMutex.Lock(); |
237 |
|
for( std::list<LSCPEvent::event_t>::iterator iter = events.begin(); |
238 |
|
iter != events.end(); iter++) |
239 |
|
{ |
240 |
|
subs += eventSubscriptions.count(*iter); |
241 |
|
} |
242 |
|
SubscriptionMutex.Unlock(); |
243 |
|
return subs; |
244 |
|
} |
245 |
|
|
246 |
void LSCPServer::SendLSCPNotify( LSCPEvent event ) { |
void LSCPServer::SendLSCPNotify( LSCPEvent event ) { |
247 |
SubscriptionMutex.Lock(); |
SubscriptionMutex.Lock(); |
248 |
if (eventSubscriptions.count(event.GetType()) == 0) { |
if (eventSubscriptions.count(event.GetType()) == 0) { |
256 |
while (true) { |
while (true) { |
257 |
if (NotifyMutex.Trylock()) { |
if (NotifyMutex.Trylock()) { |
258 |
for(;iter != end; iter++) |
for(;iter != end; iter++) |
259 |
send(*iter, notify.c_str(), notify.size(), 0); |
send(*iter, notify.c_str(), notify.size(), MSG_NOSIGNAL); |
260 |
NotifyMutex.Unlock(); |
NotifyMutex.Unlock(); |
261 |
break; |
break; |
262 |
} else { |
} else { |
365 |
dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str())); |
dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str())); |
366 |
if (currentSocket != -1) { |
if (currentSocket != -1) { |
367 |
NotifyMutex.Lock(); |
NotifyMutex.Lock(); |
368 |
send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0); |
send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), MSG_NOSIGNAL); |
369 |
NotifyMutex.Unlock(); |
NotifyMutex.Unlock(); |
370 |
} |
} |
371 |
} |
} |
472 |
LSCPResultSet result; |
LSCPResultSet result; |
473 |
try { |
try { |
474 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
475 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
476 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
477 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel yet"); |
478 |
if (!pSamplerChannel->GetAudioOutputDevice()) |
if (!pSamplerChannel->GetAudioOutputDevice()) |
479 |
throw LinuxSamplerException("No audio output device on channel"); |
throw LinuxSamplerException("No audio output device connected to sampler channel"); |
480 |
if (bBackground) { |
if (bBackground) { |
481 |
LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument); |
InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngineChannel); |
482 |
pLoadInstrument->StartThread(); |
} |
483 |
|
else { |
484 |
|
// tell the engine channel which instrument to load |
485 |
|
pEngineChannel->PrepareLoadInstrument(Filename.c_str(), uiInstrument); |
486 |
|
// actually start to load the instrument (blocks until completed) |
487 |
|
pEngineChannel->LoadInstrument(); |
488 |
} |
} |
|
else pEngine->LoadInstrument(Filename.c_str(), uiInstrument); |
|
489 |
} |
} |
490 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
491 |
result.Error(e); |
result.Error(e); |
494 |
} |
} |
495 |
|
|
496 |
/** |
/** |
497 |
* 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 |
498 |
|
* sampler channel. |
499 |
*/ |
*/ |
500 |
String LSCPServer::LoadEngine(String EngineName, uint uiSamplerChannel) { |
String LSCPServer::SetEngineType(String EngineName, uint uiSamplerChannel) { |
501 |
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)); |
502 |
LSCPResultSet result; |
LSCPResultSet result; |
503 |
try { |
try { |
|
Engine::type_t type; |
|
|
if ((EngineName == "GigEngine") || (EngineName == "gig")) type = Engine::type_gig; |
|
|
else throw LinuxSamplerException("Unknown engine type"); |
|
504 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
505 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
506 |
pSamplerChannel->LoadEngine(type); |
LockRTNotify(); |
507 |
|
pSamplerChannel->SetEngineType(EngineName); |
508 |
|
if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1); |
509 |
|
UnlockRTNotify(); |
510 |
} |
} |
511 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
512 |
result.Error(e); |
result.Error(e); |
557 |
String LSCPServer::RemoveChannel(uint uiSamplerChannel) { |
String LSCPServer::RemoveChannel(uint uiSamplerChannel) { |
558 |
dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
559 |
LSCPResultSet result; |
LSCPResultSet result; |
560 |
|
LockRTNotify(); |
561 |
pSampler->RemoveSamplerChannel(uiSamplerChannel); |
pSampler->RemoveSamplerChannel(uiSamplerChannel); |
562 |
|
UnlockRTNotify(); |
563 |
return result.Produce(); |
return result.Produce(); |
564 |
} |
} |
565 |
|
|
566 |
/** |
/** |
567 |
* 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. |
568 |
*/ |
*/ |
569 |
String LSCPServer::GetAvailableEngines() { |
String LSCPServer::GetAvailableEngines() { |
570 |
dmsg(2,("LSCPServer: GetAvailableEngines()\n")); |
dmsg(2,("LSCPServer: GetAvailableEngines()\n")); |
571 |
LSCPResultSet result("GigEngine"); |
LSCPResultSet result("1"); |
572 |
|
return result.Produce(); |
573 |
|
} |
574 |
|
|
575 |
|
/** |
576 |
|
* Will be called by the parser to get a list of all available engines. |
577 |
|
*/ |
578 |
|
String LSCPServer::ListAvailableEngines() { |
579 |
|
dmsg(2,("LSCPServer: ListAvailableEngines()\n")); |
580 |
|
LSCPResultSet result("\'GIG\'"); |
581 |
return result.Produce(); |
return result.Produce(); |
582 |
} |
} |
583 |
|
|
584 |
/** |
/** |
585 |
* 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 |
586 |
|
* sampler engine. |
587 |
*/ |
*/ |
588 |
String LSCPServer::GetEngineInfo(String EngineName) { |
String LSCPServer::GetEngineInfo(String EngineName) { |
589 |
dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str())); |
dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str())); |
590 |
LSCPResultSet result; |
LSCPResultSet result; |
591 |
try { |
try { |
592 |
if ((EngineName == "GigEngine") || (EngineName == "gig")) { |
Engine* pEngine = EngineFactory::Create(EngineName); |
593 |
Engine* pEngine = new LinuxSampler::gig::Engine; |
result.Add("DESCRIPTION", pEngine->Description()); |
594 |
result.Add("DESCRIPTION", pEngine->Description()); |
result.Add("VERSION", pEngine->Version()); |
595 |
result.Add("VERSION", pEngine->Version()); |
EngineFactory::Destroy(pEngine); |
|
delete pEngine; |
|
|
} |
|
|
else throw LinuxSamplerException("Unknown engine type"); |
|
596 |
} |
} |
597 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
598 |
result.Error(e); |
result.Error(e); |
609 |
LSCPResultSet result; |
LSCPResultSet result; |
610 |
try { |
try { |
611 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
612 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
613 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
614 |
|
|
615 |
//Defaults values |
//Defaults values |
616 |
String EngineName = "NONE"; |
String EngineName = "NONE"; |
617 |
float Volume = 0.0f; |
float Volume = 0.0f; |
618 |
String InstrumentFileName = "NONE"; |
String InstrumentFileName = "NONE"; |
619 |
|
String InstrumentName = "NONE"; |
620 |
int InstrumentIndex = -1; |
int InstrumentIndex = -1; |
621 |
int InstrumentStatus = -1; |
int InstrumentStatus = -1; |
622 |
int AudioOutputChannels = 0; |
int AudioOutputChannels = 0; |
623 |
String AudioRouting; |
String AudioRouting; |
624 |
|
int Mute = 0; |
625 |
|
bool Solo = false; |
626 |
|
|
627 |
if (pEngine) { |
if (pEngineChannel) { |
628 |
EngineName = pEngine->EngineName(); |
EngineName = pEngineChannel->EngineName(); |
629 |
AudioOutputChannels = pEngine->Channels(); |
AudioOutputChannels = pEngineChannel->Channels(); |
630 |
Volume = pEngine->Volume(); |
Volume = pEngineChannel->Volume(); |
631 |
InstrumentStatus = pEngine->InstrumentStatus(); |
InstrumentStatus = pEngineChannel->InstrumentStatus(); |
632 |
InstrumentIndex = pEngine->InstrumentIndex(); |
InstrumentIndex = pEngineChannel->InstrumentIndex(); |
633 |
if (InstrumentIndex != -1) |
if (InstrumentIndex != -1) { |
634 |
InstrumentFileName = pEngine->InstrumentFileName(); |
InstrumentFileName = pEngineChannel->InstrumentFileName(); |
635 |
for (int chan = 0; chan < pEngine->Channels(); chan++) { |
InstrumentName = pEngineChannel->InstrumentName(); |
636 |
|
} |
637 |
|
for (int chan = 0; chan < pEngineChannel->Channels(); chan++) { |
638 |
if (AudioRouting != "") AudioRouting += ","; |
if (AudioRouting != "") AudioRouting += ","; |
639 |
AudioRouting += ToString(pEngine->OutputChannel(chan)); |
AudioRouting += ToString(pEngineChannel->OutputChannel(chan)); |
640 |
} |
} |
641 |
|
Mute = pEngineChannel->GetMute(); |
642 |
|
Solo = pEngineChannel->GetSolo(); |
643 |
} |
} |
644 |
|
|
645 |
result.Add("ENGINE_NAME", EngineName); |
result.Add("ENGINE_NAME", EngineName); |
652 |
|
|
653 |
result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice())); |
result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice())); |
654 |
result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort()); |
result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort()); |
655 |
if (pSamplerChannel->GetMidiInputChannel()) result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); |
if (pSamplerChannel->GetMidiInputChannel() == midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL"); |
656 |
else result.Add("MIDI_INPUT_CHANNEL", "ALL"); |
else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); |
657 |
|
|
658 |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
659 |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
660 |
|
result.Add("INSTRUMENT_NAME", InstrumentName); |
661 |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
662 |
|
result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false")); |
663 |
|
result.Add("SOLO", Solo); |
664 |
} |
} |
665 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
666 |
result.Error(e); |
result.Error(e); |
677 |
LSCPResultSet result; |
LSCPResultSet result; |
678 |
try { |
try { |
679 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
680 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
681 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
682 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine loaded on sampler channel"); |
683 |
result.Add(pEngine->VoiceCount()); |
if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel"); |
684 |
|
result.Add(pEngineChannel->GetEngine()->VoiceCount()); |
685 |
} |
} |
686 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
687 |
result.Error(e); |
result.Error(e); |
698 |
LSCPResultSet result; |
LSCPResultSet result; |
699 |
try { |
try { |
700 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
701 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
702 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
703 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
704 |
result.Add(pEngine->DiskStreamCount()); |
if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel"); |
705 |
|
result.Add(pEngineChannel->GetEngine()->DiskStreamCount()); |
706 |
} |
} |
707 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
708 |
result.Error(e); |
result.Error(e); |
719 |
LSCPResultSet result; |
LSCPResultSet result; |
720 |
try { |
try { |
721 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
722 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
723 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
724 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
725 |
if (!pEngine->DiskStreamSupported()) |
if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel"); |
726 |
result.Add("NA"); |
if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA"); |
727 |
else { |
else { |
728 |
switch (ResponseType) { |
switch (ResponseType) { |
729 |
case fill_response_bytes: |
case fill_response_bytes: |
730 |
result.Add(pEngine->DiskStreamBufferFillBytes()); |
result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillBytes()); |
731 |
break; |
break; |
732 |
case fill_response_percentage: |
case fill_response_percentage: |
733 |
result.Add(pEngine->DiskStreamBufferFillPercentage()); |
result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage()); |
734 |
break; |
break; |
735 |
default: |
default: |
736 |
throw LinuxSamplerException("Unknown fill response type"); |
throw LinuxSamplerException("Unknown fill response type"); |
737 |
} |
} |
747 |
dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n")); |
dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n")); |
748 |
LSCPResultSet result; |
LSCPResultSet result; |
749 |
try { |
try { |
750 |
|
int n = AudioOutputDeviceFactory::AvailableDrivers().size(); |
751 |
|
result.Add(n); |
752 |
|
} |
753 |
|
catch (LinuxSamplerException e) { |
754 |
|
result.Error(e); |
755 |
|
} |
756 |
|
return result.Produce(); |
757 |
|
} |
758 |
|
|
759 |
|
String LSCPServer::ListAvailableAudioOutputDrivers() { |
760 |
|
dmsg(2,("LSCPServer: ListAvailableAudioOutputDrivers()\n")); |
761 |
|
LSCPResultSet result; |
762 |
|
try { |
763 |
String s = AudioOutputDeviceFactory::AvailableDriversAsString(); |
String s = AudioOutputDeviceFactory::AvailableDriversAsString(); |
764 |
result.Add(s); |
result.Add(s); |
765 |
} |
} |
773 |
dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n")); |
dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n")); |
774 |
LSCPResultSet result; |
LSCPResultSet result; |
775 |
try { |
try { |
776 |
|
int n = MidiInputDeviceFactory::AvailableDrivers().size(); |
777 |
|
result.Add(n); |
778 |
|
} |
779 |
|
catch (LinuxSamplerException e) { |
780 |
|
result.Error(e); |
781 |
|
} |
782 |
|
return result.Produce(); |
783 |
|
} |
784 |
|
|
785 |
|
String LSCPServer::ListAvailableMidiInputDrivers() { |
786 |
|
dmsg(2,("LSCPServer: ListAvailableMidiInputDrivers()\n")); |
787 |
|
LSCPResultSet result; |
788 |
|
try { |
789 |
String s = MidiInputDeviceFactory::AvailableDriversAsString(); |
String s = MidiInputDeviceFactory::AvailableDriversAsString(); |
790 |
result.Add(s); |
result.Add(s); |
791 |
} |
} |
1037 |
|
|
1038 |
// get audio channel |
// get audio channel |
1039 |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
1040 |
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) + "."); |
1041 |
|
|
1042 |
// return the values of all audio channel parameters |
// return the values of all audio channel parameters |
1043 |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
1096 |
|
|
1097 |
// get audio channel |
// get audio channel |
1098 |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
1099 |
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) + "."); |
1100 |
|
|
1101 |
// get desired audio channel parameter |
// get desired audio channel parameter |
1102 |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
1129 |
|
|
1130 |
// get audio channel |
// get audio channel |
1131 |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
1132 |
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) + "."); |
1133 |
|
|
1134 |
// get desired audio channel parameter |
// get desired audio channel parameter |
1135 |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
1212 |
LSCPResultSet result; |
LSCPResultSet result; |
1213 |
try { |
try { |
1214 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1215 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1216 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
1217 |
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)); |
1218 |
pEngine->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel); |
if (!pSamplerChannel->GetAudioOutputDevice()) throw LinuxSamplerException("No audio output device connected to sampler channel " + ToString(uiSamplerChannel)); |
1219 |
|
pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel); |
1220 |
} |
} |
1221 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1222 |
result.Error(e); |
result.Error(e); |
1229 |
LSCPResultSet result; |
LSCPResultSet result; |
1230 |
try { |
try { |
1231 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1232 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1233 |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1234 |
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)); |
1235 |
AudioOutputDevice* pDevice = devices[AudioDeviceId]; |
AudioOutputDevice* pDevice = devices[AudioDeviceId]; |
1246 |
LSCPResultSet result; |
LSCPResultSet result; |
1247 |
try { |
try { |
1248 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1249 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1250 |
// Driver type name aliasing... |
// Driver type name aliasing... |
1251 |
if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA"; |
if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA"; |
1252 |
if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK"; |
if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK"; |
1283 |
LSCPResultSet result; |
LSCPResultSet result; |
1284 |
try { |
try { |
1285 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1286 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1287 |
pSamplerChannel->SetMidiInputPort(MIDIPort); |
pSamplerChannel->SetMidiInputPort(MIDIPort); |
1288 |
} |
} |
1289 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1297 |
LSCPResultSet result; |
LSCPResultSet result; |
1298 |
try { |
try { |
1299 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1300 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1301 |
pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel); |
pSamplerChannel->SetMidiInputChannel((midi_chan_t) MIDIChannel); |
1302 |
} |
} |
1303 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1304 |
result.Error(e); |
result.Error(e); |
1311 |
LSCPResultSet result; |
LSCPResultSet result; |
1312 |
try { |
try { |
1313 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1314 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1315 |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1316 |
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)); |
1317 |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
1328 |
LSCPResultSet result; |
LSCPResultSet result; |
1329 |
try { |
try { |
1330 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1331 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1332 |
// Driver type name aliasing... |
// Driver type name aliasing... |
1333 |
if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA"; |
if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA"; |
1334 |
// Check if there's one MIDI input device already created |
// Check if there's one MIDI input device already created |
1371 |
LSCPResultSet result; |
LSCPResultSet result; |
1372 |
try { |
try { |
1373 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1374 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1375 |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1376 |
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)); |
1377 |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
1378 |
pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (MidiInputPort::midi_chan_t) MIDIChannel); |
pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (midi_chan_t) MIDIChannel); |
1379 |
} |
} |
1380 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1381 |
result.Error(e); |
result.Error(e); |
1392 |
LSCPResultSet result; |
LSCPResultSet result; |
1393 |
try { |
try { |
1394 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1395 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1396 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
1397 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
1398 |
pEngine->Volume(dVolume); |
pEngineChannel->Volume(dVolume); |
1399 |
} |
} |
1400 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1401 |
result.Error(e); |
result.Error(e); |
1404 |
} |
} |
1405 |
|
|
1406 |
/** |
/** |
1407 |
|
* Will be called by the parser to mute/unmute particular sampler channel. |
1408 |
|
*/ |
1409 |
|
String LSCPServer::SetChannelMute(bool bMute, uint uiSamplerChannel) { |
1410 |
|
dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel)); |
1411 |
|
LSCPResultSet result; |
1412 |
|
try { |
1413 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1414 |
|
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1415 |
|
|
1416 |
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
1417 |
|
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
1418 |
|
|
1419 |
|
if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0); |
1420 |
|
else pEngineChannel->SetMute(1); |
1421 |
|
} catch (LinuxSamplerException e) { |
1422 |
|
result.Error(e); |
1423 |
|
} |
1424 |
|
return result.Produce(); |
1425 |
|
} |
1426 |
|
|
1427 |
|
/** |
1428 |
|
* Will be called by the parser to solo particular sampler channel. |
1429 |
|
*/ |
1430 |
|
String LSCPServer::SetChannelSolo(bool bSolo, uint uiSamplerChannel) { |
1431 |
|
dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel)); |
1432 |
|
LSCPResultSet result; |
1433 |
|
try { |
1434 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1435 |
|
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1436 |
|
|
1437 |
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
1438 |
|
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
1439 |
|
|
1440 |
|
bool oldSolo = pEngineChannel->GetSolo(); |
1441 |
|
bool hadSoloChannel = HasSoloChannel(); |
1442 |
|
|
1443 |
|
pEngineChannel->SetSolo(bSolo); |
1444 |
|
|
1445 |
|
if(!oldSolo && bSolo) { |
1446 |
|
if(pEngineChannel->GetMute() == -1) pEngineChannel->SetMute(0); |
1447 |
|
if(!hadSoloChannel) MuteNonSoloChannels(); |
1448 |
|
} |
1449 |
|
|
1450 |
|
if(oldSolo && !bSolo) { |
1451 |
|
if(!HasSoloChannel()) UnmuteChannels(); |
1452 |
|
else if(!pEngineChannel->GetMute()) pEngineChannel->SetMute(-1); |
1453 |
|
} |
1454 |
|
} catch (LinuxSamplerException e) { |
1455 |
|
result.Error(e); |
1456 |
|
} |
1457 |
|
return result.Produce(); |
1458 |
|
} |
1459 |
|
|
1460 |
|
/** |
1461 |
|
* Determines whether there is at least one solo channel in the channel list. |
1462 |
|
* |
1463 |
|
* @returns true if there is at least one solo channel in the channel list, |
1464 |
|
* false otherwise. |
1465 |
|
*/ |
1466 |
|
bool LSCPServer::HasSoloChannel() { |
1467 |
|
std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels(); |
1468 |
|
std::map<uint,SamplerChannel*>::iterator iter = channels.begin(); |
1469 |
|
for (; iter != channels.end(); iter++) { |
1470 |
|
EngineChannel* c = iter->second->GetEngineChannel(); |
1471 |
|
if(c && c->GetSolo()) return true; |
1472 |
|
} |
1473 |
|
|
1474 |
|
return false; |
1475 |
|
} |
1476 |
|
|
1477 |
|
/** |
1478 |
|
* Mutes all unmuted non-solo channels. Notice that the channels are muted |
1479 |
|
* with -1 which indicates that they are muted because of the presence |
1480 |
|
* of a solo channel(s). Channels muted with -1 will be automatically unmuted |
1481 |
|
* when there are no solo channels left. |
1482 |
|
*/ |
1483 |
|
void LSCPServer::MuteNonSoloChannels() { |
1484 |
|
dmsg(2,("LSCPServer: MuteNonSoloChannels()\n")); |
1485 |
|
std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels(); |
1486 |
|
std::map<uint,SamplerChannel*>::iterator iter = channels.begin(); |
1487 |
|
for (; iter != channels.end(); iter++) { |
1488 |
|
EngineChannel* c = iter->second->GetEngineChannel(); |
1489 |
|
if(c && !c->GetSolo() && !c->GetMute()) c->SetMute(-1); |
1490 |
|
} |
1491 |
|
} |
1492 |
|
|
1493 |
|
/** |
1494 |
|
* Unmutes all channels that are muted because of the presence |
1495 |
|
* of a solo channel(s). |
1496 |
|
*/ |
1497 |
|
void LSCPServer::UnmuteChannels() { |
1498 |
|
dmsg(2,("LSCPServer: UnmuteChannels()\n")); |
1499 |
|
std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels(); |
1500 |
|
std::map<uint,SamplerChannel*>::iterator iter = channels.begin(); |
1501 |
|
for (; iter != channels.end(); iter++) { |
1502 |
|
EngineChannel* c = iter->second->GetEngineChannel(); |
1503 |
|
if(c && c->GetMute() == -1) c->SetMute(0); |
1504 |
|
} |
1505 |
|
} |
1506 |
|
|
1507 |
|
/** |
1508 |
* Will be called by the parser to reset a particular sampler channel. |
* Will be called by the parser to reset a particular sampler channel. |
1509 |
*/ |
*/ |
1510 |
String LSCPServer::ResetChannel(uint uiSamplerChannel) { |
String LSCPServer::ResetChannel(uint uiSamplerChannel) { |
1512 |
LSCPResultSet result; |
LSCPResultSet result; |
1513 |
try { |
try { |
1514 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1515 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1516 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
1517 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
1518 |
pEngine->Reset(); |
pEngineChannel->Reset(); |
1519 |
} |
} |
1520 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1521 |
result.Error(e); |
result.Error(e); |
1534 |
} |
} |
1535 |
|
|
1536 |
/** |
/** |
1537 |
|
* Will be called by the parser to return general informations about this |
1538 |
|
* sampler. |
1539 |
|
*/ |
1540 |
|
String LSCPServer::GetServerInfo() { |
1541 |
|
dmsg(2,("LSCPServer: GetServerInfo()\n")); |
1542 |
|
LSCPResultSet result; |
1543 |
|
result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler"); |
1544 |
|
result.Add("VERSION", VERSION); |
1545 |
|
result.Add("PROTOCOL_VERSION", "1.0"); |
1546 |
|
return result.Produce(); |
1547 |
|
} |
1548 |
|
|
1549 |
|
/** |
1550 |
|
* Will be called by the parser to return the current number of all active voices. |
1551 |
|
*/ |
1552 |
|
String LSCPServer::GetTotalVoiceCount() { |
1553 |
|
dmsg(2,("LSCPServer: GetTotalVoiceCount()\n")); |
1554 |
|
LSCPResultSet result; |
1555 |
|
result.Add(pSampler->GetVoiceCount()); |
1556 |
|
return result.Produce(); |
1557 |
|
} |
1558 |
|
|
1559 |
|
/** |
1560 |
|
* Will be called by the parser to return the maximum number of voices. |
1561 |
|
*/ |
1562 |
|
String LSCPServer::GetTotalVoiceCountMax() { |
1563 |
|
dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n")); |
1564 |
|
LSCPResultSet result; |
1565 |
|
result.Add(EngineFactory::EngineInstances().size() * CONFIG_MAX_VOICES); |
1566 |
|
return result.Produce(); |
1567 |
|
} |
1568 |
|
|
1569 |
|
/** |
1570 |
* 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 |
1571 |
* server for receiving event messages. |
* server for receiving event messages. |
1572 |
*/ |
*/ |
1592 |
return result.Produce(); |
return result.Produce(); |
1593 |
} |
} |
1594 |
|
|
1595 |
|
static int select_callback(void * lscpResultSet, int argc, |
1596 |
|
char **argv, char **azColName) |
1597 |
|
{ |
1598 |
|
LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet; |
1599 |
|
resultSet->Add(argc, argv); |
1600 |
|
return 0; |
1601 |
|
} |
1602 |
|
|
1603 |
|
String LSCPServer::QueryDatabase(String query) { |
1604 |
|
LSCPResultSet result; |
1605 |
|
#if HAVE_SQLITE3 |
1606 |
|
char* zErrMsg = NULL; |
1607 |
|
sqlite3 *db; |
1608 |
|
String selectStr = "SELECT " + query; |
1609 |
|
|
1610 |
|
int rc = sqlite3_open("linuxsampler.db", &db); |
1611 |
|
if (rc == SQLITE_OK) |
1612 |
|
{ |
1613 |
|
rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg); |
1614 |
|
} |
1615 |
|
if ( rc != SQLITE_OK ) |
1616 |
|
{ |
1617 |
|
result.Error(String(zErrMsg), rc); |
1618 |
|
} |
1619 |
|
sqlite3_close(db); |
1620 |
|
#else |
1621 |
|
result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0); |
1622 |
|
#endif |
1623 |
|
return result.Produce(); |
1624 |
|
} |
1625 |
|
|
1626 |
/** |
/** |
1627 |
* 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 |
1628 |
* mode is enabled, all commands from the client will (immediately) be |
* mode is enabled, all commands from the client will (immediately) be |
1641 |
} |
} |
1642 |
return result.Produce(); |
return result.Produce(); |
1643 |
} |
} |
|
|
|
|
// 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; |
|
|
} |
|