1 |
// device.c |
2 |
// |
3 |
/**************************************************************************** |
4 |
liblscp - LinuxSampler Control Protocol API |
5 |
Copyright (C) 2004, rncbc aka Rui Nuno Capela. All rights reserved. |
6 |
|
7 |
This library is free software; you can redistribute it and/or |
8 |
modify it under the terms of the GNU Lesser General Public |
9 |
License as published by the Free Software Foundation; either |
10 |
version 2.1 of the License, or (at your option) any later version. |
11 |
|
12 |
This library is distributed in the hope that it will be useful, |
13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 |
Lesser General Public License for more details. |
16 |
|
17 |
You should have received a copy of the GNU Lesser General Public |
18 |
License along with this library; if not, write to the Free Software |
19 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 |
|
21 |
*****************************************************************************/ |
22 |
|
23 |
#include "common.h" |
24 |
|
25 |
|
26 |
// Local prototypes. |
27 |
|
28 |
static lscp_driver_info_t *_lscp_driver_info_query (lscp_client_t *pClient, lscp_driver_info_t *pDriverInfo, char *pszQuery); |
29 |
static lscp_param_info_t *_lscp_param_info_query (lscp_client_t *pClient, lscp_param_info_t *pParamInfo, char *pszQuery, lscp_param_t *pDepList); |
30 |
|
31 |
|
32 |
//------------------------------------------------------------------------- |
33 |
// Local funtions. |
34 |
|
35 |
// Common driver type query command. |
36 |
static lscp_driver_info_t *_lscp_driver_info_query ( lscp_client_t *pClient, lscp_driver_info_t *pDriverInfo, char *pszQuery ) |
37 |
{ |
38 |
const char *pszResult; |
39 |
const char *pszSeps = ":"; |
40 |
const char *pszCrlf = "\r\n"; |
41 |
char *pszToken; |
42 |
char *pch; |
43 |
|
44 |
// Lock this section up. |
45 |
lscp_mutex_lock(pClient->mutex); |
46 |
|
47 |
lscp_driver_info_reset(pDriverInfo); |
48 |
if (lscp_client_call(pClient, pszQuery) == LSCP_OK) { |
49 |
pszResult = lscp_client_get_result(pClient); |
50 |
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
51 |
while (pszToken) { |
52 |
if (strcasecmp(pszToken, "DESCRIPTION") == 0) { |
53 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
54 |
if (pszToken) |
55 |
pDriverInfo->description = lscp_unquote(&pszToken, 1); |
56 |
} |
57 |
else if (strcasecmp(pszToken, "VERSION") == 0) { |
58 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
59 |
if (pszToken) |
60 |
pDriverInfo->version = lscp_unquote(&pszToken, 1); |
61 |
} |
62 |
else if (strcasecmp(pszToken, "PARAMETERS") == 0) { |
63 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
64 |
if (pszToken) |
65 |
pDriverInfo->parameters = lscp_szsplit_create(pszToken, ","); |
66 |
} |
67 |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
68 |
} |
69 |
} |
70 |
|
71 |
// Unlock this section down. |
72 |
lscp_mutex_unlock(pClient->mutex); |
73 |
|
74 |
return pDriverInfo; |
75 |
} |
76 |
|
77 |
|
78 |
// Common parameter info query command. |
79 |
static lscp_param_info_t *_lscp_param_info_query ( lscp_client_t *pClient, lscp_param_info_t *pParamInfo, char *pszQuery, lscp_param_t *pDepList ) |
80 |
{ |
81 |
const char *pszResult; |
82 |
const char *pszSeps = ":"; |
83 |
const char *pszCrlf = "\r\n"; |
84 |
char *pszToken; |
85 |
char *pch; |
86 |
|
87 |
// Lock this section up. |
88 |
lscp_mutex_lock(pClient->mutex); |
89 |
|
90 |
lscp_param_info_reset(pParamInfo); |
91 |
lscp_param_concat(pszQuery, LSCP_BUFSIZ, pDepList); |
92 |
if (lscp_client_call(pClient, pszQuery) == LSCP_OK) { |
93 |
pszResult = lscp_client_get_result(pClient); |
94 |
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
95 |
while (pszToken) { |
96 |
if (strcasecmp(pszToken, "TYPE") == 0) { |
97 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
98 |
if (pszToken) { |
99 |
pszToken = lscp_unquote(&pszToken, 0); |
100 |
if (strcasecmp(pszToken, "BOOL") == 0) |
101 |
pParamInfo->type = LSCP_TYPE_BOOL; |
102 |
else if (strcasecmp(pszToken, "INT") == 0) |
103 |
pParamInfo->type = LSCP_TYPE_INT; |
104 |
else if (strcasecmp(pszToken, "FLOAT") == 0) |
105 |
pParamInfo->type = LSCP_TYPE_FLOAT; |
106 |
else if (strcasecmp(pszToken, "STRING") == 0) |
107 |
pParamInfo->type = LSCP_TYPE_STRING; |
108 |
} |
109 |
} |
110 |
else if (strcasecmp(pszToken, "DESCRIPTION") == 0) { |
111 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
112 |
if (pszToken) |
113 |
pParamInfo->description = lscp_unquote(&pszToken, 1); |
114 |
} |
115 |
else if (strcasecmp(pszToken, "MANDATORY") == 0) { |
116 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
117 |
if (pszToken) |
118 |
pParamInfo->mandatory = (strcasecmp(lscp_unquote(&pszToken, 0), "TRUE") == 0); |
119 |
} |
120 |
else if (strcasecmp(pszToken, "FIX") == 0) { |
121 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
122 |
if (pszToken) |
123 |
pParamInfo->fix = (strcasecmp(lscp_unquote(&pszToken, 0), "TRUE") == 0); |
124 |
} |
125 |
else if (strcasecmp(pszToken, "MULTIPLICITY") == 0) { |
126 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
127 |
if (pszToken) |
128 |
pParamInfo->multiplicity = (strcasecmp(lscp_unquote(&pszToken, 0), "TRUE") == 0); |
129 |
} |
130 |
else if (strcasecmp(pszToken, "DEPENDS") == 0) { |
131 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
132 |
if (pszToken) |
133 |
pParamInfo->depends = lscp_szsplit_create(pszToken, ","); |
134 |
} |
135 |
else if (strcasecmp(pszToken, "DEFAULT") == 0) { |
136 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
137 |
if (pszToken) |
138 |
pParamInfo->defaultv = lscp_unquote(&pszToken, 1); |
139 |
} |
140 |
else if (strcasecmp(pszToken, "RANGE_MIN") == 0) { |
141 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
142 |
if (pszToken) |
143 |
pParamInfo->range_min = lscp_unquote(&pszToken, 1); |
144 |
} |
145 |
else if (strcasecmp(pszToken, "RANGE_MAX") == 0) { |
146 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
147 |
if (pszToken) |
148 |
pParamInfo->range_max = lscp_unquote(&pszToken, 1); |
149 |
} |
150 |
else if (strcasecmp(pszToken, "POSSIBILITIES") == 0) { |
151 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
152 |
if (pszToken) |
153 |
pParamInfo->possibilities = lscp_szsplit_create(pszToken, ","); |
154 |
} |
155 |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
156 |
} |
157 |
} |
158 |
|
159 |
// Unlock this section down. |
160 |
lscp_mutex_unlock(pClient->mutex); |
161 |
|
162 |
return pParamInfo; |
163 |
} |
164 |
|
165 |
|
166 |
//------------------------------------------------------------------------- |
167 |
// Audio driver control functions. |
168 |
|
169 |
/** |
170 |
* Getting all available audio output drivers. |
171 |
* GET AVAILABLE_AUDIO_OUTPUT_DRIVERS |
172 |
* |
173 |
* @param pClient Pointer to client instance structure. |
174 |
* |
175 |
* @returns A NULL terminated array of audio output driver type |
176 |
* name strings, or NULL in case of failure. |
177 |
*/ |
178 |
const char ** lscp_get_available_audio_drivers ( lscp_client_t *pClient ) |
179 |
{ |
180 |
const char *pszSeps = ","; |
181 |
|
182 |
// Lock this section up. |
183 |
lscp_mutex_lock(pClient->mutex); |
184 |
|
185 |
if (pClient->audio_drivers) { |
186 |
lscp_szsplit_destroy(pClient->audio_drivers); |
187 |
pClient->audio_drivers = NULL; |
188 |
} |
189 |
|
190 |
if (lscp_client_call(pClient, "GET AVAILABLE_AUDIO_OUTPUT_DRIVERS\r\n") == LSCP_OK) |
191 |
pClient->audio_drivers = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps); |
192 |
|
193 |
// Unlock this section down. |
194 |
lscp_mutex_unlock(pClient->mutex); |
195 |
|
196 |
return (const char **) pClient->audio_drivers; |
197 |
} |
198 |
|
199 |
|
200 |
/** |
201 |
* Getting informations about a specific audio output driver. |
202 |
* GET AUDIO_OUTPUT_DRIVER INFO <audio-output-type> |
203 |
* |
204 |
* @param pClient Pointer to client instance structure. |
205 |
* @param pszAudioDriver Audio driver type string (e.g. "ALSA"). |
206 |
* |
207 |
* @returns A pointer to a @ref lscp_driver_info_t structure, with |
208 |
* the given audio driver information, or NULL in case of failure. |
209 |
*/ |
210 |
lscp_driver_info_t* lscp_get_audio_driver_info ( lscp_client_t *pClient, const char *pszAudioDriver ) |
211 |
{ |
212 |
char szQuery[LSCP_BUFSIZ]; |
213 |
|
214 |
if (pszAudioDriver == NULL) |
215 |
return NULL; |
216 |
|
217 |
sprintf(szQuery, "GET AUDIO_OUTPUT_DRIVER INFO %s\r\n", pszAudioDriver); |
218 |
return _lscp_driver_info_query(pClient, &(pClient->audio_info), szQuery); |
219 |
} |
220 |
|
221 |
|
222 |
/** |
223 |
* Getting informations about specific audio output driver parameter. |
224 |
* GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO <audio-output-driver> <param> [<dep-list>] |
225 |
* |
226 |
* @param pClient Pointer to client instance structure. |
227 |
* @param pszAudioDriver Audio driver type string (e.g. "ALSA"). |
228 |
* @param pszParam Audio driver parameter name. |
229 |
* @param pDepList Pointer to specific dependencies parameter list. |
230 |
* |
231 |
* @returns A pointer to a @ref lscp_param_info_t structure, with |
232 |
* the given audio driver parameter information, or NULL in case of failure. |
233 |
*/ |
234 |
lscp_param_info_t *lscp_get_audio_driver_param_info ( lscp_client_t *pClient, const char *pszAudioDriver, const char *pszParam, lscp_param_t *pDepList ) |
235 |
{ |
236 |
char szQuery[LSCP_BUFSIZ]; |
237 |
|
238 |
if (pClient == NULL) |
239 |
return NULL; |
240 |
if (pszAudioDriver == NULL) |
241 |
return NULL; |
242 |
if (pszParam == NULL) |
243 |
return NULL; |
244 |
|
245 |
sprintf(szQuery, "GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO %s %s\r\n", pszAudioDriver, pszParam); |
246 |
return _lscp_param_info_query(pClient, &(pClient->audio_param_info), szQuery, pDepList); |
247 |
} |
248 |
|
249 |
|
250 |
//------------------------------------------------------------------------- |
251 |
// Audio device control functions. |
252 |
|
253 |
/** |
254 |
* Creating an audio output device. |
255 |
* CREATE AUDIO_OUTPUT_DEVICE <audio-output-driver> [<params>] |
256 |
* |
257 |
* @param pClient Pointer to client instance structure. |
258 |
* @param pszAudioDriver Audio driver type string (e.g. "ALSA"). |
259 |
* @param pParams Pointer to specific parameter list. |
260 |
* |
261 |
* @returns The new audio device number identifier on success, |
262 |
* or -1 in case of failure. |
263 |
*/ |
264 |
int lscp_create_audio_device ( lscp_client_t *pClient, const char *pszAudioDriver, lscp_param_t *pParams ) |
265 |
{ |
266 |
int iAudioDevice = -1; |
267 |
|
268 |
if (pClient == NULL) |
269 |
return -1; |
270 |
if (pszAudioDriver == NULL) |
271 |
return -1; |
272 |
if (pParams == NULL) |
273 |
return -1; |
274 |
|
275 |
return iAudioDevice; |
276 |
} |
277 |
|
278 |
|
279 |
/** |
280 |
* Destroying an audio output device. |
281 |
* DESTROY AUDIO_OUTPUT_DEVICE <audio-device-id> |
282 |
* |
283 |
* @param pClient Pointer to client instance structure. |
284 |
* @param iAudioDevice Audio device number identifier. |
285 |
* |
286 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
287 |
*/ |
288 |
lscp_status_t lscp_destroy_audio_device ( lscp_client_t *pClient, int iAudioDevice ) |
289 |
{ |
290 |
lscp_status_t ret = LSCP_FAILED; |
291 |
|
292 |
if (pClient == NULL) |
293 |
return ret; |
294 |
if (iAudioDevice < 0) |
295 |
return ret; |
296 |
|
297 |
return ret; |
298 |
} |
299 |
|
300 |
|
301 |
/** |
302 |
* Getting all created audio output device count. |
303 |
* GET AUDIO_OUTPUT_DEVICES |
304 |
* |
305 |
* @param pClient Pointer to client instance structure. |
306 |
* |
307 |
* @returns The current total number of audio devices on success, |
308 |
* -1 otherwise. |
309 |
*/ |
310 |
int lscp_get_audio_devices ( lscp_client_t *pClient ) |
311 |
{ |
312 |
int iAudioDevices = -1; |
313 |
|
314 |
// Lock this section up. |
315 |
lscp_mutex_lock(pClient->mutex); |
316 |
|
317 |
if (lscp_client_call(pClient, "GET AUDIO_OUTPUT_DEVICES\r\n") == LSCP_OK) |
318 |
iAudioDevices = atoi(lscp_client_get_result(pClient)); |
319 |
|
320 |
// Unlock this section down. |
321 |
lscp_mutex_unlock(pClient->mutex); |
322 |
|
323 |
return iAudioDevices; |
324 |
} |
325 |
|
326 |
|
327 |
/** |
328 |
* Getting all created audio output device list. |
329 |
* LIST AUDIO_OUTPUT_DEVICES |
330 |
* |
331 |
* @param pClient Pointer to client instance structure. |
332 |
* |
333 |
* @returns An array of audio device number identifiers, |
334 |
* terminated with -1 on success, or NULL in case of failure. |
335 |
*/ |
336 |
int *lscp_list_audio_devices ( lscp_client_t *pClient ) |
337 |
{ |
338 |
const char *pszSeps = ","; |
339 |
|
340 |
if (pClient == NULL) |
341 |
return NULL; |
342 |
|
343 |
// Lock this section up. |
344 |
lscp_mutex_lock(pClient->mutex); |
345 |
|
346 |
if (pClient->audio_devices) { |
347 |
lscp_isplit_destroy(pClient->audio_devices); |
348 |
pClient->audio_devices = NULL; |
349 |
} |
350 |
|
351 |
if (lscp_client_call(pClient, "LIST AUDIO_OUTPUT_DEVICES\r\n") == LSCP_OK) |
352 |
pClient->audio_devices = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps); |
353 |
|
354 |
// Unlock this section down. |
355 |
lscp_mutex_unlock(pClient->mutex); |
356 |
|
357 |
return pClient->audio_devices; |
358 |
} |
359 |
|
360 |
|
361 |
/** |
362 |
* Getting current settings of an audio output device. |
363 |
* GET AUDIO_OUTPUT_DEVICE INFO <audio-device-id> |
364 |
* |
365 |
* @param pClient Pointer to client instance structure. |
366 |
* @param iAudioDevice Audio device number identifier. |
367 |
* |
368 |
* @returns A pointer to a @ref lscp_device_info_t structure, with |
369 |
* the given audio device information, or NULL in case of failure. |
370 |
*/ |
371 |
lscp_device_info_t *lscp_get_audio_device_info ( lscp_client_t *pClient, int iAudioDevice ) |
372 |
{ |
373 |
lscp_device_info_t *pDeviceInfo = NULL; |
374 |
|
375 |
if (pClient == NULL) |
376 |
return NULL; |
377 |
if (iAudioDevice < 0) |
378 |
return NULL; |
379 |
|
380 |
return pDeviceInfo; |
381 |
} |
382 |
|
383 |
|
384 |
/** |
385 |
* Changing settings of audio output devices. |
386 |
* SET AUDIO_OUTPUT_DEVICE_PARAMETER <audio-device-id> <param> <value> |
387 |
* |
388 |
* @param pClient Pointer to client instance structure. |
389 |
* @param iAudioDevice Audio device number identifier. |
390 |
* @param pParam Pointer to a key-valued audio device parameter. |
391 |
* |
392 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
393 |
*/ |
394 |
lscp_status_t lscp_set_audio_device_param ( lscp_client_t *pClient, int iAudioDevice, lscp_param_t *pParam ) |
395 |
{ |
396 |
lscp_status_t ret = LSCP_FAILED; |
397 |
|
398 |
if (pClient == NULL) |
399 |
return ret; |
400 |
if (iAudioDevice < 0) |
401 |
return ret; |
402 |
if (pParam == NULL) |
403 |
return ret; |
404 |
|
405 |
return ret; |
406 |
} |
407 |
|
408 |
|
409 |
/** |
410 |
* Getting informations about an audio channel. |
411 |
* GET AUDIO_OUTPUT_CHANNEL INFO <audio-device-id> <audio-channel> |
412 |
* |
413 |
* @param pClient Pointer to client instance structure. |
414 |
* @param iAudioDevice Audio device number identifier. |
415 |
* @param iAudioChannel Audio channel number. |
416 |
* |
417 |
* @returns A pointer to a @ref lscp_device_channel_info_t structure, |
418 |
* with the given audio channel information, or NULL in case of failure. |
419 |
*/ |
420 |
lscp_device_channel_info_t* lscp_get_audio_channel_info ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel ) |
421 |
{ |
422 |
lscp_device_channel_info_t *pDevChannelInfo = NULL; |
423 |
|
424 |
if (pClient == NULL) |
425 |
return NULL; |
426 |
if (iAudioDevice < 0) |
427 |
return NULL; |
428 |
if (iAudioChannel < 0) |
429 |
return NULL; |
430 |
|
431 |
return pDevChannelInfo; |
432 |
} |
433 |
|
434 |
|
435 |
/** |
436 |
* Getting informations about specific audio channel parameter. |
437 |
* GET AUDIO_OUTPUT_CHANNEL_PARAMETER INFO <audio-device-id> <audio-channel> <param> |
438 |
* |
439 |
* @param pClient Pointer to client instance structure. |
440 |
* @param iAudioDevice Audio device number identifier. |
441 |
* @param iAudioChannel Audio channel number. |
442 |
* @param pszParam Audio channel parameter name. |
443 |
* |
444 |
* @returns A pointer to a @ref lscp_param_info_t structure, with |
445 |
* the given audio channel parameter information, or NULL in case of failure. |
446 |
*/ |
447 |
lscp_param_info_t* lscp_get_audio_channel_param_info ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel, const char *pszParam ) |
448 |
{ |
449 |
lscp_param_info_t *pParamInfo = NULL; |
450 |
|
451 |
if (pClient == NULL) |
452 |
return NULL; |
453 |
if (iAudioDevice < 0) |
454 |
return NULL; |
455 |
if (iAudioChannel < 0) |
456 |
return NULL; |
457 |
if (pszParam == NULL) |
458 |
return NULL; |
459 |
|
460 |
return pParamInfo; |
461 |
} |
462 |
|
463 |
|
464 |
/** |
465 |
* Changing settings of audio output channels. |
466 |
* SET AUDIO_OUTPUT_CHANNEL_PARAMETER <audio-device-id> <audio-channel> <param> <value> |
467 |
* |
468 |
* @param pClient Pointer to client instance structure. |
469 |
* @param iAudioDevice Audio device number identifier. |
470 |
* @param iAudioChannel Audio channel number. |
471 |
* @param pParam Pointer to a key-valued audio channel parameter. |
472 |
* |
473 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
474 |
*/ |
475 |
lscp_status_t lscp_set_audio_channel_param ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel, lscp_param_t *pParam ) |
476 |
{ |
477 |
lscp_status_t ret = LSCP_FAILED; |
478 |
|
479 |
if (pClient == NULL) |
480 |
return ret; |
481 |
if (iAudioDevice < 0) |
482 |
return ret; |
483 |
if (iAudioChannel < 0) |
484 |
return ret; |
485 |
if (pParam == NULL) |
486 |
return ret; |
487 |
|
488 |
return ret; |
489 |
} |
490 |
|
491 |
|
492 |
//------------------------------------------------------------------------- |
493 |
// MIDI driver control functions. |
494 |
|
495 |
/** |
496 |
* Getting all available MIDI input drivers. |
497 |
* GET AVAILABLE_MIDI_INPUT_DRIVERS |
498 |
* |
499 |
* @param pClient Pointer to client instance structure. |
500 |
* |
501 |
* @returns A NULL terminated array of MIDI input driver type |
502 |
* name strings, or NULL in case of failure. |
503 |
*/ |
504 |
const char** lscp_get_available_midi_drivers ( lscp_client_t *pClient ) |
505 |
{ |
506 |
const char *pszSeps = ","; |
507 |
|
508 |
// Lock this section up. |
509 |
lscp_mutex_lock(pClient->mutex); |
510 |
|
511 |
if (pClient->midi_drivers) { |
512 |
lscp_szsplit_destroy(pClient->midi_drivers); |
513 |
pClient->midi_drivers = NULL; |
514 |
} |
515 |
|
516 |
if (lscp_client_call(pClient, "GET AVAILABLE_MIDI_INPUT_DRIVERS\r\n") == LSCP_OK) |
517 |
pClient->midi_drivers = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps); |
518 |
|
519 |
// Unlock this section up. |
520 |
lscp_mutex_unlock(pClient->mutex); |
521 |
|
522 |
return (const char **) pClient->midi_drivers; |
523 |
} |
524 |
|
525 |
|
526 |
/** |
527 |
* Getting informations about a specific MIDI input driver. |
528 |
* GET MIDI_INPUT_DRIVER INFO <midi-input-type> |
529 |
* |
530 |
* @param pClient Pointer to client instance structure. |
531 |
* @param pszMidiDriver MIDI driver type string (e.g. "ALSA"). |
532 |
* |
533 |
* @returns A pointer to a @ref lscp_driver_info_t structure, with |
534 |
* the given MIDI driver information, or NULL in case of failure. |
535 |
*/ |
536 |
lscp_driver_info_t* lscp_get_midi_driver_info ( lscp_client_t *pClient, const char *pszMidiDriver ) |
537 |
{ |
538 |
char szQuery[LSCP_BUFSIZ]; |
539 |
|
540 |
if (pszMidiDriver == NULL) |
541 |
return NULL; |
542 |
|
543 |
sprintf(szQuery, "GET MIDI_INPUT_DRIVER INFO %s\r\n", pszMidiDriver); |
544 |
return _lscp_driver_info_query(pClient, &(pClient->midi_info), szQuery); |
545 |
} |
546 |
|
547 |
|
548 |
/** |
549 |
* Getting informations about specific MIDI input driver parameter. |
550 |
* GET MIDI_INPUT_DRIVER_PARAMETER INFO <midi-input-driver> <param> [<dep-list>] |
551 |
* |
552 |
* @param pClient Pointer to client instance structure. |
553 |
* @param pszMidiDriver MIDI driver type string (e.g. "ALSA"). |
554 |
* @param pszParam MIDI driver parameter name. |
555 |
* @param pDepList Pointer to specific dependencies parameter list. |
556 |
* |
557 |
* @returns A pointer to a @ref lscp_param_info_t structure, with |
558 |
* the given MIDI driver parameter information, or NULL in case of failure. |
559 |
* |
560 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
561 |
*/ |
562 |
lscp_param_info_t *lscp_get_midi_driver_param_info ( lscp_client_t *pClient, const char *pszMidiDriver, const char *pszParam, lscp_param_t *pDepList ) |
563 |
{ |
564 |
char szQuery[LSCP_BUFSIZ]; |
565 |
|
566 |
if (pClient == NULL) |
567 |
return NULL; |
568 |
if (pszMidiDriver == NULL) |
569 |
return NULL; |
570 |
if (pszParam == NULL) |
571 |
return NULL; |
572 |
|
573 |
sprintf(szQuery, "GET MIDI_INPUT_DRIVER_PARAMETER INFO %s %s\r\n", pszMidiDriver, pszParam); |
574 |
return _lscp_param_info_query(pClient, &(pClient->midi_param_info), szQuery, pDepList); |
575 |
} |
576 |
|
577 |
|
578 |
//------------------------------------------------------------------------- |
579 |
// MIDI device control functions. |
580 |
|
581 |
/** |
582 |
* Creating a MIDI input device. |
583 |
* CREATE MIDI_INPUT_DEVICE <midi-input-driver> [<params>] |
584 |
* |
585 |
* @param pClient Pointer to client instance structure. |
586 |
* @param pszMidiDriver MIDI driver type string (e.g. "ALSA"). |
587 |
* @param pParams Pointer to specific parameter list. |
588 |
* |
589 |
* @returns The new audio device number identifier on success, |
590 |
* or -1 in case of failure. |
591 |
*/ |
592 |
int lscp_create_midi_device ( lscp_client_t *pClient, const char *pszMidiDriver, lscp_param_t *pParams ) |
593 |
{ |
594 |
int iMidiDevice = -1; |
595 |
|
596 |
if (pClient == NULL) |
597 |
return -1; |
598 |
if (pszMidiDriver == NULL) |
599 |
return -1; |
600 |
if (pParams == NULL) |
601 |
return -1; |
602 |
|
603 |
return iMidiDevice; |
604 |
} |
605 |
|
606 |
|
607 |
/** |
608 |
* Destroying a MIDI input device. |
609 |
* DESTROY MIDI_INPUT_DEVICE <midi-device-id> |
610 |
* |
611 |
* @param pClient Pointer to client instance structure. |
612 |
* @param iMidiDevice MIDI device number identifier. |
613 |
* |
614 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
615 |
*/ |
616 |
lscp_status_t lscp_destroy_midi_device ( lscp_client_t *pClient, int iMidiDevice ) |
617 |
{ |
618 |
lscp_status_t ret = LSCP_FAILED; |
619 |
|
620 |
if (pClient == NULL) |
621 |
return ret; |
622 |
if (iMidiDevice < 0) |
623 |
return ret; |
624 |
|
625 |
return ret; |
626 |
} |
627 |
|
628 |
|
629 |
/** |
630 |
* Getting all created MIDI intput device count. |
631 |
* GET MIDI_INPUT_DEVICES |
632 |
* |
633 |
* @param pClient Pointer to client instance structure. |
634 |
* |
635 |
* @returns The current total number of MIDI devices on success, |
636 |
* -1 otherwise. |
637 |
*/ |
638 |
int lscp_get_midi_devices ( lscp_client_t *pClient ) |
639 |
{ |
640 |
int iMidiDevices = -1; |
641 |
|
642 |
// Lock this section up. |
643 |
lscp_mutex_lock(pClient->mutex); |
644 |
|
645 |
if (lscp_client_call(pClient, "GET MIDI_INPUT_DEVICES\r\n") == LSCP_OK) |
646 |
iMidiDevices = atoi(lscp_client_get_result(pClient)); |
647 |
|
648 |
// Unlock this section down. |
649 |
lscp_mutex_unlock(pClient->mutex); |
650 |
|
651 |
return iMidiDevices; |
652 |
} |
653 |
|
654 |
|
655 |
/** |
656 |
* Getting all created MIDI intput device list. |
657 |
* LIST MIDI_INPUT_DEVICES |
658 |
* |
659 |
* @param pClient Pointer to client instance structure. |
660 |
* |
661 |
* @returns An array of MIDI device number identifiers, |
662 |
* terminated with -1 on success, or NULL in case of failure. |
663 |
*/ |
664 |
int *lscp_list_midi_devices ( lscp_client_t *pClient ) |
665 |
{ |
666 |
const char *pszSeps = ","; |
667 |
|
668 |
if (pClient == NULL) |
669 |
return NULL; |
670 |
|
671 |
// Lock this section up. |
672 |
lscp_mutex_lock(pClient->mutex); |
673 |
|
674 |
if (pClient->midi_devices) { |
675 |
lscp_isplit_destroy(pClient->midi_devices); |
676 |
pClient->midi_devices = NULL; |
677 |
} |
678 |
|
679 |
if (lscp_client_call(pClient, "LIST MIDI_INPUT_DEVICES\r\n") == LSCP_OK) |
680 |
pClient->midi_devices = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps); |
681 |
|
682 |
// Unlock this section down. |
683 |
lscp_mutex_unlock(pClient->mutex); |
684 |
|
685 |
return pClient->midi_devices; |
686 |
} |
687 |
|
688 |
|
689 |
/** |
690 |
* Getting current settings of a MIDI input device. |
691 |
* GET MIDI_INPUT_DEVICE INFO <midi-device-id> |
692 |
* |
693 |
* @param pClient Pointer to client instance structure. |
694 |
* @param iMidiDevice MIDI device number identifier. |
695 |
* |
696 |
* @returns A pointer to a @ref lscp_device_info_t structure, with |
697 |
* the given MIDI device information, or NULL in case of failure. |
698 |
*/ |
699 |
lscp_device_info_t* lscp_get_midi_device_info ( lscp_client_t *pClient, int iMidiDevice ) |
700 |
{ |
701 |
lscp_device_info_t *pDeviceInfo = NULL; |
702 |
|
703 |
if (pClient == NULL) |
704 |
return NULL; |
705 |
if (iMidiDevice < 0) |
706 |
return NULL; |
707 |
|
708 |
return pDeviceInfo; |
709 |
} |
710 |
|
711 |
|
712 |
/** |
713 |
* Changing settings of MIDI input devices. |
714 |
* SET MIDI_INPUT_DEVICE_PARAMETER <midi-device-id> <param> <value> |
715 |
* |
716 |
* @param pClient Pointer to client instance structure. |
717 |
* @param iMidiDevice MIDI device number identifier. |
718 |
* @param pParam Pointer to a key-valued MIDI device parameter. |
719 |
* |
720 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
721 |
*/ |
722 |
lscp_status_t lscp_set_midi_device_param ( lscp_client_t *pClient, int iMidiDevice, lscp_param_t *pParam ) |
723 |
{ |
724 |
lscp_status_t ret = LSCP_FAILED; |
725 |
|
726 |
if (pClient == NULL) |
727 |
return ret; |
728 |
if (iMidiDevice < 0) |
729 |
return ret; |
730 |
if (pParam == NULL) |
731 |
return ret; |
732 |
|
733 |
return ret; |
734 |
} |
735 |
|
736 |
|
737 |
/** |
738 |
* Getting informations about a MIDI port. |
739 |
* GET MIDI_INPUT_PORT INFO <midi-device-id> <midi-port> |
740 |
* |
741 |
* @param pClient Pointer to client instance structure. |
742 |
* @param iMidiDevice MIDI device number identifier. |
743 |
* @param iMidiPort MIDI port number. |
744 |
* |
745 |
* @returns A pointer to a @ref lscp_device_channel_info_t structure, |
746 |
* with the given MIDI port information, or NULL in case of failure. |
747 |
*/ |
748 |
lscp_device_channel_info_t* lscp_get_midi_port_info ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort ) |
749 |
{ |
750 |
lscp_device_channel_info_t *pDevChannelInfo = NULL; |
751 |
|
752 |
if (pClient == NULL) |
753 |
return NULL; |
754 |
if (iMidiDevice < 0) |
755 |
return NULL; |
756 |
if (iMidiPort < 0) |
757 |
return NULL; |
758 |
|
759 |
return pDevChannelInfo; |
760 |
} |
761 |
|
762 |
|
763 |
/** |
764 |
* Getting informations about specific MIDI port parameter. |
765 |
* GET MIDI_INPUT_PORT_PARAMETER INFO <midi-device-id> <midi-port> <param> |
766 |
* |
767 |
* @param pClient Pointer to client instance structure. |
768 |
* @param iMidiDevice MIDI device number identifier. |
769 |
* @param iMidiPort MIDI port number. |
770 |
* @param pszParam MIDI port parameter name. |
771 |
* |
772 |
* @returns A pointer to a @ref lscp_param_info_t structure, with |
773 |
* the given MIDI port parameter information, or NULL in case of failure. |
774 |
*/ |
775 |
lscp_param_info_t* lscp_get_midi_port_param_info ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort, const char *pszParam ) |
776 |
{ |
777 |
lscp_param_info_t *pParamInfo = NULL; |
778 |
|
779 |
if (pClient == NULL) |
780 |
return NULL; |
781 |
if (iMidiDevice < 0) |
782 |
return NULL; |
783 |
if (iMidiPort < 0) |
784 |
return NULL; |
785 |
if (pszParam == NULL) |
786 |
return NULL; |
787 |
|
788 |
return pParamInfo; |
789 |
} |
790 |
|
791 |
|
792 |
/** |
793 |
* Changing settings of MIDI input ports. |
794 |
* SET MIDI_INPUT_PORT_PARAMETER <midi-device-id> <midi-port> <param> <value> |
795 |
* |
796 |
* @param pClient Pointer to client instance structure. |
797 |
* @param iMidiDevice MIDI device number identifier. |
798 |
* @param iMidiPort MIDI port number. |
799 |
* @param pParam Pointer to a key-valued MIDI port parameter. |
800 |
* |
801 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
802 |
*/ |
803 |
lscp_status_t lscp_set_midi_port_param ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort, lscp_param_t *pParam ) |
804 |
{ |
805 |
lscp_status_t ret = LSCP_FAILED; |
806 |
|
807 |
if (pClient == NULL) |
808 |
return ret; |
809 |
if (iMidiDevice < 0) |
810 |
return ret; |
811 |
if (iMidiPort < 0) |
812 |
return ret; |
813 |
if (pParam == NULL) |
814 |
return ret; |
815 |
|
816 |
return ret; |
817 |
} |
818 |
|
819 |
// end of device.c |
820 |
|