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 drivers. |
267 |
* GET AVAILABLE_AUDIO_OUTPUT_DRIVERS |
268 |
* |
269 |
* @param pClient Pointer to client instance structure. |
270 |
* |
271 |
* @returns A NULL terminated array of audio output driver type |
272 |
* name strings, or NULL in case of failure. |
273 |
*/ |
274 |
const char ** lscp_get_available_audio_drivers ( lscp_client_t *pClient ) |
275 |
{ |
276 |
const char *pszSeps = ","; |
277 |
|
278 |
// Lock this section up. |
279 |
lscp_mutex_lock(pClient->mutex); |
280 |
|
281 |
if (pClient->audio_drivers) { |
282 |
lscp_szsplit_destroy(pClient->audio_drivers); |
283 |
pClient->audio_drivers = NULL; |
284 |
} |
285 |
|
286 |
if (lscp_client_call(pClient, "GET AVAILABLE_AUDIO_OUTPUT_DRIVERS\r\n") == LSCP_OK) |
287 |
pClient->audio_drivers = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps); |
288 |
|
289 |
// Unlock this section down. |
290 |
lscp_mutex_unlock(pClient->mutex); |
291 |
|
292 |
return (const char **) pClient->audio_drivers; |
293 |
} |
294 |
|
295 |
|
296 |
/** |
297 |
* Getting informations about a specific audio output driver. |
298 |
* GET AUDIO_OUTPUT_DRIVER INFO <audio-output-type> |
299 |
* |
300 |
* @param pClient Pointer to client instance structure. |
301 |
* @param pszAudioDriver Audio driver type string (e.g. "ALSA"). |
302 |
* |
303 |
* @returns A pointer to a @ref lscp_driver_info_t structure, with |
304 |
* the given audio driver information, or NULL in case of failure. |
305 |
*/ |
306 |
lscp_driver_info_t* lscp_get_audio_driver_info ( lscp_client_t *pClient, const char *pszAudioDriver ) |
307 |
{ |
308 |
char szQuery[LSCP_BUFSIZ]; |
309 |
|
310 |
if (pszAudioDriver == NULL) |
311 |
return NULL; |
312 |
|
313 |
sprintf(szQuery, "GET AUDIO_OUTPUT_DRIVER INFO %s\r\n", pszAudioDriver); |
314 |
return _lscp_driver_info_query(pClient, &(pClient->audio_driver_info), szQuery); |
315 |
} |
316 |
|
317 |
|
318 |
/** |
319 |
* Getting informations about specific audio output driver parameter. |
320 |
* GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO <audio-output-driver> <param> [<dep-list>] |
321 |
* |
322 |
* @param pClient Pointer to client instance structure. |
323 |
* @param pszAudioDriver Audio driver type string (e.g. "ALSA"). |
324 |
* @param pszParam Audio driver parameter name. |
325 |
* @param pDepList Pointer to specific dependencies parameter list. |
326 |
* |
327 |
* @returns A pointer to a @ref lscp_param_info_t structure, with |
328 |
* the given audio driver parameter information, or NULL in case of failure. |
329 |
*/ |
330 |
lscp_param_info_t *lscp_get_audio_driver_param_info ( lscp_client_t *pClient, const char *pszAudioDriver, const char *pszParam, lscp_param_t *pDepList ) |
331 |
{ |
332 |
char szQuery[LSCP_BUFSIZ]; |
333 |
|
334 |
if (pClient == NULL) |
335 |
return NULL; |
336 |
if (pszAudioDriver == NULL) |
337 |
return NULL; |
338 |
if (pszParam == NULL) |
339 |
return NULL; |
340 |
|
341 |
sprintf(szQuery, "GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO %s %s", pszAudioDriver, pszParam); |
342 |
return _lscp_param_info_query(pClient, &(pClient->audio_param_info), szQuery, sizeof(szQuery), pDepList); |
343 |
} |
344 |
|
345 |
|
346 |
//------------------------------------------------------------------------- |
347 |
// Audio device control functions. |
348 |
|
349 |
/** |
350 |
* Creating an audio output device. |
351 |
* CREATE AUDIO_OUTPUT_DEVICE <audio-output-driver> [<params>] |
352 |
* |
353 |
* @param pClient Pointer to client instance structure. |
354 |
* @param pszAudioDriver Audio driver type string (e.g. "ALSA"). |
355 |
* @param pParams Pointer to specific parameter list. |
356 |
* |
357 |
* @returns The new audio device number identifier on success, |
358 |
* or -1 in case of failure. |
359 |
*/ |
360 |
int lscp_create_audio_device ( lscp_client_t *pClient, const char *pszAudioDriver, lscp_param_t *pParams ) |
361 |
{ |
362 |
char szQuery[LSCP_BUFSIZ]; |
363 |
int iAudioDevice = -1; |
364 |
|
365 |
if (pClient == NULL) |
366 |
return iAudioDevice; |
367 |
if (pszAudioDriver == NULL) |
368 |
return iAudioDevice; |
369 |
|
370 |
// Lock this section up. |
371 |
lscp_mutex_lock(pClient->mutex); |
372 |
|
373 |
sprintf(szQuery, "CREATE AUDIO_OUTPUT_DEVICE %s", pszAudioDriver); |
374 |
lscp_param_concat(szQuery, sizeof(szQuery), pParams); |
375 |
if (lscp_client_call(pClient, szQuery) == LSCP_OK) |
376 |
iAudioDevice = atoi(lscp_client_get_result(pClient)); |
377 |
|
378 |
// Unlock this section down. |
379 |
lscp_mutex_unlock(pClient->mutex); |
380 |
|
381 |
return iAudioDevice; |
382 |
} |
383 |
|
384 |
|
385 |
/** |
386 |
* Destroying an audio output device. |
387 |
* DESTROY AUDIO_OUTPUT_DEVICE <audio-device-id> |
388 |
* |
389 |
* @param pClient Pointer to client instance structure. |
390 |
* @param iAudioDevice Audio device number identifier. |
391 |
* |
392 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
393 |
*/ |
394 |
lscp_status_t lscp_destroy_audio_device ( lscp_client_t *pClient, int iAudioDevice ) |
395 |
{ |
396 |
lscp_status_t ret = LSCP_FAILED; |
397 |
char szQuery[LSCP_BUFSIZ]; |
398 |
|
399 |
if (pClient == NULL) |
400 |
return ret; |
401 |
if (iAudioDevice < 0) |
402 |
return ret; |
403 |
|
404 |
sprintf(szQuery, "DESTROY AUDIO_OUTPUT_DEVICE %d\r\n", iAudioDevice); |
405 |
return lscp_client_query(pClient, szQuery); |
406 |
} |
407 |
|
408 |
|
409 |
/** |
410 |
* Getting all created audio output device count. |
411 |
* GET AUDIO_OUTPUT_DEVICES |
412 |
* |
413 |
* @param pClient Pointer to client instance structure. |
414 |
* |
415 |
* @returns The current total number of audio devices on success, |
416 |
* -1 otherwise. |
417 |
*/ |
418 |
int lscp_get_audio_devices ( lscp_client_t *pClient ) |
419 |
{ |
420 |
int iAudioDevices = -1; |
421 |
|
422 |
// Lock this section up. |
423 |
lscp_mutex_lock(pClient->mutex); |
424 |
|
425 |
if (lscp_client_call(pClient, "GET AUDIO_OUTPUT_DEVICES\r\n") == LSCP_OK) |
426 |
iAudioDevices = atoi(lscp_client_get_result(pClient)); |
427 |
|
428 |
// Unlock this section down. |
429 |
lscp_mutex_unlock(pClient->mutex); |
430 |
|
431 |
return iAudioDevices; |
432 |
} |
433 |
|
434 |
|
435 |
/** |
436 |
* Getting all created audio output device list. |
437 |
* LIST AUDIO_OUTPUT_DEVICES |
438 |
* |
439 |
* @param pClient Pointer to client instance structure. |
440 |
* |
441 |
* @returns An array of audio device number identifiers, |
442 |
* terminated with -1 on success, or NULL in case of failure. |
443 |
*/ |
444 |
int *lscp_list_audio_devices ( lscp_client_t *pClient ) |
445 |
{ |
446 |
const char *pszSeps = ","; |
447 |
|
448 |
if (pClient == NULL) |
449 |
return NULL; |
450 |
|
451 |
// Lock this section up. |
452 |
lscp_mutex_lock(pClient->mutex); |
453 |
|
454 |
if (pClient->audio_devices) { |
455 |
lscp_isplit_destroy(pClient->audio_devices); |
456 |
pClient->audio_devices = NULL; |
457 |
} |
458 |
|
459 |
if (lscp_client_call(pClient, "LIST AUDIO_OUTPUT_DEVICES\r\n") == LSCP_OK) |
460 |
pClient->audio_devices = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps); |
461 |
|
462 |
// Unlock this section down. |
463 |
lscp_mutex_unlock(pClient->mutex); |
464 |
|
465 |
return pClient->audio_devices; |
466 |
} |
467 |
|
468 |
|
469 |
/** |
470 |
* Getting current settings of an audio output device. |
471 |
* GET AUDIO_OUTPUT_DEVICE INFO <audio-device-id> |
472 |
* |
473 |
* @param pClient Pointer to client instance structure. |
474 |
* @param iAudioDevice Audio device number identifier. |
475 |
* |
476 |
* @returns A pointer to a @ref lscp_device_info_t structure, with |
477 |
* the given audio device information, or NULL in case of failure. |
478 |
*/ |
479 |
lscp_device_info_t *lscp_get_audio_device_info ( lscp_client_t *pClient, int iAudioDevice ) |
480 |
{ |
481 |
char szQuery[LSCP_BUFSIZ]; |
482 |
|
483 |
if (pClient == NULL) |
484 |
return NULL; |
485 |
if (iAudioDevice < 0) |
486 |
return NULL; |
487 |
|
488 |
sprintf(szQuery, "GET AUDIO_OUTPUT_DEVICE INFO %d\r\n", iAudioDevice); |
489 |
return _lscp_device_info_query(pClient, &(pClient->audio_device_info), szQuery); |
490 |
} |
491 |
|
492 |
|
493 |
/** |
494 |
* Changing settings of audio output devices. |
495 |
* SET AUDIO_OUTPUT_DEVICE_PARAMETER <audio-device-id> <param>=<value> |
496 |
* |
497 |
* @param pClient Pointer to client instance structure. |
498 |
* @param iAudioDevice Audio device number identifier. |
499 |
* @param pParam Pointer to a key-valued audio device parameter. |
500 |
* |
501 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
502 |
*/ |
503 |
lscp_status_t lscp_set_audio_device_param ( lscp_client_t *pClient, int iAudioDevice, lscp_param_t *pParam ) |
504 |
{ |
505 |
char szQuery[LSCP_BUFSIZ]; |
506 |
|
507 |
if (pClient == NULL) |
508 |
return LSCP_FAILED; |
509 |
if (iAudioDevice < 0) |
510 |
return LSCP_FAILED; |
511 |
if (pParam == NULL) |
512 |
return LSCP_FAILED; |
513 |
|
514 |
sprintf(szQuery, "SET AUDIO_OUTPUT_DEVICE_PARAMETER %d %s='%s'", iAudioDevice, pParam->key, pParam->value); |
515 |
return lscp_client_query(pClient, szQuery); |
516 |
} |
517 |
|
518 |
|
519 |
/** |
520 |
* Getting informations about an audio channel. |
521 |
* GET AUDIO_OUTPUT_CHANNEL INFO <audio-device-id> <audio-channel> |
522 |
* |
523 |
* @param pClient Pointer to client instance structure. |
524 |
* @param iAudioDevice Audio device number identifier. |
525 |
* @param iAudioChannel Audio channel number. |
526 |
* |
527 |
* @returns A pointer to a @ref lscp_device_port_info_t structure, |
528 |
* with the given audio channel information, or NULL in case of failure. |
529 |
*/ |
530 |
lscp_device_port_info_t* lscp_get_audio_channel_info ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel ) |
531 |
{ |
532 |
char szQuery[LSCP_BUFSIZ]; |
533 |
|
534 |
if (pClient == NULL) |
535 |
return NULL; |
536 |
if (iAudioDevice < 0) |
537 |
return NULL; |
538 |
if (iAudioChannel < 0) |
539 |
return NULL; |
540 |
|
541 |
sprintf(szQuery, "GET AUDIO_OUTPUT_CHANNEL INFO %d %d\r\n", iAudioDevice, iAudioChannel); |
542 |
return _lscp_device_port_info_query(pClient, &(pClient->audio_channel_info), szQuery); |
543 |
} |
544 |
|
545 |
|
546 |
/** |
547 |
* Getting informations about specific audio channel parameter. |
548 |
* GET AUDIO_OUTPUT_CHANNEL_PARAMETER INFO <audio-device-id> <audio-channel> <param> |
549 |
* |
550 |
* @param pClient Pointer to client instance structure. |
551 |
* @param iAudioDevice Audio device number identifier. |
552 |
* @param iAudioChannel Audio channel number. |
553 |
* @param pszParam Audio channel parameter name. |
554 |
* |
555 |
* @returns A pointer to a @ref lscp_param_info_t structure, with |
556 |
* the given audio channel parameter information, or NULL in case of failure. |
557 |
*/ |
558 |
lscp_param_info_t* lscp_get_audio_channel_param_info ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel, const char *pszParam ) |
559 |
{ |
560 |
char szQuery[LSCP_BUFSIZ]; |
561 |
|
562 |
if (pClient == NULL) |
563 |
return NULL; |
564 |
if (iAudioDevice < 0) |
565 |
return NULL; |
566 |
if (iAudioChannel < 0) |
567 |
return NULL; |
568 |
if (pszParam == NULL) |
569 |
return NULL; |
570 |
|
571 |
sprintf(szQuery, "GET AUDIO_OUTPUT_CHANNEL_PARAMETER INFO %d %d %s", iAudioDevice, iAudioChannel, pszParam); |
572 |
return _lscp_param_info_query(pClient, &(pClient->audio_channel_param_info), szQuery, sizeof(szQuery), NULL); |
573 |
} |
574 |
|
575 |
|
576 |
/** |
577 |
* Changing settings of audio output channels. |
578 |
* SET AUDIO_OUTPUT_CHANNEL_PARAMETER <audio-device-id> <audio-channel> <param> <value> |
579 |
* |
580 |
* @param pClient Pointer to client instance structure. |
581 |
* @param iAudioDevice Audio device number identifier. |
582 |
* @param iAudioChannel Audio channel number. |
583 |
* @param pParam Pointer to a key-valued audio channel parameter. |
584 |
* |
585 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
586 |
*/ |
587 |
lscp_status_t lscp_set_audio_channel_param ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel, lscp_param_t *pParam ) |
588 |
{ |
589 |
char szQuery[LSCP_BUFSIZ]; |
590 |
|
591 |
if (pClient == NULL) |
592 |
return LSCP_FAILED; |
593 |
if (iAudioDevice < 0) |
594 |
return LSCP_FAILED; |
595 |
if (iAudioChannel < 0) |
596 |
return LSCP_FAILED; |
597 |
if (pParam == NULL) |
598 |
return LSCP_FAILED; |
599 |
|
600 |
sprintf(szQuery, "SET AUDIO_OUTPUT_CHANNEL_PARAMETER %d %d %s='%s'", iAudioDevice, iAudioChannel, pParam->key, pParam->value); |
601 |
return lscp_client_query(pClient, szQuery); |
602 |
} |
603 |
|
604 |
|
605 |
//------------------------------------------------------------------------- |
606 |
// MIDI driver control functions. |
607 |
|
608 |
/** |
609 |
* Getting all available MIDI input drivers. |
610 |
* GET AVAILABLE_MIDI_INPUT_DRIVERS |
611 |
* |
612 |
* @param pClient Pointer to client instance structure. |
613 |
* |
614 |
* @returns A NULL terminated array of MIDI input driver type |
615 |
* name strings, or NULL in case of failure. |
616 |
*/ |
617 |
const char** lscp_get_available_midi_drivers ( lscp_client_t *pClient ) |
618 |
{ |
619 |
const char *pszSeps = ","; |
620 |
|
621 |
// Lock this section up. |
622 |
lscp_mutex_lock(pClient->mutex); |
623 |
|
624 |
if (pClient->midi_drivers) { |
625 |
lscp_szsplit_destroy(pClient->midi_drivers); |
626 |
pClient->midi_drivers = NULL; |
627 |
} |
628 |
|
629 |
if (lscp_client_call(pClient, "GET AVAILABLE_MIDI_INPUT_DRIVERS\r\n") == LSCP_OK) |
630 |
pClient->midi_drivers = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps); |
631 |
|
632 |
// Unlock this section up. |
633 |
lscp_mutex_unlock(pClient->mutex); |
634 |
|
635 |
return (const char **) pClient->midi_drivers; |
636 |
} |
637 |
|
638 |
|
639 |
/** |
640 |
* Getting informations about a specific MIDI input driver. |
641 |
* GET MIDI_INPUT_DRIVER INFO <midi-input-type> |
642 |
* |
643 |
* @param pClient Pointer to client instance structure. |
644 |
* @param pszMidiDriver MIDI driver type string (e.g. "ALSA"). |
645 |
* |
646 |
* @returns A pointer to a @ref lscp_driver_info_t structure, with |
647 |
* the given MIDI driver information, or NULL in case of failure. |
648 |
*/ |
649 |
lscp_driver_info_t* lscp_get_midi_driver_info ( lscp_client_t *pClient, const char *pszMidiDriver ) |
650 |
{ |
651 |
char szQuery[LSCP_BUFSIZ]; |
652 |
|
653 |
if (pszMidiDriver == NULL) |
654 |
return NULL; |
655 |
|
656 |
sprintf(szQuery, "GET MIDI_INPUT_DRIVER INFO %s\r\n", pszMidiDriver); |
657 |
return _lscp_driver_info_query(pClient, &(pClient->midi_driver_info), szQuery); |
658 |
} |
659 |
|
660 |
|
661 |
/** |
662 |
* Getting informations about specific MIDI input driver parameter. |
663 |
* GET MIDI_INPUT_DRIVER_PARAMETER INFO <midi-input-driver> <param> [<dep-list>] |
664 |
* |
665 |
* @param pClient Pointer to client instance structure. |
666 |
* @param pszMidiDriver MIDI driver type string (e.g. "ALSA"). |
667 |
* @param pszParam MIDI driver parameter name. |
668 |
* @param pDepList Pointer to specific dependencies parameter list. |
669 |
* |
670 |
* @returns A pointer to a @ref lscp_param_info_t structure, with |
671 |
* the given MIDI driver parameter information, or NULL in case of failure. |
672 |
* |
673 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
674 |
*/ |
675 |
lscp_param_info_t *lscp_get_midi_driver_param_info ( lscp_client_t *pClient, const char *pszMidiDriver, const char *pszParam, lscp_param_t *pDepList ) |
676 |
{ |
677 |
char szQuery[LSCP_BUFSIZ]; |
678 |
|
679 |
if (pClient == NULL) |
680 |
return NULL; |
681 |
if (pszMidiDriver == NULL) |
682 |
return NULL; |
683 |
if (pszParam == NULL) |
684 |
return NULL; |
685 |
|
686 |
sprintf(szQuery, "GET MIDI_INPUT_DRIVER_PARAMETER INFO %s %s", pszMidiDriver, pszParam); |
687 |
return _lscp_param_info_query(pClient, &(pClient->midi_param_info), szQuery, sizeof(szQuery), pDepList); |
688 |
} |
689 |
|
690 |
|
691 |
//------------------------------------------------------------------------- |
692 |
// MIDI device control functions. |
693 |
|
694 |
/** |
695 |
* Creating a MIDI input device. |
696 |
* CREATE MIDI_INPUT_DEVICE <midi-input-driver> [<params>] |
697 |
* |
698 |
* @param pClient Pointer to client instance structure. |
699 |
* @param pszMidiDriver MIDI driver type string (e.g. "ALSA"). |
700 |
* @param pParams Pointer to specific parameter list. |
701 |
* |
702 |
* @returns The new audio device number identifier on success, |
703 |
* or -1 in case of failure. |
704 |
*/ |
705 |
int lscp_create_midi_device ( lscp_client_t *pClient, const char *pszMidiDriver, lscp_param_t *pParams ) |
706 |
{ |
707 |
char szQuery[LSCP_BUFSIZ]; |
708 |
int iMidiDevice = -1; |
709 |
|
710 |
if (pClient == NULL) |
711 |
return iMidiDevice; |
712 |
if (pszMidiDriver == NULL) |
713 |
return iMidiDevice; |
714 |
|
715 |
// Lock this section up. |
716 |
lscp_mutex_lock(pClient->mutex); |
717 |
|
718 |
sprintf(szQuery, "CREATE MIDI_INPUT_DEVICE %s", pszMidiDriver); |
719 |
lscp_param_concat(szQuery, sizeof(szQuery), pParams); |
720 |
if (lscp_client_call(pClient, szQuery) == LSCP_OK) |
721 |
iMidiDevice = atoi(lscp_client_get_result(pClient)); |
722 |
|
723 |
// Unlock this section down. |
724 |
lscp_mutex_unlock(pClient->mutex); |
725 |
|
726 |
return iMidiDevice; |
727 |
} |
728 |
|
729 |
|
730 |
/** |
731 |
* Destroying a MIDI input device. |
732 |
* DESTROY MIDI_INPUT_DEVICE <midi-device-id> |
733 |
* |
734 |
* @param pClient Pointer to client instance structure. |
735 |
* @param iMidiDevice MIDI device number identifier. |
736 |
* |
737 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
738 |
*/ |
739 |
lscp_status_t lscp_destroy_midi_device ( lscp_client_t *pClient, int iMidiDevice ) |
740 |
{ |
741 |
lscp_status_t ret = LSCP_FAILED; |
742 |
char szQuery[LSCP_BUFSIZ]; |
743 |
|
744 |
if (pClient == NULL) |
745 |
return ret; |
746 |
if (iMidiDevice < 0) |
747 |
return ret; |
748 |
|
749 |
sprintf(szQuery, "DESTROY MIDI_INPUT_DEVICE %d\r\n", iMidiDevice); |
750 |
return lscp_client_query(pClient, szQuery); |
751 |
} |
752 |
|
753 |
|
754 |
/** |
755 |
* Getting all created MIDI intput device count. |
756 |
* GET MIDI_INPUT_DEVICES |
757 |
* |
758 |
* @param pClient Pointer to client instance structure. |
759 |
* |
760 |
* @returns The current total number of MIDI devices on success, |
761 |
* -1 otherwise. |
762 |
*/ |
763 |
int lscp_get_midi_devices ( lscp_client_t *pClient ) |
764 |
{ |
765 |
int iMidiDevices = -1; |
766 |
|
767 |
// Lock this section up. |
768 |
lscp_mutex_lock(pClient->mutex); |
769 |
|
770 |
if (lscp_client_call(pClient, "GET MIDI_INPUT_DEVICES\r\n") == LSCP_OK) |
771 |
iMidiDevices = atoi(lscp_client_get_result(pClient)); |
772 |
|
773 |
// Unlock this section down. |
774 |
lscp_mutex_unlock(pClient->mutex); |
775 |
|
776 |
return iMidiDevices; |
777 |
} |
778 |
|
779 |
|
780 |
/** |
781 |
* Getting all created MIDI intput device list. |
782 |
* LIST MIDI_INPUT_DEVICES |
783 |
* |
784 |
* @param pClient Pointer to client instance structure. |
785 |
* |
786 |
* @returns An array of MIDI device number identifiers, |
787 |
* terminated with -1 on success, or NULL in case of failure. |
788 |
*/ |
789 |
int *lscp_list_midi_devices ( lscp_client_t *pClient ) |
790 |
{ |
791 |
const char *pszSeps = ","; |
792 |
|
793 |
if (pClient == NULL) |
794 |
return NULL; |
795 |
|
796 |
// Lock this section up. |
797 |
lscp_mutex_lock(pClient->mutex); |
798 |
|
799 |
if (pClient->midi_devices) { |
800 |
lscp_isplit_destroy(pClient->midi_devices); |
801 |
pClient->midi_devices = NULL; |
802 |
} |
803 |
|
804 |
if (lscp_client_call(pClient, "LIST MIDI_INPUT_DEVICES\r\n") == LSCP_OK) |
805 |
pClient->midi_devices = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps); |
806 |
|
807 |
// Unlock this section down. |
808 |
lscp_mutex_unlock(pClient->mutex); |
809 |
|
810 |
return pClient->midi_devices; |
811 |
} |
812 |
|
813 |
|
814 |
/** |
815 |
* Getting current settings of a MIDI input device. |
816 |
* GET MIDI_INPUT_DEVICE INFO <midi-device-id> |
817 |
* |
818 |
* @param pClient Pointer to client instance structure. |
819 |
* @param iMidiDevice MIDI device number identifier. |
820 |
* |
821 |
* @returns A pointer to a @ref lscp_device_info_t structure, with |
822 |
* the given MIDI device information, or NULL in case of failure. |
823 |
*/ |
824 |
lscp_device_info_t* lscp_get_midi_device_info ( lscp_client_t *pClient, int iMidiDevice ) |
825 |
{ |
826 |
char szQuery[LSCP_BUFSIZ]; |
827 |
|
828 |
if (pClient == NULL) |
829 |
return NULL; |
830 |
if (iMidiDevice < 0) |
831 |
return NULL; |
832 |
|
833 |
sprintf(szQuery, "GET MIDI_INPUT_DEVICE INFO %d\r\n", iMidiDevice); |
834 |
return _lscp_device_info_query(pClient, &(pClient->midi_device_info), szQuery); |
835 |
} |
836 |
|
837 |
|
838 |
/** |
839 |
* Changing settings of MIDI input devices. |
840 |
* SET MIDI_INPUT_DEVICE_PARAMETER <midi-device-id> <param>=<value> |
841 |
* |
842 |
* @param pClient Pointer to client instance structure. |
843 |
* @param iMidiDevice MIDI device number identifier. |
844 |
* @param pParam Pointer to a key-valued MIDI device parameter. |
845 |
* |
846 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
847 |
*/ |
848 |
lscp_status_t lscp_set_midi_device_param ( lscp_client_t *pClient, int iMidiDevice, lscp_param_t *pParam ) |
849 |
{ |
850 |
char szQuery[LSCP_BUFSIZ]; |
851 |
|
852 |
if (pClient == NULL) |
853 |
return LSCP_FAILED; |
854 |
if (iMidiDevice < 0) |
855 |
return LSCP_FAILED; |
856 |
if (pParam == NULL) |
857 |
return LSCP_FAILED; |
858 |
|
859 |
sprintf(szQuery, "SET MIDI_INPUT_DEVICE_PARAMETER %d %s='%s'", iMidiDevice, pParam->key, pParam->value); |
860 |
return lscp_client_query(pClient, szQuery); |
861 |
} |
862 |
|
863 |
|
864 |
/** |
865 |
* Getting informations about a MIDI port. |
866 |
* GET MIDI_INPUT_PORT INFO <midi-device-id> <midi-port> |
867 |
* |
868 |
* @param pClient Pointer to client instance structure. |
869 |
* @param iMidiDevice MIDI device number identifier. |
870 |
* @param iMidiPort MIDI port number. |
871 |
* |
872 |
* @returns A pointer to a @ref lscp_device_port_info_t structure, |
873 |
* with the given MIDI port information, or NULL in case of failure. |
874 |
*/ |
875 |
lscp_device_port_info_t* lscp_get_midi_port_info ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort ) |
876 |
{ |
877 |
char szQuery[LSCP_BUFSIZ]; |
878 |
|
879 |
if (pClient == NULL) |
880 |
return NULL; |
881 |
if (iMidiDevice < 0) |
882 |
return NULL; |
883 |
if (iMidiPort < 0) |
884 |
return NULL; |
885 |
|
886 |
sprintf(szQuery, "GET MIDI_INPUT_PORT INFO %d %d\r\n", iMidiDevice, iMidiPort); |
887 |
return _lscp_device_port_info_query(pClient, &(pClient->midi_port_info), szQuery); |
888 |
} |
889 |
|
890 |
|
891 |
/** |
892 |
* Getting informations about specific MIDI port parameter. |
893 |
* GET MIDI_INPUT_PORT_PARAMETER INFO <midi-device-id> <midi-port> <param> |
894 |
* |
895 |
* @param pClient Pointer to client instance structure. |
896 |
* @param iMidiDevice MIDI device number identifier. |
897 |
* @param iMidiPort MIDI port number. |
898 |
* @param pszParam MIDI port parameter name. |
899 |
* |
900 |
* @returns A pointer to a @ref lscp_param_info_t structure, with |
901 |
* the given MIDI port parameter information, or NULL in case of failure. |
902 |
*/ |
903 |
lscp_param_info_t* lscp_get_midi_port_param_info ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort, const char *pszParam ) |
904 |
{ |
905 |
char szQuery[LSCP_BUFSIZ]; |
906 |
|
907 |
if (pClient == NULL) |
908 |
return NULL; |
909 |
if (iMidiDevice < 0) |
910 |
return NULL; |
911 |
if (iMidiPort < 0) |
912 |
return NULL; |
913 |
if (pszParam == NULL) |
914 |
return NULL; |
915 |
|
916 |
sprintf(szQuery, "GET MIDI_INPUT_PORT_PARAMETER INFO %d %d %s", iMidiDevice, iMidiPort, pszParam); |
917 |
return _lscp_param_info_query(pClient, &(pClient->midi_port_param_info), szQuery, sizeof(szQuery), NULL); |
918 |
} |
919 |
|
920 |
|
921 |
/** |
922 |
* Changing settings of MIDI input ports. |
923 |
* SET MIDI_INPUT_PORT_PARAMETER <midi-device-id> <midi-port> <param> <value> |
924 |
* |
925 |
* @param pClient Pointer to client instance structure. |
926 |
* @param iMidiDevice MIDI device number identifier. |
927 |
* @param iMidiPort MIDI port number. |
928 |
* @param pParam Pointer to a key-valued MIDI port parameter. |
929 |
* |
930 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
931 |
*/ |
932 |
lscp_status_t lscp_set_midi_port_param ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort, lscp_param_t *pParam ) |
933 |
{ |
934 |
char szQuery[LSCP_BUFSIZ]; |
935 |
|
936 |
if (pClient == NULL) |
937 |
return LSCP_FAILED; |
938 |
if (iMidiDevice < 0) |
939 |
return LSCP_FAILED; |
940 |
if (iMidiPort < 0) |
941 |
return LSCP_FAILED; |
942 |
if (pParam == NULL) |
943 |
return LSCP_FAILED; |
944 |
|
945 |
sprintf(szQuery, "SET MIDI_INPUT_PORT_PARAMETER %d %d %s='%s'", iMidiDevice, iMidiPort, pParam->key, pParam->value); |
946 |
return lscp_client_query(pClient, szQuery); |
947 |
} |
948 |
|
949 |
|
950 |
//------------------------------------------------------------------------- |
951 |
// Generic parameter list functions. |
952 |
|
953 |
const char *lscp_get_param_value ( lscp_param_t *pParams, const char *pszParam ) |
954 |
{ |
955 |
int i; |
956 |
|
957 |
for (i = 0; pParams && pParams[i].key; i++) { |
958 |
if (strcasecmp(pParams[i].key, pszParam) == 0) |
959 |
return (const char *) pParams[i].value; |
960 |
} |
961 |
return NULL; |
962 |
} |
963 |
|
964 |
|
965 |
// end of device.c |
966 |
|