26 |
#include "lscpevent.h" |
#include "lscpevent.h" |
27 |
//#include "../common/global.h" |
//#include "../common/global.h" |
28 |
|
|
29 |
|
#include <fcntl.h> |
30 |
|
|
31 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
32 |
# include "sqlite3.h" |
# include "sqlite3.h" |
33 |
#endif |
#endif |
34 |
|
|
35 |
#include "../engines/gig/Engine.h" |
#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 |
|
|
454 |
try { |
try { |
455 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
456 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
457 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
458 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel yet"); |
459 |
if (!pSamplerChannel->GetAudioOutputDevice()) |
if (!pSamplerChannel->GetAudioOutputDevice()) |
460 |
throw LinuxSamplerException("No audio output device connected to sampler channel"); |
throw LinuxSamplerException("No audio output device connected to sampler channel"); |
461 |
if (bBackground) { |
if (bBackground) { |
462 |
InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngine); |
InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngineChannel); |
463 |
} |
} |
464 |
else { |
else { |
465 |
// tell the engine which instrument to load |
// tell the engine channel which instrument to load |
466 |
pEngine->PrepareLoadInstrument(Filename.c_str(), uiInstrument); |
pEngineChannel->PrepareLoadInstrument(Filename.c_str(), uiInstrument); |
467 |
// actually start to load the instrument (blocks until completed) |
// actually start to load the instrument (blocks until completed) |
468 |
pEngine->LoadInstrument(); |
pEngineChannel->LoadInstrument(); |
469 |
} |
} |
470 |
} |
} |
471 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
475 |
} |
} |
476 |
|
|
477 |
/** |
/** |
478 |
* 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 |
479 |
|
* sampler channel. |
480 |
*/ |
*/ |
481 |
String LSCPServer::LoadEngine(String EngineName, uint uiSamplerChannel) { |
String LSCPServer::SetEngineType(String EngineName, uint uiSamplerChannel) { |
482 |
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)); |
483 |
LSCPResultSet result; |
LSCPResultSet result; |
484 |
try { |
try { |
|
Engine::type_t type; |
|
|
if ((EngineName == "GigEngine") || (EngineName == "gig")) type = Engine::type_gig; |
|
|
else throw LinuxSamplerException("Unknown engine type"); |
|
485 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
486 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
487 |
LockRTNotify(); |
LockRTNotify(); |
488 |
pSamplerChannel->LoadEngine(type); |
pSamplerChannel->SetEngineType(EngineName); |
489 |
UnlockRTNotify(); |
UnlockRTNotify(); |
490 |
} |
} |
491 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
553 |
} |
} |
554 |
|
|
555 |
/** |
/** |
556 |
* 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 |
557 |
|
* sampler engine. |
558 |
*/ |
*/ |
559 |
String LSCPServer::GetEngineInfo(String EngineName) { |
String LSCPServer::GetEngineInfo(String EngineName) { |
560 |
dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str())); |
dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str())); |
561 |
LSCPResultSet result; |
LSCPResultSet result; |
562 |
try { |
try { |
563 |
if ((EngineName == "GigEngine") || (EngineName == "gig")) { |
Engine* pEngine = EngineFactory::Create(EngineName); |
564 |
Engine* pEngine = new LinuxSampler::gig::Engine; |
result.Add("DESCRIPTION", pEngine->Description()); |
565 |
result.Add("DESCRIPTION", pEngine->Description()); |
result.Add("VERSION", pEngine->Version()); |
566 |
result.Add("VERSION", pEngine->Version()); |
delete pEngine; |
|
delete pEngine; |
|
|
} |
|
|
else throw LinuxSamplerException("Unknown engine type"); |
|
567 |
} |
} |
568 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
569 |
result.Error(e); |
result.Error(e); |
581 |
try { |
try { |
582 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
583 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
584 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
585 |
|
|
586 |
//Defaults values |
//Defaults values |
587 |
String EngineName = "NONE"; |
String EngineName = "NONE"; |
593 |
int AudioOutputChannels = 0; |
int AudioOutputChannels = 0; |
594 |
String AudioRouting; |
String AudioRouting; |
595 |
|
|
596 |
if (pEngine) { |
if (pEngineChannel) { |
597 |
EngineName = pEngine->EngineName(); |
EngineName = pEngineChannel->GetEngine()->EngineName(); |
598 |
AudioOutputChannels = pEngine->Channels(); |
AudioOutputChannels = pEngineChannel->Channels(); |
599 |
Volume = pEngine->Volume(); |
Volume = pEngineChannel->Volume(); |
600 |
InstrumentStatus = pEngine->InstrumentStatus(); |
InstrumentStatus = pEngineChannel->InstrumentStatus(); |
601 |
InstrumentIndex = pEngine->InstrumentIndex(); |
InstrumentIndex = pEngineChannel->InstrumentIndex(); |
602 |
if (InstrumentIndex != -1) |
if (InstrumentIndex != -1) { |
603 |
{ |
InstrumentFileName = pEngineChannel->InstrumentFileName(); |
604 |
InstrumentFileName = pEngine->InstrumentFileName(); |
InstrumentName = pEngineChannel->InstrumentName(); |
605 |
InstrumentName = pEngine->InstrumentName(); |
} |
606 |
} |
for (int chan = 0; chan < pEngineChannel->Channels(); chan++) { |
|
for (int chan = 0; chan < pEngine->Channels(); chan++) { |
|
607 |
if (AudioRouting != "") AudioRouting += ","; |
if (AudioRouting != "") AudioRouting += ","; |
608 |
AudioRouting += ToString(pEngine->OutputChannel(chan)); |
AudioRouting += ToString(pEngineChannel->OutputChannel(chan)); |
609 |
} |
} |
610 |
} |
} |
611 |
|
|
643 |
try { |
try { |
644 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
645 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
646 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
647 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine loaded on sampler channel"); |
648 |
result.Add(pEngine->VoiceCount()); |
result.Add(pEngineChannel->GetEngine()->VoiceCount()); |
649 |
} |
} |
650 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
651 |
result.Error(e); |
result.Error(e); |
663 |
try { |
try { |
664 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
665 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
666 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
667 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
668 |
result.Add(pEngine->DiskStreamCount()); |
result.Add(pEngineChannel->GetEngine()->DiskStreamCount()); |
669 |
} |
} |
670 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
671 |
result.Error(e); |
result.Error(e); |
683 |
try { |
try { |
684 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
685 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
686 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
687 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
688 |
if (!pEngine->DiskStreamSupported()) |
if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA"); |
|
result.Add("NA"); |
|
689 |
else { |
else { |
690 |
switch (ResponseType) { |
switch (ResponseType) { |
691 |
case fill_response_bytes: |
case fill_response_bytes: |
692 |
result.Add(pEngine->DiskStreamBufferFillBytes()); |
result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillBytes()); |
693 |
break; |
break; |
694 |
case fill_response_percentage: |
case fill_response_percentage: |
695 |
result.Add(pEngine->DiskStreamBufferFillPercentage()); |
result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage()); |
696 |
break; |
break; |
697 |
default: |
default: |
698 |
throw LinuxSamplerException("Unknown fill response type"); |
throw LinuxSamplerException("Unknown fill response type"); |
699 |
} |
} |
1149 |
try { |
try { |
1150 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1151 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1152 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
1153 |
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)); |
1154 |
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)); |
1155 |
pEngine->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel); |
pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel); |
1156 |
} |
} |
1157 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1158 |
result.Error(e); |
result.Error(e); |
1329 |
try { |
try { |
1330 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1331 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1332 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
1333 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
1334 |
pEngine->Volume(dVolume); |
pEngineChannel->Volume(dVolume); |
1335 |
} |
} |
1336 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1337 |
result.Error(e); |
result.Error(e); |
1348 |
try { |
try { |
1349 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1350 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1351 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
1352 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
1353 |
pEngine->Reset(); |
pEngineChannel->GetEngine()->Reset(); |
1354 |
} |
} |
1355 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1356 |
result.Error(e); |
result.Error(e); |