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 |
***************************************************************************/ |
***************************************************************************/ |
51 |
Mutex LSCPServer::NotifyMutex = Mutex(); |
Mutex LSCPServer::NotifyMutex = Mutex(); |
52 |
Mutex LSCPServer::NotifyBufferMutex = Mutex(); |
Mutex LSCPServer::NotifyBufferMutex = Mutex(); |
53 |
Mutex LSCPServer::SubscriptionMutex = Mutex(); |
Mutex LSCPServer::SubscriptionMutex = Mutex(); |
54 |
|
Mutex LSCPServer::RTNotifyMutex = Mutex(); |
55 |
|
|
56 |
LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) { |
LSCPServer::LSCPServer(Sampler* pSampler) : Thread(true, false, 0, -4) { |
57 |
this->pSampler = pSampler; |
this->pSampler = pSampler; |
58 |
LSCPEvent::RegisterEvent(LSCPEvent::event_channels, "CHANNELS"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_channels, "CHANNELS"); |
59 |
LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT"); |
90 |
SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY); |
SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY); |
91 |
|
|
92 |
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
93 |
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..."; |
94 |
close(hSocket); |
for (int trial = 0; true; trial++) { // retry for LSCP_SERVER_BIND_TIMEOUT seconds |
95 |
//return -1; |
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
96 |
exit(EXIT_FAILURE); |
if (trial > LSCP_SERVER_BIND_TIMEOUT) { |
97 |
|
std::cerr << "gave up!" << std::endl; |
98 |
|
close(hSocket); |
99 |
|
//return -1; |
100 |
|
exit(EXIT_FAILURE); |
101 |
|
} |
102 |
|
else sleep(1); // sleep 1s |
103 |
|
} |
104 |
|
else break; // success |
105 |
|
} |
106 |
} |
} |
107 |
|
|
108 |
listen(hSocket, 1); |
listen(hSocket, 1); |
158 |
if (FD_ISSET((*iter).hSession, &selectSet)) { //Was it this socket? |
if (FD_ISSET((*iter).hSession, &selectSet)) { //Was it this socket? |
159 |
if (GetLSCPCommand(iter)) { //Have we read the entire command? |
if (GetLSCPCommand(iter)) { //Have we read the entire command? |
160 |
dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket)); |
dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket)); |
161 |
yylex_init(&((*iter).pScanner)); //FIXME: should me moved out of this loop and initialized only when a new session is created |
int dummy; // just a temporary hack to fulfill the restart() function prototype |
162 |
|
restart(NULL, dummy); // restart the 'scanner' |
163 |
currentSocket = (*iter).hSession; //a hack |
currentSocket = (*iter).hSession; //a hack |
164 |
if ((*iter).bVerbose) { // if echo mode enabled |
if ((*iter).bVerbose) { // if echo mode enabled |
165 |
AnswerClient(bufferedCommands[currentSocket]); |
AnswerClient(bufferedCommands[currentSocket]); |
185 |
} |
} |
186 |
NotifyBufferMutex.Unlock(); |
NotifyBufferMutex.Unlock(); |
187 |
} |
} |
|
//It will never get here anyway |
|
|
//yylex_destroy(yyparse_param.pScanner); |
|
188 |
} |
} |
189 |
|
|
190 |
void LSCPServer::CloseConnection( std::vector<yyparse_param_t>::iterator iter ) { |
void LSCPServer::CloseConnection( std::vector<yyparse_param_t>::iterator iter ) { |
203 |
bufferedNotifies.erase(socket); |
bufferedNotifies.erase(socket); |
204 |
close(socket); |
close(socket); |
205 |
NotifyMutex.Unlock(); |
NotifyMutex.Unlock(); |
206 |
//yylex_destroy((*iter).pScanner); |
} |
207 |
|
|
208 |
|
int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) { |
209 |
|
int subs = 0; |
210 |
|
SubscriptionMutex.Lock(); |
211 |
|
for( std::list<LSCPEvent::event_t>::iterator iter = events.begin(); |
212 |
|
iter != events.end(); iter++) |
213 |
|
{ |
214 |
|
subs += eventSubscriptions.count(*iter); |
215 |
|
} |
216 |
|
SubscriptionMutex.Unlock(); |
217 |
|
return subs; |
218 |
} |
} |
219 |
|
|
220 |
void LSCPServer::SendLSCPNotify( LSCPEvent event ) { |
void LSCPServer::SendLSCPNotify( LSCPEvent event ) { |
413 |
LSCPResultSet result; |
LSCPResultSet result; |
414 |
try { |
try { |
415 |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
416 |
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) + "."); |
417 |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
418 |
pSampler->DestroyAudioOutputDevice(pDevice); |
pSampler->DestroyAudioOutputDevice(pDevice); |
419 |
} |
} |
428 |
LSCPResultSet result; |
LSCPResultSet result; |
429 |
try { |
try { |
430 |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
431 |
|
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
432 |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
|
if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
|
433 |
pSampler->DestroyMidiInputDevice(pDevice); |
pSampler->DestroyMidiInputDevice(pDevice); |
434 |
} |
} |
435 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
446 |
LSCPResultSet result; |
LSCPResultSet result; |
447 |
try { |
try { |
448 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
449 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
450 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
451 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); |
452 |
if (pSamplerChannel->GetAudioOutputDevice() == NULL) |
if (!pSamplerChannel->GetAudioOutputDevice()) |
453 |
throw LinuxSamplerException("No audio output device on channel"); |
throw LinuxSamplerException("No audio output device connected to sampler channel"); |
454 |
if (bBackground) { |
if (bBackground) { |
455 |
LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument); |
InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngine); |
456 |
pLoadInstrument->StartThread(); |
} |
457 |
|
else { |
458 |
|
// tell the engine which instrument to load |
459 |
|
pEngine->PrepareLoadInstrument(Filename.c_str(), uiInstrument); |
460 |
|
// actually start to load the instrument (blocks until completed) |
461 |
|
pEngine->LoadInstrument(); |
462 |
} |
} |
|
else pEngine->LoadInstrument(Filename.c_str(), uiInstrument); |
|
463 |
} |
} |
464 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
465 |
result.Error(e); |
result.Error(e); |
478 |
if ((EngineName == "GigEngine") || (EngineName == "gig")) type = Engine::type_gig; |
if ((EngineName == "GigEngine") || (EngineName == "gig")) type = Engine::type_gig; |
479 |
else throw LinuxSamplerException("Unknown engine type"); |
else throw LinuxSamplerException("Unknown engine type"); |
480 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
481 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
482 |
|
LockRTNotify(); |
483 |
pSamplerChannel->LoadEngine(type); |
pSamplerChannel->LoadEngine(type); |
484 |
|
UnlockRTNotify(); |
485 |
} |
} |
486 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
487 |
result.Error(e); |
result.Error(e); |
532 |
String LSCPServer::RemoveChannel(uint uiSamplerChannel) { |
String LSCPServer::RemoveChannel(uint uiSamplerChannel) { |
533 |
dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
534 |
LSCPResultSet result; |
LSCPResultSet result; |
535 |
|
LockRTNotify(); |
536 |
pSampler->RemoveSamplerChannel(uiSamplerChannel); |
pSampler->RemoveSamplerChannel(uiSamplerChannel); |
537 |
|
UnlockRTNotify(); |
538 |
return result.Produce(); |
return result.Produce(); |
539 |
} |
} |
540 |
|
|
556 |
try { |
try { |
557 |
if ((EngineName == "GigEngine") || (EngineName == "gig")) { |
if ((EngineName == "GigEngine") || (EngineName == "gig")) { |
558 |
Engine* pEngine = new LinuxSampler::gig::Engine; |
Engine* pEngine = new LinuxSampler::gig::Engine; |
559 |
result.Add(pEngine->Description()); |
result.Add("DESCRIPTION", pEngine->Description()); |
560 |
result.Add(pEngine->Version()); |
result.Add("VERSION", pEngine->Version()); |
561 |
delete pEngine; |
delete pEngine; |
562 |
} |
} |
563 |
else throw LinuxSamplerException("Unknown engine type"); |
else throw LinuxSamplerException("Unknown engine type"); |
577 |
LSCPResultSet result; |
LSCPResultSet result; |
578 |
try { |
try { |
579 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
580 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
581 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
582 |
|
|
583 |
//Defaults values |
//Defaults values |
584 |
String EngineName = "NONE"; |
String EngineName = "NONE"; |
585 |
float Volume = 0; |
float Volume = 0.0f; |
586 |
String InstrumentFileName = "NONE"; |
String InstrumentFileName = "NONE"; |
587 |
|
String InstrumentName = "NONE"; |
588 |
int InstrumentIndex = -1; |
int InstrumentIndex = -1; |
589 |
int InstrumentStatus = -1; |
int InstrumentStatus = -1; |
590 |
|
int AudioOutputChannels = 0; |
591 |
|
String AudioRouting; |
592 |
|
|
593 |
if (pEngine) { |
if (pEngine) { |
594 |
EngineName = pEngine->EngineName(); |
EngineName = pEngine->EngineName(); |
595 |
|
AudioOutputChannels = pEngine->Channels(); |
596 |
Volume = pEngine->Volume(); |
Volume = pEngine->Volume(); |
597 |
InstrumentStatus = pEngine->InstrumentStatus(); |
InstrumentStatus = pEngine->InstrumentStatus(); |
598 |
InstrumentIndex = pEngine->InstrumentIndex(); |
InstrumentIndex = pEngine->InstrumentIndex(); |
599 |
if (InstrumentIndex != -1) |
if (InstrumentIndex != -1) |
600 |
|
{ |
601 |
InstrumentFileName = pEngine->InstrumentFileName(); |
InstrumentFileName = pEngine->InstrumentFileName(); |
602 |
|
InstrumentName = pEngine->InstrumentName(); |
603 |
|
} |
604 |
|
for (int chan = 0; chan < pEngine->Channels(); chan++) { |
605 |
|
if (AudioRouting != "") AudioRouting += ","; |
606 |
|
AudioRouting += ToString(pEngine->OutputChannel(chan)); |
607 |
|
} |
608 |
} |
} |
609 |
|
|
610 |
result.Add("ENGINE_NAME", EngineName); |
result.Add("ENGINE_NAME", EngineName); |
612 |
|
|
613 |
//Some not-so-hardcoded stuff to make GUI look good |
//Some not-so-hardcoded stuff to make GUI look good |
614 |
result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice())); |
result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice())); |
615 |
result.Add("AUDIO_OUTPUT_CHANNELS", "2"); |
result.Add("AUDIO_OUTPUT_CHANNELS", AudioOutputChannels); |
616 |
result.Add("AUDIO_OUTPUT_ROUTING", "0,1"); |
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
617 |
|
|
618 |
result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice())); |
result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice())); |
619 |
result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort()); |
result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort()); |
620 |
result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); |
if (pSamplerChannel->GetMidiInputChannel() == MidiInputPort::midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL"); |
621 |
|
else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); |
622 |
|
|
623 |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
624 |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
625 |
|
result.Add("INSTRUMENT_NAME", InstrumentName); |
626 |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
627 |
} |
} |
628 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
640 |
LSCPResultSet result; |
LSCPResultSet result; |
641 |
try { |
try { |
642 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
643 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
644 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
645 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); |
646 |
result.Add(pEngine->VoiceCount()); |
result.Add(pEngine->VoiceCount()); |
647 |
} |
} |
648 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
660 |
LSCPResultSet result; |
LSCPResultSet result; |
661 |
try { |
try { |
662 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
663 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
664 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
665 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); |
666 |
result.Add(pEngine->DiskStreamCount()); |
result.Add(pEngine->DiskStreamCount()); |
667 |
} |
} |
668 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
680 |
LSCPResultSet result; |
LSCPResultSet result; |
681 |
try { |
try { |
682 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
683 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
684 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
685 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); |
686 |
if (!pEngine->DiskStreamSupported()) |
if (!pEngine->DiskStreamSupported()) |
687 |
result.Add("NA"); |
result.Add("NA"); |
688 |
else { |
else { |
779 |
} |
} |
780 |
|
|
781 |
String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) { |
String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) { |
782 |
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())); |
783 |
LSCPResultSet result; |
LSCPResultSet result; |
784 |
try { |
try { |
785 |
DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter); |
DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter); |
788 |
result.Add("MANDATORY", pParameter->Mandatory()); |
result.Add("MANDATORY", pParameter->Mandatory()); |
789 |
result.Add("FIX", pParameter->Fix()); |
result.Add("FIX", pParameter->Fix()); |
790 |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
791 |
if (pParameter->Depends()) result.Add("DEPENDS", pParameter->Depends()); |
optional<String> oDepends = pParameter->Depends(); |
792 |
if (pParameter->Default()) result.Add("DEFAULT", pParameter->Default()); |
optional<String> oDefault = pParameter->Default(DependencyList); |
793 |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", pParameter->RangeMin()); |
optional<String> oRangeMin = pParameter->RangeMin(DependencyList); |
794 |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", pParameter->RangeMax()); |
optional<String> oRangeMax = pParameter->RangeMax(DependencyList); |
795 |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities()); |
optional<String> oPossibilities = pParameter->Possibilities(DependencyList); |
796 |
|
if (oDepends) result.Add("DEPENDS", *oDepends); |
797 |
|
if (oDefault) result.Add("DEFAULT", *oDefault); |
798 |
|
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
799 |
|
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
800 |
|
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
801 |
} |
} |
802 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
803 |
result.Error(e); |
result.Error(e); |
806 |
} |
} |
807 |
|
|
808 |
String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) { |
String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) { |
809 |
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())); |
810 |
LSCPResultSet result; |
LSCPResultSet result; |
811 |
try { |
try { |
812 |
DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter); |
DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter); |
815 |
result.Add("MANDATORY", pParameter->Mandatory()); |
result.Add("MANDATORY", pParameter->Mandatory()); |
816 |
result.Add("FIX", pParameter->Fix()); |
result.Add("FIX", pParameter->Fix()); |
817 |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
818 |
if (pParameter->Depends()) result.Add("DEPENDS", pParameter->Depends()); |
optional<String> oDepends = pParameter->Depends(); |
819 |
if (pParameter->Default()) result.Add("DEFAULT", pParameter->Default()); |
optional<String> oDefault = pParameter->Default(DependencyList); |
820 |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", pParameter->RangeMin()); |
optional<String> oRangeMin = pParameter->RangeMin(DependencyList); |
821 |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", pParameter->RangeMax()); |
optional<String> oRangeMax = pParameter->RangeMax(DependencyList); |
822 |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities()); |
optional<String> oPossibilities = pParameter->Possibilities(DependencyList); |
823 |
|
if (oDepends) result.Add("DEPENDS", *oDepends); |
824 |
|
if (oDefault) result.Add("DEFAULT", *oDefault); |
825 |
|
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
826 |
|
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
827 |
|
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
828 |
} |
} |
829 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
830 |
result.Error(e); |
result.Error(e); |
901 |
LSCPResultSet result; |
LSCPResultSet result; |
902 |
try { |
try { |
903 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
904 |
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) + "."); |
905 |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
906 |
result.Add("driver", pDevice->Driver()); |
result.Add("DRIVER", pDevice->Driver()); |
907 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
908 |
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
909 |
for (; iter != parameters.end(); iter++) { |
for (; iter != parameters.end(); iter++) { |
921 |
LSCPResultSet result; |
LSCPResultSet result; |
922 |
try { |
try { |
923 |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
924 |
|
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
925 |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
926 |
if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
result.Add("DRIVER", pDevice->Driver()); |
|
result.Add("driver", pDevice->Driver()); |
|
927 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
928 |
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
929 |
for (; iter != parameters.end(); iter++) { |
for (; iter != parameters.end(); iter++) { |
939 |
dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex)); |
dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex)); |
940 |
LSCPResultSet result; |
LSCPResultSet result; |
941 |
try { |
try { |
942 |
|
// get MIDI input device |
943 |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
944 |
|
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
945 |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
946 |
if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
|
947 |
MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); |
// get MIDI port |
948 |
if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); |
MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); |
949 |
std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters(); |
if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); |
950 |
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
|
951 |
|
// return the values of all MIDI port parameters |
952 |
|
std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters(); |
953 |
|
std::map<String,DeviceRuntimeParameter*>::iterator iter = parameters.begin(); |
954 |
for (; iter != parameters.end(); iter++) { |
for (; iter != parameters.end(); iter++) { |
955 |
result.Add(iter->first, iter->second->Value()); |
result.Add(iter->first, iter->second->Value()); |
956 |
} |
} |
967 |
try { |
try { |
968 |
// get audio output device |
// get audio output device |
969 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
970 |
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) + "."); |
971 |
AudioOutputDevice* pDevice = devices[DeviceId]; |
AudioOutputDevice* pDevice = devices[DeviceId]; |
972 |
|
|
973 |
// get audio channel |
// get audio channel |
974 |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
975 |
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) + "."); |
976 |
|
|
977 |
// return the values of all audio channel parameters |
// return the values of all audio channel parameters |
978 |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
991 |
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())); |
992 |
LSCPResultSet result; |
LSCPResultSet result; |
993 |
try { |
try { |
994 |
// get audio output device |
// get MIDI input device |
995 |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
996 |
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) + "."); |
997 |
MidiInputDevice* pDevice = devices[DeviceId]; |
MidiInputDevice* pDevice = devices[DeviceId]; |
998 |
|
|
999 |
// get midi port |
// get midi port |
1000 |
MidiInputDevice::MidiInputPort* pPort = pDevice->GetPort(PortId); |
MidiInputPort* pPort = pDevice->GetPort(PortId); |
1001 |
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) + "."); |
1002 |
|
|
1003 |
// get desired port parameter |
// get desired port parameter |
1004 |
std::map<String,DeviceCreationParameter*> parameters = pPort->DeviceParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pPort->PortParameters(); |
1005 |
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 + "'."); |
1006 |
DeviceCreationParameter* pParameter = parameters[ParameterName]; |
DeviceRuntimeParameter* pParameter = parameters[ParameterName]; |
1007 |
|
|
1008 |
// return all fields of this audio channel parameter |
// return all fields of this audio channel parameter |
1009 |
result.Add("TYPE", pParameter->Type()); |
result.Add("TYPE", pParameter->Type()); |
1010 |
result.Add("DESCRIPTION", pParameter->Description()); |
result.Add("DESCRIPTION", pParameter->Description()); |
1011 |
result.Add("FIX", pParameter->Fix()); |
result.Add("FIX", pParameter->Fix()); |
1012 |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
1013 |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", pParameter->RangeMin()); |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", *pParameter->RangeMin()); |
1014 |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", pParameter->RangeMax()); |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", *pParameter->RangeMax()); |
1015 |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities()); |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities()); |
1016 |
} |
} |
1017 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1018 |
result.Error(e); |
result.Error(e); |
1026 |
try { |
try { |
1027 |
// get audio output device |
// get audio output device |
1028 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1029 |
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) + "."); |
1030 |
AudioOutputDevice* pDevice = devices[DeviceId]; |
AudioOutputDevice* pDevice = devices[DeviceId]; |
1031 |
|
|
1032 |
// get audio channel |
// get audio channel |
1033 |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
1034 |
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) + "."); |
1035 |
|
|
1036 |
// get desired audio channel parameter |
// get desired audio channel parameter |
1037 |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
1038 |
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 + "'."); |
1039 |
DeviceRuntimeParameter* pParameter = parameters[ParameterName]; |
DeviceRuntimeParameter* pParameter = parameters[ParameterName]; |
1040 |
|
|
1041 |
// return all fields of this audio channel parameter |
// return all fields of this audio channel parameter |
1043 |
result.Add("DESCRIPTION", pParameter->Description()); |
result.Add("DESCRIPTION", pParameter->Description()); |
1044 |
result.Add("FIX", pParameter->Fix()); |
result.Add("FIX", pParameter->Fix()); |
1045 |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
1046 |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", pParameter->RangeMin()); |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", *pParameter->RangeMin()); |
1047 |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", pParameter->RangeMax()); |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", *pParameter->RangeMax()); |
1048 |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities()); |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities()); |
1049 |
} |
} |
1050 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1051 |
result.Error(e); |
result.Error(e); |
1059 |
try { |
try { |
1060 |
// get audio output device |
// get audio output device |
1061 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1062 |
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) + "."); |
1063 |
AudioOutputDevice* pDevice = devices[DeviceId]; |
AudioOutputDevice* pDevice = devices[DeviceId]; |
1064 |
|
|
1065 |
// get audio channel |
// get audio channel |
1066 |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
1067 |
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) + "."); |
1068 |
|
|
1069 |
// get desired audio channel parameter |
// get desired audio channel parameter |
1070 |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
1071 |
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 + "'."); |
1072 |
DeviceRuntimeParameter* pParameter = parameters[ParamKey]; |
DeviceRuntimeParameter* pParameter = parameters[ParamKey]; |
1073 |
|
|
1074 |
// set new channel parameter value |
// set new channel parameter value |
1085 |
LSCPResultSet result; |
LSCPResultSet result; |
1086 |
try { |
try { |
1087 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1088 |
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) + "."); |
1089 |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
1090 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
1091 |
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 + "'"); |
1092 |
parameters[ParamKey]->SetValue(ParamVal); |
parameters[ParamKey]->SetValue(ParamVal); |
1093 |
} |
} |
1094 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1102 |
LSCPResultSet result; |
LSCPResultSet result; |
1103 |
try { |
try { |
1104 |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1105 |
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) + "."); |
1106 |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
1107 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
1108 |
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 + "'"); |
1109 |
parameters[ParamKey]->SetValue(ParamVal); |
parameters[ParamKey]->SetValue(ParamVal); |
1110 |
} |
} |
1111 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1118 |
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())); |
1119 |
LSCPResultSet result; |
LSCPResultSet result; |
1120 |
try { |
try { |
1121 |
|
// get MIDI input device |
1122 |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1123 |
|
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
1124 |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
1125 |
if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
|
1126 |
MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); |
// get MIDI port |
1127 |
if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); |
MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); |
1128 |
std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters(); |
if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); |
1129 |
if (!parameters[ParamKey]) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'"); |
|
1130 |
|
// set port parameter value |
1131 |
|
std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters(); |
1132 |
|
if (!parameters.count(ParamKey)) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'"); |
1133 |
parameters[ParamKey]->SetValue(ParamVal); |
parameters[ParamKey]->SetValue(ParamVal); |
1134 |
} |
} |
1135 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1144 |
*/ |
*/ |
1145 |
String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) { |
String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) { |
1146 |
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)); |
1147 |
return "ERR:0:Not implemented yet.\r\n"; //FIXME: Add support for this in resultset class? |
LSCPResultSet result; |
1148 |
|
try { |
1149 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1150 |
|
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1151 |
|
Engine* pEngine = pSamplerChannel->GetEngine(); |
1152 |
|
if (!pEngine) throw LinuxSamplerException("No engine deployed on sampler channel " + ToString(uiSamplerChannel)); |
1153 |
|
if (!pSamplerChannel->GetAudioOutputDevice()) throw LinuxSamplerException("No audio output device connected to sampler channel " + ToString(uiSamplerChannel)); |
1154 |
|
pEngine->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel); |
1155 |
|
} |
1156 |
|
catch (LinuxSamplerException e) { |
1157 |
|
result.Error(e); |
1158 |
|
} |
1159 |
|
return result.Produce(); |
1160 |
} |
} |
1161 |
|
|
1162 |
String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) { |
String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) { |
1164 |
LSCPResultSet result; |
LSCPResultSet result; |
1165 |
try { |
try { |
1166 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1167 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1168 |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1169 |
|
if (!devices.count(AudioDeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId)); |
1170 |
AudioOutputDevice* pDevice = devices[AudioDeviceId]; |
AudioOutputDevice* pDevice = devices[AudioDeviceId]; |
|
if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId)); |
|
1171 |
pSamplerChannel->SetAudioOutputDevice(pDevice); |
pSamplerChannel->SetAudioOutputDevice(pDevice); |
1172 |
} |
} |
1173 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1181 |
LSCPResultSet result; |
LSCPResultSet result; |
1182 |
try { |
try { |
1183 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1184 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1185 |
// Driver type name aliasing... |
// Driver type name aliasing... |
1186 |
if (AudioOutputDriver == "ALSA") AudioOutputDriver = "Alsa"; |
if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA"; |
1187 |
if (AudioOutputDriver == "JACK") AudioOutputDriver = "Jack"; |
if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK"; |
1188 |
// Check if there's one audio output device already created |
// Check if there's one audio output device already created |
1189 |
// for the intended audio driver type (AudioOutputDriver)... |
// for the intended audio driver type (AudioOutputDriver)... |
1190 |
AudioOutputDevice *pDevice = NULL; |
AudioOutputDevice *pDevice = NULL; |
1218 |
LSCPResultSet result; |
LSCPResultSet result; |
1219 |
try { |
try { |
1220 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1221 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1222 |
pSamplerChannel->SetMidiInputPort(MIDIPort); |
pSamplerChannel->SetMidiInputPort(MIDIPort); |
1223 |
} |
} |
1224 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1232 |
LSCPResultSet result; |
LSCPResultSet result; |
1233 |
try { |
try { |
1234 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1235 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1236 |
pSamplerChannel->SetMidiInputChannel((MidiInputDevice::MidiInputPort::midi_chan_t) MIDIChannel); |
pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel); |
1237 |
} |
} |
1238 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1239 |
result.Error(e); |
result.Error(e); |
1246 |
LSCPResultSet result; |
LSCPResultSet result; |
1247 |
try { |
try { |
1248 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1249 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1250 |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1251 |
|
if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
1252 |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
|
if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
|
1253 |
pSamplerChannel->SetMidiInputDevice(pDevice); |
pSamplerChannel->SetMidiInputDevice(pDevice); |
1254 |
} |
} |
1255 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1263 |
LSCPResultSet result; |
LSCPResultSet result; |
1264 |
try { |
try { |
1265 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1266 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1267 |
// Driver type name aliasing... |
// Driver type name aliasing... |
1268 |
if (MidiInputDriver == "ALSA") MidiInputDriver = "Alsa"; |
if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA"; |
1269 |
// Check if there's one MIDI input device already created |
// Check if there's one MIDI input device already created |
1270 |
// for the intended MIDI driver type (MidiInputDriver)... |
// for the intended MIDI driver type (MidiInputDriver)... |
1271 |
MidiInputDevice *pDevice = NULL; |
MidiInputDevice *pDevice = NULL; |
1283 |
pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params); |
pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params); |
1284 |
// Make it with at least one initial port. |
// Make it with at least one initial port. |
1285 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
1286 |
parameters["ports"]->SetValue("1"); |
parameters["PORTS"]->SetValue("1"); |
1287 |
} |
} |
1288 |
// Must have a device... |
// Must have a device... |
1289 |
if (pDevice == NULL) |
if (pDevice == NULL) |
1306 |
LSCPResultSet result; |
LSCPResultSet result; |
1307 |
try { |
try { |
1308 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1309 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1310 |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1311 |
|
if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
1312 |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
1313 |
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); |
|
1314 |
} |
} |
1315 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1316 |
result.Error(e); |
result.Error(e); |
1322 |
* 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 |
1323 |
* particular sampler channel. |
* particular sampler channel. |
1324 |
*/ |
*/ |
1325 |
String LSCPServer::SetVolume(double Volume, uint uiSamplerChannel) { |
String LSCPServer::SetVolume(double dVolume, uint uiSamplerChannel) { |
1326 |
dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel)); |
1327 |
LSCPResultSet result; |
LSCPResultSet result; |
1328 |
try { |
try { |
1329 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1330 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1331 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
1332 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); |
1333 |
pEngine->Volume(Volume); |
pEngine->Volume(dVolume); |
1334 |
} |
} |
1335 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1336 |
result.Error(e); |
result.Error(e); |
1346 |
LSCPResultSet result; |
LSCPResultSet result; |
1347 |
try { |
try { |
1348 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1349 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1350 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
1351 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); |
1352 |
pEngine->Reset(); |
pEngine->Reset(); |
1353 |
} |
} |
1354 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1358 |
} |
} |
1359 |
|
|
1360 |
/** |
/** |
1361 |
|
* Will be called by the parser to reset the whole sampler. |
1362 |
|
*/ |
1363 |
|
String LSCPServer::ResetSampler() { |
1364 |
|
dmsg(2,("LSCPServer: ResetSampler()\n")); |
1365 |
|
pSampler->Reset(); |
1366 |
|
LSCPResultSet result; |
1367 |
|
return result.Produce(); |
1368 |
|
} |
1369 |
|
|
1370 |
|
/** |
1371 |
* Will be called by the parser to subscribe a client (frontend) on the |
* Will be called by the parser to subscribe a client (frontend) on the |
1372 |
* server for receiving event messages. |
* server for receiving event messages. |
1373 |
*/ |
*/ |
1411 |
} |
} |
1412 |
return result.Produce(); |
return result.Produce(); |
1413 |
} |
} |
|
|
|
|
// 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; |
|
|
} |
|