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. |
86 |
// now wait for client connections and handle their requests |
// now wait for client connections and handle their requests |
87 |
sockaddr_in client; |
sockaddr_in client; |
88 |
int length = sizeof(client); |
int length = sizeof(client); |
|
struct timeval tv; |
|
|
tv.tv_sec = 30; |
|
|
tv.tv_usec = 0; |
|
89 |
FD_ZERO(&fdSet); |
FD_ZERO(&fdSet); |
90 |
FD_SET(hSocket, &fdSet); |
FD_SET(hSocket, &fdSet); |
91 |
int maxSessions = hSocket; |
int maxSessions = hSocket; |
92 |
|
|
93 |
// Parser initialization |
// Parser initialization |
94 |
yyparse_param_t yyparse_param; |
yyparse_param_t yyparse_param; |
95 |
yyparse_param.pServer = this; |
yyparse_param.pServer = this; |
96 |
|
|
97 |
while (true) { |
while (true) { |
98 |
fd_set selectSet = fdSet; |
fd_set selectSet = fdSet; |
99 |
int retval = select(maxSessions+1, &selectSet, NULL, NULL, &tv); |
int retval = select(maxSessions+1, &selectSet, NULL, NULL, NULL); |
100 |
if (retval == 0) |
if (retval == 0) |
101 |
continue; //Nothing in 30 seconds, try again |
continue; //Nothing try again |
102 |
if (retval == -1) { |
if (retval == -1) { |
103 |
std::cerr << "LSCPServer: Socket select error." << std::endl; |
std::cerr << "LSCPServer: Socket select error." << std::endl; |
104 |
close(hSocket); |
close(hSocket); |
105 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
106 |
} |
} |
107 |
|
|
108 |
//Accept new connections now (if any) |
//Accept new connections now (if any) |
109 |
if (FD_ISSET(hSocket, &selectSet)) { |
if (FD_ISSET(hSocket, &selectSet)) { |
110 |
int socket = accept(hSocket, (sockaddr*) &client, (socklen_t*) &length); |
int socket = accept(hSocket, (sockaddr*) &client, (socklen_t*) &length); |
143 |
} |
} |
144 |
//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. |
145 |
//we'll be back if there is data. |
//we'll be back if there is data. |
146 |
break; |
break; |
147 |
} |
} |
148 |
} |
} |
149 |
|
|
238 |
break; |
break; |
239 |
} |
} |
240 |
if (result == 1) { |
if (result == 1) { |
241 |
if (c == '\r') |
if (c == '\r') |
242 |
continue; //Ignore CR |
continue; //Ignore CR |
243 |
if (c == '\n') { |
if (c == '\n') { |
244 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket)); |
245 |
bufferedCommands[socket] += "\n"; |
bufferedCommands[socket] += "\n"; |
246 |
return true; //Complete command was read |
return true; //Complete command was read |
247 |
} |
} |
265 |
break; |
break; |
266 |
case EAGAIN: |
case EAGAIN: |
267 |
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")); |
268 |
break; |
break; |
269 |
case EINTR: |
case EINTR: |
270 |
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")); |
271 |
break; |
break; |
272 |
case EFAULT: |
case EFAULT: |
273 |
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")); |
274 |
break; |
break; |
275 |
case EINVAL: |
case EINVAL: |
276 |
dmsg(2,("LSCPScanner: Invalid argument passed.\n")); |
dmsg(2,("LSCPScanner: Invalid argument passed.\n")); |
277 |
break; |
break; |
278 |
case ENOMEM: |
case ENOMEM: |
279 |
dmsg(2,("LSCPScanner: Could not allocate memory for recvmsg.\n")); |
dmsg(2,("LSCPScanner: Could not allocate memory for recvmsg.\n")); |
280 |
break; |
break; |
281 |
default: |
default: |
282 |
dmsg(2,("LSCPScanner: Unknown recv() error.\n")); |
dmsg(2,("LSCPScanner: Unknown recv() error.\n")); |
283 |
break; |
break; |
284 |
} |
} |
285 |
CloseConnection(iter); |
CloseConnection(iter); |
286 |
break; |
break; |
287 |
} |
} |
894 |
return result.Produce(); |
return result.Produce(); |
895 |
} |
} |
896 |
|
|
897 |
|
String LSCPServer::GetMidiInputPortParameterInfo(uint DeviceId, uint PortId, String ParameterName) { |
898 |
|
dmsg(2,("LSCPServer: GetMidiInputPortParameterInfo(DeviceId=%d,PortId=%d,ParameterName=%s)\n",DeviceId,PortId,ParameterName.c_str())); |
899 |
|
LSCPResultSet result; |
900 |
|
try { |
901 |
|
// get audio output device |
902 |
|
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
903 |
|
if (!devices[DeviceId]) throw LinuxSamplerException("There is no midi input device with index " + ToString(DeviceId) + "."); |
904 |
|
MidiInputDevice* pDevice = devices[DeviceId]; |
905 |
|
|
906 |
|
// get midi port |
907 |
|
MidiInputDevice::MidiInputPort* pPort = pDevice->GetPort(PortId); |
908 |
|
if (!pPort) throw LinuxSamplerException("Midi input device does not have port " + ToString(PortId) + "."); |
909 |
|
|
910 |
|
// get desired port parameter |
911 |
|
std::map<String,DeviceCreationParameter*> parameters = pPort->DeviceParameters(); |
912 |
|
if (!parameters[ParameterName]) throw LinuxSamplerException("Midi port does not provice a parameters '" + ParameterName + "'."); |
913 |
|
DeviceCreationParameter* pParameter = parameters[ParameterName]; |
914 |
|
|
915 |
|
// return all fields of this audio channel parameter |
916 |
|
result.Add("TYPE", pParameter->Type()); |
917 |
|
result.Add("DESCRIPTION", pParameter->Description()); |
918 |
|
result.Add("FIX", pParameter->Fix()); |
919 |
|
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
920 |
|
if (pParameter->RangeMin()) result.Add("RANGE_MIN", pParameter->RangeMin()); |
921 |
|
if (pParameter->RangeMax()) result.Add("RANGE_MAX", pParameter->RangeMax()); |
922 |
|
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities()); |
923 |
|
} |
924 |
|
catch (LinuxSamplerException e) { |
925 |
|
result.Error(e); |
926 |
|
} |
927 |
|
return result.Produce(); |
928 |
|
} |
929 |
|
|
930 |
String LSCPServer::GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName) { |
String LSCPServer::GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName) { |
931 |
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())); |
932 |
LSCPResultSet result; |
LSCPResultSet result; |
1074 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
1075 |
// Driver type name aliasing... |
// Driver type name aliasing... |
1076 |
if (AudioOutputDriver == "ALSA") AudioOutputDriver = "Alsa"; |
if (AudioOutputDriver == "ALSA") AudioOutputDriver = "Alsa"; |
1077 |
if (AudioOutputDriver == "JACK") AudioOutputDriver = "Jack"; |
if (AudioOutputDriver == "JACK") AudioOutputDriver = "Jack"; |
1078 |
// Check if there's one audio output device already created |
// Check if there's one audio output device already created |
1079 |
// for the intended audio driver type (AudioOutputDriver)... |
// for the intended audio driver type (AudioOutputDriver)... |
1080 |
AudioOutputDevice *pDevice = NULL; |
AudioOutputDevice *pDevice = NULL; |