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 |
|
|
60 |
Mutex LSCPServer::SubscriptionMutex = Mutex(); |
Mutex LSCPServer::SubscriptionMutex = Mutex(); |
61 |
Mutex LSCPServer::RTNotifyMutex = Mutex(); |
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_channel_count, "CHANNEL_COUNT"); |
66 |
LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT"); |
67 |
LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_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_channel_info, "CHANNEL_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 |
} |
} |
460 |
try { |
try { |
461 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
462 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
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 sampler 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 connected to sampler 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("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
493 |
LockRTNotify(); |
LockRTNotify(); |
494 |
pSamplerChannel->LoadEngine(type); |
pSamplerChannel->SetEngineType(EngineName); |
495 |
UnlockRTNotify(); |
UnlockRTNotify(); |
496 |
} |
} |
497 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
550 |
} |
} |
551 |
|
|
552 |
/** |
/** |
553 |
* 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. |
554 |
*/ |
*/ |
555 |
String LSCPServer::GetAvailableEngines() { |
String LSCPServer::GetAvailableEngines() { |
556 |
dmsg(2,("LSCPServer: GetAvailableEngines()\n")); |
dmsg(2,("LSCPServer: GetAvailableEngines()\n")); |
557 |
LSCPResultSet result("GigEngine"); |
LSCPResultSet result("1"); |
558 |
return result.Produce(); |
return result.Produce(); |
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 a list of all available engines. |
563 |
|
*/ |
564 |
|
String LSCPServer::ListAvailableEngines() { |
565 |
|
dmsg(2,("LSCPServer: ListAvailableEngines()\n")); |
566 |
|
LSCPResultSet result("\'GIG\'"); |
567 |
|
return result.Produce(); |
568 |
|
} |
569 |
|
|
570 |
|
/** |
571 |
|
* Will be called by the parser to get descriptions for a particular |
572 |
|
* sampler engine. |
573 |
*/ |
*/ |
574 |
String LSCPServer::GetEngineInfo(String EngineName) { |
String LSCPServer::GetEngineInfo(String EngineName) { |
575 |
dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str())); |
dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str())); |
576 |
LSCPResultSet result; |
LSCPResultSet result; |
577 |
try { |
try { |
578 |
if ((EngineName == "GigEngine") || (EngineName == "gig")) { |
Engine* pEngine = EngineFactory::Create(EngineName); |
579 |
Engine* pEngine = new LinuxSampler::gig::Engine; |
result.Add("DESCRIPTION", pEngine->Description()); |
580 |
result.Add("DESCRIPTION", pEngine->Description()); |
result.Add("VERSION", pEngine->Version()); |
581 |
result.Add("VERSION", pEngine->Version()); |
delete pEngine; |
|
delete pEngine; |
|
|
} |
|
|
else throw LinuxSamplerException("Unknown engine type"); |
|
582 |
} |
} |
583 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
584 |
result.Error(e); |
result.Error(e); |
596 |
try { |
try { |
597 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
598 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
599 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
600 |
|
|
601 |
//Defaults values |
//Defaults values |
602 |
String EngineName = "NONE"; |
String EngineName = "NONE"; |
608 |
int AudioOutputChannels = 0; |
int AudioOutputChannels = 0; |
609 |
String AudioRouting; |
String AudioRouting; |
610 |
|
|
611 |
if (pEngine) { |
if (pEngineChannel) { |
612 |
EngineName = pEngine->EngineName(); |
EngineName = pEngineChannel->EngineName(); |
613 |
AudioOutputChannels = pEngine->Channels(); |
AudioOutputChannels = pEngineChannel->Channels(); |
614 |
Volume = pEngine->Volume(); |
Volume = pEngineChannel->Volume(); |
615 |
InstrumentStatus = pEngine->InstrumentStatus(); |
InstrumentStatus = pEngineChannel->InstrumentStatus(); |
616 |
InstrumentIndex = pEngine->InstrumentIndex(); |
InstrumentIndex = pEngineChannel->InstrumentIndex(); |
617 |
if (InstrumentIndex != -1) |
if (InstrumentIndex != -1) { |
618 |
{ |
InstrumentFileName = pEngineChannel->InstrumentFileName(); |
619 |
InstrumentFileName = pEngine->InstrumentFileName(); |
InstrumentName = pEngineChannel->InstrumentName(); |
620 |
InstrumentName = pEngine->InstrumentName(); |
} |
621 |
} |
for (int chan = 0; chan < pEngineChannel->Channels(); chan++) { |
|
for (int chan = 0; chan < pEngine->Channels(); chan++) { |
|
622 |
if (AudioRouting != "") AudioRouting += ","; |
if (AudioRouting != "") AudioRouting += ","; |
623 |
AudioRouting += ToString(pEngine->OutputChannel(chan)); |
AudioRouting += ToString(pEngineChannel->OutputChannel(chan)); |
624 |
} |
} |
625 |
} |
} |
626 |
|
|
658 |
try { |
try { |
659 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
660 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
661 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
662 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine loaded on sampler channel"); |
663 |
result.Add(pEngine->VoiceCount()); |
result.Add(pEngineChannel->GetEngine()->VoiceCount()); |
664 |
} |
} |
665 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
666 |
result.Error(e); |
result.Error(e); |
678 |
try { |
try { |
679 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
680 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
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 sampler channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
683 |
result.Add(pEngine->DiskStreamCount()); |
result.Add(pEngineChannel->GetEngine()->DiskStreamCount()); |
684 |
} |
} |
685 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
686 |
result.Error(e); |
result.Error(e); |
698 |
try { |
try { |
699 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
700 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
701 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
702 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
703 |
if (!pEngine->DiskStreamSupported()) |
if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA"); |
|
result.Add("NA"); |
|
704 |
else { |
else { |
705 |
switch (ResponseType) { |
switch (ResponseType) { |
706 |
case fill_response_bytes: |
case fill_response_bytes: |
707 |
result.Add(pEngine->DiskStreamBufferFillBytes()); |
result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillBytes()); |
708 |
break; |
break; |
709 |
case fill_response_percentage: |
case fill_response_percentage: |
710 |
result.Add(pEngine->DiskStreamBufferFillPercentage()); |
result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage()); |
711 |
break; |
break; |
712 |
default: |
default: |
713 |
throw LinuxSamplerException("Unknown fill response type"); |
throw LinuxSamplerException("Unknown fill response type"); |
714 |
} |
} |
724 |
dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n")); |
dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n")); |
725 |
LSCPResultSet result; |
LSCPResultSet result; |
726 |
try { |
try { |
727 |
|
int n = AudioOutputDeviceFactory::AvailableDrivers().size(); |
728 |
|
result.Add(n); |
729 |
|
} |
730 |
|
catch (LinuxSamplerException e) { |
731 |
|
result.Error(e); |
732 |
|
} |
733 |
|
return result.Produce(); |
734 |
|
} |
735 |
|
|
736 |
|
String LSCPServer::ListAvailableAudioOutputDrivers() { |
737 |
|
dmsg(2,("LSCPServer: ListAvailableAudioOutputDrivers()\n")); |
738 |
|
LSCPResultSet result; |
739 |
|
try { |
740 |
String s = AudioOutputDeviceFactory::AvailableDriversAsString(); |
String s = AudioOutputDeviceFactory::AvailableDriversAsString(); |
741 |
result.Add(s); |
result.Add(s); |
742 |
} |
} |
750 |
dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n")); |
dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n")); |
751 |
LSCPResultSet result; |
LSCPResultSet result; |
752 |
try { |
try { |
753 |
|
int n = MidiInputDeviceFactory::AvailableDrivers().size(); |
754 |
|
result.Add(n); |
755 |
|
} |
756 |
|
catch (LinuxSamplerException e) { |
757 |
|
result.Error(e); |
758 |
|
} |
759 |
|
return result.Produce(); |
760 |
|
} |
761 |
|
|
762 |
|
String LSCPServer::ListAvailableMidiInputDrivers() { |
763 |
|
dmsg(2,("LSCPServer: ListAvailableMidiInputDrivers()\n")); |
764 |
|
LSCPResultSet result; |
765 |
|
try { |
766 |
String s = MidiInputDeviceFactory::AvailableDriversAsString(); |
String s = MidiInputDeviceFactory::AvailableDriversAsString(); |
767 |
result.Add(s); |
result.Add(s); |
768 |
} |
} |
1190 |
try { |
try { |
1191 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1192 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1193 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
1194 |
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)); |
1195 |
if (!pSamplerChannel->GetAudioOutputDevice()) throw LinuxSamplerException("No audio output device connected to sampler channel " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel->GetAudioOutputDevice()) throw LinuxSamplerException("No audio output device connected to sampler channel " + ToString(uiSamplerChannel)); |
1196 |
pEngine->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel); |
pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel); |
1197 |
} |
} |
1198 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1199 |
result.Error(e); |
result.Error(e); |
1370 |
try { |
try { |
1371 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1372 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1373 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
1374 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
1375 |
pEngine->Volume(dVolume); |
pEngineChannel->Volume(dVolume); |
1376 |
} |
} |
1377 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1378 |
result.Error(e); |
result.Error(e); |
1389 |
try { |
try { |
1390 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1391 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1392 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
1393 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
1394 |
pEngine->Reset(); |
pEngineChannel->GetEngine()->Reset(); |
1395 |
} |
} |
1396 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1397 |
result.Error(e); |
result.Error(e); |
1435 |
return result.Produce(); |
return result.Produce(); |
1436 |
} |
} |
1437 |
|
|
1438 |
|
static int select_callback(void * lscpResultSet, int argc, |
1439 |
|
char **argv, char **azColName) |
1440 |
|
{ |
1441 |
|
LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet; |
1442 |
|
resultSet->Add(argc, argv); |
1443 |
|
return 0; |
1444 |
|
} |
1445 |
|
|
1446 |
|
String LSCPServer::QueryDatabase(String query) { |
1447 |
|
LSCPResultSet result; |
1448 |
|
#if HAVE_SQLITE3 |
1449 |
|
char* zErrMsg = NULL; |
1450 |
|
sqlite3 *db; |
1451 |
|
String selectStr = "SELECT " + query; |
1452 |
|
|
1453 |
|
int rc = sqlite3_open("linuxsampler.db", &db); |
1454 |
|
if (rc == SQLITE_OK) |
1455 |
|
{ |
1456 |
|
rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg); |
1457 |
|
} |
1458 |
|
if ( rc != SQLITE_OK ) |
1459 |
|
{ |
1460 |
|
result.Error(String(zErrMsg), rc); |
1461 |
|
} |
1462 |
|
sqlite3_close(db); |
1463 |
|
#else |
1464 |
|
result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0); |
1465 |
|
#endif |
1466 |
|
return result.Produce(); |
1467 |
|
} |
1468 |
|
|
1469 |
/** |
/** |
1470 |
* 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 |
1471 |
* mode is enabled, all commands from the client will (immediately) be |
* mode is enabled, all commands from the client will (immediately) be |
1484 |
} |
} |
1485 |
return result.Produce(); |
return result.Produce(); |
1486 |
} |
} |
|
|
|
|
// 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; |
|
|
} |
|