22 |
|
|
23 |
#include "lscpserver.h" |
#include "lscpserver.h" |
24 |
#include "lscpresultset.h" |
#include "lscpresultset.h" |
25 |
|
#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 "../drivers/midi/MidiInputDeviceFactory.h" |
30 |
|
|
31 |
|
/** |
32 |
|
* Below are a few static members of the LSCPServer class. |
33 |
|
* The big assumption here is that LSCPServer is going to remain a singleton. |
34 |
|
* These members are used to support client connections. |
35 |
|
* Class handles multiple connections at the same time using select() and non-blocking recv() |
36 |
|
* Commands are processed by a single LSCPServer thread. |
37 |
|
* Notifications are delivered either by the thread that originated them |
38 |
|
* or (if the resultset is currently in progress) by the LSCPServer thread |
39 |
|
* after the resultset was sent out. |
40 |
|
* This makes sure that resultsets can not be interrupted by notifications. |
41 |
|
* This also makes sure that the thread sending notification is not blocked |
42 |
|
* by the LSCPServer thread. |
43 |
|
*/ |
44 |
|
fd_set LSCPServer::fdSet; |
45 |
|
int LSCPServer::currentSocket = -1; |
46 |
|
std::vector<yyparse_param_t> LSCPServer::Sessions = std::vector<yyparse_param_t>(); |
47 |
|
std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>(); |
48 |
|
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> >(); |
50 |
|
Mutex LSCPServer::NotifyMutex = Mutex(); |
51 |
|
Mutex LSCPServer::NotifyBufferMutex = Mutex(); |
52 |
|
Mutex LSCPServer::SubscriptionMutex = Mutex(); |
53 |
|
Mutex LSCPServer::RTNotifyMutex = Mutex(); |
54 |
|
|
55 |
LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) { |
LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) { |
56 |
this->pSampler = pSampler; |
this->pSampler = pSampler; |
57 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_channels, "CHANNELS"); |
58 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT"); |
59 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT"); |
60 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL"); |
61 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_info, "INFO"); |
62 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
63 |
|
} |
64 |
|
|
65 |
|
/** |
66 |
|
* Blocks the calling thread until the LSCP Server is initialized and |
67 |
|
* accepting socket connections, if the server is already initialized then |
68 |
|
* this method will return immediately. |
69 |
|
* @param TimeoutSeconds - optional: max. wait time in seconds |
70 |
|
* (default: 0s) |
71 |
|
* @param TimeoutNanoSeconds - optional: max wait time in nano seconds |
72 |
|
* (default: 0ns) |
73 |
|
* @returns 0 on success, a value less than 0 if timeout exceeded |
74 |
|
*/ |
75 |
|
int LSCPServer::WaitUntilInitialized(long TimeoutSeconds, long TimeoutNanoSeconds) { |
76 |
|
return Initialized.WaitAndUnlockIf(false, TimeoutSeconds, TimeoutNanoSeconds); |
77 |
} |
} |
78 |
|
|
79 |
int LSCPServer::Main() { |
int LSCPServer::Main() { |
80 |
hSocket = socket(AF_INET, SOCK_STREAM, 0); |
int hSocket = socket(AF_INET, SOCK_STREAM, 0); |
81 |
if (hSocket < 0) { |
if (hSocket < 0) { |
82 |
std::cerr << "LSCPServer: Could not create server socket." << std::endl; |
std::cerr << "LSCPServer: Could not create server socket." << std::endl; |
83 |
//return -1; |
//return -1; |
89 |
SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY); |
SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY); |
90 |
|
|
91 |
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
92 |
std::cerr << "LSCPServer: Could not bind server socket." << std::endl; |
std::cerr << "LSCPServer: Could not bind server socket, retrying for " << ToString(LSCP_SERVER_BIND_TIMEOUT) << " seconds..."; |
93 |
close(hSocket); |
for (int trial = 0; true; trial++) { // retry for LSCP_SERVER_BIND_TIMEOUT seconds |
94 |
//return -1; |
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
95 |
exit(EXIT_FAILURE); |
if (trial > LSCP_SERVER_BIND_TIMEOUT) { |
96 |
|
std::cerr << "gave up!" << std::endl; |
97 |
|
close(hSocket); |
98 |
|
//return -1; |
99 |
|
exit(EXIT_FAILURE); |
100 |
|
} |
101 |
|
else sleep(1); // sleep 1s |
102 |
|
} |
103 |
|
else break; // success |
104 |
|
} |
105 |
} |
} |
106 |
|
|
107 |
listen(hSocket, 1); |
listen(hSocket, 1); |
108 |
dmsg(1,("LSCPServer: Server running.\n")); // server running |
Initialized.Set(true); |
109 |
|
|
110 |
// now wait for client connections and handle their requests |
// now wait for client connections and handle their requests |
111 |
sockaddr_in client; |
sockaddr_in client; |
112 |
int length = sizeof(client); |
int length = sizeof(client); |
113 |
|
FD_ZERO(&fdSet); |
114 |
|
FD_SET(hSocket, &fdSet); |
115 |
|
int maxSessions = hSocket; |
116 |
|
|
117 |
while (true) { |
while (true) { |
118 |
hSession = accept(hSocket, (sockaddr*) &client, (socklen_t*) &length); |
fd_set selectSet = fdSet; |
119 |
if (hSession < 0) { |
int retval = select(maxSessions+1, &selectSet, NULL, NULL, NULL); |
120 |
std::cerr << "LSCPServer: Client connection failed." << std::endl; |
if (retval == 0) |
121 |
close(hSocket); |
continue; //Nothing try again |
122 |
//return -1; |
if (retval == -1) { |
123 |
exit(EXIT_FAILURE); |
std::cerr << "LSCPServer: Socket select error." << std::endl; |
124 |
} |
close(hSocket); |
125 |
|
exit(EXIT_FAILURE); |
126 |
dmsg(1,("LSCPServer: Client connection established.\n")); |
} |
127 |
//send(hSession, "Welcome!\r\n", 10, 0); |
|
128 |
|
//Accept new connections now (if any) |
129 |
// Parser invocation |
if (FD_ISSET(hSocket, &selectSet)) { |
130 |
yyparse_param_t yyparse_param; |
int socket = accept(hSocket, (sockaddr*) &client, (socklen_t*) &length); |
131 |
yyparse_param.pServer = this; |
if (socket < 0) { |
132 |
yylex_init(&yyparse_param.pScanner); |
std::cerr << "LSCPServer: Client connection failed." << std::endl; |
133 |
while (yyparse(&yyparse_param) == LSCP_SYNTAX_ERROR); // recall parser in case of syntax error |
exit(EXIT_FAILURE); |
134 |
yylex_destroy(yyparse_param.pScanner); |
} |
135 |
|
|
136 |
|
if (fcntl(socket, F_SETFL, O_NONBLOCK)) { |
137 |
|
std::cerr << "LSCPServer: F_SETFL O_NONBLOCK failed." << std::endl; |
138 |
|
exit(EXIT_FAILURE); |
139 |
|
} |
140 |
|
|
141 |
|
// Parser initialization |
142 |
|
yyparse_param_t yyparse_param; |
143 |
|
yyparse_param.pServer = this; |
144 |
|
yyparse_param.hSession = socket; |
145 |
|
|
146 |
|
Sessions.push_back(yyparse_param); |
147 |
|
FD_SET(socket, &fdSet); |
148 |
|
if (socket > maxSessions) |
149 |
|
maxSessions = socket; |
150 |
|
dmsg(1,("LSCPServer: Client connection established on socket:%d.\n", socket)); |
151 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection established on socket", socket)); |
152 |
|
continue; //Maybe this was the only selected socket, better select again |
153 |
|
} |
154 |
|
|
155 |
close(hSession); |
//Something was selected and it was not the hSocket, so it must be some command(s) coming. |
156 |
dmsg(1,("LSCPServer: Client connection terminated.\n")); |
for (std::vector<yyparse_param_t>::iterator iter = Sessions.begin(); iter != Sessions.end(); iter++) { |
157 |
|
if (FD_ISSET((*iter).hSession, &selectSet)) { //Was it this socket? |
158 |
|
if (GetLSCPCommand(iter)) { //Have we read the entire command? |
159 |
|
dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket)); |
160 |
|
int dummy; // just a temporary hack to fulfill the restart() function prototype |
161 |
|
restart(NULL, dummy); // restart the 'scanner' |
162 |
|
currentSocket = (*iter).hSession; //a hack |
163 |
|
if ((*iter).bVerbose) { // if echo mode enabled |
164 |
|
AnswerClient(bufferedCommands[currentSocket]); |
165 |
|
} |
166 |
|
int result = yyparse(&(*iter)); |
167 |
|
currentSocket = -1; //continuation of a hack |
168 |
|
dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket)); |
169 |
|
if (result == LSCP_QUIT) { //Was it a quit command by any chance? |
170 |
|
CloseConnection(iter); |
171 |
|
} |
172 |
|
} |
173 |
|
//socket may have been closed, iter may be invalid, get out of the loop for now. |
174 |
|
//we'll be back if there is data. |
175 |
|
break; |
176 |
|
} |
177 |
|
} |
178 |
|
|
179 |
|
//Now let's deliver late notifies (if any) |
180 |
|
NotifyBufferMutex.Lock(); |
181 |
|
for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) { |
182 |
|
send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0); |
183 |
|
bufferedNotifies.erase(iterNotify); |
184 |
|
} |
185 |
|
NotifyBufferMutex.Unlock(); |
186 |
} |
} |
187 |
} |
} |
188 |
|
|
189 |
|
void LSCPServer::CloseConnection( std::vector<yyparse_param_t>::iterator iter ) { |
190 |
|
int socket = (*iter).hSession; |
191 |
|
dmsg(1,("LSCPServer: Client connection terminated on socket:%d.\n",socket)); |
192 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection terminated on socket", socket)); |
193 |
|
Sessions.erase(iter); |
194 |
|
FD_CLR(socket, &fdSet); |
195 |
|
SubscriptionMutex.Lock(); //Must unsubscribe this socket from all events (if any) |
196 |
|
for (std::map< LSCPEvent::event_t, std::list<int> >::iterator iter = eventSubscriptions.begin(); iter != eventSubscriptions.end(); iter++) { |
197 |
|
iter->second.remove(socket); |
198 |
|
} |
199 |
|
SubscriptionMutex.Unlock(); |
200 |
|
NotifyMutex.Lock(); |
201 |
|
bufferedCommands.erase(socket); |
202 |
|
bufferedNotifies.erase(socket); |
203 |
|
close(socket); |
204 |
|
NotifyMutex.Unlock(); |
205 |
|
} |
206 |
|
|
207 |
|
int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) { |
208 |
|
int subs = 0; |
209 |
|
SubscriptionMutex.Lock(); |
210 |
|
for( std::list<LSCPEvent::event_t>::iterator iter = events.begin(); |
211 |
|
iter != events.end(); iter++) |
212 |
|
{ |
213 |
|
subs += eventSubscriptions.count(*iter); |
214 |
|
} |
215 |
|
SubscriptionMutex.Unlock(); |
216 |
|
return subs; |
217 |
|
} |
218 |
|
|
219 |
|
void LSCPServer::SendLSCPNotify( LSCPEvent event ) { |
220 |
|
SubscriptionMutex.Lock(); |
221 |
|
if (eventSubscriptions.count(event.GetType()) == 0) { |
222 |
|
SubscriptionMutex.Unlock(); //Nobody is subscribed to this event |
223 |
|
return; |
224 |
|
} |
225 |
|
std::list<int>::iterator iter = eventSubscriptions[event.GetType()].begin(); |
226 |
|
std::list<int>::iterator end = eventSubscriptions[event.GetType()].end(); |
227 |
|
String notify = event.Produce(); |
228 |
|
|
229 |
|
while (true) { |
230 |
|
if (NotifyMutex.Trylock()) { |
231 |
|
for(;iter != end; iter++) |
232 |
|
send(*iter, notify.c_str(), notify.size(), 0); |
233 |
|
NotifyMutex.Unlock(); |
234 |
|
break; |
235 |
|
} else { |
236 |
|
if (NotifyBufferMutex.Trylock()) { |
237 |
|
for(;iter != end; iter++) |
238 |
|
bufferedNotifies[*iter] += notify; |
239 |
|
NotifyBufferMutex.Unlock(); |
240 |
|
break; |
241 |
|
} |
242 |
|
} |
243 |
|
} |
244 |
|
SubscriptionMutex.Unlock(); |
245 |
|
} |
246 |
|
|
247 |
|
extern int GetLSCPCommand( void *buf, int max_size ) { |
248 |
|
String command = LSCPServer::bufferedCommands[LSCPServer::currentSocket]; |
249 |
|
if (command.size() == 0) { //Parser wants input but we have nothing. |
250 |
|
strcpy((char*) buf, "\n"); //So give it an empty command |
251 |
|
return 1; //to keep it happy. |
252 |
|
} |
253 |
|
|
254 |
|
if (max_size < command.size()) { |
255 |
|
std::cerr << "getLSCPCommand: Flex buffer too small, ignoring the command." << std::endl; |
256 |
|
return 0; //This will never happen |
257 |
|
} |
258 |
|
|
259 |
|
strcpy((char*) buf, command.c_str()); |
260 |
|
LSCPServer::bufferedCommands.erase(LSCPServer::currentSocket); |
261 |
|
return command.size(); |
262 |
|
} |
263 |
|
|
264 |
|
/** |
265 |
|
* Will be called to try to read the command from the socket |
266 |
|
* If command is read, it will return true. Otherwise false is returned. |
267 |
|
* In any case the received portion (complete or incomplete) is saved into bufferedCommand map. |
268 |
|
*/ |
269 |
|
bool LSCPServer::GetLSCPCommand( std::vector<yyparse_param_t>::iterator iter ) { |
270 |
|
int socket = (*iter).hSession; |
271 |
|
char c; |
272 |
|
int i = 0; |
273 |
|
while (true) { |
274 |
|
int result = recv(socket, (void *)&c, 1, 0); //Read one character at a time for now |
275 |
|
if (result == 0) { //socket was selected, so 0 here means client has closed the connection |
276 |
|
CloseConnection(iter); |
277 |
|
break; |
278 |
|
} |
279 |
|
if (result == 1) { |
280 |
|
if (c == '\r') |
281 |
|
continue; //Ignore CR |
282 |
|
if (c == '\n') { |
283 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket)); |
284 |
|
bufferedCommands[socket] += "\n"; |
285 |
|
return true; //Complete command was read |
286 |
|
} |
287 |
|
bufferedCommands[socket] += c; |
288 |
|
} |
289 |
|
if (result == -1) { |
290 |
|
if (errno == EAGAIN) //Would block, try again later. |
291 |
|
return false; |
292 |
|
switch(errno) { |
293 |
|
case EBADF: |
294 |
|
dmsg(2,("LSCPScanner: The argument s is an invalid descriptor.\n")); |
295 |
|
break; |
296 |
|
case ECONNREFUSED: |
297 |
|
dmsg(2,("LSCPScanner: A remote host refused to allow the network connection (typically because it is not running the requested service).\n")); |
298 |
|
break; |
299 |
|
case ENOTCONN: |
300 |
|
dmsg(2,("LSCPScanner: The socket is associated with a connection-oriented protocol and has not been connected (see connect(2) and accept(2)).\n")); |
301 |
|
break; |
302 |
|
case ENOTSOCK: |
303 |
|
dmsg(2,("LSCPScanner: The argument s does not refer to a socket.\n")); |
304 |
|
break; |
305 |
|
case EAGAIN: |
306 |
|
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")); |
307 |
|
break; |
308 |
|
case EINTR: |
309 |
|
dmsg(2,("LSCPScanner: The receive was interrupted by delivery of a signal before any data were available.\n")); |
310 |
|
break; |
311 |
|
case EFAULT: |
312 |
|
dmsg(2,("LSCPScanner: The receive buffer pointer(s) point outside the process's address space.\n")); |
313 |
|
break; |
314 |
|
case EINVAL: |
315 |
|
dmsg(2,("LSCPScanner: Invalid argument passed.\n")); |
316 |
|
break; |
317 |
|
case ENOMEM: |
318 |
|
dmsg(2,("LSCPScanner: Could not allocate memory for recvmsg.\n")); |
319 |
|
break; |
320 |
|
default: |
321 |
|
dmsg(2,("LSCPScanner: Unknown recv() error.\n")); |
322 |
|
break; |
323 |
|
} |
324 |
|
CloseConnection(iter); |
325 |
|
break; |
326 |
|
} |
327 |
|
} |
328 |
|
return false; |
329 |
|
} |
330 |
|
|
331 |
/** |
/** |
332 |
* Will be called by the parser whenever it wants to send an answer to the |
* Will be called by the parser whenever it wants to send an answer to the |
333 |
* client / frontend. |
* client / frontend. |
336 |
*/ |
*/ |
337 |
void LSCPServer::AnswerClient(String ReturnMessage) { |
void LSCPServer::AnswerClient(String ReturnMessage) { |
338 |
dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str())); |
dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str())); |
339 |
send(hSession, ReturnMessage.c_str(), ReturnMessage.size(), 0); |
if (currentSocket != -1) { |
340 |
|
NotifyMutex.Lock(); |
341 |
|
send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0); |
342 |
|
NotifyMutex.Unlock(); |
343 |
|
} |
344 |
|
} |
345 |
|
|
346 |
|
/** |
347 |
|
* Find a created audio output device index. |
348 |
|
*/ |
349 |
|
int LSCPServer::GetAudioOutputDeviceIndex ( AudioOutputDevice *pDevice ) |
350 |
|
{ |
351 |
|
// Search for the created device to get its index |
352 |
|
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
353 |
|
std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin(); |
354 |
|
for (; iter != devices.end(); iter++) { |
355 |
|
if (iter->second == pDevice) |
356 |
|
return iter->first; |
357 |
|
} |
358 |
|
// Not found. |
359 |
|
return -1; |
360 |
|
} |
361 |
|
|
362 |
|
/** |
363 |
|
* Find a created midi input device index. |
364 |
|
*/ |
365 |
|
int LSCPServer::GetMidiInputDeviceIndex ( MidiInputDevice *pDevice ) |
366 |
|
{ |
367 |
|
// Search for the created device to get its index |
368 |
|
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
369 |
|
std::map<uint, MidiInputDevice*>::iterator iter = devices.begin(); |
370 |
|
for (; iter != devices.end(); iter++) { |
371 |
|
if (iter->second == pDevice) |
372 |
|
return iter->first; |
373 |
|
} |
374 |
|
// Not found. |
375 |
|
return -1; |
376 |
} |
} |
377 |
|
|
378 |
String LSCPServer::CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters) { |
String LSCPServer::CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters) { |
380 |
LSCPResultSet result; |
LSCPResultSet result; |
381 |
try { |
try { |
382 |
AudioOutputDevice* pDevice = pSampler->CreateAudioOutputDevice(Driver, Parameters); |
AudioOutputDevice* pDevice = pSampler->CreateAudioOutputDevice(Driver, Parameters); |
|
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
|
383 |
// search for the created device to get its index |
// search for the created device to get its index |
384 |
int index = -1; |
int index = GetAudioOutputDeviceIndex(pDevice); |
|
std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin(); |
|
|
for (; iter != devices.end(); iter++) { |
|
|
if (iter->second == pDevice) { |
|
|
index = iter->first; |
|
|
break; |
|
|
} |
|
|
} |
|
385 |
if (index == -1) throw LinuxSamplerException("Internal error: could not find created audio output device."); |
if (index == -1) throw LinuxSamplerException("Internal error: could not find created audio output device."); |
386 |
result = index; // success |
result = index; // success |
387 |
} |
} |
391 |
return result.Produce(); |
return result.Produce(); |
392 |
} |
} |
393 |
|
|
394 |
|
String LSCPServer::CreateMidiInputDevice(String Driver, std::map<String,String> Parameters) { |
395 |
|
dmsg(2,("LSCPServer: CreateMidiInputDevice(Driver=%s)\n", Driver.c_str())); |
396 |
|
LSCPResultSet result; |
397 |
|
try { |
398 |
|
MidiInputDevice* pDevice = pSampler->CreateMidiInputDevice(Driver, Parameters); |
399 |
|
// search for the created device to get its index |
400 |
|
int index = GetMidiInputDeviceIndex(pDevice); |
401 |
|
if (index == -1) throw LinuxSamplerException("Internal error: could not find created midi input device."); |
402 |
|
result = index; // success |
403 |
|
} |
404 |
|
catch (LinuxSamplerException e) { |
405 |
|
result.Error(e); |
406 |
|
} |
407 |
|
return result.Produce(); |
408 |
|
} |
409 |
|
|
410 |
String LSCPServer::DestroyAudioOutputDevice(uint DeviceIndex) { |
String LSCPServer::DestroyAudioOutputDevice(uint DeviceIndex) { |
411 |
dmsg(2,("LSCPServer: DestroyAudioOutputDevice(DeviceIndex=%d)\n", DeviceIndex)); |
dmsg(2,("LSCPServer: DestroyAudioOutputDevice(DeviceIndex=%d)\n", DeviceIndex)); |
412 |
LSCPResultSet result; |
LSCPResultSet result; |
413 |
try { |
try { |
414 |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
415 |
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) + "."); |
416 |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
417 |
pSampler->DestroyAudioOutputDevice(pDevice); |
pSampler->DestroyAudioOutputDevice(pDevice); |
418 |
} |
} |
422 |
return result.Produce(); |
return result.Produce(); |
423 |
} |
} |
424 |
|
|
425 |
|
String LSCPServer::DestroyMidiInputDevice(uint DeviceIndex) { |
426 |
|
dmsg(2,("LSCPServer: DestroyMidiInputDevice(DeviceIndex=%d)\n", DeviceIndex)); |
427 |
|
LSCPResultSet result; |
428 |
|
try { |
429 |
|
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
430 |
|
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
431 |
|
MidiInputDevice* pDevice = devices[DeviceIndex]; |
432 |
|
pSampler->DestroyMidiInputDevice(pDevice); |
433 |
|
} |
434 |
|
catch (LinuxSamplerException e) { |
435 |
|
result.Error(e); |
436 |
|
} |
437 |
|
return result.Produce(); |
438 |
|
} |
439 |
|
|
440 |
/** |
/** |
441 |
* Will be called by the parser to load an instrument. |
* Will be called by the parser to load an instrument. |
442 |
*/ |
*/ |
443 |
String LSCPServer::LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel) { |
String LSCPServer::LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel, bool bBackground) { |
444 |
dmsg(2,("LSCPServer: LoadInstrument(Filename=%s,Instrument=%d,SamplerChannel=%d)\n", Filename.c_str(), uiInstrument, uiSamplerChannel)); |
dmsg(2,("LSCPServer: LoadInstrument(Filename=%s,Instrument=%d,SamplerChannel=%d)\n", Filename.c_str(), uiInstrument, uiSamplerChannel)); |
445 |
LSCPResultSet result; |
LSCPResultSet result; |
446 |
try { |
try { |
448 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
449 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
450 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
451 |
LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument); |
if (!pSamplerChannel->GetAudioOutputDevice()) |
452 |
pLoadInstrument->StartThread(); |
throw LinuxSamplerException("No audio output device on channel"); |
453 |
|
if (bBackground) { |
454 |
|
LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument); |
455 |
|
pLoadInstrument->StartThread(); |
456 |
|
} |
457 |
|
else pEngine->LoadInstrument(Filename.c_str(), uiInstrument); |
458 |
} |
} |
459 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
460 |
result.Error(e); |
result.Error(e); |
474 |
else throw LinuxSamplerException("Unknown engine type"); |
else throw LinuxSamplerException("Unknown engine type"); |
475 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
476 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
477 |
|
LockRTNotify(); |
478 |
pSamplerChannel->LoadEngine(type); |
pSamplerChannel->LoadEngine(type); |
479 |
|
UnlockRTNotify(); |
480 |
} |
} |
481 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
482 |
result.Error(e); |
result.Error(e); |
495 |
} |
} |
496 |
|
|
497 |
/** |
/** |
498 |
|
* Will be called by the parser to get the list of sampler channels. |
499 |
|
*/ |
500 |
|
String LSCPServer::ListChannels() { |
501 |
|
dmsg(2,("LSCPServer: ListChannels()\n")); |
502 |
|
String list; |
503 |
|
std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels(); |
504 |
|
std::map<uint,SamplerChannel*>::iterator iter = channels.begin(); |
505 |
|
for (; iter != channels.end(); iter++) { |
506 |
|
if (list != "") list += ","; |
507 |
|
list += ToString(iter->first); |
508 |
|
} |
509 |
|
LSCPResultSet result; |
510 |
|
result.Add(list); |
511 |
|
return result.Produce(); |
512 |
|
} |
513 |
|
|
514 |
|
/** |
515 |
* Will be called by the parser to add a sampler channel. |
* Will be called by the parser to add a sampler channel. |
516 |
*/ |
*/ |
517 |
String LSCPServer::AddChannel() { |
String LSCPServer::AddChannel() { |
527 |
String LSCPServer::RemoveChannel(uint uiSamplerChannel) { |
String LSCPServer::RemoveChannel(uint uiSamplerChannel) { |
528 |
dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
529 |
LSCPResultSet result; |
LSCPResultSet result; |
530 |
|
LockRTNotify(); |
531 |
pSampler->RemoveSamplerChannel(uiSamplerChannel); |
pSampler->RemoveSamplerChannel(uiSamplerChannel); |
532 |
|
UnlockRTNotify(); |
533 |
return result.Produce(); |
return result.Produce(); |
534 |
} |
} |
535 |
|
|
551 |
try { |
try { |
552 |
if ((EngineName == "GigEngine") || (EngineName == "gig")) { |
if ((EngineName == "GigEngine") || (EngineName == "gig")) { |
553 |
Engine* pEngine = new LinuxSampler::gig::Engine; |
Engine* pEngine = new LinuxSampler::gig::Engine; |
554 |
result.Add(pEngine->Description()); |
result.Add("DESCRIPTION", pEngine->Description()); |
555 |
result.Add(pEngine->Version()); |
result.Add("VERSION", pEngine->Version()); |
556 |
delete pEngine; |
delete pEngine; |
557 |
} |
} |
558 |
else throw LinuxSamplerException("Unknown engine type"); |
else throw LinuxSamplerException("Unknown engine type"); |
577 |
|
|
578 |
//Defaults values |
//Defaults values |
579 |
String EngineName = "NONE"; |
String EngineName = "NONE"; |
580 |
float Volume = 0; |
float Volume = 0.0f; |
581 |
String InstrumentFileName = "NONE"; |
String InstrumentFileName = "NONE"; |
582 |
int InstrumentIndex = -1; |
int InstrumentIndex = -1; |
583 |
int InstrumentStatus = -1; |
int InstrumentStatus = -1; |
584 |
|
int AudioOutputChannels = 0; |
585 |
|
String AudioRouting; |
586 |
|
|
587 |
if (pEngine) { |
if (pEngine) { |
588 |
EngineName = pEngine->EngineName(); |
EngineName = pEngine->EngineName(); |
589 |
|
AudioOutputChannels = pEngine->Channels(); |
590 |
Volume = pEngine->Volume(); |
Volume = pEngine->Volume(); |
591 |
InstrumentStatus = pEngine->InstrumentStatus(); |
InstrumentStatus = pEngine->InstrumentStatus(); |
592 |
InstrumentIndex = pEngine->InstrumentIndex(); |
InstrumentIndex = pEngine->InstrumentIndex(); |
593 |
if (InstrumentIndex != -1) |
if (InstrumentIndex != -1) |
594 |
InstrumentFileName = pEngine->InstrumentFileName(); |
InstrumentFileName = pEngine->InstrumentFileName(); |
595 |
|
for (int chan = 0; chan < pEngine->Channels(); chan++) { |
596 |
|
if (AudioRouting != "") AudioRouting += ","; |
597 |
|
AudioRouting += ToString(pEngine->OutputChannel(chan)); |
598 |
|
} |
599 |
} |
} |
600 |
|
|
601 |
result.Add("ENGINE_NAME", EngineName); |
result.Add("ENGINE_NAME", EngineName); |
602 |
result.Add("VOLUME", Volume); |
result.Add("VOLUME", Volume); |
603 |
|
|
604 |
//Some hardcoded stuff for now to make GUI look good |
//Some not-so-hardcoded stuff to make GUI look good |
605 |
result.Add("AUDIO_OUTPUT_DEVICE", "0"); |
result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice())); |
606 |
result.Add("AUDIO_OUTPUT_CHANNELS", "2"); |
result.Add("AUDIO_OUTPUT_CHANNELS", AudioOutputChannels); |
607 |
result.Add("AUDIO_OUTPUT_ROUTING", "0,1"); |
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
608 |
|
|
609 |
|
result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice())); |
610 |
|
result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort()); |
611 |
|
if (pSamplerChannel->GetMidiInputChannel() == MidiInputPort::midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL"); |
612 |
|
else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); |
613 |
|
|
614 |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
615 |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
616 |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
|
|
|
|
//Some more hardcoded stuff for now to make GUI look good |
|
|
result.Add("MIDI_INPUT_DEVICE", "0"); |
|
|
result.Add("MIDI_INPUT_PORT", "0"); |
|
|
result.Add("MIDI_INPUT_CHANNEL", "1"); |
|
617 |
} |
} |
618 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
619 |
result.Error(e); |
result.Error(e); |
707 |
return result.Produce(); |
return result.Produce(); |
708 |
} |
} |
709 |
|
|
710 |
|
String LSCPServer::GetAvailableMidiInputDrivers() { |
711 |
|
dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n")); |
712 |
|
LSCPResultSet result; |
713 |
|
try { |
714 |
|
String s = MidiInputDeviceFactory::AvailableDriversAsString(); |
715 |
|
result.Add(s); |
716 |
|
} |
717 |
|
catch (LinuxSamplerException e) { |
718 |
|
result.Error(e); |
719 |
|
} |
720 |
|
return result.Produce(); |
721 |
|
} |
722 |
|
|
723 |
|
String LSCPServer::GetMidiInputDriverInfo(String Driver) { |
724 |
|
dmsg(2,("LSCPServer: GetMidiInputDriverInfo(Driver=%s)\n",Driver.c_str())); |
725 |
|
LSCPResultSet result; |
726 |
|
try { |
727 |
|
result.Add("DESCRIPTION", MidiInputDeviceFactory::GetDriverDescription(Driver)); |
728 |
|
result.Add("VERSION", MidiInputDeviceFactory::GetDriverVersion(Driver)); |
729 |
|
|
730 |
|
std::map<String,DeviceCreationParameter*> parameters = MidiInputDeviceFactory::GetAvailableDriverParameters(Driver); |
731 |
|
if (parameters.size()) { // if there are parameters defined for this driver |
732 |
|
String s; |
733 |
|
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
734 |
|
for (;iter != parameters.end(); iter++) { |
735 |
|
if (s != "") s += ","; |
736 |
|
s += iter->first; |
737 |
|
} |
738 |
|
result.Add("PARAMETERS", s); |
739 |
|
} |
740 |
|
} |
741 |
|
catch (LinuxSamplerException e) { |
742 |
|
result.Error(e); |
743 |
|
} |
744 |
|
return result.Produce(); |
745 |
|
} |
746 |
|
|
747 |
String LSCPServer::GetAudioOutputDriverInfo(String Driver) { |
String LSCPServer::GetAudioOutputDriverInfo(String Driver) { |
748 |
dmsg(2,("LSCPServer: GetAudioOutputDriverInfo(Driver=%s)\n",Driver.c_str())); |
dmsg(2,("LSCPServer: GetAudioOutputDriverInfo(Driver=%s)\n",Driver.c_str())); |
749 |
LSCPResultSet result; |
LSCPResultSet result; |
768 |
return result.Produce(); |
return result.Produce(); |
769 |
} |
} |
770 |
|
|
771 |
|
String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) { |
772 |
|
dmsg(2,("LSCPServer: GetMidiInputDriverParameterInfo(Driver=%s,Parameter=%s,DependencyListSize=%d)\n",Driver.c_str(),Parameter.c_str(),DependencyList.size())); |
773 |
|
LSCPResultSet result; |
774 |
|
try { |
775 |
|
DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter); |
776 |
|
result.Add("TYPE", pParameter->Type()); |
777 |
|
result.Add("DESCRIPTION", pParameter->Description()); |
778 |
|
result.Add("MANDATORY", pParameter->Mandatory()); |
779 |
|
result.Add("FIX", pParameter->Fix()); |
780 |
|
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
781 |
|
optional<String> oDepends = pParameter->Depends(); |
782 |
|
optional<String> oDefault = pParameter->Default(DependencyList); |
783 |
|
optional<String> oRangeMin = pParameter->RangeMin(DependencyList); |
784 |
|
optional<String> oRangeMax = pParameter->RangeMax(DependencyList); |
785 |
|
optional<String> oPossibilities = pParameter->Possibilities(DependencyList); |
786 |
|
if (oDepends) result.Add("DEPENDS", *oDepends); |
787 |
|
if (oDefault) result.Add("DEFAULT", *oDefault); |
788 |
|
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
789 |
|
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
790 |
|
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
791 |
|
} |
792 |
|
catch (LinuxSamplerException e) { |
793 |
|
result.Error(e); |
794 |
|
} |
795 |
|
return result.Produce(); |
796 |
|
} |
797 |
|
|
798 |
String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) { |
String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) { |
799 |
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())); |
800 |
LSCPResultSet result; |
LSCPResultSet result; |
801 |
try { |
try { |
802 |
DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter); |
DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter); |
805 |
result.Add("MANDATORY", pParameter->Mandatory()); |
result.Add("MANDATORY", pParameter->Mandatory()); |
806 |
result.Add("FIX", pParameter->Fix()); |
result.Add("FIX", pParameter->Fix()); |
807 |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
808 |
if (pParameter->Depends()) result.Add("DEPENDS", pParameter->Depends()); |
optional<String> oDepends = pParameter->Depends(); |
809 |
if (pParameter->Default()) result.Add("DEFAULT", pParameter->Default()); |
optional<String> oDefault = pParameter->Default(DependencyList); |
810 |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", pParameter->RangeMin()); |
optional<String> oRangeMin = pParameter->RangeMin(DependencyList); |
811 |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", pParameter->RangeMax()); |
optional<String> oRangeMax = pParameter->RangeMax(DependencyList); |
812 |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities()); |
optional<String> oPossibilities = pParameter->Possibilities(DependencyList); |
813 |
|
if (oDepends) result.Add("DEPENDS", *oDepends); |
814 |
|
if (oDefault) result.Add("DEFAULT", *oDefault); |
815 |
|
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
816 |
|
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
817 |
|
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
818 |
} |
} |
819 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
820 |
result.Error(e); |
result.Error(e); |
827 |
LSCPResultSet result; |
LSCPResultSet result; |
828 |
try { |
try { |
829 |
uint count = pSampler->AudioOutputDevices(); |
uint count = pSampler->AudioOutputDevices(); |
830 |
result = count; // success |
result.Add(count); // success |
831 |
|
} |
832 |
|
catch (LinuxSamplerException e) { |
833 |
|
result.Error(e); |
834 |
|
} |
835 |
|
return result.Produce(); |
836 |
|
} |
837 |
|
|
838 |
|
String LSCPServer::GetMidiInputDeviceCount() { |
839 |
|
dmsg(2,("LSCPServer: GetMidiInputDeviceCount()\n")); |
840 |
|
LSCPResultSet result; |
841 |
|
try { |
842 |
|
uint count = pSampler->MidiInputDevices(); |
843 |
|
result.Add(count); // success |
844 |
} |
} |
845 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
846 |
result.Error(e); |
result.Error(e); |
867 |
return result.Produce(); |
return result.Produce(); |
868 |
} |
} |
869 |
|
|
870 |
|
String LSCPServer::GetMidiInputDevices() { |
871 |
|
dmsg(2,("LSCPServer: GetMidiInputDevices()\n")); |
872 |
|
LSCPResultSet result; |
873 |
|
try { |
874 |
|
String s; |
875 |
|
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
876 |
|
std::map<uint, MidiInputDevice*>::iterator iter = devices.begin(); |
877 |
|
for (; iter != devices.end(); iter++) { |
878 |
|
if (s != "") s += ","; |
879 |
|
s += ToString(iter->first); |
880 |
|
} |
881 |
|
result.Add(s); |
882 |
|
} |
883 |
|
catch (LinuxSamplerException e) { |
884 |
|
result.Error(e); |
885 |
|
} |
886 |
|
return result.Produce(); |
887 |
|
} |
888 |
|
|
889 |
String LSCPServer::GetAudioOutputDeviceInfo(uint DeviceIndex) { |
String LSCPServer::GetAudioOutputDeviceInfo(uint DeviceIndex) { |
890 |
dmsg(2,("LSCPServer: GetAudioOutputDeviceInfo(DeviceIndex=%d)\n",DeviceIndex)); |
dmsg(2,("LSCPServer: GetAudioOutputDeviceInfo(DeviceIndex=%d)\n",DeviceIndex)); |
891 |
LSCPResultSet result; |
LSCPResultSet result; |
892 |
try { |
try { |
893 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
894 |
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) + "."); |
895 |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
896 |
|
result.Add("DRIVER", pDevice->Driver()); |
897 |
|
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
898 |
|
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
899 |
|
for (; iter != parameters.end(); iter++) { |
900 |
|
result.Add(iter->first, iter->second->Value()); |
901 |
|
} |
902 |
|
} |
903 |
|
catch (LinuxSamplerException e) { |
904 |
|
result.Error(e); |
905 |
|
} |
906 |
|
return result.Produce(); |
907 |
|
} |
908 |
|
|
909 |
|
String LSCPServer::GetMidiInputDeviceInfo(uint DeviceIndex) { |
910 |
|
dmsg(2,("LSCPServer: GetMidiInputDeviceInfo(DeviceIndex=%d)\n",DeviceIndex)); |
911 |
|
LSCPResultSet result; |
912 |
|
try { |
913 |
|
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
914 |
|
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
915 |
|
MidiInputDevice* pDevice = devices[DeviceIndex]; |
916 |
|
result.Add("DRIVER", pDevice->Driver()); |
917 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
918 |
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
919 |
for (; iter != parameters.end(); iter++) { |
for (; iter != parameters.end(); iter++) { |
925 |
} |
} |
926 |
return result.Produce(); |
return result.Produce(); |
927 |
} |
} |
928 |
|
String LSCPServer::GetMidiInputPortInfo(uint DeviceIndex, uint PortIndex) { |
929 |
|
dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex)); |
930 |
|
LSCPResultSet result; |
931 |
|
try { |
932 |
|
// get MIDI input device |
933 |
|
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
934 |
|
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
935 |
|
MidiInputDevice* pDevice = devices[DeviceIndex]; |
936 |
|
|
937 |
|
// get MIDI port |
938 |
|
MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); |
939 |
|
if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); |
940 |
|
|
941 |
|
// return the values of all MIDI port parameters |
942 |
|
std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters(); |
943 |
|
std::map<String,DeviceRuntimeParameter*>::iterator iter = parameters.begin(); |
944 |
|
for (; iter != parameters.end(); iter++) { |
945 |
|
result.Add(iter->first, iter->second->Value()); |
946 |
|
} |
947 |
|
} |
948 |
|
catch (LinuxSamplerException e) { |
949 |
|
result.Error(e); |
950 |
|
} |
951 |
|
return result.Produce(); |
952 |
|
} |
953 |
|
|
954 |
String LSCPServer::GetAudioOutputChannelInfo(uint DeviceId, uint ChannelId) { |
String LSCPServer::GetAudioOutputChannelInfo(uint DeviceId, uint ChannelId) { |
955 |
dmsg(2,("LSCPServer: GetAudioOutputChannelInfo(DeviceId=%d,ChannelId)\n",DeviceId,ChannelId)); |
dmsg(2,("LSCPServer: GetAudioOutputChannelInfo(DeviceId=%d,ChannelId)\n",DeviceId,ChannelId)); |
957 |
try { |
try { |
958 |
// get audio output device |
// get audio output device |
959 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
960 |
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) + "."); |
961 |
AudioOutputDevice* pDevice = devices[DeviceId]; |
AudioOutputDevice* pDevice = devices[DeviceId]; |
962 |
|
|
963 |
// get audio channel |
// get audio channel |
977 |
return result.Produce(); |
return result.Produce(); |
978 |
} |
} |
979 |
|
|
980 |
|
String LSCPServer::GetMidiInputPortParameterInfo(uint DeviceId, uint PortId, String ParameterName) { |
981 |
|
dmsg(2,("LSCPServer: GetMidiInputPortParameterInfo(DeviceId=%d,PortId=%d,ParameterName=%s)\n",DeviceId,PortId,ParameterName.c_str())); |
982 |
|
LSCPResultSet result; |
983 |
|
try { |
984 |
|
// get MIDI input device |
985 |
|
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
986 |
|
if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no midi input device with index " + ToString(DeviceId) + "."); |
987 |
|
MidiInputDevice* pDevice = devices[DeviceId]; |
988 |
|
|
989 |
|
// get midi port |
990 |
|
MidiInputPort* pPort = pDevice->GetPort(PortId); |
991 |
|
if (!pPort) throw LinuxSamplerException("Midi input device does not have port " + ToString(PortId) + "."); |
992 |
|
|
993 |
|
// get desired port parameter |
994 |
|
std::map<String,DeviceRuntimeParameter*> parameters = pPort->PortParameters(); |
995 |
|
if (!parameters.count(ParameterName)) throw LinuxSamplerException("Midi port does not provide a parameter '" + ParameterName + "'."); |
996 |
|
DeviceRuntimeParameter* pParameter = parameters[ParameterName]; |
997 |
|
|
998 |
|
// return all fields of this audio channel parameter |
999 |
|
result.Add("TYPE", pParameter->Type()); |
1000 |
|
result.Add("DESCRIPTION", pParameter->Description()); |
1001 |
|
result.Add("FIX", pParameter->Fix()); |
1002 |
|
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
1003 |
|
if (pParameter->RangeMin()) result.Add("RANGE_MIN", *pParameter->RangeMin()); |
1004 |
|
if (pParameter->RangeMax()) result.Add("RANGE_MAX", *pParameter->RangeMax()); |
1005 |
|
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities()); |
1006 |
|
} |
1007 |
|
catch (LinuxSamplerException e) { |
1008 |
|
result.Error(e); |
1009 |
|
} |
1010 |
|
return result.Produce(); |
1011 |
|
} |
1012 |
|
|
1013 |
String LSCPServer::GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName) { |
String LSCPServer::GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName) { |
1014 |
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())); |
1015 |
LSCPResultSet result; |
LSCPResultSet result; |
1016 |
try { |
try { |
1017 |
// get audio output device |
// get audio output device |
1018 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1019 |
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) + "."); |
1020 |
AudioOutputDevice* pDevice = devices[DeviceId]; |
AudioOutputDevice* pDevice = devices[DeviceId]; |
1021 |
|
|
1022 |
// get audio channel |
// get audio channel |
1025 |
|
|
1026 |
// get desired audio channel parameter |
// get desired audio channel parameter |
1027 |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
1028 |
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 + "'."); |
1029 |
DeviceRuntimeParameter* pParameter = parameters[ParameterName]; |
DeviceRuntimeParameter* pParameter = parameters[ParameterName]; |
1030 |
|
|
1031 |
// return all fields of this audio channel parameter |
// return all fields of this audio channel parameter |
1033 |
result.Add("DESCRIPTION", pParameter->Description()); |
result.Add("DESCRIPTION", pParameter->Description()); |
1034 |
result.Add("FIX", pParameter->Fix()); |
result.Add("FIX", pParameter->Fix()); |
1035 |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
1036 |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", pParameter->RangeMin()); |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", *pParameter->RangeMin()); |
1037 |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", pParameter->RangeMax()); |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", *pParameter->RangeMax()); |
1038 |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities()); |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities()); |
1039 |
} |
} |
1040 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1041 |
result.Error(e); |
result.Error(e); |
1049 |
try { |
try { |
1050 |
// get audio output device |
// get audio output device |
1051 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1052 |
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) + "."); |
1053 |
AudioOutputDevice* pDevice = devices[DeviceId]; |
AudioOutputDevice* pDevice = devices[DeviceId]; |
1054 |
|
|
1055 |
// get audio channel |
// get audio channel |
1058 |
|
|
1059 |
// get desired audio channel parameter |
// get desired audio channel parameter |
1060 |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
1061 |
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 + "'."); |
1062 |
DeviceRuntimeParameter* pParameter = parameters[ParamKey]; |
DeviceRuntimeParameter* pParameter = parameters[ParamKey]; |
1063 |
|
|
1064 |
// set new channel parameter value |
// set new channel parameter value |
1075 |
LSCPResultSet result; |
LSCPResultSet result; |
1076 |
try { |
try { |
1077 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1078 |
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) + "."); |
1079 |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
1080 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
1081 |
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 + "'"); |
1082 |
|
parameters[ParamKey]->SetValue(ParamVal); |
1083 |
|
} |
1084 |
|
catch (LinuxSamplerException e) { |
1085 |
|
result.Error(e); |
1086 |
|
} |
1087 |
|
return result.Produce(); |
1088 |
|
} |
1089 |
|
|
1090 |
|
String LSCPServer::SetMidiInputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal) { |
1091 |
|
dmsg(2,("LSCPServer: SetMidiOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str())); |
1092 |
|
LSCPResultSet result; |
1093 |
|
try { |
1094 |
|
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1095 |
|
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
1096 |
|
MidiInputDevice* pDevice = devices[DeviceIndex]; |
1097 |
|
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
1098 |
|
if (!parameters.count(ParamKey)) throw LinuxSamplerException("MIDI input device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'"); |
1099 |
|
parameters[ParamKey]->SetValue(ParamVal); |
1100 |
|
} |
1101 |
|
catch (LinuxSamplerException e) { |
1102 |
|
result.Error(e); |
1103 |
|
} |
1104 |
|
return result.Produce(); |
1105 |
|
} |
1106 |
|
|
1107 |
|
String LSCPServer::SetMidiInputPortParameter(uint DeviceIndex, uint PortIndex, String ParamKey, String ParamVal) { |
1108 |
|
dmsg(2,("LSCPServer: SetMidiOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str())); |
1109 |
|
LSCPResultSet result; |
1110 |
|
try { |
1111 |
|
// get MIDI input device |
1112 |
|
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1113 |
|
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
1114 |
|
MidiInputDevice* pDevice = devices[DeviceIndex]; |
1115 |
|
|
1116 |
|
// get MIDI port |
1117 |
|
MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); |
1118 |
|
if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); |
1119 |
|
|
1120 |
|
// set port parameter value |
1121 |
|
std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters(); |
1122 |
|
if (!parameters.count(ParamKey)) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'"); |
1123 |
parameters[ParamKey]->SetValue(ParamVal); |
parameters[ParamKey]->SetValue(ParamVal); |
1124 |
} |
} |
1125 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1134 |
*/ |
*/ |
1135 |
String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) { |
String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) { |
1136 |
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)); |
1137 |
return "ERR:0:Not implemented yet.\r\n"; //FIXME: Add support for this in resultset class? |
LSCPResultSet result; |
1138 |
|
try { |
1139 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1140 |
|
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
1141 |
|
Engine* pEngine = pSamplerChannel->GetEngine(); |
1142 |
|
if (!pEngine) throw LinuxSamplerException("No engine deployed on sampler channel " + ToString(uiSamplerChannel)); |
1143 |
|
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1144 |
|
if (!devices.count(ChannelAudioOutputChannel)) throw LinuxSamplerException("There is no audio output device with index " + ToString(ChannelAudioOutputChannel)); |
1145 |
|
pEngine->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel); |
1146 |
|
} |
1147 |
|
catch (LinuxSamplerException e) { |
1148 |
|
result.Error(e); |
1149 |
|
} |
1150 |
|
return result.Produce(); |
1151 |
} |
} |
1152 |
|
|
1153 |
String LSCPServer::SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel) { |
String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) { |
1154 |
dmsg(2,("LSCPServer: SetMIDIInputType(String MidiInputDriver=%s, SamplerChannel=%d)\n",MidiInputDriver.c_str(),uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel)); |
1155 |
LSCPResultSet result; |
LSCPResultSet result; |
1156 |
try { |
try { |
1157 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1158 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
1159 |
// FIXME: workaround until MIDI driver configuration is implemented (using a Factory class for the MIDI input drivers then, like its already done for audio output drivers) |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1160 |
if (MidiInputDriver != "Alsa") throw LinuxSamplerException("Unknown MIDI input driver '" + MidiInputDriver + "'."); |
if (!devices.count(AudioDeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId)); |
1161 |
MidiInputDevice::type_t MidiInputType = MidiInputDevice::type_alsa; |
AudioOutputDevice* pDevice = devices[AudioDeviceId]; |
1162 |
pSamplerChannel->SetMidiInputDevice(MidiInputType); |
pSamplerChannel->SetAudioOutputDevice(pDevice); |
1163 |
} |
} |
1164 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1165 |
result.Error(e); |
result.Error(e); |
1167 |
return result.Produce(); |
return result.Produce(); |
1168 |
} |
} |
1169 |
|
|
1170 |
/** |
String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) { |
1171 |
* Will be called by the parser to change the MIDI input port on which the |
dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel)); |
|
* engine of a particular sampler channel should listen to. |
|
|
*/ |
|
|
String LSCPServer::SetMIDIInputPort(String MIDIInputPort, uint uiSamplerChannel) { |
|
|
dmsg(2,("LSCPServer: SetMIDIInputPort(MIDIInputPort=%s, Samplerchannel=%d)\n", MIDIInputPort.c_str(), uiSamplerChannel)); |
|
1172 |
LSCPResultSet result; |
LSCPResultSet result; |
1173 |
try { |
try { |
1174 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1175 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
1176 |
if (!pSamplerChannel->GetMidiInputDevice()) throw LinuxSamplerException("No MIDI input device connected yet"); |
// Driver type name aliasing... |
1177 |
pSamplerChannel->GetMidiInputDevice()->SetInputPort(MIDIInputPort.c_str()); |
if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA"; |
1178 |
|
if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK"; |
1179 |
|
// Check if there's one audio output device already created |
1180 |
|
// for the intended audio driver type (AudioOutputDriver)... |
1181 |
|
AudioOutputDevice *pDevice = NULL; |
1182 |
|
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1183 |
|
std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin(); |
1184 |
|
for (; iter != devices.end(); iter++) { |
1185 |
|
if ((iter->second)->Driver() == AudioOutputDriver) { |
1186 |
|
pDevice = iter->second; |
1187 |
|
break; |
1188 |
|
} |
1189 |
|
} |
1190 |
|
// If it doesn't exist, create a new one with default parameters... |
1191 |
|
if (pDevice == NULL) { |
1192 |
|
std::map<String,String> params; |
1193 |
|
pDevice = pSampler->CreateAudioOutputDevice(AudioOutputDriver, params); |
1194 |
|
} |
1195 |
|
// Must have a device... |
1196 |
|
if (pDevice == NULL) |
1197 |
|
throw LinuxSamplerException("Internal error: could not create audio output device."); |
1198 |
|
// Set it as the current channel device... |
1199 |
|
pSamplerChannel->SetAudioOutputDevice(pDevice); |
1200 |
|
} |
1201 |
|
catch (LinuxSamplerException e) { |
1202 |
|
result.Error(e); |
1203 |
|
} |
1204 |
|
return result.Produce(); |
1205 |
|
} |
1206 |
|
|
1207 |
|
String LSCPServer::SetMIDIInputPort(uint MIDIPort, uint uiSamplerChannel) { |
1208 |
|
dmsg(2,("LSCPServer: SetMIDIInputPort(MIDIPort=%d, SamplerChannel=%d)\n",MIDIPort,uiSamplerChannel)); |
1209 |
|
LSCPResultSet result; |
1210 |
|
try { |
1211 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1212 |
|
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
1213 |
|
pSamplerChannel->SetMidiInputPort(MIDIPort); |
1214 |
} |
} |
1215 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1216 |
result.Error(e); |
result.Error(e); |
1218 |
return result.Produce(); |
return result.Produce(); |
1219 |
} |
} |
1220 |
|
|
|
/** |
|
|
* Will be called by the parser to change the MIDI input channel on which the |
|
|
* engine of a particular sampler channel should listen to. |
|
|
*/ |
|
1221 |
String LSCPServer::SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel) { |
String LSCPServer::SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel) { |
1222 |
dmsg(2,("LSCPServer: SetMIDIInputChannel(MIDIChannel=%d, SamplerChannel=%d)\n", MIDIChannel, uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetMIDIInputChannel(MIDIChannel=%d, SamplerChannel=%d)\n",MIDIChannel,uiSamplerChannel)); |
1223 |
LSCPResultSet result; |
LSCPResultSet result; |
1224 |
try { |
try { |
1225 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1226 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
1227 |
if (!pSamplerChannel->GetMidiInputDevice()) throw LinuxSamplerException("No MIDI input device connected yet"); |
pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel); |
|
MidiInputDevice::type_t oldtype = pSamplerChannel->GetMidiInputDevice()->Type(); |
|
|
pSamplerChannel->SetMidiInputDevice(oldtype, (MidiInputDevice::midi_chan_t) MIDIChannel); |
|
1228 |
} |
} |
1229 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1230 |
result.Error(e); |
result.Error(e); |
1232 |
return result.Produce(); |
return result.Produce(); |
1233 |
} |
} |
1234 |
|
|
1235 |
String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint SamplerChannel) { |
String LSCPServer::SetMIDIInputDevice(uint MIDIDeviceId, uint uiSamplerChannel) { |
1236 |
|
dmsg(2,("LSCPServer: SetMIDIInputDevice(MIDIDeviceId=%d, SamplerChannel=%d)\n",MIDIDeviceId,uiSamplerChannel)); |
1237 |
LSCPResultSet result; |
LSCPResultSet result; |
1238 |
try { |
try { |
1239 |
throw LinuxSamplerException("Command not yet implemented"); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1240 |
|
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
1241 |
|
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1242 |
|
if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
1243 |
|
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
1244 |
|
pSamplerChannel->SetMidiInputDevice(pDevice); |
1245 |
|
} |
1246 |
|
catch (LinuxSamplerException e) { |
1247 |
|
result.Error(e); |
1248 |
|
} |
1249 |
|
return result.Produce(); |
1250 |
|
} |
1251 |
|
|
1252 |
|
String LSCPServer::SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel) { |
1253 |
|
dmsg(2,("LSCPServer: SetMIDIInputType(String MidiInputDriver=%s, SamplerChannel=%d)\n",MidiInputDriver.c_str(),uiSamplerChannel)); |
1254 |
|
LSCPResultSet result; |
1255 |
|
try { |
1256 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1257 |
|
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
1258 |
|
// Driver type name aliasing... |
1259 |
|
if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA"; |
1260 |
|
// Check if there's one MIDI input device already created |
1261 |
|
// for the intended MIDI driver type (MidiInputDriver)... |
1262 |
|
MidiInputDevice *pDevice = NULL; |
1263 |
|
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1264 |
|
std::map<uint, MidiInputDevice*>::iterator iter = devices.begin(); |
1265 |
|
for (; iter != devices.end(); iter++) { |
1266 |
|
if ((iter->second)->Driver() == MidiInputDriver) { |
1267 |
|
pDevice = iter->second; |
1268 |
|
break; |
1269 |
|
} |
1270 |
|
} |
1271 |
|
// If it doesn't exist, create a new one with default parameters... |
1272 |
|
if (pDevice == NULL) { |
1273 |
|
std::map<String,String> params; |
1274 |
|
pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params); |
1275 |
|
// Make it with at least one initial port. |
1276 |
|
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
1277 |
|
parameters["PORTS"]->SetValue("1"); |
1278 |
|
} |
1279 |
|
// Must have a device... |
1280 |
|
if (pDevice == NULL) |
1281 |
|
throw LinuxSamplerException("Internal error: could not create MIDI input device."); |
1282 |
|
// Set it as the current channel device... |
1283 |
|
pSamplerChannel->SetMidiInputDevice(pDevice); |
1284 |
|
} |
1285 |
|
catch (LinuxSamplerException e) { |
1286 |
|
result.Error(e); |
1287 |
|
} |
1288 |
|
return result.Produce(); |
1289 |
|
} |
1290 |
|
|
1291 |
|
/** |
1292 |
|
* Will be called by the parser to change the MIDI input device, port and channel on which |
1293 |
|
* engine of a particular sampler channel should listen to. |
1294 |
|
*/ |
1295 |
|
String LSCPServer::SetMIDIInput(uint MIDIDeviceId, uint MIDIPort, uint MIDIChannel, uint uiSamplerChannel) { |
1296 |
|
dmsg(2,("LSCPServer: SetMIDIInput(MIDIDeviceId=%d, MIDIPort=%d, MIDIChannel=%d, SamplerChannel=%d)\n", MIDIDeviceId, MIDIPort, MIDIChannel, uiSamplerChannel)); |
1297 |
|
LSCPResultSet result; |
1298 |
|
try { |
1299 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1300 |
|
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
1301 |
|
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1302 |
|
if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
1303 |
|
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
1304 |
|
pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (MidiInputPort::midi_chan_t) MIDIChannel); |
1305 |
} |
} |
1306 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1307 |
result.Error(e); |
result.Error(e); |
1313 |
* 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 |
1314 |
* particular sampler channel. |
* particular sampler channel. |
1315 |
*/ |
*/ |
1316 |
String LSCPServer::SetVolume(double Volume, uint uiSamplerChannel) { |
String LSCPServer::SetVolume(double dVolume, uint uiSamplerChannel) { |
1317 |
dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel)); |
1318 |
LSCPResultSet result; |
LSCPResultSet result; |
1319 |
try { |
try { |
1320 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1321 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
1322 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
1323 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
1324 |
pEngine->Volume(Volume); |
pEngine->Volume(dVolume); |
1325 |
} |
} |
1326 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1327 |
result.Error(e); |
result.Error(e); |
1349 |
} |
} |
1350 |
|
|
1351 |
/** |
/** |
1352 |
|
* Will be called by the parser to reset the whole sampler. |
1353 |
|
*/ |
1354 |
|
String LSCPServer::ResetSampler() { |
1355 |
|
dmsg(2,("LSCPServer: ResetSampler()\n")); |
1356 |
|
pSampler->Reset(); |
1357 |
|
LSCPResultSet result; |
1358 |
|
return result.Produce(); |
1359 |
|
} |
1360 |
|
|
1361 |
|
/** |
1362 |
* 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 |
1363 |
* server for receiving event messages. |
* server for receiving event messages. |
1364 |
*/ |
*/ |
1365 |
String LSCPServer::SubscribeNotification(event_t Event) { |
String LSCPServer::SubscribeNotification(LSCPEvent::event_t type) { |
1366 |
dmsg(2,("LSCPServer: SubscribeNotification(Event=%d)\n", Event)); |
dmsg(2,("LSCPServer: SubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str())); |
1367 |
return "ERR:0:Not implemented yet.\r\n"; |
LSCPResultSet result; |
1368 |
|
SubscriptionMutex.Lock(); |
1369 |
|
eventSubscriptions[type].push_back(currentSocket); |
1370 |
|
SubscriptionMutex.Unlock(); |
1371 |
|
return result.Produce(); |
1372 |
} |
} |
1373 |
|
|
1374 |
/** |
/** |
1375 |
* Will be called by the parser to unsubscribe a client on the server |
* Will be called by the parser to unsubscribe a client on the server |
1376 |
* for not receiving further event messages. |
* for not receiving further event messages. |
1377 |
*/ |
*/ |
1378 |
String LSCPServer::UnsubscribeNotification(event_t Event) { |
String LSCPServer::UnsubscribeNotification(LSCPEvent::event_t type) { |
1379 |
dmsg(2,("LSCPServer: UnsubscribeNotification(Event=%d)\n", Event)); |
dmsg(2,("LSCPServer: UnsubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str())); |
1380 |
return "ERR:0:Not implemented yet.\r\n"; |
LSCPResultSet result; |
1381 |
|
SubscriptionMutex.Lock(); |
1382 |
|
eventSubscriptions[type].remove(currentSocket); |
1383 |
|
SubscriptionMutex.Unlock(); |
1384 |
|
return result.Produce(); |
1385 |
} |
} |
1386 |
|
|
1387 |
|
/** |
1388 |
|
* Will be called by the parser to enable or disable echo mode; if echo |
1389 |
|
* mode is enabled, all commands from the client will (immediately) be |
1390 |
|
* echoed back to the client. |
1391 |
|
*/ |
1392 |
|
String LSCPServer::SetEcho(yyparse_param_t* pSession, double boolean_value) { |
1393 |
|
dmsg(2,("LSCPServer: SetEcho(val=%f)\n", boolean_value)); |
1394 |
|
LSCPResultSet result; |
1395 |
|
try { |
1396 |
|
if (boolean_value == 0) pSession->bVerbose = false; |
1397 |
|
else if (boolean_value == 1) pSession->bVerbose = true; |
1398 |
|
else throw LinuxSamplerException("Not a boolean value, must either be 0 or 1"); |
1399 |
|
} |
1400 |
|
catch (LinuxSamplerException e) { |
1401 |
|
result.Error(e); |
1402 |
|
} |
1403 |
|
return result.Produce(); |
1404 |
|
} |
1405 |
|
|
1406 |
// Instrument loader constructor. |
// Instrument loader constructor. |
1407 |
LSCPLoadInstrument::LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument) |
LSCPLoadInstrument::LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument) |