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"); |
97 |
SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY); |
SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY); |
98 |
|
|
99 |
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
100 |
std::cerr << "LSCPServer: Could not bind server socket." << std::endl; |
std::cerr << "LSCPServer: Could not bind server socket, retrying for " << ToString(LSCP_SERVER_BIND_TIMEOUT) << " seconds..."; |
101 |
close(hSocket); |
for (int trial = 0; true; trial++) { // retry for LSCP_SERVER_BIND_TIMEOUT seconds |
102 |
//return -1; |
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
103 |
exit(EXIT_FAILURE); |
if (trial > LSCP_SERVER_BIND_TIMEOUT) { |
104 |
|
std::cerr << "gave up!" << std::endl; |
105 |
|
close(hSocket); |
106 |
|
//return -1; |
107 |
|
exit(EXIT_FAILURE); |
108 |
|
} |
109 |
|
else sleep(1); // sleep 1s |
110 |
|
} |
111 |
|
else break; // success |
112 |
|
} |
113 |
} |
} |
114 |
|
|
115 |
listen(hSocket, 1); |
listen(hSocket, 1); |
212 |
NotifyMutex.Unlock(); |
NotifyMutex.Unlock(); |
213 |
} |
} |
214 |
|
|
215 |
|
int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) { |
216 |
|
int subs = 0; |
217 |
|
SubscriptionMutex.Lock(); |
218 |
|
for( std::list<LSCPEvent::event_t>::iterator iter = events.begin(); |
219 |
|
iter != events.end(); iter++) |
220 |
|
{ |
221 |
|
subs += eventSubscriptions.count(*iter); |
222 |
|
} |
223 |
|
SubscriptionMutex.Unlock(); |
224 |
|
return subs; |
225 |
|
} |
226 |
|
|
227 |
void LSCPServer::SendLSCPNotify( LSCPEvent event ) { |
void LSCPServer::SendLSCPNotify( LSCPEvent event ) { |
228 |
SubscriptionMutex.Lock(); |
SubscriptionMutex.Lock(); |
229 |
if (eventSubscriptions.count(event.GetType()) == 0) { |
if (eventSubscriptions.count(event.GetType()) == 0) { |
420 |
LSCPResultSet result; |
LSCPResultSet result; |
421 |
try { |
try { |
422 |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
423 |
if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
424 |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
425 |
pSampler->DestroyAudioOutputDevice(pDevice); |
pSampler->DestroyAudioOutputDevice(pDevice); |
426 |
} |
} |
435 |
LSCPResultSet result; |
LSCPResultSet result; |
436 |
try { |
try { |
437 |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
438 |
|
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
439 |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
|
if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
|
440 |
pSampler->DestroyMidiInputDevice(pDevice); |
pSampler->DestroyMidiInputDevice(pDevice); |
441 |
} |
} |
442 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
453 |
LSCPResultSet result; |
LSCPResultSet result; |
454 |
try { |
try { |
455 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
456 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
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 channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel yet"); |
459 |
if (pSamplerChannel->GetAudioOutputDevice() == NULL) |
if (!pSamplerChannel->GetAudioOutputDevice()) |
460 |
throw LinuxSamplerException("No audio output device on channel"); |
throw LinuxSamplerException("No audio output device connected to sampler channel"); |
461 |
if (bBackground) { |
if (bBackground) { |
462 |
LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument); |
InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngineChannel); |
463 |
pLoadInstrument->StartThread(); |
} |
464 |
|
else { |
465 |
|
// tell the engine channel which instrument to load |
466 |
|
pEngineChannel->PrepareLoadInstrument(Filename.c_str(), uiInstrument); |
467 |
|
// actually start to load the instrument (blocks until completed) |
468 |
|
pEngineChannel->LoadInstrument(); |
469 |
} |
} |
|
else pEngine->LoadInstrument(Filename.c_str(), uiInstrument); |
|
470 |
} |
} |
471 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
472 |
result.Error(e); |
result.Error(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("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
487 |
pSamplerChannel->LoadEngine(type); |
LockRTNotify(); |
488 |
|
pSamplerChannel->SetEngineType(EngineName); |
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 |
|
|
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(pEngine->Description()); |
result.Add("VERSION", pEngine->Version()); |
566 |
result.Add(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); |
580 |
LSCPResultSet result; |
LSCPResultSet result; |
581 |
try { |
try { |
582 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
583 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
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"; |
588 |
float Volume = 0; |
float Volume = 0.0f; |
589 |
String InstrumentFileName = "NONE"; |
String InstrumentFileName = "NONE"; |
590 |
|
String InstrumentName = "NONE"; |
591 |
int InstrumentIndex = -1; |
int InstrumentIndex = -1; |
592 |
int InstrumentStatus = -1; |
int InstrumentStatus = -1; |
593 |
|
int AudioOutputChannels = 0; |
594 |
|
String AudioRouting; |
595 |
|
|
596 |
if (pEngine) { |
if (pEngineChannel) { |
597 |
EngineName = pEngine->EngineName(); |
EngineName = pEngineChannel->GetEngine()->EngineName(); |
598 |
Volume = pEngine->Volume(); |
AudioOutputChannels = pEngineChannel->Channels(); |
599 |
InstrumentStatus = pEngine->InstrumentStatus(); |
Volume = pEngineChannel->Volume(); |
600 |
InstrumentIndex = pEngine->InstrumentIndex(); |
InstrumentStatus = pEngineChannel->InstrumentStatus(); |
601 |
if (InstrumentIndex != -1) |
InstrumentIndex = pEngineChannel->InstrumentIndex(); |
602 |
InstrumentFileName = pEngine->InstrumentFileName(); |
if (InstrumentIndex != -1) { |
603 |
|
InstrumentFileName = pEngineChannel->InstrumentFileName(); |
604 |
|
InstrumentName = pEngineChannel->InstrumentName(); |
605 |
|
} |
606 |
|
for (int chan = 0; chan < pEngineChannel->Channels(); chan++) { |
607 |
|
if (AudioRouting != "") AudioRouting += ","; |
608 |
|
AudioRouting += ToString(pEngineChannel->OutputChannel(chan)); |
609 |
|
} |
610 |
} |
} |
611 |
|
|
612 |
result.Add("ENGINE_NAME", EngineName); |
result.Add("ENGINE_NAME", EngineName); |
614 |
|
|
615 |
//Some not-so-hardcoded stuff to make GUI look good |
//Some not-so-hardcoded stuff to make GUI look good |
616 |
result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice())); |
result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice())); |
617 |
result.Add("AUDIO_OUTPUT_CHANNELS", "2"); |
result.Add("AUDIO_OUTPUT_CHANNELS", AudioOutputChannels); |
618 |
result.Add("AUDIO_OUTPUT_ROUTING", "0,1"); |
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
619 |
|
|
620 |
result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice())); |
result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice())); |
621 |
result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort()); |
result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort()); |
622 |
result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); |
if (pSamplerChannel->GetMidiInputChannel() == MidiInputPort::midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL"); |
623 |
|
else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); |
624 |
|
|
625 |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
626 |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
627 |
|
result.Add("INSTRUMENT_NAME", InstrumentName); |
628 |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
629 |
} |
} |
630 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
642 |
LSCPResultSet result; |
LSCPResultSet result; |
643 |
try { |
try { |
644 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
645 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
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 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); |
662 |
LSCPResultSet result; |
LSCPResultSet result; |
663 |
try { |
try { |
664 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
665 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
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 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); |
682 |
LSCPResultSet result; |
LSCPResultSet result; |
683 |
try { |
try { |
684 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
685 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
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 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 |
} |
} |
780 |
} |
} |
781 |
|
|
782 |
String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) { |
String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) { |
783 |
dmsg(2,("LSCPServer: GetMidiInputDriverParameterInfo(Driver=%s,Parameter=%s)\n",Driver.c_str(),Parameter.c_str())); |
dmsg(2,("LSCPServer: GetMidiInputDriverParameterInfo(Driver=%s,Parameter=%s,DependencyListSize=%d)\n",Driver.c_str(),Parameter.c_str(),DependencyList.size())); |
784 |
LSCPResultSet result; |
LSCPResultSet result; |
785 |
try { |
try { |
786 |
DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter); |
DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter); |
787 |
result.Add("TYPE", pParameter->Type()); |
result.Add("TYPE", pParameter->Type()); |
788 |
result.Add("DESCRIPTION", pParameter->Description()); |
result.Add("DESCRIPTION", pParameter->Description()); |
789 |
result.Add("MANDATORY", (pParameter->Mandatory()) ? "true" : "false"); |
result.Add("MANDATORY", pParameter->Mandatory()); |
790 |
result.Add("FIX", (pParameter->Fix()) ? "true" : "false"); |
result.Add("FIX", pParameter->Fix()); |
791 |
result.Add("MULTIPLICITY", (pParameter->Multiplicity()) ? "true" : "false"); |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
792 |
if (pParameter->Depends()) result.Add("DEPENDS", *pParameter->Depends()); |
optional<String> oDepends = pParameter->Depends(); |
793 |
if (pParameter->Default()) result.Add("DEFAULT", *pParameter->Default()); |
optional<String> oDefault = pParameter->Default(DependencyList); |
794 |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", *pParameter->RangeMin()); |
optional<String> oRangeMin = pParameter->RangeMin(DependencyList); |
795 |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", *pParameter->RangeMax()); |
optional<String> oRangeMax = pParameter->RangeMax(DependencyList); |
796 |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities()); |
optional<String> oPossibilities = pParameter->Possibilities(DependencyList); |
797 |
|
if (oDepends) result.Add("DEPENDS", *oDepends); |
798 |
|
if (oDefault) result.Add("DEFAULT", *oDefault); |
799 |
|
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
800 |
|
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
801 |
|
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
802 |
} |
} |
803 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
804 |
result.Error(e); |
result.Error(e); |
807 |
} |
} |
808 |
|
|
809 |
String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) { |
String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) { |
810 |
dmsg(2,("LSCPServer: GetAudioOutputDriverParameterInfo(Driver=%s,Parameter=%s)\n",Driver.c_str(),Parameter.c_str())); |
dmsg(2,("LSCPServer: GetAudioOutputDriverParameterInfo(Driver=%s,Parameter=%s,DependencyListSize=%d)\n",Driver.c_str(),Parameter.c_str(),DependencyList.size())); |
811 |
LSCPResultSet result; |
LSCPResultSet result; |
812 |
try { |
try { |
813 |
DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter); |
DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter); |
814 |
result.Add("TYPE", pParameter->Type()); |
result.Add("TYPE", pParameter->Type()); |
815 |
result.Add("DESCRIPTION", pParameter->Description()); |
result.Add("DESCRIPTION", pParameter->Description()); |
816 |
result.Add("MANDATORY", (pParameter->Mandatory()) ? "true" : "false"); |
result.Add("MANDATORY", pParameter->Mandatory()); |
817 |
result.Add("FIX", (pParameter->Fix()) ? "true" : "false"); |
result.Add("FIX", pParameter->Fix()); |
818 |
result.Add("MULTIPLICITY", (pParameter->Multiplicity()) ? "true" : "false"); |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
819 |
if (pParameter->Depends()) result.Add("DEPENDS", *pParameter->Depends()); |
optional<String> oDepends = pParameter->Depends(); |
820 |
if (pParameter->Default()) result.Add("DEFAULT", *pParameter->Default()); |
optional<String> oDefault = pParameter->Default(DependencyList); |
821 |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", *pParameter->RangeMin()); |
optional<String> oRangeMin = pParameter->RangeMin(DependencyList); |
822 |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", *pParameter->RangeMax()); |
optional<String> oRangeMax = pParameter->RangeMax(DependencyList); |
823 |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities()); |
optional<String> oPossibilities = pParameter->Possibilities(DependencyList); |
824 |
|
if (oDepends) result.Add("DEPENDS", *oDepends); |
825 |
|
if (oDefault) result.Add("DEFAULT", *oDefault); |
826 |
|
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
827 |
|
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
828 |
|
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
829 |
} |
} |
830 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
831 |
result.Error(e); |
result.Error(e); |
902 |
LSCPResultSet result; |
LSCPResultSet result; |
903 |
try { |
try { |
904 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
905 |
if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
906 |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
907 |
result.Add("driver", pDevice->Driver()); |
result.Add("DRIVER", pDevice->Driver()); |
908 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
909 |
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
910 |
for (; iter != parameters.end(); iter++) { |
for (; iter != parameters.end(); iter++) { |
922 |
LSCPResultSet result; |
LSCPResultSet result; |
923 |
try { |
try { |
924 |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
925 |
|
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
926 |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
927 |
if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
result.Add("DRIVER", pDevice->Driver()); |
|
result.Add("driver", pDevice->Driver()); |
|
928 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
929 |
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
930 |
for (; iter != parameters.end(); iter++) { |
for (; iter != parameters.end(); iter++) { |
940 |
dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex)); |
dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex)); |
941 |
LSCPResultSet result; |
LSCPResultSet result; |
942 |
try { |
try { |
943 |
|
// get MIDI input device |
944 |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
945 |
|
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
946 |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
947 |
if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
|
948 |
MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); |
// get MIDI port |
949 |
if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); |
MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); |
950 |
std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters(); |
if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); |
951 |
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
|
952 |
|
// return the values of all MIDI port parameters |
953 |
|
std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters(); |
954 |
|
std::map<String,DeviceRuntimeParameter*>::iterator iter = parameters.begin(); |
955 |
for (; iter != parameters.end(); iter++) { |
for (; iter != parameters.end(); iter++) { |
956 |
result.Add(iter->first, iter->second->Value()); |
result.Add(iter->first, iter->second->Value()); |
957 |
} |
} |
968 |
try { |
try { |
969 |
// get audio output device |
// get audio output device |
970 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
971 |
if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + "."); |
if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + "."); |
972 |
AudioOutputDevice* pDevice = devices[DeviceId]; |
AudioOutputDevice* pDevice = devices[DeviceId]; |
973 |
|
|
974 |
// get audio channel |
// get audio channel |
975 |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
976 |
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) + "."); |
977 |
|
|
978 |
// return the values of all audio channel parameters |
// return the values of all audio channel parameters |
979 |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
992 |
dmsg(2,("LSCPServer: GetMidiInputPortParameterInfo(DeviceId=%d,PortId=%d,ParameterName=%s)\n",DeviceId,PortId,ParameterName.c_str())); |
dmsg(2,("LSCPServer: GetMidiInputPortParameterInfo(DeviceId=%d,PortId=%d,ParameterName=%s)\n",DeviceId,PortId,ParameterName.c_str())); |
993 |
LSCPResultSet result; |
LSCPResultSet result; |
994 |
try { |
try { |
995 |
// get audio output device |
// get MIDI input device |
996 |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
997 |
if (!devices[DeviceId]) throw LinuxSamplerException("There is no midi input device with index " + ToString(DeviceId) + "."); |
if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no midi input device with index " + ToString(DeviceId) + "."); |
998 |
MidiInputDevice* pDevice = devices[DeviceId]; |
MidiInputDevice* pDevice = devices[DeviceId]; |
999 |
|
|
1000 |
// get midi port |
// get midi port |
1001 |
MidiInputDevice::MidiInputPort* pPort = pDevice->GetPort(PortId); |
MidiInputPort* pPort = pDevice->GetPort(PortId); |
1002 |
if (!pPort) throw LinuxSamplerException("Midi input device does not have port " + ToString(PortId) + "."); |
if (!pPort) throw LinuxSamplerException("Midi input device does not have port " + ToString(PortId) + "."); |
1003 |
|
|
1004 |
// get desired port parameter |
// get desired port parameter |
1005 |
std::map<String,DeviceCreationParameter*> parameters = pPort->DeviceParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pPort->PortParameters(); |
1006 |
if (!parameters[ParameterName]) throw LinuxSamplerException("Midi port does not provice a parameters '" + ParameterName + "'."); |
if (!parameters.count(ParameterName)) throw LinuxSamplerException("Midi port does not provide a parameter '" + ParameterName + "'."); |
1007 |
DeviceCreationParameter* pParameter = parameters[ParameterName]; |
DeviceRuntimeParameter* pParameter = parameters[ParameterName]; |
1008 |
|
|
1009 |
// return all fields of this audio channel parameter |
// return all fields of this audio channel parameter |
1010 |
result.Add("TYPE", pParameter->Type()); |
result.Add("TYPE", pParameter->Type()); |
1011 |
result.Add("DESCRIPTION", pParameter->Description()); |
result.Add("DESCRIPTION", pParameter->Description()); |
1012 |
result.Add("FIX", pParameter->Fix()); |
result.Add("FIX", pParameter->Fix()); |
1013 |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
1014 |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", pParameter->RangeMin()); |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", *pParameter->RangeMin()); |
1015 |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", pParameter->RangeMax()); |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", *pParameter->RangeMax()); |
1016 |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities()); |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities()); |
1017 |
} |
} |
1018 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1019 |
result.Error(e); |
result.Error(e); |
1027 |
try { |
try { |
1028 |
// get audio output device |
// get audio output device |
1029 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1030 |
if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + "."); |
if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + "."); |
1031 |
AudioOutputDevice* pDevice = devices[DeviceId]; |
AudioOutputDevice* pDevice = devices[DeviceId]; |
1032 |
|
|
1033 |
// get audio channel |
// get audio channel |
1034 |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
1035 |
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) + "."); |
1036 |
|
|
1037 |
// get desired audio channel parameter |
// get desired audio channel parameter |
1038 |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
1039 |
if (!parameters[ParameterName]) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParameterName + "'."); |
if (!parameters.count(ParameterName)) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParameterName + "'."); |
1040 |
DeviceRuntimeParameter* pParameter = parameters[ParameterName]; |
DeviceRuntimeParameter* pParameter = parameters[ParameterName]; |
1041 |
|
|
1042 |
// return all fields of this audio channel parameter |
// return all fields of this audio channel parameter |
1044 |
result.Add("DESCRIPTION", pParameter->Description()); |
result.Add("DESCRIPTION", pParameter->Description()); |
1045 |
result.Add("FIX", pParameter->Fix()); |
result.Add("FIX", pParameter->Fix()); |
1046 |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
1047 |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", pParameter->RangeMin()); |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", *pParameter->RangeMin()); |
1048 |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", pParameter->RangeMax()); |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", *pParameter->RangeMax()); |
1049 |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities()); |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities()); |
1050 |
} |
} |
1051 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1052 |
result.Error(e); |
result.Error(e); |
1060 |
try { |
try { |
1061 |
// get audio output device |
// get audio output device |
1062 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1063 |
if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + "."); |
if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + "."); |
1064 |
AudioOutputDevice* pDevice = devices[DeviceId]; |
AudioOutputDevice* pDevice = devices[DeviceId]; |
1065 |
|
|
1066 |
// get audio channel |
// get audio channel |
1067 |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
1068 |
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) + "."); |
1069 |
|
|
1070 |
// get desired audio channel parameter |
// get desired audio channel parameter |
1071 |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
1072 |
if (!parameters[ParamKey]) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParamKey + "'."); |
if (!parameters.count(ParamKey)) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParamKey + "'."); |
1073 |
DeviceRuntimeParameter* pParameter = parameters[ParamKey]; |
DeviceRuntimeParameter* pParameter = parameters[ParamKey]; |
1074 |
|
|
1075 |
// set new channel parameter value |
// set new channel parameter value |
1086 |
LSCPResultSet result; |
LSCPResultSet result; |
1087 |
try { |
try { |
1088 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1089 |
if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
1090 |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
1091 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
1092 |
if (!parameters[ParamKey]) throw LinuxSamplerException("Audio output device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'"); |
if (!parameters.count(ParamKey)) throw LinuxSamplerException("Audio output device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'"); |
1093 |
parameters[ParamKey]->SetValue(ParamVal); |
parameters[ParamKey]->SetValue(ParamVal); |
1094 |
} |
} |
1095 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1103 |
LSCPResultSet result; |
LSCPResultSet result; |
1104 |
try { |
try { |
1105 |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1106 |
if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
1107 |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
1108 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
1109 |
if (!parameters[ParamKey]) throw LinuxSamplerException("MIDI input device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'"); |
if (!parameters.count(ParamKey)) throw LinuxSamplerException("MIDI input device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'"); |
1110 |
parameters[ParamKey]->SetValue(ParamVal); |
parameters[ParamKey]->SetValue(ParamVal); |
1111 |
} |
} |
1112 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1119 |
dmsg(2,("LSCPServer: SetMidiOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str())); |
dmsg(2,("LSCPServer: SetMidiOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str())); |
1120 |
LSCPResultSet result; |
LSCPResultSet result; |
1121 |
try { |
try { |
1122 |
|
// get MIDI input device |
1123 |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1124 |
|
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
1125 |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
1126 |
if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
|
1127 |
MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); |
// get MIDI port |
1128 |
if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); |
MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); |
1129 |
std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters(); |
if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); |
1130 |
if (!parameters[ParamKey]) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'"); |
|
1131 |
|
// set port parameter value |
1132 |
|
std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters(); |
1133 |
|
if (!parameters.count(ParamKey)) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'"); |
1134 |
parameters[ParamKey]->SetValue(ParamVal); |
parameters[ParamKey]->SetValue(ParamVal); |
1135 |
} |
} |
1136 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1145 |
*/ |
*/ |
1146 |
String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) { |
String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) { |
1147 |
dmsg(2,("LSCPServer: SetAudioOutputChannel(ChannelAudioOutputChannel=%d, AudioOutputDeviceInputChannel=%d, SamplerChannel=%d)\n",ChannelAudioOutputChannel,AudioOutputDeviceInputChannel,uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetAudioOutputChannel(ChannelAudioOutputChannel=%d, AudioOutputDeviceInputChannel=%d, SamplerChannel=%d)\n",ChannelAudioOutputChannel,AudioOutputDeviceInputChannel,uiSamplerChannel)); |
1148 |
return "ERR:0:Not implemented yet.\r\n"; //FIXME: Add support for this in resultset class? |
LSCPResultSet result; |
1149 |
|
try { |
1150 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1151 |
|
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1152 |
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
1153 |
|
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)); |
1155 |
|
pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel); |
1156 |
|
} |
1157 |
|
catch (LinuxSamplerException e) { |
1158 |
|
result.Error(e); |
1159 |
|
} |
1160 |
|
return result.Produce(); |
1161 |
} |
} |
1162 |
|
|
1163 |
String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) { |
String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) { |
1165 |
LSCPResultSet result; |
LSCPResultSet result; |
1166 |
try { |
try { |
1167 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1168 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1169 |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1170 |
|
if (!devices.count(AudioDeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId)); |
1171 |
AudioOutputDevice* pDevice = devices[AudioDeviceId]; |
AudioOutputDevice* pDevice = devices[AudioDeviceId]; |
|
if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId)); |
|
1172 |
pSamplerChannel->SetAudioOutputDevice(pDevice); |
pSamplerChannel->SetAudioOutputDevice(pDevice); |
1173 |
} |
} |
1174 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1182 |
LSCPResultSet result; |
LSCPResultSet result; |
1183 |
try { |
try { |
1184 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1185 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1186 |
// Driver type name aliasing... |
// Driver type name aliasing... |
1187 |
if (AudioOutputDriver == "ALSA") AudioOutputDriver = "Alsa"; |
if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA"; |
1188 |
if (AudioOutputDriver == "JACK") AudioOutputDriver = "Jack"; |
if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK"; |
1189 |
// Check if there's one audio output device already created |
// Check if there's one audio output device already created |
1190 |
// for the intended audio driver type (AudioOutputDriver)... |
// for the intended audio driver type (AudioOutputDriver)... |
1191 |
AudioOutputDevice *pDevice = NULL; |
AudioOutputDevice *pDevice = NULL; |
1219 |
LSCPResultSet result; |
LSCPResultSet result; |
1220 |
try { |
try { |
1221 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1222 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1223 |
pSamplerChannel->SetMidiInputPort(MIDIPort); |
pSamplerChannel->SetMidiInputPort(MIDIPort); |
1224 |
} |
} |
1225 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1233 |
LSCPResultSet result; |
LSCPResultSet result; |
1234 |
try { |
try { |
1235 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1236 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1237 |
pSamplerChannel->SetMidiInputChannel((MidiInputDevice::MidiInputPort::midi_chan_t) MIDIChannel); |
pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel); |
1238 |
} |
} |
1239 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1240 |
result.Error(e); |
result.Error(e); |
1247 |
LSCPResultSet result; |
LSCPResultSet result; |
1248 |
try { |
try { |
1249 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1250 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1251 |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1252 |
|
if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
1253 |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
|
if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
|
1254 |
pSamplerChannel->SetMidiInputDevice(pDevice); |
pSamplerChannel->SetMidiInputDevice(pDevice); |
1255 |
} |
} |
1256 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1264 |
LSCPResultSet result; |
LSCPResultSet result; |
1265 |
try { |
try { |
1266 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1267 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1268 |
// Driver type name aliasing... |
// Driver type name aliasing... |
1269 |
if (MidiInputDriver == "ALSA") MidiInputDriver = "Alsa"; |
if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA"; |
1270 |
// Check if there's one MIDI input device already created |
// Check if there's one MIDI input device already created |
1271 |
// for the intended MIDI driver type (MidiInputDriver)... |
// for the intended MIDI driver type (MidiInputDriver)... |
1272 |
MidiInputDevice *pDevice = NULL; |
MidiInputDevice *pDevice = NULL; |
1284 |
pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params); |
pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params); |
1285 |
// Make it with at least one initial port. |
// Make it with at least one initial port. |
1286 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
1287 |
parameters["ports"]->SetValue("1"); |
parameters["PORTS"]->SetValue("1"); |
1288 |
} |
} |
1289 |
// Must have a device... |
// Must have a device... |
1290 |
if (pDevice == NULL) |
if (pDevice == NULL) |
1307 |
LSCPResultSet result; |
LSCPResultSet result; |
1308 |
try { |
try { |
1309 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1310 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1311 |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1312 |
|
if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
1313 |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
1314 |
if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (MidiInputPort::midi_chan_t) MIDIChannel); |
|
pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (MidiInputDevice::MidiInputPort::midi_chan_t) MIDIChannel); |
|
1315 |
} |
} |
1316 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1317 |
result.Error(e); |
result.Error(e); |
1323 |
* Will be called by the parser to change the global volume factor on a |
* Will be called by the parser to change the global volume factor on a |
1324 |
* particular sampler channel. |
* particular sampler channel. |
1325 |
*/ |
*/ |
1326 |
String LSCPServer::SetVolume(double Volume, uint uiSamplerChannel) { |
String LSCPServer::SetVolume(double dVolume, uint uiSamplerChannel) { |
1327 |
dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel)); |
1328 |
LSCPResultSet result; |
LSCPResultSet result; |
1329 |
try { |
try { |
1330 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1331 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
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 channel"); |
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
1334 |
pEngine->Volume(Volume); |
pEngineChannel->Volume(dVolume); |
1335 |
} |
} |
1336 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1337 |
result.Error(e); |
result.Error(e); |
1347 |
LSCPResultSet result; |
LSCPResultSet result; |
1348 |
try { |
try { |
1349 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1350 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
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 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); |
1394 |
return result.Produce(); |
return result.Produce(); |
1395 |
} |
} |
1396 |
|
|
1397 |
|
static int select_callback(void * lscpResultSet, int argc, |
1398 |
|
char **argv, char **azColName) |
1399 |
|
{ |
1400 |
|
LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet; |
1401 |
|
resultSet->Add(argc, argv); |
1402 |
|
return 0; |
1403 |
|
} |
1404 |
|
|
1405 |
|
String LSCPServer::QueryDatabase(String query) { |
1406 |
|
LSCPResultSet result; |
1407 |
|
#if HAVE_SQLITE3 |
1408 |
|
char* zErrMsg = NULL; |
1409 |
|
sqlite3 *db; |
1410 |
|
String selectStr = "SELECT " + query; |
1411 |
|
|
1412 |
|
int rc = sqlite3_open("linuxsampler.db", &db); |
1413 |
|
if (rc == SQLITE_OK) |
1414 |
|
{ |
1415 |
|
rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg); |
1416 |
|
} |
1417 |
|
if ( rc != SQLITE_OK ) |
1418 |
|
{ |
1419 |
|
result.Error(String(zErrMsg), rc); |
1420 |
|
} |
1421 |
|
sqlite3_close(db); |
1422 |
|
#else |
1423 |
|
result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0); |
1424 |
|
#endif |
1425 |
|
return result.Produce(); |
1426 |
|
} |
1427 |
|
|
1428 |
/** |
/** |
1429 |
* 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 |
1430 |
* mode is enabled, all commands from the client will (immediately) be |
* mode is enabled, all commands from the client will (immediately) be |
1443 |
} |
} |
1444 |
return result.Produce(); |
return result.Produce(); |
1445 |
} |
} |
|
|
|
|
// 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; |
|
|
} |
|