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 "../drivers/audio/AudioOutputDeviceFactory.h" |
#include "../drivers/audio/AudioOutputDeviceFactory.h" |
37 |
#include "../drivers/midi/MidiInputDeviceFactory.h" |
#include "../drivers/midi/MidiInputDeviceFactory.h" |
38 |
|
|
58 |
Mutex LSCPServer::NotifyMutex = Mutex(); |
Mutex LSCPServer::NotifyMutex = Mutex(); |
59 |
Mutex LSCPServer::NotifyBufferMutex = Mutex(); |
Mutex LSCPServer::NotifyBufferMutex = Mutex(); |
60 |
Mutex LSCPServer::SubscriptionMutex = Mutex(); |
Mutex LSCPServer::SubscriptionMutex = Mutex(); |
61 |
|
Mutex LSCPServer::RTNotifyMutex = Mutex(); |
62 |
|
|
63 |
LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) { |
LSCPServer::LSCPServer(Sampler* pSampler) : Thread(true, false, 0, -4) { |
64 |
this->pSampler = pSampler; |
this->pSampler = pSampler; |
65 |
LSCPEvent::RegisterEvent(LSCPEvent::event_channels, "CHANNELS"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_channels, "CHANNELS"); |
66 |
LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT"); |
68 |
LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL"); |
69 |
LSCPEvent::RegisterEvent(LSCPEvent::event_info, "INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_info, "INFO"); |
70 |
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
71 |
|
hSocket = -1; |
72 |
|
} |
73 |
|
|
74 |
|
LSCPServer::~LSCPServer() { |
75 |
|
if (hSocket >= 0) close(hSocket); |
76 |
} |
} |
77 |
|
|
78 |
/** |
/** |
90 |
} |
} |
91 |
|
|
92 |
int LSCPServer::Main() { |
int LSCPServer::Main() { |
93 |
int hSocket = socket(AF_INET, SOCK_STREAM, 0); |
hSocket = socket(AF_INET, SOCK_STREAM, 0); |
94 |
if (hSocket < 0) { |
if (hSocket < 0) { |
95 |
std::cerr << "LSCPServer: Could not create server socket." << std::endl; |
std::cerr << "LSCPServer: Could not create server socket." << std::endl; |
96 |
//return -1; |
//return -1; |
173 |
int dummy; // just a temporary hack to fulfill the restart() function prototype |
int dummy; // just a temporary hack to fulfill the restart() function prototype |
174 |
restart(NULL, dummy); // restart the 'scanner' |
restart(NULL, dummy); // restart the 'scanner' |
175 |
currentSocket = (*iter).hSession; //a hack |
currentSocket = (*iter).hSession; //a hack |
176 |
|
dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str())); |
177 |
if ((*iter).bVerbose) { // if echo mode enabled |
if ((*iter).bVerbose) { // if echo mode enabled |
178 |
AnswerClient(bufferedCommands[currentSocket]); |
AnswerClient(bufferedCommands[currentSocket]); |
179 |
} |
} |
218 |
NotifyMutex.Unlock(); |
NotifyMutex.Unlock(); |
219 |
} |
} |
220 |
|
|
221 |
|
int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) { |
222 |
|
int subs = 0; |
223 |
|
SubscriptionMutex.Lock(); |
224 |
|
for( std::list<LSCPEvent::event_t>::iterator iter = events.begin(); |
225 |
|
iter != events.end(); iter++) |
226 |
|
{ |
227 |
|
subs += eventSubscriptions.count(*iter); |
228 |
|
} |
229 |
|
SubscriptionMutex.Unlock(); |
230 |
|
return subs; |
231 |
|
} |
232 |
|
|
233 |
void LSCPServer::SendLSCPNotify( LSCPEvent event ) { |
void LSCPServer::SendLSCPNotify( LSCPEvent event ) { |
234 |
SubscriptionMutex.Lock(); |
SubscriptionMutex.Lock(); |
235 |
if (eventSubscriptions.count(event.GetType()) == 0) { |
if (eventSubscriptions.count(event.GetType()) == 0) { |
459 |
LSCPResultSet result; |
LSCPResultSet result; |
460 |
try { |
try { |
461 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
462 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
463 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
464 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel yet"); |
465 |
if (!pSamplerChannel->GetAudioOutputDevice()) |
if (!pSamplerChannel->GetAudioOutputDevice()) |
466 |
throw LinuxSamplerException("No audio output device on channel"); |
throw LinuxSamplerException("No audio output device connected to sampler channel"); |
467 |
if (bBackground) { |
if (bBackground) { |
468 |
LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument); |
InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngineChannel); |
469 |
pLoadInstrument->StartThread(); |
} |
470 |
|
else { |
471 |
|
// tell the engine channel which instrument to load |
472 |
|
pEngineChannel->PrepareLoadInstrument(Filename.c_str(), uiInstrument); |
473 |
|
// actually start to load the instrument (blocks until completed) |
474 |
|
pEngineChannel->LoadInstrument(); |
475 |
} |
} |
|
else pEngine->LoadInstrument(Filename.c_str(), uiInstrument); |
|
476 |
} |
} |
477 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
478 |
result.Error(e); |
result.Error(e); |
481 |
} |
} |
482 |
|
|
483 |
/** |
/** |
484 |
* 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 |
485 |
|
* sampler channel. |
486 |
*/ |
*/ |
487 |
String LSCPServer::LoadEngine(String EngineName, uint uiSamplerChannel) { |
String LSCPServer::SetEngineType(String EngineName, uint uiSamplerChannel) { |
488 |
dmsg(2,("LSCPServer: LoadEngine(EngineName=%s,SamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel)); |
dmsg(2,("LSCPServer: LoadEngine(EngineName=%s,SamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel)); |
489 |
LSCPResultSet result; |
LSCPResultSet result; |
490 |
try { |
try { |
|
Engine::type_t type; |
|
|
if ((EngineName == "GigEngine") || (EngineName == "gig")) type = Engine::type_gig; |
|
|
else throw LinuxSamplerException("Unknown engine type"); |
|
491 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
492 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
493 |
pSamplerChannel->LoadEngine(type); |
LockRTNotify(); |
494 |
|
pSamplerChannel->SetEngineType(EngineName); |
495 |
|
UnlockRTNotify(); |
496 |
} |
} |
497 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
498 |
result.Error(e); |
result.Error(e); |
543 |
String LSCPServer::RemoveChannel(uint uiSamplerChannel) { |
String LSCPServer::RemoveChannel(uint uiSamplerChannel) { |
544 |
dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
545 |
LSCPResultSet result; |
LSCPResultSet result; |
546 |
|
LockRTNotify(); |
547 |
pSampler->RemoveSamplerChannel(uiSamplerChannel); |
pSampler->RemoveSamplerChannel(uiSamplerChannel); |
548 |
|
UnlockRTNotify(); |
549 |
return result.Produce(); |
return result.Produce(); |
550 |
} |
} |
551 |
|
|
559 |
} |
} |
560 |
|
|
561 |
/** |
/** |
562 |
* 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 |
563 |
|
* sampler engine. |
564 |
*/ |
*/ |
565 |
String LSCPServer::GetEngineInfo(String EngineName) { |
String LSCPServer::GetEngineInfo(String EngineName) { |
566 |
dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str())); |
dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str())); |
567 |
LSCPResultSet result; |
LSCPResultSet result; |
568 |
try { |
try { |
569 |
if ((EngineName == "GigEngine") || (EngineName == "gig")) { |
Engine* pEngine = EngineFactory::Create(EngineName); |
570 |
Engine* pEngine = new LinuxSampler::gig::Engine; |
result.Add("DESCRIPTION", pEngine->Description()); |
571 |
result.Add("DESCRIPTION", pEngine->Description()); |
result.Add("VERSION", pEngine->Version()); |
572 |
result.Add("VERSION", pEngine->Version()); |
delete pEngine; |
|
delete pEngine; |
|
|
} |
|
|
else throw LinuxSamplerException("Unknown engine type"); |
|
573 |
} |
} |
574 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
575 |
result.Error(e); |
result.Error(e); |
586 |
LSCPResultSet result; |
LSCPResultSet result; |
587 |
try { |
try { |
588 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
589 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
590 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
591 |
|
|
592 |
//Defaults values |
//Defaults values |
593 |
String EngineName = "NONE"; |
String EngineName = "NONE"; |
594 |
float Volume = 0.0f; |
float Volume = 0.0f; |
595 |
String InstrumentFileName = "NONE"; |
String InstrumentFileName = "NONE"; |
596 |
|
String InstrumentName = "NONE"; |
597 |
int InstrumentIndex = -1; |
int InstrumentIndex = -1; |
598 |
int InstrumentStatus = -1; |
int InstrumentStatus = -1; |
599 |
int AudioOutputChannels = 0; |
int AudioOutputChannels = 0; |
600 |
String AudioRouting; |
String AudioRouting; |
601 |
|
|
602 |
if (pEngine) { |
if (pEngineChannel) { |
603 |
EngineName = pEngine->EngineName(); |
EngineName = pEngineChannel->EngineName(); |
604 |
AudioOutputChannels = pEngine->Channels(); |
AudioOutputChannels = pEngineChannel->Channels(); |
605 |
Volume = pEngine->Volume(); |
Volume = pEngineChannel->Volume(); |
606 |
InstrumentStatus = pEngine->InstrumentStatus(); |
InstrumentStatus = pEngineChannel->InstrumentStatus(); |
607 |
InstrumentIndex = pEngine->InstrumentIndex(); |
InstrumentIndex = pEngineChannel->InstrumentIndex(); |
608 |
if (InstrumentIndex != -1) |
if (InstrumentIndex != -1) { |
609 |
InstrumentFileName = pEngine->InstrumentFileName(); |
InstrumentFileName = pEngineChannel->InstrumentFileName(); |
610 |
for (int chan = 0; chan < pEngine->Channels(); chan++) { |
InstrumentName = pEngineChannel->InstrumentName(); |
611 |
|
} |
612 |
|
for (int chan = 0; chan < pEngineChannel->Channels(); chan++) { |
613 |
if (AudioRouting != "") AudioRouting += ","; |
if (AudioRouting != "") AudioRouting += ","; |
614 |
AudioRouting += ToString(pEngine->OutputChannel(chan)); |
AudioRouting += ToString(pEngineChannel->OutputChannel(chan)); |
615 |
} |
} |
616 |
} |
} |
617 |
|
|
630 |
|
|
631 |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
632 |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
633 |
|
result.Add("INSTRUMENT_NAME", InstrumentName); |
634 |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
635 |
} |
} |
636 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
648 |
LSCPResultSet result; |
LSCPResultSet result; |
649 |
try { |
try { |
650 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
651 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
652 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
653 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine loaded on sampler channel"); |
654 |
result.Add(pEngine->VoiceCount()); |
result.Add(pEngineChannel->GetEngine()->VoiceCount()); |
655 |
} |
} |
656 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
657 |
result.Error(e); |
result.Error(e); |
668 |
LSCPResultSet result; |
LSCPResultSet result; |
669 |
try { |
try { |
670 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
671 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
672 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
673 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
674 |
result.Add(pEngine->DiskStreamCount()); |
result.Add(pEngineChannel->GetEngine()->DiskStreamCount()); |
675 |
} |
} |
676 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
677 |
result.Error(e); |
result.Error(e); |
688 |
LSCPResultSet result; |
LSCPResultSet result; |
689 |
try { |
try { |
690 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
691 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
692 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
693 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
694 |
if (!pEngine->DiskStreamSupported()) |
if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA"); |
|
result.Add("NA"); |
|
695 |
else { |
else { |
696 |
switch (ResponseType) { |
switch (ResponseType) { |
697 |
case fill_response_bytes: |
case fill_response_bytes: |
698 |
result.Add(pEngine->DiskStreamBufferFillBytes()); |
result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillBytes()); |
699 |
break; |
break; |
700 |
case fill_response_percentage: |
case fill_response_percentage: |
701 |
result.Add(pEngine->DiskStreamBufferFillPercentage()); |
result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage()); |
702 |
break; |
break; |
703 |
default: |
default: |
704 |
throw LinuxSamplerException("Unknown fill response type"); |
throw LinuxSamplerException("Unknown fill response type"); |
705 |
} |
} |
979 |
|
|
980 |
// get audio channel |
// get audio channel |
981 |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
982 |
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) + "."); |
983 |
|
|
984 |
// return the values of all audio channel parameters |
// return the values of all audio channel parameters |
985 |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
1038 |
|
|
1039 |
// get audio channel |
// get audio channel |
1040 |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
1041 |
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) + "."); |
1042 |
|
|
1043 |
// get desired audio channel parameter |
// get desired audio channel parameter |
1044 |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
1071 |
|
|
1072 |
// get audio channel |
// get audio channel |
1073 |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
1074 |
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) + "."); |
1075 |
|
|
1076 |
// get desired audio channel parameter |
// get desired audio channel parameter |
1077 |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
1154 |
LSCPResultSet result; |
LSCPResultSet result; |
1155 |
try { |
try { |
1156 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1157 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1158 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
1159 |
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)); |
1160 |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
if (!pSamplerChannel->GetAudioOutputDevice()) throw LinuxSamplerException("No audio output device connected to sampler channel " + ToString(uiSamplerChannel)); |
1161 |
if (!devices.count(ChannelAudioOutputChannel)) throw LinuxSamplerException("There is no audio output device with index " + ToString(ChannelAudioOutputChannel)); |
pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel); |
|
pEngine->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel); |
|
1162 |
} |
} |
1163 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1164 |
result.Error(e); |
result.Error(e); |
1171 |
LSCPResultSet result; |
LSCPResultSet result; |
1172 |
try { |
try { |
1173 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1174 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1175 |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1176 |
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)); |
1177 |
AudioOutputDevice* pDevice = devices[AudioDeviceId]; |
AudioOutputDevice* pDevice = devices[AudioDeviceId]; |
1188 |
LSCPResultSet result; |
LSCPResultSet result; |
1189 |
try { |
try { |
1190 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1191 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1192 |
// Driver type name aliasing... |
// Driver type name aliasing... |
1193 |
if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA"; |
if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA"; |
1194 |
if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK"; |
if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK"; |
1225 |
LSCPResultSet result; |
LSCPResultSet result; |
1226 |
try { |
try { |
1227 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1228 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1229 |
pSamplerChannel->SetMidiInputPort(MIDIPort); |
pSamplerChannel->SetMidiInputPort(MIDIPort); |
1230 |
} |
} |
1231 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1239 |
LSCPResultSet result; |
LSCPResultSet result; |
1240 |
try { |
try { |
1241 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1242 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1243 |
pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel); |
pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel); |
1244 |
} |
} |
1245 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1253 |
LSCPResultSet result; |
LSCPResultSet result; |
1254 |
try { |
try { |
1255 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1256 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1257 |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1258 |
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)); |
1259 |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
1270 |
LSCPResultSet result; |
LSCPResultSet result; |
1271 |
try { |
try { |
1272 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1273 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1274 |
// Driver type name aliasing... |
// Driver type name aliasing... |
1275 |
if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA"; |
if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA"; |
1276 |
// Check if there's one MIDI input device already created |
// Check if there's one MIDI input device already created |
1313 |
LSCPResultSet result; |
LSCPResultSet result; |
1314 |
try { |
try { |
1315 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1316 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1317 |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1318 |
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)); |
1319 |
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("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1338 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
1339 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
1340 |
pEngine->Volume(dVolume); |
pEngineChannel->Volume(dVolume); |
1341 |
} |
} |
1342 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1343 |
result.Error(e); |
result.Error(e); |
1353 |
LSCPResultSet result; |
LSCPResultSet result; |
1354 |
try { |
try { |
1355 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1356 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1357 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
1358 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
1359 |
pEngine->Reset(); |
pEngineChannel->GetEngine()->Reset(); |
1360 |
} |
} |
1361 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1362 |
result.Error(e); |
result.Error(e); |
1400 |
return result.Produce(); |
return result.Produce(); |
1401 |
} |
} |
1402 |
|
|
1403 |
|
static int select_callback(void * lscpResultSet, int argc, |
1404 |
|
char **argv, char **azColName) |
1405 |
|
{ |
1406 |
|
LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet; |
1407 |
|
resultSet->Add(argc, argv); |
1408 |
|
return 0; |
1409 |
|
} |
1410 |
|
|
1411 |
|
String LSCPServer::QueryDatabase(String query) { |
1412 |
|
LSCPResultSet result; |
1413 |
|
#if HAVE_SQLITE3 |
1414 |
|
char* zErrMsg = NULL; |
1415 |
|
sqlite3 *db; |
1416 |
|
String selectStr = "SELECT " + query; |
1417 |
|
|
1418 |
|
int rc = sqlite3_open("linuxsampler.db", &db); |
1419 |
|
if (rc == SQLITE_OK) |
1420 |
|
{ |
1421 |
|
rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg); |
1422 |
|
} |
1423 |
|
if ( rc != SQLITE_OK ) |
1424 |
|
{ |
1425 |
|
result.Error(String(zErrMsg), rc); |
1426 |
|
} |
1427 |
|
sqlite3_close(db); |
1428 |
|
#else |
1429 |
|
result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0); |
1430 |
|
#endif |
1431 |
|
return result.Produce(); |
1432 |
|
} |
1433 |
|
|
1434 |
/** |
/** |
1435 |
* 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 |
1436 |
* mode is enabled, all commands from the client will (immediately) be |
* mode is enabled, all commands from the client will (immediately) be |
1449 |
} |
} |
1450 |
return result.Produce(); |
return result.Produce(); |
1451 |
} |
} |
|
|
|
|
// 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; |
|
|
} |
|