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 |
|
#if HAVE_SQLITE3 |
30 |
|
# include "sqlite3.h" |
31 |
|
#endif |
32 |
|
|
33 |
#include "../engines/gig/Engine.h" |
#include "../engines/gig/Engine.h" |
34 |
#include "../drivers/audio/AudioOutputDeviceFactory.h" |
#include "../drivers/audio/AudioOutputDeviceFactory.h" |
56 |
Mutex LSCPServer::NotifyMutex = Mutex(); |
Mutex LSCPServer::NotifyMutex = Mutex(); |
57 |
Mutex LSCPServer::NotifyBufferMutex = Mutex(); |
Mutex LSCPServer::NotifyBufferMutex = Mutex(); |
58 |
Mutex LSCPServer::SubscriptionMutex = Mutex(); |
Mutex LSCPServer::SubscriptionMutex = Mutex(); |
59 |
|
Mutex LSCPServer::RTNotifyMutex = Mutex(); |
60 |
|
|
61 |
LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) { |
LSCPServer::LSCPServer(Sampler* pSampler) : Thread(true, false, 0, -4) { |
62 |
this->pSampler = pSampler; |
this->pSampler = pSampler; |
63 |
LSCPEvent::RegisterEvent(LSCPEvent::event_channels, "CHANNELS"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_channels, "CHANNELS"); |
64 |
LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT"); |
210 |
NotifyMutex.Unlock(); |
NotifyMutex.Unlock(); |
211 |
} |
} |
212 |
|
|
213 |
|
int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) { |
214 |
|
int subs = 0; |
215 |
|
SubscriptionMutex.Lock(); |
216 |
|
for( std::list<LSCPEvent::event_t>::iterator iter = events.begin(); |
217 |
|
iter != events.end(); iter++) |
218 |
|
{ |
219 |
|
subs += eventSubscriptions.count(*iter); |
220 |
|
} |
221 |
|
SubscriptionMutex.Unlock(); |
222 |
|
return subs; |
223 |
|
} |
224 |
|
|
225 |
void LSCPServer::SendLSCPNotify( LSCPEvent event ) { |
void LSCPServer::SendLSCPNotify( LSCPEvent event ) { |
226 |
SubscriptionMutex.Lock(); |
SubscriptionMutex.Lock(); |
227 |
if (eventSubscriptions.count(event.GetType()) == 0) { |
if (eventSubscriptions.count(event.GetType()) == 0) { |
451 |
LSCPResultSet result; |
LSCPResultSet result; |
452 |
try { |
try { |
453 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
454 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
455 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
456 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); |
457 |
if (!pSamplerChannel->GetAudioOutputDevice()) |
if (!pSamplerChannel->GetAudioOutputDevice()) |
458 |
throw LinuxSamplerException("No audio output device on channel"); |
throw LinuxSamplerException("No audio output device connected to sampler channel"); |
459 |
if (bBackground) { |
if (bBackground) { |
460 |
LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument); |
InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngine); |
461 |
pLoadInstrument->StartThread(); |
} |
462 |
|
else { |
463 |
|
// tell the engine which instrument to load |
464 |
|
pEngine->PrepareLoadInstrument(Filename.c_str(), uiInstrument); |
465 |
|
// actually start to load the instrument (blocks until completed) |
466 |
|
pEngine->LoadInstrument(); |
467 |
} |
} |
|
else pEngine->LoadInstrument(Filename.c_str(), uiInstrument); |
|
468 |
} |
} |
469 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
470 |
result.Error(e); |
result.Error(e); |
483 |
if ((EngineName == "GigEngine") || (EngineName == "gig")) type = Engine::type_gig; |
if ((EngineName == "GigEngine") || (EngineName == "gig")) type = Engine::type_gig; |
484 |
else throw LinuxSamplerException("Unknown engine type"); |
else throw LinuxSamplerException("Unknown engine type"); |
485 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
486 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
487 |
|
LockRTNotify(); |
488 |
pSamplerChannel->LoadEngine(type); |
pSamplerChannel->LoadEngine(type); |
489 |
|
UnlockRTNotify(); |
490 |
} |
} |
491 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
492 |
result.Error(e); |
result.Error(e); |
537 |
String LSCPServer::RemoveChannel(uint uiSamplerChannel) { |
String LSCPServer::RemoveChannel(uint uiSamplerChannel) { |
538 |
dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
539 |
LSCPResultSet result; |
LSCPResultSet result; |
540 |
|
LockRTNotify(); |
541 |
pSampler->RemoveSamplerChannel(uiSamplerChannel); |
pSampler->RemoveSamplerChannel(uiSamplerChannel); |
542 |
|
UnlockRTNotify(); |
543 |
return result.Produce(); |
return result.Produce(); |
544 |
} |
} |
545 |
|
|
582 |
LSCPResultSet result; |
LSCPResultSet result; |
583 |
try { |
try { |
584 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
585 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
586 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
587 |
|
|
588 |
//Defaults values |
//Defaults values |
589 |
String EngineName = "NONE"; |
String EngineName = "NONE"; |
590 |
float Volume = 0.0f; |
float Volume = 0.0f; |
591 |
String InstrumentFileName = "NONE"; |
String InstrumentFileName = "NONE"; |
592 |
|
String InstrumentName = "NONE"; |
593 |
int InstrumentIndex = -1; |
int InstrumentIndex = -1; |
594 |
int InstrumentStatus = -1; |
int InstrumentStatus = -1; |
595 |
int AudioOutputChannels = 0; |
int AudioOutputChannels = 0; |
602 |
InstrumentStatus = pEngine->InstrumentStatus(); |
InstrumentStatus = pEngine->InstrumentStatus(); |
603 |
InstrumentIndex = pEngine->InstrumentIndex(); |
InstrumentIndex = pEngine->InstrumentIndex(); |
604 |
if (InstrumentIndex != -1) |
if (InstrumentIndex != -1) |
605 |
|
{ |
606 |
InstrumentFileName = pEngine->InstrumentFileName(); |
InstrumentFileName = pEngine->InstrumentFileName(); |
607 |
|
InstrumentName = pEngine->InstrumentName(); |
608 |
|
} |
609 |
for (int chan = 0; chan < pEngine->Channels(); chan++) { |
for (int chan = 0; chan < pEngine->Channels(); chan++) { |
610 |
if (AudioRouting != "") AudioRouting += ","; |
if (AudioRouting != "") AudioRouting += ","; |
611 |
AudioRouting += ToString(pEngine->OutputChannel(chan)); |
AudioRouting += ToString(pEngine->OutputChannel(chan)); |
627 |
|
|
628 |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
629 |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
630 |
|
result.Add("INSTRUMENT_NAME", InstrumentName); |
631 |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
632 |
} |
} |
633 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
645 |
LSCPResultSet result; |
LSCPResultSet result; |
646 |
try { |
try { |
647 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
648 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
649 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
650 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); |
651 |
result.Add(pEngine->VoiceCount()); |
result.Add(pEngine->VoiceCount()); |
652 |
} |
} |
653 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
665 |
LSCPResultSet result; |
LSCPResultSet result; |
666 |
try { |
try { |
667 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
668 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
669 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
670 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); |
671 |
result.Add(pEngine->DiskStreamCount()); |
result.Add(pEngine->DiskStreamCount()); |
672 |
} |
} |
673 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
685 |
LSCPResultSet result; |
LSCPResultSet result; |
686 |
try { |
try { |
687 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
688 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
689 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
690 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); |
691 |
if (!pEngine->DiskStreamSupported()) |
if (!pEngine->DiskStreamSupported()) |
692 |
result.Add("NA"); |
result.Add("NA"); |
693 |
else { |
else { |
977 |
|
|
978 |
// get audio channel |
// get audio channel |
979 |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
980 |
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) + "."); |
981 |
|
|
982 |
// return the values of all audio channel parameters |
// return the values of all audio channel parameters |
983 |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
1036 |
|
|
1037 |
// get audio channel |
// get audio channel |
1038 |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
1039 |
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) + "."); |
1040 |
|
|
1041 |
// get desired audio channel parameter |
// get desired audio channel parameter |
1042 |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
1069 |
|
|
1070 |
// get audio channel |
// get audio channel |
1071 |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
1072 |
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) + "."); |
1073 |
|
|
1074 |
// get desired audio channel parameter |
// get desired audio channel parameter |
1075 |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
1152 |
LSCPResultSet result; |
LSCPResultSet result; |
1153 |
try { |
try { |
1154 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1155 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1156 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
1157 |
if (!pEngine) throw LinuxSamplerException("No engine deployed on sampler channel " + ToString(uiSamplerChannel)); |
if (!pEngine) throw LinuxSamplerException("No engine deployed on sampler channel " + ToString(uiSamplerChannel)); |
1158 |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
if (!pSamplerChannel->GetAudioOutputDevice()) throw LinuxSamplerException("No audio output device connected to sampler channel " + ToString(uiSamplerChannel)); |
|
if (!devices.count(ChannelAudioOutputChannel)) throw LinuxSamplerException("There is no audio output device with index " + ToString(ChannelAudioOutputChannel)); |
|
1159 |
pEngine->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel); |
pEngine->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel); |
1160 |
} |
} |
1161 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1169 |
LSCPResultSet result; |
LSCPResultSet result; |
1170 |
try { |
try { |
1171 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1172 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1173 |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1174 |
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)); |
1175 |
AudioOutputDevice* pDevice = devices[AudioDeviceId]; |
AudioOutputDevice* pDevice = devices[AudioDeviceId]; |
1186 |
LSCPResultSet result; |
LSCPResultSet result; |
1187 |
try { |
try { |
1188 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1189 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1190 |
// Driver type name aliasing... |
// Driver type name aliasing... |
1191 |
if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA"; |
if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA"; |
1192 |
if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK"; |
if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK"; |
1223 |
LSCPResultSet result; |
LSCPResultSet result; |
1224 |
try { |
try { |
1225 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1226 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1227 |
pSamplerChannel->SetMidiInputPort(MIDIPort); |
pSamplerChannel->SetMidiInputPort(MIDIPort); |
1228 |
} |
} |
1229 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1237 |
LSCPResultSet result; |
LSCPResultSet result; |
1238 |
try { |
try { |
1239 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1240 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1241 |
pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel); |
pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel); |
1242 |
} |
} |
1243 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1251 |
LSCPResultSet result; |
LSCPResultSet result; |
1252 |
try { |
try { |
1253 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1254 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1255 |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1256 |
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)); |
1257 |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
1268 |
LSCPResultSet result; |
LSCPResultSet result; |
1269 |
try { |
try { |
1270 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1271 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1272 |
// Driver type name aliasing... |
// Driver type name aliasing... |
1273 |
if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA"; |
if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA"; |
1274 |
// Check if there's one MIDI input device already created |
// Check if there's one MIDI input device already created |
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]; |
1332 |
LSCPResultSet result; |
LSCPResultSet result; |
1333 |
try { |
try { |
1334 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1335 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1336 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
1337 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); |
1338 |
pEngine->Volume(dVolume); |
pEngine->Volume(dVolume); |
1339 |
} |
} |
1340 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1351 |
LSCPResultSet result; |
LSCPResultSet result; |
1352 |
try { |
try { |
1353 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1354 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1355 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
1356 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); |
1357 |
pEngine->Reset(); |
pEngine->Reset(); |
1358 |
} |
} |
1359 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1398 |
return result.Produce(); |
return result.Produce(); |
1399 |
} |
} |
1400 |
|
|
1401 |
|
static int select_callback(void * lscpResultSet, int argc, |
1402 |
|
char **argv, char **azColName) |
1403 |
|
{ |
1404 |
|
LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet; |
1405 |
|
resultSet->Add(argc, argv); |
1406 |
|
return 0; |
1407 |
|
} |
1408 |
|
|
1409 |
|
String LSCPServer::QueryDatabase(String query) { |
1410 |
|
LSCPResultSet result; |
1411 |
|
#if HAVE_SQLITE3 |
1412 |
|
char* zErrMsg = NULL; |
1413 |
|
sqlite3 *db; |
1414 |
|
String selectStr = "SELECT " + query; |
1415 |
|
|
1416 |
|
int rc = sqlite3_open("linuxsampler.db", &db); |
1417 |
|
if (rc == SQLITE_OK) |
1418 |
|
{ |
1419 |
|
rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg); |
1420 |
|
} |
1421 |
|
if ( rc != SQLITE_OK ) |
1422 |
|
{ |
1423 |
|
result.Error(String(zErrMsg), rc); |
1424 |
|
} |
1425 |
|
sqlite3_close(db); |
1426 |
|
#else |
1427 |
|
result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0); |
1428 |
|
#endif |
1429 |
|
return result.Produce(); |
1430 |
|
} |
1431 |
|
|
1432 |
/** |
/** |
1433 |
* 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 |
1434 |
* mode is enabled, all commands from the client will (immediately) be |
* mode is enabled, all commands from the client will (immediately) be |
1447 |
} |
} |
1448 |
return result.Produce(); |
return result.Produce(); |
1449 |
} |
} |
|
|
|
|
// 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; |
|
|
} |
|