25 |
#include "lscpevent.h" |
#include "lscpevent.h" |
26 |
|
|
27 |
#include "../engines/gig/Engine.h" |
#include "../engines/gig/Engine.h" |
28 |
#include "../audiodriver/AudioOutputDeviceFactory.h" |
#include "../drivers/audio/AudioOutputDeviceFactory.h" |
29 |
#include "../mididriver/MidiInputDeviceFactory.h" |
#include "../drivers/midi/MidiInputDeviceFactory.h" |
30 |
|
|
31 |
/** |
/** |
32 |
* Below are a few static members of the LSCPServer class. |
* Below are a few static members of the LSCPServer class. |
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; |
102 |
int length = sizeof(client); |
int length = sizeof(client); |
|
struct timeval tv; |
|
|
tv.tv_sec = 30; |
|
|
tv.tv_usec = 0; |
|
103 |
FD_ZERO(&fdSet); |
FD_ZERO(&fdSet); |
104 |
FD_SET(hSocket, &fdSet); |
FD_SET(hSocket, &fdSet); |
105 |
int maxSessions = hSocket; |
int maxSessions = hSocket; |
|
|
|
|
// Parser initialization |
|
|
yyparse_param_t yyparse_param; |
|
|
yyparse_param.pServer = this; |
|
106 |
|
|
107 |
while (true) { |
while (true) { |
108 |
fd_set selectSet = fdSet; |
fd_set selectSet = fdSet; |
109 |
int retval = select(maxSessions+1, &selectSet, NULL, NULL, &tv); |
int retval = select(maxSessions+1, &selectSet, NULL, NULL, NULL); |
110 |
if (retval == 0) |
if (retval == 0) |
111 |
continue; //Nothing in 30 seconds, try again |
continue; //Nothing try again |
112 |
if (retval == -1) { |
if (retval == -1) { |
113 |
std::cerr << "LSCPServer: Socket select error." << std::endl; |
std::cerr << "LSCPServer: Socket select error." << std::endl; |
114 |
close(hSocket); |
close(hSocket); |
115 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
116 |
} |
} |
117 |
|
|
118 |
//Accept new connections now (if any) |
//Accept new connections now (if any) |
119 |
if (FD_ISSET(hSocket, &selectSet)) { |
if (FD_ISSET(hSocket, &selectSet)) { |
120 |
int socket = accept(hSocket, (sockaddr*) &client, (socklen_t*) &length); |
int socket = accept(hSocket, (sockaddr*) &client, (socklen_t*) &length); |
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? |
162 |
} |
} |
163 |
//socket may have been closed, iter may be invalid, get out of the loop for now. |
//socket may have been closed, iter may be invalid, get out of the loop for now. |
164 |
//we'll be back if there is data. |
//we'll be back if there is data. |
165 |
break; |
break; |
166 |
} |
} |
167 |
} |
} |
168 |
|
|
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) { |
255 |
break; |
break; |
256 |
} |
} |
257 |
if (result == 1) { |
if (result == 1) { |
258 |
if (c == '\r') |
if (c == '\r') |
259 |
continue; //Ignore CR |
continue; //Ignore CR |
260 |
if (c == '\n') { |
if (c == '\n') { |
261 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket)); |
282 |
break; |
break; |
283 |
case EAGAIN: |
case EAGAIN: |
284 |
dmsg(2,("LSCPScanner: The socket is marked non-blocking and the receive operation would block, or a receive timeout had been set and the timeout expired before data was received.\n")); |
dmsg(2,("LSCPScanner: The socket is marked non-blocking and the receive operation would block, or a receive timeout had been set and the timeout expired before data was received.\n")); |
285 |
break; |
break; |
286 |
case EINTR: |
case EINTR: |
287 |
dmsg(2,("LSCPScanner: The receive was interrupted by delivery of a signal before any data were available.\n")); |
dmsg(2,("LSCPScanner: The receive was interrupted by delivery of a signal before any data were available.\n")); |
288 |
break; |
break; |
289 |
case EFAULT: |
case EFAULT: |
290 |
dmsg(2,("LSCPScanner: The receive buffer pointer(s) point outside the process's address space.\n")); |
dmsg(2,("LSCPScanner: The receive buffer pointer(s) point outside the process's address space.\n")); |
291 |
break; |
break; |
292 |
case EINVAL: |
case EINVAL: |
293 |
dmsg(2,("LSCPScanner: Invalid argument passed.\n")); |
dmsg(2,("LSCPScanner: Invalid argument passed.\n")); |
294 |
break; |
break; |
295 |
case ENOMEM: |
case ENOMEM: |
296 |
dmsg(2,("LSCPScanner: Could not allocate memory for recvmsg.\n")); |
dmsg(2,("LSCPScanner: Could not allocate memory for recvmsg.\n")); |
297 |
break; |
break; |
298 |
default: |
default: |
299 |
dmsg(2,("LSCPScanner: Unknown recv() error.\n")); |
dmsg(2,("LSCPScanner: Unknown recv() error.\n")); |
300 |
break; |
break; |
301 |
} |
} |
302 |
CloseConnection(iter); |
CloseConnection(iter); |
303 |
break; |
break; |
304 |
} |
} |
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() { |
744 |
result.Add("MANDATORY", pParameter->Mandatory()); |
result.Add("MANDATORY", pParameter->Mandatory()); |
745 |
result.Add("FIX", pParameter->Fix()); |
result.Add("FIX", pParameter->Fix()); |
746 |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
747 |
if (pParameter->Depends()) result.Add("DEPENDS", pParameter->Depends()); |
if (pParameter->Depends()) result.Add("DEPENDS", *pParameter->Depends()); |
748 |
if (pParameter->Default()) result.Add("DEFAULT", pParameter->Default()); |
if (pParameter->Default()) result.Add("DEFAULT", *pParameter->Default()); |
749 |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", pParameter->RangeMin()); |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", *pParameter->RangeMin()); |
750 |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", pParameter->RangeMax()); |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", *pParameter->RangeMax()); |
751 |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities()); |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities()); |
752 |
} |
} |
753 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
754 |
result.Error(e); |
result.Error(e); |
766 |
result.Add("MANDATORY", pParameter->Mandatory()); |
result.Add("MANDATORY", pParameter->Mandatory()); |
767 |
result.Add("FIX", pParameter->Fix()); |
result.Add("FIX", pParameter->Fix()); |
768 |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
769 |
if (pParameter->Depends()) result.Add("DEPENDS", pParameter->Depends()); |
if (pParameter->Depends()) result.Add("DEPENDS", *pParameter->Depends()); |
770 |
if (pParameter->Default()) result.Add("DEFAULT", pParameter->Default()); |
if (pParameter->Default()) result.Add("DEFAULT", *pParameter->Default()); |
771 |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", pParameter->RangeMin()); |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", *pParameter->RangeMin()); |
772 |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", pParameter->RangeMax()); |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", *pParameter->RangeMax()); |
773 |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities()); |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities()); |
774 |
} |
} |
775 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
776 |
result.Error(e); |
result.Error(e); |
847 |
LSCPResultSet result; |
LSCPResultSet result; |
848 |
try { |
try { |
849 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
850 |
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) + "."); |
851 |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
852 |
result.Add("driver", pDevice->Driver()); |
result.Add("DRIVER", pDevice->Driver()); |
853 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
854 |
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
855 |
for (; iter != parameters.end(); iter++) { |
for (; iter != parameters.end(); iter++) { |
867 |
LSCPResultSet result; |
LSCPResultSet result; |
868 |
try { |
try { |
869 |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
870 |
|
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
871 |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
872 |
if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
result.Add("DRIVER", pDevice->Driver()); |
|
result.Add("driver", pDevice->Driver()); |
|
873 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
874 |
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
875 |
for (; iter != parameters.end(); iter++) { |
for (; iter != parameters.end(); iter++) { |
885 |
dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex)); |
dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex)); |
886 |
LSCPResultSet result; |
LSCPResultSet result; |
887 |
try { |
try { |
888 |
|
// get MIDI input device |
889 |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
890 |
|
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
891 |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
892 |
if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
|
893 |
MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); |
// get MIDI port |
894 |
if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); |
MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); |
895 |
std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters(); |
if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); |
896 |
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
|
897 |
|
// return the values of all MIDI port parameters |
898 |
|
std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters(); |
899 |
|
std::map<String,DeviceRuntimeParameter*>::iterator iter = parameters.begin(); |
900 |
for (; iter != parameters.end(); iter++) { |
for (; iter != parameters.end(); iter++) { |
901 |
result.Add(iter->first, iter->second->Value()); |
result.Add(iter->first, iter->second->Value()); |
902 |
} |
} |
913 |
try { |
try { |
914 |
// get audio output device |
// get audio output device |
915 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
916 |
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) + "."); |
917 |
AudioOutputDevice* pDevice = devices[DeviceId]; |
AudioOutputDevice* pDevice = devices[DeviceId]; |
918 |
|
|
919 |
// get audio channel |
// get audio channel |
933 |
return result.Produce(); |
return result.Produce(); |
934 |
} |
} |
935 |
|
|
936 |
|
String LSCPServer::GetMidiInputPortParameterInfo(uint DeviceId, uint PortId, String ParameterName) { |
937 |
|
dmsg(2,("LSCPServer: GetMidiInputPortParameterInfo(DeviceId=%d,PortId=%d,ParameterName=%s)\n",DeviceId,PortId,ParameterName.c_str())); |
938 |
|
LSCPResultSet result; |
939 |
|
try { |
940 |
|
// get MIDI input device |
941 |
|
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
942 |
|
if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no midi input device with index " + ToString(DeviceId) + "."); |
943 |
|
MidiInputDevice* pDevice = devices[DeviceId]; |
944 |
|
|
945 |
|
// get midi port |
946 |
|
MidiInputPort* pPort = pDevice->GetPort(PortId); |
947 |
|
if (!pPort) throw LinuxSamplerException("Midi input device does not have port " + ToString(PortId) + "."); |
948 |
|
|
949 |
|
// get desired port parameter |
950 |
|
std::map<String,DeviceRuntimeParameter*> parameters = pPort->PortParameters(); |
951 |
|
if (!parameters.count(ParameterName)) throw LinuxSamplerException("Midi port does not provide a parameter '" + ParameterName + "'."); |
952 |
|
DeviceRuntimeParameter* pParameter = parameters[ParameterName]; |
953 |
|
|
954 |
|
// return all fields of this audio channel parameter |
955 |
|
result.Add("TYPE", pParameter->Type()); |
956 |
|
result.Add("DESCRIPTION", pParameter->Description()); |
957 |
|
result.Add("FIX", pParameter->Fix()); |
958 |
|
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
959 |
|
if (pParameter->RangeMin()) result.Add("RANGE_MIN", *pParameter->RangeMin()); |
960 |
|
if (pParameter->RangeMax()) result.Add("RANGE_MAX", *pParameter->RangeMax()); |
961 |
|
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities()); |
962 |
|
} |
963 |
|
catch (LinuxSamplerException e) { |
964 |
|
result.Error(e); |
965 |
|
} |
966 |
|
return result.Produce(); |
967 |
|
} |
968 |
|
|
969 |
String LSCPServer::GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName) { |
String LSCPServer::GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName) { |
970 |
dmsg(2,("LSCPServer: GetAudioOutputChannelParameterInfo(DeviceId=%d,ChannelId=%d,ParameterName=%s)\n",DeviceId,ChannelId,ParameterName.c_str())); |
dmsg(2,("LSCPServer: GetAudioOutputChannelParameterInfo(DeviceId=%d,ChannelId=%d,ParameterName=%s)\n",DeviceId,ChannelId,ParameterName.c_str())); |
971 |
LSCPResultSet result; |
LSCPResultSet result; |
972 |
try { |
try { |
973 |
// get audio output device |
// get audio output device |
974 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
975 |
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) + "."); |
976 |
AudioOutputDevice* pDevice = devices[DeviceId]; |
AudioOutputDevice* pDevice = devices[DeviceId]; |
977 |
|
|
978 |
// get audio channel |
// get audio channel |
981 |
|
|
982 |
// get desired audio channel parameter |
// get desired audio channel parameter |
983 |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
984 |
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 + "'."); |
985 |
DeviceRuntimeParameter* pParameter = parameters[ParameterName]; |
DeviceRuntimeParameter* pParameter = parameters[ParameterName]; |
986 |
|
|
987 |
// return all fields of this audio channel parameter |
// return all fields of this audio channel parameter |
989 |
result.Add("DESCRIPTION", pParameter->Description()); |
result.Add("DESCRIPTION", pParameter->Description()); |
990 |
result.Add("FIX", pParameter->Fix()); |
result.Add("FIX", pParameter->Fix()); |
991 |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
992 |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", pParameter->RangeMin()); |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", *pParameter->RangeMin()); |
993 |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", pParameter->RangeMax()); |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", *pParameter->RangeMax()); |
994 |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities()); |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities()); |
995 |
} |
} |
996 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
997 |
result.Error(e); |
result.Error(e); |
1005 |
try { |
try { |
1006 |
// get audio output device |
// get audio output device |
1007 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1008 |
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) + "."); |
1009 |
AudioOutputDevice* pDevice = devices[DeviceId]; |
AudioOutputDevice* pDevice = devices[DeviceId]; |
1010 |
|
|
1011 |
// get audio channel |
// get audio channel |
1014 |
|
|
1015 |
// get desired audio channel parameter |
// get desired audio channel parameter |
1016 |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
1017 |
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 + "'."); |
1018 |
DeviceRuntimeParameter* pParameter = parameters[ParamKey]; |
DeviceRuntimeParameter* pParameter = parameters[ParamKey]; |
1019 |
|
|
1020 |
// set new channel parameter value |
// set new channel parameter value |
1031 |
LSCPResultSet result; |
LSCPResultSet result; |
1032 |
try { |
try { |
1033 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1034 |
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) + "."); |
1035 |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
1036 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
1037 |
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 + "'"); |
1038 |
parameters[ParamKey]->SetValue(ParamVal); |
parameters[ParamKey]->SetValue(ParamVal); |
1039 |
} |
} |
1040 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1048 |
LSCPResultSet result; |
LSCPResultSet result; |
1049 |
try { |
try { |
1050 |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1051 |
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) + "."); |
1052 |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
1053 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
1054 |
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 + "'"); |
1055 |
parameters[ParamKey]->SetValue(ParamVal); |
parameters[ParamKey]->SetValue(ParamVal); |
1056 |
} |
} |
1057 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1064 |
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())); |
1065 |
LSCPResultSet result; |
LSCPResultSet result; |
1066 |
try { |
try { |
1067 |
|
// get MIDI input device |
1068 |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1069 |
|
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 |
if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
|
1072 |
MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); |
// get MIDI port |
1073 |
if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); |
MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); |
1074 |
std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters(); |
if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); |
1075 |
if (!parameters[ParamKey]) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'"); |
|
1076 |
|
// set port parameter value |
1077 |
|
std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters(); |
1078 |
|
if (!parameters.count(ParamKey)) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'"); |
1079 |
parameters[ParamKey]->SetValue(ParamVal); |
parameters[ParamKey]->SetValue(ParamVal); |
1080 |
} |
} |
1081 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1100 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1101 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
1102 |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1103 |
|
if (!devices.count(AudioDeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId)); |
1104 |
AudioOutputDevice* pDevice = devices[AudioDeviceId]; |
AudioOutputDevice* pDevice = devices[AudioDeviceId]; |
|
if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId)); |
|
1105 |
pSamplerChannel->SetAudioOutputDevice(pDevice); |
pSamplerChannel->SetAudioOutputDevice(pDevice); |
1106 |
} |
} |
1107 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1118 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
1119 |
// Driver type name aliasing... |
// Driver type name aliasing... |
1120 |
if (AudioOutputDriver == "ALSA") AudioOutputDriver = "Alsa"; |
if (AudioOutputDriver == "ALSA") AudioOutputDriver = "Alsa"; |
1121 |
if (AudioOutputDriver == "JACK") AudioOutputDriver = "Jack"; |
if (AudioOutputDriver == "JACK") AudioOutputDriver = "Jack"; |
1122 |
// Check if there's one audio output device already created |
// Check if there's one audio output device already created |
1123 |
// for the intended audio driver type (AudioOutputDriver)... |
// for the intended audio driver type (AudioOutputDriver)... |
1124 |
AudioOutputDevice *pDevice = NULL; |
AudioOutputDevice *pDevice = NULL; |
1167 |
try { |
try { |
1168 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1169 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
1170 |
pSamplerChannel->SetMidiInputChannel((MidiInputDevice::MidiInputPort::midi_chan_t) MIDIChannel); |
pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel); |
1171 |
} |
} |
1172 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1173 |
result.Error(e); |
result.Error(e); |
1182 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1183 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
1184 |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1185 |
|
if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
1186 |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
|
if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
|
1187 |
pSamplerChannel->SetMidiInputDevice(pDevice); |
pSamplerChannel->SetMidiInputDevice(pDevice); |
1188 |
} |
} |
1189 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1217 |
pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params); |
pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params); |
1218 |
// Make it with at least one initial port. |
// Make it with at least one initial port. |
1219 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
1220 |
parameters["ports"]->SetValue("1"); |
parameters["PORTS"]->SetValue("1"); |
1221 |
} |
} |
1222 |
// Must have a device... |
// Must have a device... |
1223 |
if (pDevice == NULL) |
if (pDevice == NULL) |
1242 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1243 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
1244 |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1245 |
|
if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
1246 |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
1247 |
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); |
|
1248 |
} |
} |
1249 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1250 |
result.Error(e); |
result.Error(e); |
1292 |
} |
} |
1293 |
|
|
1294 |
/** |
/** |
1295 |
|
* Will be called by the parser to reset the whole sampler. |
1296 |
|
*/ |
1297 |
|
String LSCPServer::ResetSampler() { |
1298 |
|
dmsg(2,("LSCPServer: ResetSampler()\n")); |
1299 |
|
pSampler->Reset(); |
1300 |
|
LSCPResultSet result; |
1301 |
|
return result.Produce(); |
1302 |
|
} |
1303 |
|
|
1304 |
|
/** |
1305 |
* 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 |
1306 |
* server for receiving event messages. |
* server for receiving event messages. |
1307 |
*/ |
*/ |
1327 |
return result.Produce(); |
return result.Produce(); |
1328 |
} |
} |
1329 |
|
|
1330 |
|
/** |
1331 |
|
* Will be called by the parser to enable or disable echo mode; if echo |
1332 |
|
* mode is enabled, all commands from the client will (immediately) be |
1333 |
|
* echoed back to the client. |
1334 |
|
*/ |
1335 |
|
String LSCPServer::SetEcho(yyparse_param_t* pSession, double boolean_value) { |
1336 |
|
dmsg(2,("LSCPServer: SetEcho(val=%f)\n", boolean_value)); |
1337 |
|
LSCPResultSet result; |
1338 |
|
try { |
1339 |
|
if (boolean_value == 0) pSession->bVerbose = false; |
1340 |
|
else if (boolean_value == 1) pSession->bVerbose = true; |
1341 |
|
else throw LinuxSamplerException("Not a boolean value, must either be 0 or 1"); |
1342 |
|
} |
1343 |
|
catch (LinuxSamplerException e) { |
1344 |
|
result.Error(e); |
1345 |
|
} |
1346 |
|
return result.Produce(); |
1347 |
|
} |
1348 |
|
|
1349 |
// Instrument loader constructor. |
// Instrument loader constructor. |
1350 |
LSCPLoadInstrument::LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument) |
LSCPLoadInstrument::LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument) |