1 |
// device.c |
2 |
// |
3 |
/**************************************************************************** |
4 |
liblscp - LinuxSampler Control Protocol API |
5 |
Copyright (C) 2004-2005, 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_device_info_t *_lscp_device_info_query (lscp_client_t *pClient, lscp_device_info_t *pDeviceInfo, char *pszQuery); |
30 |
static lscp_param_info_t *_lscp_param_info_query (lscp_client_t *pClient, lscp_param_info_t *pParamInfo, char *pszQuery, int cchMaxQuery, lscp_param_t *pDepList); |
31 |
|
32 |
static lscp_device_port_info_t *_lscp_device_port_info_query (lscp_client_t *pClient, lscp_device_port_info_t *pDevicePortInfo, char *pszQuery); |
33 |
|
34 |
|
35 |
//------------------------------------------------------------------------- |
36 |
// Local funtions. |
37 |
|
38 |
// Common driver type query command. |
39 |
static lscp_driver_info_t *_lscp_driver_info_query ( lscp_client_t *pClient, lscp_driver_info_t *pDriverInfo, char *pszQuery ) |
40 |
{ |
41 |
const char *pszResult; |
42 |
const char *pszSeps = ":"; |
43 |
const char *pszCrlf = "\r\n"; |
44 |
char *pszToken; |
45 |
char *pch; |
46 |
|
47 |
// Lock this section up. |
48 |
lscp_mutex_lock(pClient->mutex); |
49 |
|
50 |
lscp_driver_info_reset(pDriverInfo); |
51 |
if (lscp_client_call(pClient, pszQuery) == LSCP_OK) { |
52 |
pszResult = lscp_client_get_result(pClient); |
53 |
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
54 |
while (pszToken) { |
55 |
if (strcasecmp(pszToken, "DESCRIPTION") == 0) { |
56 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
57 |
if (pszToken) |
58 |
lscp_unquote_dup(&(pDriverInfo->description), &pszToken); |
59 |
} |
60 |
else if (strcasecmp(pszToken, "VERSION") == 0) { |
61 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
62 |
if (pszToken) |
63 |
lscp_unquote_dup(&(pDriverInfo->version), &pszToken); |
64 |
} |
65 |
else if (strcasecmp(pszToken, "PARAMETERS") == 0) { |
66 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
67 |
if (pszToken) { |
68 |
if (pDriverInfo->parameters) |
69 |
lscp_szsplit_destroy(pDriverInfo->parameters); |
70 |
pDriverInfo->parameters = lscp_szsplit_create(pszToken, ","); |
71 |
} |
72 |
} |
73 |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
74 |
} |
75 |
} |
76 |
else pDriverInfo = NULL; |
77 |
|
78 |
// Unlock this section down. |
79 |
lscp_mutex_unlock(pClient->mutex); |
80 |
|
81 |
return pDriverInfo; |
82 |
} |
83 |
|
84 |
|
85 |
// Common device info query command. |
86 |
static lscp_device_info_t *_lscp_device_info_query ( lscp_client_t *pClient, lscp_device_info_t *pDeviceInfo, char *pszQuery ) |
87 |
{ |
88 |
const char *pszResult; |
89 |
const char *pszSeps = ":"; |
90 |
const char *pszCrlf = "\r\n"; |
91 |
char *pszToken; |
92 |
char *pch; |
93 |
char *pszKey; |
94 |
|
95 |
// Lock this section up. |
96 |
lscp_mutex_lock(pClient->mutex); |
97 |
|
98 |
lscp_device_info_reset(pDeviceInfo); |
99 |
if (lscp_client_call(pClient, pszQuery) == LSCP_OK) { |
100 |
pszResult = lscp_client_get_result(pClient); |
101 |
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
102 |
while (pszToken) { |
103 |
if (strcasecmp(pszToken, "DRIVER") == 0) { |
104 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
105 |
if (pszToken) |
106 |
lscp_unquote_dup(&(pDeviceInfo->driver), &pszToken); |
107 |
} |
108 |
else { |
109 |
pszKey = pszToken; |
110 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
111 |
if (pszToken) |
112 |
lscp_plist_append(&(pDeviceInfo->params), pszKey, lscp_unquote(&pszToken, 0)); |
113 |
} |
114 |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
115 |
} |
116 |
} |
117 |
else pDeviceInfo = NULL; |
118 |
|
119 |
// Unlock this section down. |
120 |
lscp_mutex_unlock(pClient->mutex); |
121 |
|
122 |
return pDeviceInfo; |
123 |
} |
124 |
|
125 |
|
126 |
// Common device channel/port info query command. |
127 |
static lscp_device_port_info_t *_lscp_device_port_info_query ( lscp_client_t *pClient, lscp_device_port_info_t *pDevicePortInfo, char *pszQuery ) |
128 |
{ |
129 |
const char *pszResult; |
130 |
const char *pszSeps = ":"; |
131 |
const char *pszCrlf = "\r\n"; |
132 |
char *pszToken; |
133 |
char *pch; |
134 |
char *pszKey; |
135 |
|
136 |
// Lock this section up. |
137 |
lscp_mutex_lock(pClient->mutex); |
138 |
|
139 |
lscp_device_port_info_reset(pDevicePortInfo); |
140 |
if (lscp_client_call(pClient, pszQuery) == LSCP_OK) { |
141 |
pszResult = lscp_client_get_result(pClient); |
142 |
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
143 |
while (pszToken) { |
144 |
if (strcasecmp(pszToken, "NAME") == 0) { |
145 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
146 |
if (pszToken) |
147 |
lscp_unquote_dup(&(pDevicePortInfo->name), &pszToken); |
148 |
} |
149 |
else { |
150 |
pszKey = pszToken; |
151 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
152 |
if (pszToken) |
153 |
lscp_plist_append(&(pDevicePortInfo->params), pszKey, lscp_unquote(&pszToken, 0)); |
154 |
} |
155 |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
156 |
} |
157 |
} |
158 |
else pDevicePortInfo = NULL; |
159 |
|
160 |
// Unlock this section down. |
161 |
lscp_mutex_unlock(pClient->mutex); |
162 |
|
163 |
return pDevicePortInfo; |
164 |
} |
165 |
|
166 |
|
167 |
// Common parameter info query command. |
168 |
static lscp_param_info_t *_lscp_param_info_query ( lscp_client_t *pClient, lscp_param_info_t *pParamInfo, char *pszQuery, int cchMaxQuery, lscp_param_t *pDepList ) |
169 |
{ |
170 |
const char *pszResult; |
171 |
const char *pszSeps = ":"; |
172 |
const char *pszCrlf = "\r\n"; |
173 |
char *pszToken; |
174 |
char *pch; |
175 |
|
176 |
// Lock this section up. |
177 |
lscp_mutex_lock(pClient->mutex); |
178 |
|
179 |
lscp_param_info_reset(pParamInfo); |
180 |
lscp_param_concat(pszQuery, cchMaxQuery, pDepList); |
181 |
if (lscp_client_call(pClient, pszQuery) == LSCP_OK) { |
182 |
pszResult = lscp_client_get_result(pClient); |
183 |
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
184 |
while (pszToken) { |
185 |
if (strcasecmp(pszToken, "TYPE") == 0) { |
186 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
187 |
if (pszToken) { |
188 |
pszToken = lscp_unquote(&pszToken, 0); |
189 |
if (strcasecmp(pszToken, "BOOL") == 0) |
190 |
pParamInfo->type = LSCP_TYPE_BOOL; |
191 |
else if (strcasecmp(pszToken, "INT") == 0) |
192 |
pParamInfo->type = LSCP_TYPE_INT; |
193 |
else if (strcasecmp(pszToken, "FLOAT") == 0) |
194 |
pParamInfo->type = LSCP_TYPE_FLOAT; |
195 |
else if (strcasecmp(pszToken, "STRING") == 0) |
196 |
pParamInfo->type = LSCP_TYPE_STRING; |
197 |
} |
198 |
} |
199 |
else if (strcasecmp(pszToken, "DESCRIPTION") == 0) { |
200 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
201 |
if (pszToken) |
202 |
lscp_unquote_dup(&(pParamInfo->description), &pszToken); |
203 |
} |
204 |
else if (strcasecmp(pszToken, "MANDATORY") == 0) { |
205 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
206 |
if (pszToken) |
207 |
pParamInfo->mandatory = (strcasecmp(lscp_unquote(&pszToken, 0), "TRUE") == 0); |
208 |
} |
209 |
else if (strcasecmp(pszToken, "FIX") == 0) { |
210 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
211 |
if (pszToken) |
212 |
pParamInfo->fix = (strcasecmp(lscp_unquote(&pszToken, 0), "TRUE") == 0); |
213 |
} |
214 |
else if (strcasecmp(pszToken, "MULTIPLICITY") == 0) { |
215 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
216 |
if (pszToken) |
217 |
pParamInfo->multiplicity = (strcasecmp(lscp_unquote(&pszToken, 0), "TRUE") == 0); |
218 |
} |
219 |
else if (strcasecmp(pszToken, "DEPENDS") == 0) { |
220 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
221 |
if (pszToken) { |
222 |
if (pParamInfo->depends) |
223 |
lscp_szsplit_destroy(pParamInfo->depends); |
224 |
pParamInfo->depends = lscp_szsplit_create(pszToken, ","); |
225 |
} |
226 |
} |
227 |
else if (strcasecmp(pszToken, "DEFAULT") == 0) { |
228 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
229 |
if (pszToken) |
230 |
lscp_unquote_dup(&(pParamInfo->defaultv), &pszToken); |
231 |
} |
232 |
else if (strcasecmp(pszToken, "RANGE_MIN") == 0) { |
233 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
234 |
if (pszToken) |
235 |
lscp_unquote_dup(&(pParamInfo->range_min), &pszToken); |
236 |
} |
237 |
else if (strcasecmp(pszToken, "RANGE_MAX") == 0) { |
238 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
239 |
if (pszToken) |
240 |
lscp_unquote_dup(&(pParamInfo->range_max), &pszToken); |
241 |
} |
242 |
else if (strcasecmp(pszToken, "POSSIBILITIES") == 0) { |
243 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
244 |
if (pszToken) { |
245 |
if (pParamInfo->possibilities) |
246 |
lscp_szsplit_destroy(pParamInfo->possibilities); |
247 |
pParamInfo->possibilities = lscp_szsplit_create(pszToken, ","); |
248 |
} |
249 |
} |
250 |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
251 |
} |
252 |
} |
253 |
else pParamInfo = NULL; |
254 |
|
255 |
// Unlock this section down. |
256 |
lscp_mutex_unlock(pClient->mutex); |
257 |
|
258 |
return pParamInfo; |
259 |
} |
260 |
|
261 |
|
262 |
//------------------------------------------------------------------------- |
263 |
// Audio driver control functions. |
264 |
|
265 |
/** |
266 |
* Getting all available audio output driver count. |
267 |
* GET AVAILABLE_AUDIO_OUTPUT_DRIVERS |
268 |
* |
269 |
* @param pClient Pointer to client instance structure. |
270 |
* |
271 |
* @returns The current total number of audio output drivers on success, |
272 |
* -1 otherwise. |
273 |
*/ |
274 |
int lscp_get_available_audio_drivers ( lscp_client_t *pClient ) |
275 |
{ |
276 |
int iAudioDrivers = -1; |
277 |
|
278 |
// Lock this section up. |
279 |
lscp_mutex_lock(pClient->mutex); |
280 |
|
281 |
if (lscp_client_call(pClient, "GET AVAILABLE_AUDIO_OUTPUT_DRIVERS\r\n") == LSCP_OK) |
282 |
iAudioDrivers = atoi(lscp_client_get_result(pClient)); |
283 |
|
284 |
// Unlock this section down. |
285 |
lscp_mutex_unlock(pClient->mutex); |
286 |
|
287 |
return iAudioDrivers; |
288 |
} |
289 |
|
290 |
|
291 |
/** |
292 |
* Getting all available audio output drivers. |
293 |
* LIST AVAILABLE_AUDIO_OUTPUT_DRIVERS |
294 |
* |
295 |
* @param pClient Pointer to client instance structure. |
296 |
* |
297 |
* @returns A NULL terminated array of audio output driver type |
298 |
* name strings, or NULL in case of failure. |
299 |
*/ |
300 |
const char ** lscp_list_available_audio_drivers ( lscp_client_t *pClient ) |
301 |
{ |
302 |
const char *pszSeps = ","; |
303 |
|
304 |
// Lock this section up. |
305 |
lscp_mutex_lock(pClient->mutex); |
306 |
|
307 |
if (pClient->audio_drivers) { |
308 |
lscp_szsplit_destroy(pClient->audio_drivers); |
309 |
pClient->audio_drivers = NULL; |
310 |
} |
311 |
|
312 |
if (lscp_client_call(pClient, "LIST AVAILABLE_AUDIO_OUTPUT_DRIVERS\r\n") == LSCP_OK) |
313 |
pClient->audio_drivers = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps); |
314 |
|
315 |
// Unlock this section down. |
316 |
lscp_mutex_unlock(pClient->mutex); |
317 |
|
318 |
return (const char **) pClient->audio_drivers; |
319 |
} |
320 |
|
321 |
|
322 |
/** |
323 |
* Getting informations about a specific audio output driver. |
324 |
* GET AUDIO_OUTPUT_DRIVER INFO <audio-output-type> |
325 |
* |
326 |
* @param pClient Pointer to client instance structure. |
327 |
* @param pszAudioDriver Audio driver type string (e.g. "ALSA"). |
328 |
* |
329 |
* @returns A pointer to a @ref lscp_driver_info_t structure, with |
330 |
* the given audio driver information, or NULL in case of failure. |
331 |
*/ |
332 |
lscp_driver_info_t* lscp_get_audio_driver_info ( lscp_client_t *pClient, const char *pszAudioDriver ) |
333 |
{ |
334 |
char szQuery[LSCP_BUFSIZ]; |
335 |
|
336 |
if (pszAudioDriver == NULL) |
337 |
return NULL; |
338 |
|
339 |
sprintf(szQuery, "GET AUDIO_OUTPUT_DRIVER INFO %s\r\n", pszAudioDriver); |
340 |
return _lscp_driver_info_query(pClient, &(pClient->audio_driver_info), szQuery); |
341 |
} |
342 |
|
343 |
|
344 |
/** |
345 |
* Getting informations about specific audio output driver parameter. |
346 |
* GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO <audio-output-driver> <param> [<dep-list>] |
347 |
* |
348 |
* @param pClient Pointer to client instance structure. |
349 |
* @param pszAudioDriver Audio driver type string (e.g. "ALSA"). |
350 |
* @param pszParam Audio driver parameter name. |
351 |
* @param pDepList Pointer to specific dependencies parameter list. |
352 |
* |
353 |
* @returns A pointer to a @ref lscp_param_info_t structure, with |
354 |
* the given audio driver parameter information, or NULL in case of failure. |
355 |
*/ |
356 |
lscp_param_info_t *lscp_get_audio_driver_param_info ( lscp_client_t *pClient, const char *pszAudioDriver, const char *pszParam, lscp_param_t *pDepList ) |
357 |
{ |
358 |
char szQuery[LSCP_BUFSIZ]; |
359 |
|
360 |
if (pClient == NULL) |
361 |
return NULL; |
362 |
if (pszAudioDriver == NULL) |
363 |
return NULL; |
364 |
if (pszParam == NULL) |
365 |
return NULL; |
366 |
|
367 |
sprintf(szQuery, "GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO %s %s", pszAudioDriver, pszParam); |
368 |
return _lscp_param_info_query(pClient, &(pClient->audio_param_info), szQuery, sizeof(szQuery), pDepList); |
369 |
} |
370 |
|
371 |
|
372 |
//------------------------------------------------------------------------- |
373 |
// Audio device control functions. |
374 |
|
375 |
/** |
376 |
* Creating an audio output device. |
377 |
* CREATE AUDIO_OUTPUT_DEVICE <audio-output-driver> [<params>] |
378 |
* |
379 |
* @param pClient Pointer to client instance structure. |
380 |
* @param pszAudioDriver Audio driver type string (e.g. "ALSA"). |
381 |
* @param pParams Pointer to specific parameter list. |
382 |
* |
383 |
* @returns The new audio device number identifier on success, |
384 |
* or -1 in case of failure. |
385 |
*/ |
386 |
int lscp_create_audio_device ( lscp_client_t *pClient, const char *pszAudioDriver, lscp_param_t *pParams ) |
387 |
{ |
388 |
char szQuery[LSCP_BUFSIZ]; |
389 |
int iAudioDevice = -1; |
390 |
|
391 |
if (pClient == NULL) |
392 |
return iAudioDevice; |
393 |
if (pszAudioDriver == NULL) |
394 |
return iAudioDevice; |
395 |
|
396 |
// Lock this section up. |
397 |
lscp_mutex_lock(pClient->mutex); |
398 |
|
399 |
sprintf(szQuery, "CREATE AUDIO_OUTPUT_DEVICE %s", pszAudioDriver); |
400 |
lscp_param_concat(szQuery, sizeof(szQuery), pParams); |
401 |
if (lscp_client_call(pClient, szQuery) == LSCP_OK) |
402 |
iAudioDevice = atoi(lscp_client_get_result(pClient)); |
403 |
|
404 |
// Unlock this section down. |
405 |
lscp_mutex_unlock(pClient->mutex); |
406 |
|
407 |
return iAudioDevice; |
408 |
} |
409 |
|
410 |
|
411 |
/** |
412 |
* Destroying an audio output device. |
413 |
* DESTROY AUDIO_OUTPUT_DEVICE <audio-device-id> |
414 |
* |
415 |
* @param pClient Pointer to client instance structure. |
416 |
* @param iAudioDevice Audio device number identifier. |
417 |
* |
418 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
419 |
*/ |
420 |
lscp_status_t lscp_destroy_audio_device ( lscp_client_t *pClient, int iAudioDevice ) |
421 |
{ |
422 |
lscp_status_t ret = LSCP_FAILED; |
423 |
char szQuery[LSCP_BUFSIZ]; |
424 |
|
425 |
if (pClient == NULL) |
426 |
return ret; |
427 |
if (iAudioDevice < 0) |
428 |
return ret; |
429 |
|
430 |
sprintf(szQuery, "DESTROY AUDIO_OUTPUT_DEVICE %d\r\n", iAudioDevice); |
431 |
return lscp_client_query(pClient, szQuery); |
432 |
} |
433 |
|
434 |
|
435 |
/** |
436 |
* Getting all created audio output device count. |
437 |
* GET AUDIO_OUTPUT_DEVICES |
438 |
* |
439 |
* @param pClient Pointer to client instance structure. |
440 |
* |
441 |
* @returns The current total number of audio devices on success, |
442 |
* -1 otherwise. |
443 |
*/ |
444 |
int lscp_get_audio_devices ( lscp_client_t *pClient ) |
445 |
{ |
446 |
int iAudioDevices = -1; |
447 |
|
448 |
// Lock this section up. |
449 |
lscp_mutex_lock(pClient->mutex); |
450 |
|
451 |
if (lscp_client_call(pClient, "GET AUDIO_OUTPUT_DEVICES\r\n") == LSCP_OK) |
452 |
iAudioDevices = atoi(lscp_client_get_result(pClient)); |
453 |
|
454 |
// Unlock this section down. |
455 |
lscp_mutex_unlock(pClient->mutex); |
456 |
|
457 |
return iAudioDevices; |
458 |
} |
459 |
|
460 |
|
461 |
/** |
462 |
* Getting all created audio output device list. |
463 |
* LIST AUDIO_OUTPUT_DEVICES |
464 |
* |
465 |
* @param pClient Pointer to client instance structure. |
466 |
* |
467 |
* @returns An array of audio device number identifiers, |
468 |
* terminated with -1 on success, or NULL in case of failure. |
469 |
*/ |
470 |
int *lscp_list_audio_devices ( lscp_client_t *pClient ) |
471 |
{ |
472 |
const char *pszSeps = ","; |
473 |
|
474 |
if (pClient == NULL) |
475 |
return NULL; |
476 |
|
477 |
// Lock this section up. |
478 |
lscp_mutex_lock(pClient->mutex); |
479 |
|
480 |
if (pClient->audio_devices) { |
481 |
lscp_isplit_destroy(pClient->audio_devices); |
482 |
pClient->audio_devices = NULL; |
483 |
} |
484 |
|
485 |
if (lscp_client_call(pClient, "LIST AUDIO_OUTPUT_DEVICES\r\n") == LSCP_OK) |
486 |
pClient->audio_devices = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps); |
487 |
|
488 |
// Unlock this section down. |
489 |
lscp_mutex_unlock(pClient->mutex); |
490 |
|
491 |
return pClient->audio_devices; |
492 |
} |
493 |
|
494 |
|
495 |
/** |
496 |
* Getting current settings of an audio output device. |
497 |
* GET AUDIO_OUTPUT_DEVICE INFO <audio-device-id> |
498 |
* |
499 |
* @param pClient Pointer to client instance structure. |
500 |
* @param iAudioDevice Audio device number identifier. |
501 |
* |
502 |
* @returns A pointer to a @ref lscp_device_info_t structure, with |
503 |
* the given audio device information, or NULL in case of failure. |
504 |
*/ |
505 |
lscp_device_info_t *lscp_get_audio_device_info ( lscp_client_t *pClient, int iAudioDevice ) |
506 |
{ |
507 |
char szQuery[LSCP_BUFSIZ]; |
508 |
|
509 |
if (pClient == NULL) |
510 |
return NULL; |
511 |
if (iAudioDevice < 0) |
512 |
return NULL; |
513 |
|
514 |
sprintf(szQuery, "GET AUDIO_OUTPUT_DEVICE INFO %d\r\n", iAudioDevice); |
515 |
return _lscp_device_info_query(pClient, &(pClient->audio_device_info), szQuery); |
516 |
} |
517 |
|
518 |
|
519 |
/** |
520 |
* Changing settings of audio output devices. |
521 |
* SET AUDIO_OUTPUT_DEVICE_PARAMETER <audio-device-id> <param>=<value> |
522 |
* |
523 |
* @param pClient Pointer to client instance structure. |
524 |
* @param iAudioDevice Audio device number identifier. |
525 |
* @param pParam Pointer to a key-valued audio device parameter. |
526 |
* |
527 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
528 |
*/ |
529 |
lscp_status_t lscp_set_audio_device_param ( lscp_client_t *pClient, int iAudioDevice, lscp_param_t *pParam ) |
530 |
{ |
531 |
char szQuery[LSCP_BUFSIZ]; |
532 |
|
533 |
if (pClient == NULL) |
534 |
return LSCP_FAILED; |
535 |
if (iAudioDevice < 0) |
536 |
return LSCP_FAILED; |
537 |
if (pParam == NULL) |
538 |
return LSCP_FAILED; |
539 |
|
540 |
sprintf(szQuery, "SET AUDIO_OUTPUT_DEVICE_PARAMETER %d %s='%s'\r\n", iAudioDevice, pParam->key, pParam->value); |
541 |
return lscp_client_query(pClient, szQuery); |
542 |
} |
543 |
|
544 |
|
545 |
/** |
546 |
* Getting informations about an audio channel. |
547 |
* GET AUDIO_OUTPUT_CHANNEL INFO <audio-device-id> <audio-channel> |
548 |
* |
549 |
* @param pClient Pointer to client instance structure. |
550 |
* @param iAudioDevice Audio device number identifier. |
551 |
* @param iAudioChannel Audio channel number. |
552 |
* |
553 |
* @returns A pointer to a @ref lscp_device_port_info_t structure, |
554 |
* with the given audio channel information, or NULL in case of failure. |
555 |
*/ |
556 |
lscp_device_port_info_t* lscp_get_audio_channel_info ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel ) |
557 |
{ |
558 |
char szQuery[LSCP_BUFSIZ]; |
559 |
|
560 |
if (pClient == NULL) |
561 |
return NULL; |
562 |
if (iAudioDevice < 0) |
563 |
return NULL; |
564 |
if (iAudioChannel < 0) |
565 |
return NULL; |
566 |
|
567 |
sprintf(szQuery, "GET AUDIO_OUTPUT_CHANNEL INFO %d %d\r\n", iAudioDevice, iAudioChannel); |
568 |
return _lscp_device_port_info_query(pClient, &(pClient->audio_channel_info), szQuery); |
569 |
} |
570 |
|
571 |
|
572 |
/** |
573 |
* Getting informations about specific audio channel parameter. |
574 |
* GET AUDIO_OUTPUT_CHANNEL_PARAMETER INFO <audio-device-id> <audio-channel> <param> |
575 |
* |
576 |
* @param pClient Pointer to client instance structure. |
577 |
* @param iAudioDevice Audio device number identifier. |
578 |
* @param iAudioChannel Audio channel number. |
579 |
* @param pszParam Audio channel parameter name. |
580 |
* |
581 |
* @returns A pointer to a @ref lscp_param_info_t structure, with |
582 |
* the given audio channel parameter information, or NULL in case of failure. |
583 |
*/ |
584 |
lscp_param_info_t* lscp_get_audio_channel_param_info ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel, const char *pszParam ) |
585 |
{ |
586 |
char szQuery[LSCP_BUFSIZ]; |
587 |
|
588 |
if (pClient == NULL) |
589 |
return NULL; |
590 |
if (iAudioDevice < 0) |
591 |
return NULL; |
592 |
if (iAudioChannel < 0) |
593 |
return NULL; |
594 |
if (pszParam == NULL) |
595 |
return NULL; |
596 |
|
597 |
sprintf(szQuery, "GET AUDIO_OUTPUT_CHANNEL_PARAMETER INFO %d %d %s", iAudioDevice, iAudioChannel, pszParam); |
598 |
return _lscp_param_info_query(pClient, &(pClient->audio_channel_param_info), szQuery, sizeof(szQuery), NULL); |
599 |
} |
600 |
|
601 |
|
602 |
/** |
603 |
* Changing settings of audio output channels. |
604 |
* SET AUDIO_OUTPUT_CHANNEL_PARAMETER <audio-device-id> <audio-channel> <param> <value> |
605 |
* |
606 |
* @param pClient Pointer to client instance structure. |
607 |
* @param iAudioDevice Audio device number identifier. |
608 |
* @param iAudioChannel Audio channel number. |
609 |
* @param pParam Pointer to a key-valued audio channel parameter. |
610 |
* |
611 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
612 |
*/ |
613 |
lscp_status_t lscp_set_audio_channel_param ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel, lscp_param_t *pParam ) |
614 |
{ |
615 |
char szQuery[LSCP_BUFSIZ]; |
616 |
|
617 |
if (pClient == NULL) |
618 |
return LSCP_FAILED; |
619 |
if (iAudioDevice < 0) |
620 |
return LSCP_FAILED; |
621 |
if (iAudioChannel < 0) |
622 |
return LSCP_FAILED; |
623 |
if (pParam == NULL) |
624 |
return LSCP_FAILED; |
625 |
|
626 |
sprintf(szQuery, "SET AUDIO_OUTPUT_CHANNEL_PARAMETER %d %d %s='%s'\r\n", iAudioDevice, iAudioChannel, pParam->key, pParam->value); |
627 |
return lscp_client_query(pClient, szQuery); |
628 |
} |
629 |
|
630 |
|
631 |
//------------------------------------------------------------------------- |
632 |
// MIDI driver control functions. |
633 |
|
634 |
/** |
635 |
* Getting all available MIDI input driver count. |
636 |
* GET AVAILABLE_MIDI_INPUT_DRIVERS |
637 |
* |
638 |
* @param pClient Pointer to client instance structure. |
639 |
* |
640 |
* @returns The current total number of MIDI input drivers on success, |
641 |
* -1 otherwise. |
642 |
*/ |
643 |
int lscp_get_available_midi_drivers ( lscp_client_t *pClient ) |
644 |
{ |
645 |
int iMidiDrivers = -1; |
646 |
|
647 |
// Lock this section up. |
648 |
lscp_mutex_lock(pClient->mutex); |
649 |
|
650 |
if (lscp_client_call(pClient, "GET AVAILABLE_MIDI_INPUT_DRIVERS\r\n") == LSCP_OK) |
651 |
iMidiDrivers = atoi(lscp_client_get_result(pClient)); |
652 |
|
653 |
// Unlock this section up. |
654 |
lscp_mutex_unlock(pClient->mutex); |
655 |
|
656 |
return iMidiDrivers; |
657 |
} |
658 |
|
659 |
|
660 |
/** |
661 |
* Getting all available MIDI input drivers. |
662 |
* LIST AVAILABLE_MIDI_INPUT_DRIVERS |
663 |
* |
664 |
* @param pClient Pointer to client instance structure. |
665 |
* |
666 |
* @returns A NULL terminated array of MIDI input driver type |
667 |
* name strings, or NULL in case of failure. |
668 |
*/ |
669 |
const char** lscp_list_available_midi_drivers ( lscp_client_t *pClient ) |
670 |
{ |
671 |
const char *pszSeps = ","; |
672 |
|
673 |
// Lock this section up. |
674 |
lscp_mutex_lock(pClient->mutex); |
675 |
|
676 |
if (pClient->midi_drivers) { |
677 |
lscp_szsplit_destroy(pClient->midi_drivers); |
678 |
pClient->midi_drivers = NULL; |
679 |
} |
680 |
|
681 |
if (lscp_client_call(pClient, "LIST AVAILABLE_MIDI_INPUT_DRIVERS\r\n") == LSCP_OK) |
682 |
pClient->midi_drivers = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps); |
683 |
|
684 |
// Unlock this section up. |
685 |
lscp_mutex_unlock(pClient->mutex); |
686 |
|
687 |
return (const char **) pClient->midi_drivers; |
688 |
} |
689 |
|
690 |
|
691 |
/** |
692 |
* Getting informations about a specific MIDI input driver. |
693 |
* GET MIDI_INPUT_DRIVER INFO <midi-input-type> |
694 |
* |
695 |
* @param pClient Pointer to client instance structure. |
696 |
* @param pszMidiDriver MIDI driver type string (e.g. "ALSA"). |
697 |
* |
698 |
* @returns A pointer to a @ref lscp_driver_info_t structure, with |
699 |
* the given MIDI driver information, or NULL in case of failure. |
700 |
*/ |
701 |
lscp_driver_info_t* lscp_get_midi_driver_info ( lscp_client_t *pClient, const char *pszMidiDriver ) |
702 |
{ |
703 |
char szQuery[LSCP_BUFSIZ]; |
704 |
|
705 |
if (pszMidiDriver == NULL) |
706 |
return NULL; |
707 |
|
708 |
sprintf(szQuery, "GET MIDI_INPUT_DRIVER INFO %s\r\n", pszMidiDriver); |
709 |
return _lscp_driver_info_query(pClient, &(pClient->midi_driver_info), szQuery); |
710 |
} |
711 |
|
712 |
|
713 |
/** |
714 |
* Getting informations about specific MIDI input driver parameter. |
715 |
* GET MIDI_INPUT_DRIVER_PARAMETER INFO <midi-input-driver> <param> [<dep-list>] |
716 |
* |
717 |
* @param pClient Pointer to client instance structure. |
718 |
* @param pszMidiDriver MIDI driver type string (e.g. "ALSA"). |
719 |
* @param pszParam MIDI driver parameter name. |
720 |
* @param pDepList Pointer to specific dependencies parameter list. |
721 |
* |
722 |
* @returns A pointer to a @ref lscp_param_info_t structure, with |
723 |
* the given MIDI driver parameter information, or NULL in case of failure. |
724 |
* |
725 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
726 |
*/ |
727 |
lscp_param_info_t *lscp_get_midi_driver_param_info ( lscp_client_t *pClient, const char *pszMidiDriver, const char *pszParam, lscp_param_t *pDepList ) |
728 |
{ |
729 |
char szQuery[LSCP_BUFSIZ]; |
730 |
|
731 |
if (pClient == NULL) |
732 |
return NULL; |
733 |
if (pszMidiDriver == NULL) |
734 |
return NULL; |
735 |
if (pszParam == NULL) |
736 |
return NULL; |
737 |
|
738 |
sprintf(szQuery, "GET MIDI_INPUT_DRIVER_PARAMETER INFO %s %s", pszMidiDriver, pszParam); |
739 |
return _lscp_param_info_query(pClient, &(pClient->midi_param_info), szQuery, sizeof(szQuery), pDepList); |
740 |
} |
741 |
|
742 |
|
743 |
//------------------------------------------------------------------------- |
744 |
// MIDI device control functions. |
745 |
|
746 |
/** |
747 |
* Creating a MIDI input device. |
748 |
* CREATE MIDI_INPUT_DEVICE <midi-input-driver> [<params>] |
749 |
* |
750 |
* @param pClient Pointer to client instance structure. |
751 |
* @param pszMidiDriver MIDI driver type string (e.g. "ALSA"). |
752 |
* @param pParams Pointer to specific parameter list. |
753 |
* |
754 |
* @returns The new audio device number identifier on success, |
755 |
* or -1 in case of failure. |
756 |
*/ |
757 |
int lscp_create_midi_device ( lscp_client_t *pClient, const char *pszMidiDriver, lscp_param_t *pParams ) |
758 |
{ |
759 |
char szQuery[LSCP_BUFSIZ]; |
760 |
int iMidiDevice = -1; |
761 |
|
762 |
if (pClient == NULL) |
763 |
return iMidiDevice; |
764 |
if (pszMidiDriver == NULL) |
765 |
return iMidiDevice; |
766 |
|
767 |
// Lock this section up. |
768 |
lscp_mutex_lock(pClient->mutex); |
769 |
|
770 |
sprintf(szQuery, "CREATE MIDI_INPUT_DEVICE %s", pszMidiDriver); |
771 |
lscp_param_concat(szQuery, sizeof(szQuery), pParams); |
772 |
if (lscp_client_call(pClient, szQuery) == LSCP_OK) |
773 |
iMidiDevice = atoi(lscp_client_get_result(pClient)); |
774 |
|
775 |
// Unlock this section down. |
776 |
lscp_mutex_unlock(pClient->mutex); |
777 |
|
778 |
return iMidiDevice; |
779 |
} |
780 |
|
781 |
|
782 |
/** |
783 |
* Destroying a MIDI input device. |
784 |
* DESTROY MIDI_INPUT_DEVICE <midi-device-id> |
785 |
* |
786 |
* @param pClient Pointer to client instance structure. |
787 |
* @param iMidiDevice MIDI device number identifier. |
788 |
* |
789 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
790 |
*/ |
791 |
lscp_status_t lscp_destroy_midi_device ( lscp_client_t *pClient, int iMidiDevice ) |
792 |
{ |
793 |
lscp_status_t ret = LSCP_FAILED; |
794 |
char szQuery[LSCP_BUFSIZ]; |
795 |
|
796 |
if (pClient == NULL) |
797 |
return ret; |
798 |
if (iMidiDevice < 0) |
799 |
return ret; |
800 |
|
801 |
sprintf(szQuery, "DESTROY MIDI_INPUT_DEVICE %d\r\n", iMidiDevice); |
802 |
return lscp_client_query(pClient, szQuery); |
803 |
} |
804 |
|
805 |
|
806 |
/** |
807 |
* Getting all created MIDI intput device count. |
808 |
* GET MIDI_INPUT_DEVICES |
809 |
* |
810 |
* @param pClient Pointer to client instance structure. |
811 |
* |
812 |
* @returns The current total number of MIDI devices on success, |
813 |
* -1 otherwise. |
814 |
*/ |
815 |
int lscp_get_midi_devices ( lscp_client_t *pClient ) |
816 |
{ |
817 |
int iMidiDevices = -1; |
818 |
|
819 |
// Lock this section up. |
820 |
lscp_mutex_lock(pClient->mutex); |
821 |
|
822 |
if (lscp_client_call(pClient, "GET MIDI_INPUT_DEVICES\r\n") == LSCP_OK) |
823 |
iMidiDevices = atoi(lscp_client_get_result(pClient)); |
824 |
|
825 |
// Unlock this section down. |
826 |
lscp_mutex_unlock(pClient->mutex); |
827 |
|
828 |
return iMidiDevices; |
829 |
} |
830 |
|
831 |
|
832 |
/** |
833 |
* Getting all created MIDI intput device list. |
834 |
* LIST MIDI_INPUT_DEVICES |
835 |
* |
836 |
* @param pClient Pointer to client instance structure. |
837 |
* |
838 |
* @returns An array of MIDI device number identifiers, |
839 |
* terminated with -1 on success, or NULL in case of failure. |
840 |
*/ |
841 |
int *lscp_list_midi_devices ( lscp_client_t *pClient ) |
842 |
{ |
843 |
const char *pszSeps = ","; |
844 |
|
845 |
if (pClient == NULL) |
846 |
return NULL; |
847 |
|
848 |
// Lock this section up. |
849 |
lscp_mutex_lock(pClient->mutex); |
850 |
|
851 |
if (pClient->midi_devices) { |
852 |
lscp_isplit_destroy(pClient->midi_devices); |
853 |
pClient->midi_devices = NULL; |
854 |
} |
855 |
|
856 |
if (lscp_client_call(pClient, "LIST MIDI_INPUT_DEVICES\r\n") == LSCP_OK) |
857 |
pClient->midi_devices = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps); |
858 |
|
859 |
// Unlock this section down. |
860 |
lscp_mutex_unlock(pClient->mutex); |
861 |
|
862 |
return pClient->midi_devices; |
863 |
} |
864 |
|
865 |
|
866 |
/** |
867 |
* Getting current settings of a MIDI input device. |
868 |
* GET MIDI_INPUT_DEVICE INFO <midi-device-id> |
869 |
* |
870 |
* @param pClient Pointer to client instance structure. |
871 |
* @param iMidiDevice MIDI device number identifier. |
872 |
* |
873 |
* @returns A pointer to a @ref lscp_device_info_t structure, with |
874 |
* the given MIDI device information, or NULL in case of failure. |
875 |
*/ |
876 |
lscp_device_info_t* lscp_get_midi_device_info ( lscp_client_t *pClient, int iMidiDevice ) |
877 |
{ |
878 |
char szQuery[LSCP_BUFSIZ]; |
879 |
|
880 |
if (pClient == NULL) |
881 |
return NULL; |
882 |
if (iMidiDevice < 0) |
883 |
return NULL; |
884 |
|
885 |
sprintf(szQuery, "GET MIDI_INPUT_DEVICE INFO %d\r\n", iMidiDevice); |
886 |
return _lscp_device_info_query(pClient, &(pClient->midi_device_info), szQuery); |
887 |
} |
888 |
|
889 |
|
890 |
/** |
891 |
* Changing settings of MIDI input devices. |
892 |
* SET MIDI_INPUT_DEVICE_PARAMETER <midi-device-id> <param>=<value> |
893 |
* |
894 |
* @param pClient Pointer to client instance structure. |
895 |
* @param iMidiDevice MIDI device number identifier. |
896 |
* @param pParam Pointer to a key-valued MIDI device parameter. |
897 |
* |
898 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
899 |
*/ |
900 |
lscp_status_t lscp_set_midi_device_param ( lscp_client_t *pClient, int iMidiDevice, lscp_param_t *pParam ) |
901 |
{ |
902 |
char szQuery[LSCP_BUFSIZ]; |
903 |
|
904 |
if (pClient == NULL) |
905 |
return LSCP_FAILED; |
906 |
if (iMidiDevice < 0) |
907 |
return LSCP_FAILED; |
908 |
if (pParam == NULL) |
909 |
return LSCP_FAILED; |
910 |
|
911 |
sprintf(szQuery, "SET MIDI_INPUT_DEVICE_PARAMETER %d %s='%s'\r\n", iMidiDevice, pParam->key, pParam->value); |
912 |
return lscp_client_query(pClient, szQuery); |
913 |
} |
914 |
|
915 |
|
916 |
/** |
917 |
* Getting informations about a MIDI port. |
918 |
* GET MIDI_INPUT_PORT INFO <midi-device-id> <midi-port> |
919 |
* |
920 |
* @param pClient Pointer to client instance structure. |
921 |
* @param iMidiDevice MIDI device number identifier. |
922 |
* @param iMidiPort MIDI port number. |
923 |
* |
924 |
* @returns A pointer to a @ref lscp_device_port_info_t structure, |
925 |
* with the given MIDI port information, or NULL in case of failure. |
926 |
*/ |
927 |
lscp_device_port_info_t* lscp_get_midi_port_info ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort ) |
928 |
{ |
929 |
char szQuery[LSCP_BUFSIZ]; |
930 |
|
931 |
if (pClient == NULL) |
932 |
return NULL; |
933 |
if (iMidiDevice < 0) |
934 |
return NULL; |
935 |
if (iMidiPort < 0) |
936 |
return NULL; |
937 |
|
938 |
sprintf(szQuery, "GET MIDI_INPUT_PORT INFO %d %d\r\n", iMidiDevice, iMidiPort); |
939 |
return _lscp_device_port_info_query(pClient, &(pClient->midi_port_info), szQuery); |
940 |
} |
941 |
|
942 |
|
943 |
/** |
944 |
* Getting informations about specific MIDI port parameter. |
945 |
* GET MIDI_INPUT_PORT_PARAMETER INFO <midi-device-id> <midi-port> <param> |
946 |
* |
947 |
* @param pClient Pointer to client instance structure. |
948 |
* @param iMidiDevice MIDI device number identifier. |
949 |
* @param iMidiPort MIDI port number. |
950 |
* @param pszParam MIDI port parameter name. |
951 |
* |
952 |
* @returns A pointer to a @ref lscp_param_info_t structure, with |
953 |
* the given MIDI port parameter information, or NULL in case of failure. |
954 |
*/ |
955 |
lscp_param_info_t* lscp_get_midi_port_param_info ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort, const char *pszParam ) |
956 |
{ |
957 |
char szQuery[LSCP_BUFSIZ]; |
958 |
|
959 |
if (pClient == NULL) |
960 |
return NULL; |
961 |
if (iMidiDevice < 0) |
962 |
return NULL; |
963 |
if (iMidiPort < 0) |
964 |
return NULL; |
965 |
if (pszParam == NULL) |
966 |
return NULL; |
967 |
|
968 |
sprintf(szQuery, "GET MIDI_INPUT_PORT_PARAMETER INFO %d %d %s", iMidiDevice, iMidiPort, pszParam); |
969 |
return _lscp_param_info_query(pClient, &(pClient->midi_port_param_info), szQuery, sizeof(szQuery), NULL); |
970 |
} |
971 |
|
972 |
|
973 |
/** |
974 |
* Changing settings of MIDI input ports. |
975 |
* SET MIDI_INPUT_PORT_PARAMETER <midi-device-id> <midi-port> <param> <value> |
976 |
* |
977 |
* @param pClient Pointer to client instance structure. |
978 |
* @param iMidiDevice MIDI device number identifier. |
979 |
* @param iMidiPort MIDI port number. |
980 |
* @param pParam Pointer to a key-valued MIDI port parameter. |
981 |
* |
982 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
983 |
*/ |
984 |
lscp_status_t lscp_set_midi_port_param ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort, lscp_param_t *pParam ) |
985 |
{ |
986 |
char szQuery[LSCP_BUFSIZ]; |
987 |
|
988 |
if (pClient == NULL) |
989 |
return LSCP_FAILED; |
990 |
if (iMidiDevice < 0) |
991 |
return LSCP_FAILED; |
992 |
if (iMidiPort < 0) |
993 |
return LSCP_FAILED; |
994 |
if (pParam == NULL) |
995 |
return LSCP_FAILED; |
996 |
|
997 |
sprintf(szQuery, "SET MIDI_INPUT_PORT_PARAMETER %d %d %s='%s'\r\n", iMidiDevice, iMidiPort, pParam->key, pParam->value); |
998 |
return lscp_client_query(pClient, szQuery); |
999 |
} |
1000 |
|
1001 |
|
1002 |
//------------------------------------------------------------------------- |
1003 |
// Generic parameter list functions. |
1004 |
|
1005 |
const char *lscp_get_param_value ( lscp_param_t *pParams, const char *pszParam ) |
1006 |
{ |
1007 |
int i; |
1008 |
|
1009 |
for (i = 0; pParams && pParams[i].key; i++) { |
1010 |
if (strcasecmp(pParams[i].key, pszParam) == 0) |
1011 |
return (const char *) pParams[i].value; |
1012 |
} |
1013 |
return NULL; |
1014 |
} |
1015 |
|
1016 |
|
1017 |
// end of device.c |
1018 |
|