43 |
*/ |
*/ |
44 |
fd_set LSCPServer::fdSet; |
fd_set LSCPServer::fdSet; |
45 |
int LSCPServer::currentSocket = -1; |
int LSCPServer::currentSocket = -1; |
46 |
std::vector<int> LSCPServer::hSessions = std::vector<int>(); |
std::vector<yyparse_param_t> LSCPServer::Sessions = std::vector<yyparse_param_t>(); |
47 |
std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>(); |
std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>(); |
48 |
std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>(); |
std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>(); |
49 |
std::map< LSCPEvent::event_t, std::list<int> > LSCPServer::eventSubscriptions = std::map< LSCPEvent::event_t, std::list<int> >(); |
std::map< LSCPEvent::event_t, std::list<int> > LSCPServer::eventSubscriptions = std::map< LSCPEvent::event_t, std::list<int> >(); |
61 |
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
62 |
} |
} |
63 |
|
|
64 |
|
/** |
65 |
|
* Blocks the calling thread until the LSCP Server is initialized and |
66 |
|
* accepting socket connections, if the server is already initialized then |
67 |
|
* this method will return immediately. |
68 |
|
* @param TimeoutSeconds - optional: max. wait time in seconds |
69 |
|
* (default: 0s) |
70 |
|
* @param TimeoutNanoSeconds - optional: max wait time in nano seconds |
71 |
|
* (default: 0ns) |
72 |
|
* @returns 0 on success, a value less than 0 if timeout exceeded |
73 |
|
*/ |
74 |
|
int LSCPServer::WaitUntilInitialized(long TimeoutSeconds, long TimeoutNanoSeconds) { |
75 |
|
return Initialized.WaitAndUnlockIf(false, TimeoutSeconds, TimeoutNanoSeconds); |
76 |
|
} |
77 |
|
|
78 |
int LSCPServer::Main() { |
int LSCPServer::Main() { |
79 |
int hSocket = socket(AF_INET, SOCK_STREAM, 0); |
int hSocket = socket(AF_INET, SOCK_STREAM, 0); |
80 |
if (hSocket < 0) { |
if (hSocket < 0) { |
95 |
} |
} |
96 |
|
|
97 |
listen(hSocket, 1); |
listen(hSocket, 1); |
98 |
dmsg(1,("LSCPServer: Server running.\n")); // server running |
Initialized.Set(true); |
99 |
|
|
100 |
// now wait for client connections and handle their requests |
// now wait for client connections and handle their requests |
101 |
sockaddr_in client; |
sockaddr_in client; |
104 |
FD_SET(hSocket, &fdSet); |
FD_SET(hSocket, &fdSet); |
105 |
int maxSessions = hSocket; |
int maxSessions = hSocket; |
106 |
|
|
|
// Parser initialization |
|
|
yyparse_param_t yyparse_param; |
|
|
yyparse_param.pServer = this; |
|
|
|
|
107 |
while (true) { |
while (true) { |
108 |
fd_set selectSet = fdSet; |
fd_set selectSet = fdSet; |
109 |
int retval = select(maxSessions+1, &selectSet, NULL, NULL, NULL); |
int retval = select(maxSessions+1, &selectSet, NULL, NULL, NULL); |
128 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
129 |
} |
} |
130 |
|
|
131 |
hSessions.push_back(socket); |
// Parser initialization |
132 |
|
yyparse_param_t yyparse_param; |
133 |
|
yyparse_param.pServer = this; |
134 |
|
yyparse_param.hSession = socket; |
135 |
|
|
136 |
|
Sessions.push_back(yyparse_param); |
137 |
FD_SET(socket, &fdSet); |
FD_SET(socket, &fdSet); |
138 |
if (socket > maxSessions) |
if (socket > maxSessions) |
139 |
maxSessions = socket; |
maxSessions = socket; |
143 |
} |
} |
144 |
|
|
145 |
//Something was selected and it was not the hSocket, so it must be some command(s) coming. |
//Something was selected and it was not the hSocket, so it must be some command(s) coming. |
146 |
for (std::vector<int>::iterator iter = hSessions.begin(); iter != hSessions.end(); iter++) { |
for (std::vector<yyparse_param_t>::iterator iter = Sessions.begin(); iter != Sessions.end(); iter++) { |
147 |
if (FD_ISSET(*iter, &selectSet)) { //Was it this socket? |
if (FD_ISSET((*iter).hSession, &selectSet)) { //Was it this socket? |
148 |
if (GetLSCPCommand(iter)) { //Have we read the entire command? |
if (GetLSCPCommand(iter)) { //Have we read the entire command? |
149 |
dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket)); |
dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket)); |
150 |
yylex_init(&yyparse_param.pScanner); |
int dummy; // just a temporary hack to fulfill the restart() function prototype |
151 |
currentSocket = *iter; //a hack |
restart(NULL, dummy); // restart the 'scanner' |
152 |
int result = yyparse(&yyparse_param); |
currentSocket = (*iter).hSession; //a hack |
153 |
|
if ((*iter).bVerbose) { // if echo mode enabled |
154 |
|
AnswerClient(bufferedCommands[currentSocket]); |
155 |
|
} |
156 |
|
int result = yyparse(&(*iter)); |
157 |
currentSocket = -1; //continuation of a hack |
currentSocket = -1; //continuation of a hack |
158 |
dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket)); |
dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket)); |
159 |
if (result == LSCP_QUIT) { //Was it a quit command by any chance? |
if (result == LSCP_QUIT) { //Was it a quit command by any chance? |
174 |
} |
} |
175 |
NotifyBufferMutex.Unlock(); |
NotifyBufferMutex.Unlock(); |
176 |
} |
} |
|
//It will never get here anyway |
|
|
//yylex_destroy(yyparse_param.pScanner); |
|
177 |
} |
} |
178 |
|
|
179 |
void LSCPServer::CloseConnection( std::vector<int>::iterator iter ) { |
void LSCPServer::CloseConnection( std::vector<yyparse_param_t>::iterator iter ) { |
180 |
int socket = *iter; |
int socket = (*iter).hSession; |
181 |
dmsg(1,("LSCPServer: Client connection terminated on socket:%d.\n",socket)); |
dmsg(1,("LSCPServer: Client connection terminated on socket:%d.\n",socket)); |
182 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection terminated on socket", socket)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection terminated on socket", socket)); |
183 |
hSessions.erase(iter); |
Sessions.erase(iter); |
184 |
FD_CLR(socket, &fdSet); |
FD_CLR(socket, &fdSet); |
185 |
SubscriptionMutex.Lock(); //Must unsubscribe this socket from all events (if any) |
SubscriptionMutex.Lock(); //Must unsubscribe this socket from all events (if any) |
186 |
for (std::map< LSCPEvent::event_t, std::list<int> >::iterator iter = eventSubscriptions.begin(); iter != eventSubscriptions.end(); iter++) { |
for (std::map< LSCPEvent::event_t, std::list<int> >::iterator iter = eventSubscriptions.begin(); iter != eventSubscriptions.end(); iter++) { |
244 |
* If command is read, it will return true. Otherwise false is returned. |
* If command is read, it will return true. Otherwise false is returned. |
245 |
* In any case the received portion (complete or incomplete) is saved into bufferedCommand map. |
* In any case the received portion (complete or incomplete) is saved into bufferedCommand map. |
246 |
*/ |
*/ |
247 |
bool LSCPServer::GetLSCPCommand( std::vector<int>::iterator iter ) { |
bool LSCPServer::GetLSCPCommand( std::vector<yyparse_param_t>::iterator iter ) { |
248 |
int socket = *iter; |
int socket = (*iter).hSession; |
249 |
char c; |
char c; |
250 |
int i = 0; |
int i = 0; |
251 |
while (true) { |
while (true) { |
390 |
LSCPResultSet result; |
LSCPResultSet result; |
391 |
try { |
try { |
392 |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
393 |
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) + "."); |
394 |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
395 |
pSampler->DestroyAudioOutputDevice(pDevice); |
pSampler->DestroyAudioOutputDevice(pDevice); |
396 |
} |
} |
405 |
LSCPResultSet result; |
LSCPResultSet result; |
406 |
try { |
try { |
407 |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
408 |
|
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
409 |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
|
if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
|
410 |
pSampler->DestroyMidiInputDevice(pDevice); |
pSampler->DestroyMidiInputDevice(pDevice); |
411 |
} |
} |
412 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
426 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
427 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
428 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
429 |
if (pSamplerChannel->GetAudioOutputDevice() == NULL) |
if (!pSamplerChannel->GetAudioOutputDevice()) |
430 |
throw LinuxSamplerException("No audio output device on channel"); |
throw LinuxSamplerException("No audio output device on channel"); |
431 |
if (bBackground) { |
if (bBackground) { |
432 |
LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument); |
LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument); |
471 |
} |
} |
472 |
|
|
473 |
/** |
/** |
474 |
|
* Will be called by the parser to get the list of sampler channels. |
475 |
|
*/ |
476 |
|
String LSCPServer::ListChannels() { |
477 |
|
dmsg(2,("LSCPServer: ListChannels()\n")); |
478 |
|
String list; |
479 |
|
std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels(); |
480 |
|
std::map<uint,SamplerChannel*>::iterator iter = channels.begin(); |
481 |
|
for (; iter != channels.end(); iter++) { |
482 |
|
if (list != "") list += ","; |
483 |
|
list += ToString(iter->first); |
484 |
|
} |
485 |
|
LSCPResultSet result; |
486 |
|
result.Add(list); |
487 |
|
return result.Produce(); |
488 |
|
} |
489 |
|
|
490 |
|
/** |
491 |
* Will be called by the parser to add a sampler channel. |
* Will be called by the parser to add a sampler channel. |
492 |
*/ |
*/ |
493 |
String LSCPServer::AddChannel() { |
String LSCPServer::AddChannel() { |
525 |
try { |
try { |
526 |
if ((EngineName == "GigEngine") || (EngineName == "gig")) { |
if ((EngineName == "GigEngine") || (EngineName == "gig")) { |
527 |
Engine* pEngine = new LinuxSampler::gig::Engine; |
Engine* pEngine = new LinuxSampler::gig::Engine; |
528 |
result.Add(pEngine->Description()); |
result.Add("DESCRIPTION", pEngine->Description()); |
529 |
result.Add(pEngine->Version()); |
result.Add("VERSION", pEngine->Version()); |
530 |
delete pEngine; |
delete pEngine; |
531 |
} |
} |
532 |
else throw LinuxSamplerException("Unknown engine type"); |
else throw LinuxSamplerException("Unknown engine type"); |
551 |
|
|
552 |
//Defaults values |
//Defaults values |
553 |
String EngineName = "NONE"; |
String EngineName = "NONE"; |
554 |
float Volume = 0; |
float Volume = 0.0f; |
555 |
String InstrumentFileName = "NONE"; |
String InstrumentFileName = "NONE"; |
556 |
int InstrumentIndex = -1; |
int InstrumentIndex = -1; |
557 |
int InstrumentStatus = -1; |
int InstrumentStatus = -1; |
558 |
|
int AudioOutputChannels = 0; |
559 |
|
String AudioRouting; |
560 |
|
|
561 |
if (pEngine) { |
if (pEngine) { |
562 |
EngineName = pEngine->EngineName(); |
EngineName = pEngine->EngineName(); |
563 |
|
AudioOutputChannels = pEngine->Channels(); |
564 |
Volume = pEngine->Volume(); |
Volume = pEngine->Volume(); |
565 |
InstrumentStatus = pEngine->InstrumentStatus(); |
InstrumentStatus = pEngine->InstrumentStatus(); |
566 |
InstrumentIndex = pEngine->InstrumentIndex(); |
InstrumentIndex = pEngine->InstrumentIndex(); |
567 |
if (InstrumentIndex != -1) |
if (InstrumentIndex != -1) |
568 |
InstrumentFileName = pEngine->InstrumentFileName(); |
InstrumentFileName = pEngine->InstrumentFileName(); |
569 |
|
for (int chan = 0; chan < pEngine->Channels(); chan++) { |
570 |
|
if (AudioRouting != "") AudioRouting += ","; |
571 |
|
AudioRouting += ToString(pEngine->OutputChannel(chan)); |
572 |
|
} |
573 |
} |
} |
574 |
|
|
575 |
result.Add("ENGINE_NAME", EngineName); |
result.Add("ENGINE_NAME", EngineName); |
577 |
|
|
578 |
//Some not-so-hardcoded stuff to make GUI look good |
//Some not-so-hardcoded stuff to make GUI look good |
579 |
result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice())); |
result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice())); |
580 |
result.Add("AUDIO_OUTPUT_CHANNELS", "2"); |
result.Add("AUDIO_OUTPUT_CHANNELS", AudioOutputChannels); |
581 |
result.Add("AUDIO_OUTPUT_ROUTING", "0,1"); |
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
582 |
|
|
583 |
result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice())); |
result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice())); |
584 |
result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort()); |
result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort()); |
585 |
result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); |
if (pSamplerChannel->GetMidiInputChannel()) result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); |
586 |
|
else result.Add("MIDI_INPUT_CHANNEL", "ALL"); |
587 |
|
|
588 |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
589 |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
743 |
} |
} |
744 |
|
|
745 |
String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) { |
String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) { |
746 |
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())); |
747 |
LSCPResultSet result; |
LSCPResultSet result; |
748 |
try { |
try { |
749 |
DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter); |
DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter); |
752 |
result.Add("MANDATORY", pParameter->Mandatory()); |
result.Add("MANDATORY", pParameter->Mandatory()); |
753 |
result.Add("FIX", pParameter->Fix()); |
result.Add("FIX", pParameter->Fix()); |
754 |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
755 |
if (pParameter->Depends()) result.Add("DEPENDS", pParameter->Depends()); |
optional<String> oDepends = pParameter->Depends(); |
756 |
if (pParameter->Default()) result.Add("DEFAULT", pParameter->Default()); |
optional<String> oDefault = pParameter->Default(DependencyList); |
757 |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", pParameter->RangeMin()); |
optional<String> oRangeMin = pParameter->RangeMin(DependencyList); |
758 |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", pParameter->RangeMax()); |
optional<String> oRangeMax = pParameter->RangeMax(DependencyList); |
759 |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities()); |
optional<String> oPossibilities = pParameter->Possibilities(DependencyList); |
760 |
|
if (oDepends) result.Add("DEPENDS", *oDepends); |
761 |
|
if (oDefault) result.Add("DEFAULT", *oDefault); |
762 |
|
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
763 |
|
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
764 |
|
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
765 |
} |
} |
766 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
767 |
result.Error(e); |
result.Error(e); |
770 |
} |
} |
771 |
|
|
772 |
String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) { |
String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) { |
773 |
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())); |
774 |
LSCPResultSet result; |
LSCPResultSet result; |
775 |
try { |
try { |
776 |
DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter); |
DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter); |
779 |
result.Add("MANDATORY", pParameter->Mandatory()); |
result.Add("MANDATORY", pParameter->Mandatory()); |
780 |
result.Add("FIX", pParameter->Fix()); |
result.Add("FIX", pParameter->Fix()); |
781 |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
782 |
if (pParameter->Depends()) result.Add("DEPENDS", pParameter->Depends()); |
optional<String> oDepends = pParameter->Depends(); |
783 |
if (pParameter->Default()) result.Add("DEFAULT", pParameter->Default()); |
optional<String> oDefault = pParameter->Default(DependencyList); |
784 |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", pParameter->RangeMin()); |
optional<String> oRangeMin = pParameter->RangeMin(DependencyList); |
785 |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", pParameter->RangeMax()); |
optional<String> oRangeMax = pParameter->RangeMax(DependencyList); |
786 |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities()); |
optional<String> oPossibilities = pParameter->Possibilities(DependencyList); |
787 |
|
if (oDepends) result.Add("DEPENDS", *oDepends); |
788 |
|
if (oDefault) result.Add("DEFAULT", *oDefault); |
789 |
|
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
790 |
|
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
791 |
|
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
792 |
} |
} |
793 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
794 |
result.Error(e); |
result.Error(e); |
865 |
LSCPResultSet result; |
LSCPResultSet result; |
866 |
try { |
try { |
867 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
868 |
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) + "."); |
869 |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
870 |
result.Add("driver", pDevice->Driver()); |
result.Add("DRIVER", pDevice->Driver()); |
871 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
872 |
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
873 |
for (; iter != parameters.end(); iter++) { |
for (; iter != parameters.end(); iter++) { |
885 |
LSCPResultSet result; |
LSCPResultSet result; |
886 |
try { |
try { |
887 |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
888 |
|
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
889 |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
890 |
if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
result.Add("DRIVER", pDevice->Driver()); |
|
result.Add("driver", pDevice->Driver()); |
|
891 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
892 |
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
893 |
for (; iter != parameters.end(); iter++) { |
for (; iter != parameters.end(); iter++) { |
903 |
dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex)); |
dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex)); |
904 |
LSCPResultSet result; |
LSCPResultSet result; |
905 |
try { |
try { |
906 |
|
// get MIDI input device |
907 |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
908 |
|
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
909 |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
910 |
if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
|
911 |
MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); |
// get MIDI port |
912 |
if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); |
MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); |
913 |
std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters(); |
if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); |
914 |
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
|
915 |
|
// return the values of all MIDI port parameters |
916 |
|
std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters(); |
917 |
|
std::map<String,DeviceRuntimeParameter*>::iterator iter = parameters.begin(); |
918 |
for (; iter != parameters.end(); iter++) { |
for (; iter != parameters.end(); iter++) { |
919 |
result.Add(iter->first, iter->second->Value()); |
result.Add(iter->first, iter->second->Value()); |
920 |
} |
} |
931 |
try { |
try { |
932 |
// get audio output device |
// get audio output device |
933 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
934 |
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) + "."); |
935 |
AudioOutputDevice* pDevice = devices[DeviceId]; |
AudioOutputDevice* pDevice = devices[DeviceId]; |
936 |
|
|
937 |
// get audio channel |
// get audio channel |
955 |
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())); |
956 |
LSCPResultSet result; |
LSCPResultSet result; |
957 |
try { |
try { |
958 |
// get audio output device |
// get MIDI input device |
959 |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
960 |
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) + "."); |
961 |
MidiInputDevice* pDevice = devices[DeviceId]; |
MidiInputDevice* pDevice = devices[DeviceId]; |
962 |
|
|
963 |
// get midi port |
// get midi port |
964 |
MidiInputDevice::MidiInputPort* pPort = pDevice->GetPort(PortId); |
MidiInputPort* pPort = pDevice->GetPort(PortId); |
965 |
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) + "."); |
966 |
|
|
967 |
// get desired port parameter |
// get desired port parameter |
968 |
std::map<String,DeviceCreationParameter*> parameters = pPort->DeviceParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pPort->PortParameters(); |
969 |
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 + "'."); |
970 |
DeviceCreationParameter* pParameter = parameters[ParameterName]; |
DeviceRuntimeParameter* pParameter = parameters[ParameterName]; |
971 |
|
|
972 |
// return all fields of this audio channel parameter |
// return all fields of this audio channel parameter |
973 |
result.Add("TYPE", pParameter->Type()); |
result.Add("TYPE", pParameter->Type()); |
974 |
result.Add("DESCRIPTION", pParameter->Description()); |
result.Add("DESCRIPTION", pParameter->Description()); |
975 |
result.Add("FIX", pParameter->Fix()); |
result.Add("FIX", pParameter->Fix()); |
976 |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
977 |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", pParameter->RangeMin()); |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", *pParameter->RangeMin()); |
978 |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", pParameter->RangeMax()); |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", *pParameter->RangeMax()); |
979 |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities()); |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities()); |
980 |
} |
} |
981 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
982 |
result.Error(e); |
result.Error(e); |
990 |
try { |
try { |
991 |
// get audio output device |
// get audio output device |
992 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
993 |
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) + "."); |
994 |
AudioOutputDevice* pDevice = devices[DeviceId]; |
AudioOutputDevice* pDevice = devices[DeviceId]; |
995 |
|
|
996 |
// get audio channel |
// get audio channel |
999 |
|
|
1000 |
// get desired audio channel parameter |
// get desired audio channel parameter |
1001 |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
1002 |
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 + "'."); |
1003 |
DeviceRuntimeParameter* pParameter = parameters[ParameterName]; |
DeviceRuntimeParameter* pParameter = parameters[ParameterName]; |
1004 |
|
|
1005 |
// return all fields of this audio channel parameter |
// return all fields of this audio channel parameter |
1007 |
result.Add("DESCRIPTION", pParameter->Description()); |
result.Add("DESCRIPTION", pParameter->Description()); |
1008 |
result.Add("FIX", pParameter->Fix()); |
result.Add("FIX", pParameter->Fix()); |
1009 |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
1010 |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", pParameter->RangeMin()); |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", *pParameter->RangeMin()); |
1011 |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", pParameter->RangeMax()); |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", *pParameter->RangeMax()); |
1012 |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities()); |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities()); |
1013 |
} |
} |
1014 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1015 |
result.Error(e); |
result.Error(e); |
1023 |
try { |
try { |
1024 |
// get audio output device |
// get audio output device |
1025 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1026 |
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) + "."); |
1027 |
AudioOutputDevice* pDevice = devices[DeviceId]; |
AudioOutputDevice* pDevice = devices[DeviceId]; |
1028 |
|
|
1029 |
// get audio channel |
// get audio channel |
1032 |
|
|
1033 |
// get desired audio channel parameter |
// get desired audio channel parameter |
1034 |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
1035 |
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 + "'."); |
1036 |
DeviceRuntimeParameter* pParameter = parameters[ParamKey]; |
DeviceRuntimeParameter* pParameter = parameters[ParamKey]; |
1037 |
|
|
1038 |
// set new channel parameter value |
// set new channel parameter value |
1049 |
LSCPResultSet result; |
LSCPResultSet result; |
1050 |
try { |
try { |
1051 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1052 |
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) + "."); |
1053 |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
1054 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
1055 |
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 + "'"); |
1056 |
parameters[ParamKey]->SetValue(ParamVal); |
parameters[ParamKey]->SetValue(ParamVal); |
1057 |
} |
} |
1058 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1066 |
LSCPResultSet result; |
LSCPResultSet result; |
1067 |
try { |
try { |
1068 |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1069 |
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) + "."); |
1070 |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
1071 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
1072 |
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 + "'"); |
1073 |
parameters[ParamKey]->SetValue(ParamVal); |
parameters[ParamKey]->SetValue(ParamVal); |
1074 |
} |
} |
1075 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1082 |
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())); |
1083 |
LSCPResultSet result; |
LSCPResultSet result; |
1084 |
try { |
try { |
1085 |
|
// get MIDI input device |
1086 |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1087 |
|
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
1088 |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
1089 |
if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
|
1090 |
MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); |
// get MIDI port |
1091 |
if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); |
MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); |
1092 |
std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters(); |
if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); |
1093 |
if (!parameters[ParamKey]) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'"); |
|
1094 |
|
// set port parameter value |
1095 |
|
std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters(); |
1096 |
|
if (!parameters.count(ParamKey)) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'"); |
1097 |
parameters[ParamKey]->SetValue(ParamVal); |
parameters[ParamKey]->SetValue(ParamVal); |
1098 |
} |
} |
1099 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1108 |
*/ |
*/ |
1109 |
String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) { |
String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) { |
1110 |
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)); |
1111 |
return "ERR:0:Not implemented yet.\r\n"; //FIXME: Add support for this in resultset class? |
LSCPResultSet result; |
1112 |
|
try { |
1113 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1114 |
|
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
1115 |
|
Engine* pEngine = pSamplerChannel->GetEngine(); |
1116 |
|
if (!pEngine) throw LinuxSamplerException("No engine deployed on sampler channel " + ToString(uiSamplerChannel)); |
1117 |
|
pEngine->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel); |
1118 |
|
} |
1119 |
|
catch (LinuxSamplerException e) { |
1120 |
|
result.Error(e); |
1121 |
|
} |
1122 |
|
return result.Produce(); |
1123 |
} |
} |
1124 |
|
|
1125 |
String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) { |
String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) { |
1129 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1130 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
1131 |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1132 |
|
if (!devices.count(AudioDeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId)); |
1133 |
AudioOutputDevice* pDevice = devices[AudioDeviceId]; |
AudioOutputDevice* pDevice = devices[AudioDeviceId]; |
|
if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId)); |
|
1134 |
pSamplerChannel->SetAudioOutputDevice(pDevice); |
pSamplerChannel->SetAudioOutputDevice(pDevice); |
1135 |
} |
} |
1136 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1146 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1147 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
1148 |
// Driver type name aliasing... |
// Driver type name aliasing... |
1149 |
if (AudioOutputDriver == "ALSA") AudioOutputDriver = "Alsa"; |
if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA"; |
1150 |
if (AudioOutputDriver == "JACK") AudioOutputDriver = "Jack"; |
if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK"; |
1151 |
// Check if there's one audio output device already created |
// Check if there's one audio output device already created |
1152 |
// for the intended audio driver type (AudioOutputDriver)... |
// for the intended audio driver type (AudioOutputDriver)... |
1153 |
AudioOutputDevice *pDevice = NULL; |
AudioOutputDevice *pDevice = NULL; |
1196 |
try { |
try { |
1197 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1198 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
1199 |
pSamplerChannel->SetMidiInputChannel((MidiInputDevice::MidiInputPort::midi_chan_t) MIDIChannel); |
pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel); |
1200 |
} |
} |
1201 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1202 |
result.Error(e); |
result.Error(e); |
1211 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1212 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
1213 |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1214 |
|
if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
1215 |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
|
if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
|
1216 |
pSamplerChannel->SetMidiInputDevice(pDevice); |
pSamplerChannel->SetMidiInputDevice(pDevice); |
1217 |
} |
} |
1218 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1228 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1229 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
1230 |
// Driver type name aliasing... |
// Driver type name aliasing... |
1231 |
if (MidiInputDriver == "ALSA") MidiInputDriver = "Alsa"; |
if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA"; |
1232 |
// Check if there's one MIDI input device already created |
// Check if there's one MIDI input device already created |
1233 |
// for the intended MIDI driver type (MidiInputDriver)... |
// for the intended MIDI driver type (MidiInputDriver)... |
1234 |
MidiInputDevice *pDevice = NULL; |
MidiInputDevice *pDevice = NULL; |
1246 |
pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params); |
pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params); |
1247 |
// Make it with at least one initial port. |
// Make it with at least one initial port. |
1248 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
1249 |
parameters["ports"]->SetValue("1"); |
parameters["PORTS"]->SetValue("1"); |
1250 |
} |
} |
1251 |
// Must have a device... |
// Must have a device... |
1252 |
if (pDevice == NULL) |
if (pDevice == NULL) |
1271 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1272 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
1273 |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1274 |
|
if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
1275 |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
1276 |
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); |
|
1277 |
} |
} |
1278 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1279 |
result.Error(e); |
result.Error(e); |
1285 |
* 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 |
1286 |
* particular sampler channel. |
* particular sampler channel. |
1287 |
*/ |
*/ |
1288 |
String LSCPServer::SetVolume(double Volume, uint uiSamplerChannel) { |
String LSCPServer::SetVolume(double dVolume, uint uiSamplerChannel) { |
1289 |
dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel)); |
1290 |
LSCPResultSet result; |
LSCPResultSet result; |
1291 |
try { |
try { |
1292 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1293 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
1294 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
1295 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
1296 |
pEngine->Volume(Volume); |
pEngine->Volume(dVolume); |
1297 |
} |
} |
1298 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1299 |
result.Error(e); |
result.Error(e); |
1321 |
} |
} |
1322 |
|
|
1323 |
/** |
/** |
1324 |
|
* Will be called by the parser to reset the whole sampler. |
1325 |
|
*/ |
1326 |
|
String LSCPServer::ResetSampler() { |
1327 |
|
dmsg(2,("LSCPServer: ResetSampler()\n")); |
1328 |
|
pSampler->Reset(); |
1329 |
|
LSCPResultSet result; |
1330 |
|
return result.Produce(); |
1331 |
|
} |
1332 |
|
|
1333 |
|
/** |
1334 |
* 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 |
1335 |
* server for receiving event messages. |
* server for receiving event messages. |
1336 |
*/ |
*/ |
1356 |
return result.Produce(); |
return result.Produce(); |
1357 |
} |
} |
1358 |
|
|
1359 |
|
/** |
1360 |
|
* Will be called by the parser to enable or disable echo mode; if echo |
1361 |
|
* mode is enabled, all commands from the client will (immediately) be |
1362 |
|
* echoed back to the client. |
1363 |
|
*/ |
1364 |
|
String LSCPServer::SetEcho(yyparse_param_t* pSession, double boolean_value) { |
1365 |
|
dmsg(2,("LSCPServer: SetEcho(val=%f)\n", boolean_value)); |
1366 |
|
LSCPResultSet result; |
1367 |
|
try { |
1368 |
|
if (boolean_value == 0) pSession->bVerbose = false; |
1369 |
|
else if (boolean_value == 1) pSession->bVerbose = true; |
1370 |
|
else throw LinuxSamplerException("Not a boolean value, must either be 0 or 1"); |
1371 |
|
} |
1372 |
|
catch (LinuxSamplerException e) { |
1373 |
|
result.Error(e); |
1374 |
|
} |
1375 |
|
return result.Produce(); |
1376 |
|
} |
1377 |
|
|
1378 |
// Instrument loader constructor. |
// Instrument loader constructor. |
1379 |
LSCPLoadInstrument::LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument) |
LSCPLoadInstrument::LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument) |