25 |
|
|
26 |
#include "../engines/gig/Engine.h" |
#include "../engines/gig/Engine.h" |
27 |
#include "../audiodriver/AudioOutputDeviceFactory.h" |
#include "../audiodriver/AudioOutputDeviceFactory.h" |
28 |
|
#include "../mididriver/MidiInputDeviceFactory.h" |
29 |
|
|
30 |
LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) { |
LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) { |
31 |
this->pSampler = pSampler; |
this->pSampler = pSampler; |
91 |
send(hSession, ReturnMessage.c_str(), ReturnMessage.size(), 0); |
send(hSession, ReturnMessage.c_str(), ReturnMessage.size(), 0); |
92 |
} |
} |
93 |
|
|
94 |
|
/** |
95 |
|
* Find a created audio output device index. |
96 |
|
*/ |
97 |
|
int LSCPServer::GetAudioOutputDeviceIndex ( AudioOutputDevice *pDevice ) |
98 |
|
{ |
99 |
|
// Search for the created device to get its index |
100 |
|
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
101 |
|
std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin(); |
102 |
|
for (; iter != devices.end(); iter++) { |
103 |
|
if (iter->second == pDevice) |
104 |
|
return iter->first; |
105 |
|
} |
106 |
|
// Not found. |
107 |
|
return -1; |
108 |
|
} |
109 |
|
|
110 |
|
/** |
111 |
|
* Find a created midi input device index. |
112 |
|
*/ |
113 |
|
int LSCPServer::GetMidiInputDeviceIndex ( MidiInputDevice *pDevice ) |
114 |
|
{ |
115 |
|
// Search for the created device to get its index |
116 |
|
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
117 |
|
std::map<uint, MidiInputDevice*>::iterator iter = devices.begin(); |
118 |
|
for (; iter != devices.end(); iter++) { |
119 |
|
if (iter->second == pDevice) |
120 |
|
return iter->first; |
121 |
|
} |
122 |
|
// Not found. |
123 |
|
return -1; |
124 |
|
} |
125 |
|
|
126 |
String LSCPServer::CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters) { |
String LSCPServer::CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters) { |
127 |
dmsg(2,("LSCPServer: CreateAudioOutputDevice(Driver=%s)\n", Driver.c_str())); |
dmsg(2,("LSCPServer: CreateAudioOutputDevice(Driver=%s)\n", Driver.c_str())); |
128 |
LSCPResultSet result; |
LSCPResultSet result; |
129 |
try { |
try { |
130 |
AudioOutputDevice* pDevice = pSampler->CreateAudioOutputDevice(Driver, Parameters); |
AudioOutputDevice* pDevice = pSampler->CreateAudioOutputDevice(Driver, Parameters); |
|
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
|
131 |
// search for the created device to get its index |
// search for the created device to get its index |
132 |
int index = -1; |
int index = GetAudioOutputDeviceIndex(pDevice); |
|
std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin(); |
|
|
for (; iter != devices.end(); iter++) { |
|
|
if (iter->second == pDevice) { |
|
|
index = iter->first; |
|
|
break; |
|
|
} |
|
|
} |
|
133 |
if (index == -1) throw LinuxSamplerException("Internal error: could not find created audio output device."); |
if (index == -1) throw LinuxSamplerException("Internal error: could not find created audio output device."); |
134 |
result = index; // success |
result = index; // success |
135 |
} |
} |
139 |
return result.Produce(); |
return result.Produce(); |
140 |
} |
} |
141 |
|
|
142 |
|
String LSCPServer::CreateMidiInputDevice(String Driver, std::map<String,String> Parameters) { |
143 |
|
dmsg(2,("LSCPServer: CreateMidiInputDevice(Driver=%s)\n", Driver.c_str())); |
144 |
|
LSCPResultSet result; |
145 |
|
try { |
146 |
|
MidiInputDevice* pDevice = pSampler->CreateMidiInputDevice(Driver, Parameters); |
147 |
|
// search for the created device to get its index |
148 |
|
int index = GetMidiInputDeviceIndex(pDevice); |
149 |
|
if (index == -1) throw LinuxSamplerException("Internal error: could not find created midi input device."); |
150 |
|
result = index; // success |
151 |
|
} |
152 |
|
catch (LinuxSamplerException e) { |
153 |
|
result.Error(e); |
154 |
|
} |
155 |
|
return result.Produce(); |
156 |
|
} |
157 |
|
|
158 |
String LSCPServer::DestroyAudioOutputDevice(uint DeviceIndex) { |
String LSCPServer::DestroyAudioOutputDevice(uint DeviceIndex) { |
159 |
dmsg(2,("LSCPServer: DestroyAudioOutputDevice(DeviceIndex=%d)\n", DeviceIndex)); |
dmsg(2,("LSCPServer: DestroyAudioOutputDevice(DeviceIndex=%d)\n", DeviceIndex)); |
160 |
LSCPResultSet result; |
LSCPResultSet result; |
170 |
return result.Produce(); |
return result.Produce(); |
171 |
} |
} |
172 |
|
|
173 |
|
String LSCPServer::DestroyMidiInputDevice(uint DeviceIndex) { |
174 |
|
dmsg(2,("LSCPServer: DestroyMidiInputDevice(DeviceIndex=%d)\n", DeviceIndex)); |
175 |
|
LSCPResultSet result; |
176 |
|
try { |
177 |
|
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
178 |
|
MidiInputDevice* pDevice = devices[DeviceIndex]; |
179 |
|
if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
180 |
|
pSampler->DestroyMidiInputDevice(pDevice); |
181 |
|
} |
182 |
|
catch (LinuxSamplerException e) { |
183 |
|
result.Error(e); |
184 |
|
} |
185 |
|
return result.Produce(); |
186 |
|
} |
187 |
|
|
188 |
/** |
/** |
189 |
* Will be called by the parser to load an instrument. |
* Will be called by the parser to load an instrument. |
190 |
*/ |
*/ |
191 |
String LSCPServer::LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel) { |
String LSCPServer::LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel, bool bBackground) { |
192 |
dmsg(2,("LSCPServer: LoadInstrument(Filename=%s,Instrument=%d,SamplerChannel=%d)\n", Filename.c_str(), uiInstrument, uiSamplerChannel)); |
dmsg(2,("LSCPServer: LoadInstrument(Filename=%s,Instrument=%d,SamplerChannel=%d)\n", Filename.c_str(), uiInstrument, uiSamplerChannel)); |
193 |
LSCPResultSet result; |
LSCPResultSet result; |
194 |
try { |
try { |
196 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
197 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
198 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
199 |
LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument); |
if (pSamplerChannel->GetAudioOutputDevice() == NULL) |
200 |
pLoadInstrument->StartThread(); |
throw LinuxSamplerException("No audio output device on channel"); |
201 |
|
if (bBackground) { |
202 |
|
LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument); |
203 |
|
pLoadInstrument->StartThread(); |
204 |
|
} |
205 |
|
else pEngine->LoadInstrument(Filename.c_str(), uiInstrument); |
206 |
} |
} |
207 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
208 |
result.Error(e); |
result.Error(e); |
321 |
result.Add("ENGINE_NAME", EngineName); |
result.Add("ENGINE_NAME", EngineName); |
322 |
result.Add("VOLUME", Volume); |
result.Add("VOLUME", Volume); |
323 |
|
|
324 |
//Some hardcoded stuff for now to make GUI look good |
//Some not-so-hardcoded stuff to make GUI look good |
325 |
result.Add("AUDIO_OUTPUT_DEVICE", "0"); |
result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice())); |
326 |
result.Add("AUDIO_OUTPUT_CHANNELS", "2"); |
result.Add("AUDIO_OUTPUT_CHANNELS", "2"); |
327 |
result.Add("AUDIO_OUTPUT_ROUTING", "0,1"); |
result.Add("AUDIO_OUTPUT_ROUTING", "0,1"); |
328 |
|
|
329 |
|
result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice())); |
330 |
|
result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort()); |
331 |
|
result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); |
332 |
|
|
333 |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
334 |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
335 |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
|
|
|
|
//Some more hardcoded stuff for now to make GUI look good |
|
|
result.Add("MIDI_INPUT_DEVICE", "0"); |
|
|
result.Add("MIDI_INPUT_PORT", "0"); |
|
|
result.Add("MIDI_INPUT_CHANNEL", "1"); |
|
336 |
} |
} |
337 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
338 |
result.Error(e); |
result.Error(e); |
426 |
return result.Produce(); |
return result.Produce(); |
427 |
} |
} |
428 |
|
|
429 |
|
String LSCPServer::GetAvailableMidiInputDrivers() { |
430 |
|
dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n")); |
431 |
|
LSCPResultSet result; |
432 |
|
try { |
433 |
|
String s = MidiInputDeviceFactory::AvailableDriversAsString(); |
434 |
|
result.Add(s); |
435 |
|
} |
436 |
|
catch (LinuxSamplerException e) { |
437 |
|
result.Error(e); |
438 |
|
} |
439 |
|
return result.Produce(); |
440 |
|
} |
441 |
|
|
442 |
|
String LSCPServer::GetMidiInputDriverInfo(String Driver) { |
443 |
|
dmsg(2,("LSCPServer: GetMidiInputDriverInfo(Driver=%s)\n",Driver.c_str())); |
444 |
|
LSCPResultSet result; |
445 |
|
try { |
446 |
|
result.Add("DESCRIPTION", MidiInputDeviceFactory::GetDriverDescription(Driver)); |
447 |
|
result.Add("VERSION", MidiInputDeviceFactory::GetDriverVersion(Driver)); |
448 |
|
|
449 |
|
std::map<String,DeviceCreationParameter*> parameters = MidiInputDeviceFactory::GetAvailableDriverParameters(Driver); |
450 |
|
if (parameters.size()) { // if there are parameters defined for this driver |
451 |
|
String s; |
452 |
|
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
453 |
|
for (;iter != parameters.end(); iter++) { |
454 |
|
if (s != "") s += ","; |
455 |
|
s += iter->first; |
456 |
|
} |
457 |
|
result.Add("PARAMETERS", s); |
458 |
|
} |
459 |
|
} |
460 |
|
catch (LinuxSamplerException e) { |
461 |
|
result.Error(e); |
462 |
|
} |
463 |
|
return result.Produce(); |
464 |
|
} |
465 |
|
|
466 |
String LSCPServer::GetAudioOutputDriverInfo(String Driver) { |
String LSCPServer::GetAudioOutputDriverInfo(String Driver) { |
467 |
dmsg(2,("LSCPServer: GetAudioOutputDriverInfo(Driver=%s)\n",Driver.c_str())); |
dmsg(2,("LSCPServer: GetAudioOutputDriverInfo(Driver=%s)\n",Driver.c_str())); |
468 |
LSCPResultSet result; |
LSCPResultSet result; |
487 |
return result.Produce(); |
return result.Produce(); |
488 |
} |
} |
489 |
|
|
490 |
|
String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) { |
491 |
|
dmsg(2,("LSCPServer: GetMidiInputDriverParameterInfo(Driver=%s,Parameter=%s)\n",Driver.c_str(),Parameter.c_str())); |
492 |
|
LSCPResultSet result; |
493 |
|
try { |
494 |
|
DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter); |
495 |
|
result.Add("TYPE", pParameter->Type()); |
496 |
|
result.Add("DESCRIPTION", pParameter->Description()); |
497 |
|
result.Add("MANDATORY", pParameter->Mandatory()); |
498 |
|
result.Add("FIX", pParameter->Fix()); |
499 |
|
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
500 |
|
if (pParameter->Depends()) result.Add("DEPENDS", pParameter->Depends()); |
501 |
|
if (pParameter->Default()) result.Add("DEFAULT", pParameter->Default()); |
502 |
|
if (pParameter->RangeMin()) result.Add("RANGE_MIN", pParameter->RangeMin()); |
503 |
|
if (pParameter->RangeMax()) result.Add("RANGE_MAX", pParameter->RangeMax()); |
504 |
|
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities()); |
505 |
|
} |
506 |
|
catch (LinuxSamplerException e) { |
507 |
|
result.Error(e); |
508 |
|
} |
509 |
|
return result.Produce(); |
510 |
|
} |
511 |
|
|
512 |
String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) { |
String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) { |
513 |
dmsg(2,("LSCPServer: GetAudioOutputDriverParameterInfo(Driver=%s,Parameter=%s)\n",Driver.c_str(),Parameter.c_str())); |
dmsg(2,("LSCPServer: GetAudioOutputDriverParameterInfo(Driver=%s,Parameter=%s)\n",Driver.c_str(),Parameter.c_str())); |
514 |
LSCPResultSet result; |
LSCPResultSet result; |
536 |
LSCPResultSet result; |
LSCPResultSet result; |
537 |
try { |
try { |
538 |
uint count = pSampler->AudioOutputDevices(); |
uint count = pSampler->AudioOutputDevices(); |
539 |
result = count; // success |
result.Add(count); // success |
540 |
|
} |
541 |
|
catch (LinuxSamplerException e) { |
542 |
|
result.Error(e); |
543 |
|
} |
544 |
|
return result.Produce(); |
545 |
|
} |
546 |
|
|
547 |
|
String LSCPServer::GetMidiInputDeviceCount() { |
548 |
|
dmsg(2,("LSCPServer: GetMidiInputDeviceCount()\n")); |
549 |
|
LSCPResultSet result; |
550 |
|
try { |
551 |
|
uint count = pSampler->MidiInputDevices(); |
552 |
|
result.Add(count); // success |
553 |
} |
} |
554 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
555 |
result.Error(e); |
result.Error(e); |
576 |
return result.Produce(); |
return result.Produce(); |
577 |
} |
} |
578 |
|
|
579 |
|
String LSCPServer::GetMidiInputDevices() { |
580 |
|
dmsg(2,("LSCPServer: GetMidiInputDevices()\n")); |
581 |
|
LSCPResultSet result; |
582 |
|
try { |
583 |
|
String s; |
584 |
|
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
585 |
|
std::map<uint, MidiInputDevice*>::iterator iter = devices.begin(); |
586 |
|
for (; iter != devices.end(); iter++) { |
587 |
|
if (s != "") s += ","; |
588 |
|
s += ToString(iter->first); |
589 |
|
} |
590 |
|
result.Add(s); |
591 |
|
} |
592 |
|
catch (LinuxSamplerException e) { |
593 |
|
result.Error(e); |
594 |
|
} |
595 |
|
return result.Produce(); |
596 |
|
} |
597 |
|
|
598 |
String LSCPServer::GetAudioOutputDeviceInfo(uint DeviceIndex) { |
String LSCPServer::GetAudioOutputDeviceInfo(uint DeviceIndex) { |
599 |
dmsg(2,("LSCPServer: GetAudioOutputDeviceInfo(DeviceIndex=%d)\n",DeviceIndex)); |
dmsg(2,("LSCPServer: GetAudioOutputDeviceInfo(DeviceIndex=%d)\n",DeviceIndex)); |
600 |
LSCPResultSet result; |
LSCPResultSet result; |
602 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
603 |
if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
604 |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
605 |
|
result.Add("driver", pDevice->Driver()); |
606 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
607 |
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
608 |
for (; iter != parameters.end(); iter++) { |
for (; iter != parameters.end(); iter++) { |
615 |
return result.Produce(); |
return result.Produce(); |
616 |
} |
} |
617 |
|
|
618 |
|
String LSCPServer::GetMidiInputDeviceInfo(uint DeviceIndex) { |
619 |
|
dmsg(2,("LSCPServer: GetMidiInputDeviceInfo(DeviceIndex=%d)\n",DeviceIndex)); |
620 |
|
LSCPResultSet result; |
621 |
|
try { |
622 |
|
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
623 |
|
MidiInputDevice* pDevice = devices[DeviceIndex]; |
624 |
|
if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
625 |
|
result.Add("driver", pDevice->Driver()); |
626 |
|
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
627 |
|
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
628 |
|
for (; iter != parameters.end(); iter++) { |
629 |
|
result.Add(iter->first, iter->second->Value()); |
630 |
|
} |
631 |
|
} |
632 |
|
catch (LinuxSamplerException e) { |
633 |
|
result.Error(e); |
634 |
|
} |
635 |
|
return result.Produce(); |
636 |
|
} |
637 |
|
String LSCPServer::GetMidiInputPortInfo(uint DeviceIndex, uint PortIndex) { |
638 |
|
dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex)); |
639 |
|
LSCPResultSet result; |
640 |
|
try { |
641 |
|
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
642 |
|
MidiInputDevice* pDevice = devices[DeviceIndex]; |
643 |
|
if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
644 |
|
MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); |
645 |
|
if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); |
646 |
|
std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters(); |
647 |
|
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
648 |
|
for (; iter != parameters.end(); iter++) { |
649 |
|
result.Add(iter->first, iter->second->Value()); |
650 |
|
} |
651 |
|
} |
652 |
|
catch (LinuxSamplerException e) { |
653 |
|
result.Error(e); |
654 |
|
} |
655 |
|
return result.Produce(); |
656 |
|
} |
657 |
|
|
658 |
String LSCPServer::GetAudioOutputChannelInfo(uint DeviceId, uint ChannelId) { |
String LSCPServer::GetAudioOutputChannelInfo(uint DeviceId, uint ChannelId) { |
659 |
dmsg(2,("LSCPServer: GetAudioOutputChannelInfo(DeviceId=%d,ChannelId)\n",DeviceId,ChannelId)); |
dmsg(2,("LSCPServer: GetAudioOutputChannelInfo(DeviceId=%d,ChannelId)\n",DeviceId,ChannelId)); |
660 |
LSCPResultSet result; |
LSCPResultSet result; |
758 |
return result.Produce(); |
return result.Produce(); |
759 |
} |
} |
760 |
|
|
761 |
|
String LSCPServer::SetMidiInputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal) { |
762 |
|
dmsg(2,("LSCPServer: SetMidiOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str())); |
763 |
|
LSCPResultSet result; |
764 |
|
try { |
765 |
|
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
766 |
|
if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
767 |
|
MidiInputDevice* pDevice = devices[DeviceIndex]; |
768 |
|
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
769 |
|
if (!parameters[ParamKey]) throw LinuxSamplerException("MIDI input device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'"); |
770 |
|
parameters[ParamKey]->SetValue(ParamVal); |
771 |
|
} |
772 |
|
catch (LinuxSamplerException e) { |
773 |
|
result.Error(e); |
774 |
|
} |
775 |
|
return result.Produce(); |
776 |
|
} |
777 |
|
|
778 |
|
String LSCPServer::SetMidiInputPortParameter(uint DeviceIndex, uint PortIndex, String ParamKey, String ParamVal) { |
779 |
|
dmsg(2,("LSCPServer: SetMidiOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str())); |
780 |
|
LSCPResultSet result; |
781 |
|
try { |
782 |
|
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
783 |
|
MidiInputDevice* pDevice = devices[DeviceIndex]; |
784 |
|
if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
785 |
|
MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); |
786 |
|
if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); |
787 |
|
std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters(); |
788 |
|
if (!parameters[ParamKey]) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'"); |
789 |
|
parameters[ParamKey]->SetValue(ParamVal); |
790 |
|
} |
791 |
|
catch (LinuxSamplerException e) { |
792 |
|
result.Error(e); |
793 |
|
} |
794 |
|
return result.Produce(); |
795 |
|
} |
796 |
|
|
797 |
/** |
/** |
798 |
* Will be called by the parser to change the audio output channel for |
* Will be called by the parser to change the audio output channel for |
799 |
* playback on a particular sampler channel. |
* playback on a particular sampler channel. |
803 |
return "ERR:0:Not implemented yet.\r\n"; //FIXME: Add support for this in resultset class? |
return "ERR:0:Not implemented yet.\r\n"; //FIXME: Add support for this in resultset class? |
804 |
} |
} |
805 |
|
|
806 |
String LSCPServer::SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel) { |
String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) { |
807 |
dmsg(2,("LSCPServer: SetMIDIInputType(String MidiInputDriver=%s, SamplerChannel=%d)\n",MidiInputDriver.c_str(),uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel)); |
808 |
LSCPResultSet result; |
LSCPResultSet result; |
809 |
try { |
try { |
810 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
811 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
812 |
// FIXME: workaround until MIDI driver configuration is implemented (using a Factory class for the MIDI input drivers then, like its already done for audio output drivers) |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
813 |
if (MidiInputDriver != "ALSA") throw LinuxSamplerException("Unknown MIDI input driver '" + MidiInputDriver + "'."); |
AudioOutputDevice* pDevice = devices[AudioDeviceId]; |
814 |
MidiInputDevice::type_t MidiInputType = MidiInputDevice::type_alsa; |
if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId)); |
815 |
pSamplerChannel->SetMidiInputDevice(MidiInputType); |
pSamplerChannel->SetAudioOutputDevice(pDevice); |
816 |
} |
} |
817 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
818 |
result.Error(e); |
result.Error(e); |
820 |
return result.Produce(); |
return result.Produce(); |
821 |
} |
} |
822 |
|
|
823 |
/** |
String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) { |
824 |
* Will be called by the parser to change the MIDI input port on which the |
dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel)); |
|
* engine of a particular sampler channel should listen to. |
|
|
*/ |
|
|
String LSCPServer::SetMIDIInputPort(String MIDIInputPort, uint uiSamplerChannel) { |
|
|
dmsg(2,("LSCPServer: SetMIDIInputPort(MIDIInputPort=%s, Samplerchannel=%d)\n", MIDIInputPort.c_str(), uiSamplerChannel)); |
|
825 |
LSCPResultSet result; |
LSCPResultSet result; |
826 |
try { |
try { |
827 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
828 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
829 |
if (!pSamplerChannel->GetMidiInputDevice()) throw LinuxSamplerException("No MIDI input device connected yet"); |
// Driver type name aliasing... |
830 |
pSamplerChannel->GetMidiInputDevice()->SetInputPort(MIDIInputPort.c_str()); |
if (AudioOutputDriver == "ALSA") AudioOutputDriver = "Alsa"; |
831 |
|
if (AudioOutputDriver == "JACK") AudioOutputDriver = "Jack"; |
832 |
|
// Check if there's one audio output device already created |
833 |
|
// for the intended audio driver type (AudioOutputDriver)... |
834 |
|
AudioOutputDevice *pDevice = NULL; |
835 |
|
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
836 |
|
std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin(); |
837 |
|
for (; iter != devices.end(); iter++) { |
838 |
|
if ((iter->second)->Driver() == AudioOutputDriver) { |
839 |
|
pDevice = iter->second; |
840 |
|
break; |
841 |
|
} |
842 |
|
} |
843 |
|
// If it doesn't exist, create a new one with default parameters... |
844 |
|
if (pDevice == NULL) { |
845 |
|
std::map<String,String> params; |
846 |
|
pDevice = pSampler->CreateAudioOutputDevice(AudioOutputDriver, params); |
847 |
|
} |
848 |
|
// Must have a device... |
849 |
|
if (pDevice == NULL) |
850 |
|
throw LinuxSamplerException("Internal error: could not create audio output device."); |
851 |
|
// Set it as the current channel device... |
852 |
|
pSamplerChannel->SetAudioOutputDevice(pDevice); |
853 |
|
} |
854 |
|
catch (LinuxSamplerException e) { |
855 |
|
result.Error(e); |
856 |
|
} |
857 |
|
return result.Produce(); |
858 |
|
} |
859 |
|
|
860 |
|
String LSCPServer::SetMIDIInputPort(uint MIDIPort, uint uiSamplerChannel) { |
861 |
|
dmsg(2,("LSCPServer: SetMIDIInputPort(MIDIPort=%d, SamplerChannel=%d)\n",MIDIPort,uiSamplerChannel)); |
862 |
|
LSCPResultSet result; |
863 |
|
try { |
864 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
865 |
|
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
866 |
|
pSamplerChannel->SetMidiInputPort(MIDIPort); |
867 |
} |
} |
868 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
869 |
result.Error(e); |
result.Error(e); |
871 |
return result.Produce(); |
return result.Produce(); |
872 |
} |
} |
873 |
|
|
|
/** |
|
|
* Will be called by the parser to change the MIDI input channel on which the |
|
|
* engine of a particular sampler channel should listen to. |
|
|
*/ |
|
874 |
String LSCPServer::SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel) { |
String LSCPServer::SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel) { |
875 |
dmsg(2,("LSCPServer: SetMIDIInputChannel(MIDIChannel=%d, SamplerChannel=%d)\n", MIDIChannel, uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetMIDIInputChannel(MIDIChannel=%d, SamplerChannel=%d)\n",MIDIChannel,uiSamplerChannel)); |
876 |
LSCPResultSet result; |
LSCPResultSet result; |
877 |
try { |
try { |
878 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
879 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
880 |
if (!pSamplerChannel->GetMidiInputDevice()) throw LinuxSamplerException("No MIDI input device connected yet"); |
pSamplerChannel->SetMidiInputChannel((MidiInputDevice::MidiInputPort::midi_chan_t) MIDIChannel); |
881 |
MidiInputDevice::type_t oldtype = pSamplerChannel->GetMidiInputDevice()->Type(); |
} |
882 |
pSamplerChannel->SetMidiInputDevice(oldtype, (MidiInputDevice::midi_chan_t) MIDIChannel); |
catch (LinuxSamplerException e) { |
883 |
|
result.Error(e); |
884 |
|
} |
885 |
|
return result.Produce(); |
886 |
|
} |
887 |
|
|
888 |
|
String LSCPServer::SetMIDIInputDevice(uint MIDIDeviceId, uint uiSamplerChannel) { |
889 |
|
dmsg(2,("LSCPServer: SetMIDIInputDevice(MIDIDeviceId=%d, SamplerChannel=%d)\n",MIDIDeviceId,uiSamplerChannel)); |
890 |
|
LSCPResultSet result; |
891 |
|
try { |
892 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
893 |
|
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
894 |
|
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
895 |
|
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
896 |
|
if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
897 |
|
pSamplerChannel->SetMidiInputDevice(pDevice); |
898 |
} |
} |
899 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
900 |
result.Error(e); |
result.Error(e); |
902 |
return result.Produce(); |
return result.Produce(); |
903 |
} |
} |
904 |
|
|
905 |
String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint SamplerChannel) { |
String LSCPServer::SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel) { |
906 |
|
dmsg(2,("LSCPServer: SetMIDIInputType(String MidiInputDriver=%s, SamplerChannel=%d)\n",MidiInputDriver.c_str(),uiSamplerChannel)); |
907 |
LSCPResultSet result; |
LSCPResultSet result; |
908 |
try { |
try { |
909 |
throw LinuxSamplerException("Command not yet implemented"); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
910 |
|
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
911 |
|
// Driver type name aliasing... |
912 |
|
if (MidiInputDriver == "ALSA") MidiInputDriver = "Alsa"; |
913 |
|
// Check if there's one MIDI input device already created |
914 |
|
// for the intended MIDI driver type (MidiInputDriver)... |
915 |
|
MidiInputDevice *pDevice = NULL; |
916 |
|
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
917 |
|
std::map<uint, MidiInputDevice*>::iterator iter = devices.begin(); |
918 |
|
for (; iter != devices.end(); iter++) { |
919 |
|
if ((iter->second)->Driver() == MidiInputDriver) { |
920 |
|
pDevice = iter->second; |
921 |
|
break; |
922 |
|
} |
923 |
|
} |
924 |
|
// If it doesn't exist, create a new one with default parameters... |
925 |
|
if (pDevice == NULL) { |
926 |
|
std::map<String,String> params; |
927 |
|
pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params); |
928 |
|
// Make it with at least one initial port. |
929 |
|
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
930 |
|
parameters["ports"]->SetValue("1"); |
931 |
|
} |
932 |
|
// Must have a device... |
933 |
|
if (pDevice == NULL) |
934 |
|
throw LinuxSamplerException("Internal error: could not create MIDI input device."); |
935 |
|
// Set it as the current channel device... |
936 |
|
pSamplerChannel->SetMidiInputDevice(pDevice); |
937 |
|
} |
938 |
|
catch (LinuxSamplerException e) { |
939 |
|
result.Error(e); |
940 |
|
} |
941 |
|
return result.Produce(); |
942 |
|
} |
943 |
|
|
944 |
|
/** |
945 |
|
* Will be called by the parser to change the MIDI input device, port and channel on which |
946 |
|
* engine of a particular sampler channel should listen to. |
947 |
|
*/ |
948 |
|
String LSCPServer::SetMIDIInput(uint MIDIDeviceId, uint MIDIPort, uint MIDIChannel, uint uiSamplerChannel) { |
949 |
|
dmsg(2,("LSCPServer: SetMIDIInput(MIDIDeviceId=%d, MIDIPort=%d, MIDIChannel=%d, SamplerChannel=%d)\n", MIDIDeviceId, MIDIPort, MIDIChannel, uiSamplerChannel)); |
950 |
|
LSCPResultSet result; |
951 |
|
try { |
952 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
953 |
|
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
954 |
|
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
955 |
|
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
956 |
|
if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
957 |
|
pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (MidiInputDevice::MidiInputPort::midi_chan_t) MIDIChannel); |
958 |
} |
} |
959 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
960 |
result.Error(e); |
result.Error(e); |
1005 |
* 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 |
1006 |
* server for receiving event messages. |
* server for receiving event messages. |
1007 |
*/ |
*/ |
1008 |
String LSCPServer::SubscribeNotification(uint UDPPort) { |
String LSCPServer::SubscribeNotification(event_t Event) { |
1009 |
dmsg(2,("LSCPServer: SubscribeNotification(UDPPort=%d)\n", UDPPort)); |
dmsg(2,("LSCPServer: SubscribeNotification(Event=%d)\n", Event)); |
1010 |
return "ERR:0:Not implemented yet.\r\n"; |
return "ERR:0:Not implemented yet.\r\n"; |
1011 |
} |
} |
1012 |
|
|
1014 |
* Will be called by the parser to unsubscribe a client on the server |
* Will be called by the parser to unsubscribe a client on the server |
1015 |
* for not receiving further event messages. |
* for not receiving further event messages. |
1016 |
*/ |
*/ |
1017 |
String LSCPServer::UnsubscribeNotification(String SessionID) { |
String LSCPServer::UnsubscribeNotification(event_t Event) { |
1018 |
dmsg(2,("LSCPServer: UnsubscribeNotification(SessionID=%s)\n", SessionID.c_str())); |
dmsg(2,("LSCPServer: UnsubscribeNotification(Event=%d)\n", Event)); |
1019 |
return "ERR:0:Not implemented yet.\r\n"; |
return "ERR:0:Not implemented yet.\r\n"; |
1020 |
} |
} |
1021 |
|
|