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_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", iAudioDevice); |
515 |
lscp_param_concat(szQuery, sizeof(szQuery), pParam); |
516 |
return lscp_client_query(pClient, szQuery); |
517 |
} |
518 |
|
519 |
|
520 |
/** |
521 |
* Getting informations about an audio channel. |
522 |
* GET AUDIO_OUTPUT_CHANNEL INFO <audio-device-id> <audio-channel> |
523 |
* |
524 |
* @param pClient Pointer to client instance structure. |
525 |
* @param iAudioDevice Audio device number identifier. |
526 |
* @param iAudioChannel Audio channel number. |
527 |
* |
528 |
* @returns A pointer to a @ref lscp_device_port_info_t structure, |
529 |
* with the given audio channel information, or NULL in case of failure. |
530 |
*/ |
531 |
lscp_device_port_info_t* lscp_get_audio_channel_info ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel ) |
532 |
{ |
533 |
char szQuery[LSCP_BUFSIZ]; |
534 |
|
535 |
if (pClient == NULL) |
536 |
return NULL; |
537 |
if (iAudioDevice < 0) |
538 |
return NULL; |
539 |
if (iAudioChannel < 0) |
540 |
return NULL; |
541 |
|
542 |
sprintf(szQuery, "GET AUDIO_OUTPUT_CHANNEL INFO %d %d\r\n", iAudioDevice, iAudioChannel); |
543 |
return _lscp_device_port_info_query(pClient, &(pClient->audio_channel_info), szQuery); |
544 |
} |
545 |
|
546 |
|
547 |
/** |
548 |
* Getting informations about specific audio channel parameter. |
549 |
* GET AUDIO_OUTPUT_CHANNEL_PARAMETER INFO <audio-device-id> <audio-channel> <param> |
550 |
* |
551 |
* @param pClient Pointer to client instance structure. |
552 |
* @param iAudioDevice Audio device number identifier. |
553 |
* @param iAudioChannel Audio channel number. |
554 |
* @param pszParam Audio channel parameter name. |
555 |
* |
556 |
* @returns A pointer to a @ref lscp_param_info_t structure, with |
557 |
* the given audio channel parameter information, or NULL in case of failure. |
558 |
*/ |
559 |
lscp_param_info_t* lscp_get_audio_channel_param_info ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel, const char *pszParam ) |
560 |
{ |
561 |
char szQuery[LSCP_BUFSIZ]; |
562 |
|
563 |
if (pClient == NULL) |
564 |
return NULL; |
565 |
if (iAudioDevice < 0) |
566 |
return NULL; |
567 |
if (iAudioChannel < 0) |
568 |
return NULL; |
569 |
if (pszParam == NULL) |
570 |
return NULL; |
571 |
|
572 |
sprintf(szQuery, "GET AUDIO_OUTPUT_CHANNEL_PARAMETER INFO %d %d %s", iAudioDevice, iAudioChannel, pszParam); |
573 |
return _lscp_param_info_query(pClient, &(pClient->audio_channel_param_info), szQuery, sizeof(szQuery), NULL); |
574 |
} |
575 |
|
576 |
|
577 |
/** |
578 |
* Changing settings of audio output channels. |
579 |
* SET AUDIO_OUTPUT_CHANNEL_PARAMETER <audio-device-id> <audio-channel> <param> <value> |
580 |
* |
581 |
* @param pClient Pointer to client instance structure. |
582 |
* @param iAudioDevice Audio device number identifier. |
583 |
* @param iAudioChannel Audio channel number. |
584 |
* @param pParam Pointer to a key-valued audio channel parameter. |
585 |
* |
586 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
587 |
*/ |
588 |
lscp_status_t lscp_set_audio_channel_param ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel, lscp_param_t *pParam ) |
589 |
{ |
590 |
char szQuery[LSCP_BUFSIZ]; |
591 |
|
592 |
if (pClient == NULL) |
593 |
return LSCP_FAILED; |
594 |
if (iAudioDevice < 0) |
595 |
return LSCP_FAILED; |
596 |
if (iAudioChannel < 0) |
597 |
return LSCP_FAILED; |
598 |
if (pParam == NULL) |
599 |
return LSCP_FAILED; |
600 |
|
601 |
sprintf(szQuery, "SET AUDIO_OUTPUT_CHANNEL_PARAMETER %d %d", iAudioDevice, iAudioChannel); |
602 |
lscp_param_concat(szQuery, sizeof(szQuery), pParam); |
603 |
return lscp_client_query(pClient, szQuery); |
604 |
} |
605 |
|
606 |
|
607 |
//------------------------------------------------------------------------- |
608 |
// MIDI driver control functions. |
609 |
|
610 |
/** |
611 |
* Getting all available MIDI input drivers. |
612 |
* GET AVAILABLE_MIDI_INPUT_DRIVERS |
613 |
* |
614 |
* @param pClient Pointer to client instance structure. |
615 |
* |
616 |
* @returns A NULL terminated array of MIDI input driver type |
617 |
* name strings, or NULL in case of failure. |
618 |
*/ |
619 |
const char** lscp_get_available_midi_drivers ( lscp_client_t *pClient ) |
620 |
{ |
621 |
const char *pszSeps = ","; |
622 |
|
623 |
// Lock this section up. |
624 |
lscp_mutex_lock(pClient->mutex); |
625 |
|
626 |
if (pClient->midi_drivers) { |
627 |
lscp_szsplit_destroy(pClient->midi_drivers); |
628 |
pClient->midi_drivers = NULL; |
629 |
} |
630 |
|
631 |
if (lscp_client_call(pClient, "GET AVAILABLE_MIDI_INPUT_DRIVERS\r\n") == LSCP_OK) |
632 |
pClient->midi_drivers = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps); |
633 |
|
634 |
// Unlock this section up. |
635 |
lscp_mutex_unlock(pClient->mutex); |
636 |
|
637 |
return (const char **) pClient->midi_drivers; |
638 |
} |
639 |
|
640 |
|
641 |
/** |
642 |
* Getting informations about a specific MIDI input driver. |
643 |
* GET MIDI_INPUT_DRIVER INFO <midi-input-type> |
644 |
* |
645 |
* @param pClient Pointer to client instance structure. |
646 |
* @param pszMidiDriver MIDI driver type string (e.g. "ALSA"). |
647 |
* |
648 |
* @returns A pointer to a @ref lscp_driver_info_t structure, with |
649 |
* the given MIDI driver information, or NULL in case of failure. |
650 |
*/ |
651 |
lscp_driver_info_t* lscp_get_midi_driver_info ( lscp_client_t *pClient, const char *pszMidiDriver ) |
652 |
{ |
653 |
char szQuery[LSCP_BUFSIZ]; |
654 |
|
655 |
if (pszMidiDriver == NULL) |
656 |
return NULL; |
657 |
|
658 |
sprintf(szQuery, "GET MIDI_INPUT_DRIVER INFO %s\r\n", pszMidiDriver); |
659 |
return _lscp_driver_info_query(pClient, &(pClient->midi_driver_info), szQuery); |
660 |
} |
661 |
|
662 |
|
663 |
/** |
664 |
* Getting informations about specific MIDI input driver parameter. |
665 |
* GET MIDI_INPUT_DRIVER_PARAMETER INFO <midi-input-driver> <param> [<dep-list>] |
666 |
* |
667 |
* @param pClient Pointer to client instance structure. |
668 |
* @param pszMidiDriver MIDI driver type string (e.g. "ALSA"). |
669 |
* @param pszParam MIDI driver parameter name. |
670 |
* @param pDepList Pointer to specific dependencies parameter list. |
671 |
* |
672 |
* @returns A pointer to a @ref lscp_param_info_t structure, with |
673 |
* the given MIDI driver parameter information, or NULL in case of failure. |
674 |
* |
675 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
676 |
*/ |
677 |
lscp_param_info_t *lscp_get_midi_driver_param_info ( lscp_client_t *pClient, const char *pszMidiDriver, const char *pszParam, lscp_param_t *pDepList ) |
678 |
{ |
679 |
char szQuery[LSCP_BUFSIZ]; |
680 |
|
681 |
if (pClient == NULL) |
682 |
return NULL; |
683 |
if (pszMidiDriver == NULL) |
684 |
return NULL; |
685 |
if (pszParam == NULL) |
686 |
return NULL; |
687 |
|
688 |
sprintf(szQuery, "GET MIDI_INPUT_DRIVER_PARAMETER INFO %s %s", pszMidiDriver, pszParam); |
689 |
return _lscp_param_info_query(pClient, &(pClient->midi_param_info), szQuery, sizeof(szQuery), pDepList); |
690 |
} |
691 |
|
692 |
|
693 |
//------------------------------------------------------------------------- |
694 |
// MIDI device control functions. |
695 |
|
696 |
/** |
697 |
* Creating a MIDI input device. |
698 |
* CREATE MIDI_INPUT_DEVICE <midi-input-driver> [<params>] |
699 |
* |
700 |
* @param pClient Pointer to client instance structure. |
701 |
* @param pszMidiDriver MIDI driver type string (e.g. "ALSA"). |
702 |
* @param pParams Pointer to specific parameter list. |
703 |
* |
704 |
* @returns The new audio device number identifier on success, |
705 |
* or -1 in case of failure. |
706 |
*/ |
707 |
int lscp_create_midi_device ( lscp_client_t *pClient, const char *pszMidiDriver, lscp_param_t *pParams ) |
708 |
{ |
709 |
char szQuery[LSCP_BUFSIZ]; |
710 |
int iMidiDevice = -1; |
711 |
|
712 |
if (pClient == NULL) |
713 |
return iMidiDevice; |
714 |
if (pszMidiDriver == NULL) |
715 |
return iMidiDevice; |
716 |
|
717 |
// Lock this section up. |
718 |
lscp_mutex_lock(pClient->mutex); |
719 |
|
720 |
sprintf(szQuery, "CREATE MIDI_INPUT_DEVICE %s", pszMidiDriver); |
721 |
lscp_param_concat(szQuery, sizeof(szQuery), pParams); |
722 |
if (lscp_client_call(pClient, szQuery) == LSCP_OK) |
723 |
iMidiDevice = atoi(lscp_client_get_result(pClient)); |
724 |
|
725 |
// Unlock this section down. |
726 |
lscp_mutex_unlock(pClient->mutex); |
727 |
|
728 |
return iMidiDevice; |
729 |
} |
730 |
|
731 |
|
732 |
/** |
733 |
* Destroying a MIDI input device. |
734 |
* DESTROY MIDI_INPUT_DEVICE <midi-device-id> |
735 |
* |
736 |
* @param pClient Pointer to client instance structure. |
737 |
* @param iMidiDevice MIDI device number identifier. |
738 |
* |
739 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
740 |
*/ |
741 |
lscp_status_t lscp_destroy_midi_device ( lscp_client_t *pClient, int iMidiDevice ) |
742 |
{ |
743 |
lscp_status_t ret = LSCP_FAILED; |
744 |
char szQuery[LSCP_BUFSIZ]; |
745 |
|
746 |
if (pClient == NULL) |
747 |
return ret; |
748 |
if (iMidiDevice < 0) |
749 |
return ret; |
750 |
|
751 |
sprintf(szQuery, "DESTROY MIDI_INPUT_DEVICE %d\r\n", iMidiDevice); |
752 |
return lscp_client_query(pClient, szQuery); |
753 |
} |
754 |
|
755 |
|
756 |
/** |
757 |
* Getting all created MIDI intput device count. |
758 |
* GET MIDI_INPUT_DEVICES |
759 |
* |
760 |
* @param pClient Pointer to client instance structure. |
761 |
* |
762 |
* @returns The current total number of MIDI devices on success, |
763 |
* -1 otherwise. |
764 |
*/ |
765 |
int lscp_get_midi_devices ( lscp_client_t *pClient ) |
766 |
{ |
767 |
int iMidiDevices = -1; |
768 |
|
769 |
// Lock this section up. |
770 |
lscp_mutex_lock(pClient->mutex); |
771 |
|
772 |
if (lscp_client_call(pClient, "GET MIDI_INPUT_DEVICES\r\n") == LSCP_OK) |
773 |
iMidiDevices = atoi(lscp_client_get_result(pClient)); |
774 |
|
775 |
// Unlock this section down. |
776 |
lscp_mutex_unlock(pClient->mutex); |
777 |
|
778 |
return iMidiDevices; |
779 |
} |
780 |
|
781 |
|
782 |
/** |
783 |
* Getting all created MIDI intput device list. |
784 |
* LIST MIDI_INPUT_DEVICES |
785 |
* |
786 |
* @param pClient Pointer to client instance structure. |
787 |
* |
788 |
* @returns An array of MIDI device number identifiers, |
789 |
* terminated with -1 on success, or NULL in case of failure. |
790 |
*/ |
791 |
int *lscp_list_midi_devices ( lscp_client_t *pClient ) |
792 |
{ |
793 |
const char *pszSeps = ","; |
794 |
|
795 |
if (pClient == NULL) |
796 |
return NULL; |
797 |
|
798 |
// Lock this section up. |
799 |
lscp_mutex_lock(pClient->mutex); |
800 |
|
801 |
if (pClient->midi_devices) { |
802 |
lscp_isplit_destroy(pClient->midi_devices); |
803 |
pClient->midi_devices = NULL; |
804 |
} |
805 |
|
806 |
if (lscp_client_call(pClient, "LIST MIDI_INPUT_DEVICES\r\n") == LSCP_OK) |
807 |
pClient->midi_devices = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps); |
808 |
|
809 |
// Unlock this section down. |
810 |
lscp_mutex_unlock(pClient->mutex); |
811 |
|
812 |
return pClient->midi_devices; |
813 |
} |
814 |
|
815 |
|
816 |
/** |
817 |
* Getting current settings of a MIDI input device. |
818 |
* GET MIDI_INPUT_DEVICE INFO <midi-device-id> |
819 |
* |
820 |
* @param pClient Pointer to client instance structure. |
821 |
* @param iMidiDevice MIDI device number identifier. |
822 |
* |
823 |
* @returns A pointer to a @ref lscp_device_info_t structure, with |
824 |
* the given MIDI device information, or NULL in case of failure. |
825 |
*/ |
826 |
lscp_device_info_t* lscp_get_midi_device_info ( lscp_client_t *pClient, int iMidiDevice ) |
827 |
{ |
828 |
char szQuery[LSCP_BUFSIZ]; |
829 |
|
830 |
if (pClient == NULL) |
831 |
return NULL; |
832 |
if (iMidiDevice < 0) |
833 |
return NULL; |
834 |
|
835 |
sprintf(szQuery, "GET MIDI_INPUT_DEVICE INFO %d\r\n", iMidiDevice); |
836 |
return _lscp_device_info_query(pClient, &(pClient->midi_device_info), szQuery); |
837 |
} |
838 |
|
839 |
|
840 |
/** |
841 |
* Changing settings of MIDI input devices. |
842 |
* SET MIDI_INPUT_DEVICE_PARAMETER <midi-device-id> <param>=<value> |
843 |
* |
844 |
* @param pClient Pointer to client instance structure. |
845 |
* @param iMidiDevice MIDI device number identifier. |
846 |
* @param pParam Pointer to a key-valued MIDI device parameter. |
847 |
* |
848 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
849 |
*/ |
850 |
lscp_status_t lscp_set_midi_device_param ( lscp_client_t *pClient, int iMidiDevice, lscp_param_t *pParam ) |
851 |
{ |
852 |
char szQuery[LSCP_BUFSIZ]; |
853 |
|
854 |
if (pClient == NULL) |
855 |
return LSCP_FAILED; |
856 |
if (iMidiDevice < 0) |
857 |
return LSCP_FAILED; |
858 |
if (pParam == NULL) |
859 |
return LSCP_FAILED; |
860 |
|
861 |
sprintf(szQuery, "SET MIDI_INPUT_DEVICE_PARAMETER %d", iMidiDevice); |
862 |
lscp_param_concat(szQuery, sizeof(szQuery), pParam); |
863 |
return lscp_client_query(pClient, szQuery); |
864 |
} |
865 |
|
866 |
|
867 |
/** |
868 |
* Getting informations about a MIDI port. |
869 |
* GET MIDI_INPUT_PORT INFO <midi-device-id> <midi-port> |
870 |
* |
871 |
* @param pClient Pointer to client instance structure. |
872 |
* @param iMidiDevice MIDI device number identifier. |
873 |
* @param iMidiPort MIDI port number. |
874 |
* |
875 |
* @returns A pointer to a @ref lscp_device_port_info_t structure, |
876 |
* with the given MIDI port information, or NULL in case of failure. |
877 |
*/ |
878 |
lscp_device_port_info_t* lscp_get_midi_port_info ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort ) |
879 |
{ |
880 |
char szQuery[LSCP_BUFSIZ]; |
881 |
|
882 |
if (pClient == NULL) |
883 |
return NULL; |
884 |
if (iMidiDevice < 0) |
885 |
return NULL; |
886 |
if (iMidiPort < 0) |
887 |
return NULL; |
888 |
|
889 |
sprintf(szQuery, "GET MIDI_INPUT_PORT INFO %d %d\r\n", iMidiDevice, iMidiPort); |
890 |
return _lscp_device_port_info_query(pClient, &(pClient->midi_port_info), szQuery); |
891 |
} |
892 |
|
893 |
|
894 |
/** |
895 |
* Getting informations about specific MIDI port parameter. |
896 |
* GET MIDI_INPUT_PORT_PARAMETER INFO <midi-device-id> <midi-port> <param> |
897 |
* |
898 |
* @param pClient Pointer to client instance structure. |
899 |
* @param iMidiDevice MIDI device number identifier. |
900 |
* @param iMidiPort MIDI port number. |
901 |
* @param pszParam MIDI port parameter name. |
902 |
* |
903 |
* @returns A pointer to a @ref lscp_param_info_t structure, with |
904 |
* the given MIDI port parameter information, or NULL in case of failure. |
905 |
*/ |
906 |
lscp_param_info_t* lscp_get_midi_port_param_info ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort, const char *pszParam ) |
907 |
{ |
908 |
char szQuery[LSCP_BUFSIZ]; |
909 |
|
910 |
if (pClient == NULL) |
911 |
return NULL; |
912 |
if (iMidiDevice < 0) |
913 |
return NULL; |
914 |
if (iMidiPort < 0) |
915 |
return NULL; |
916 |
if (pszParam == NULL) |
917 |
return NULL; |
918 |
|
919 |
sprintf(szQuery, "GET MIDI_INPUT_PORT_PARAMETER INFO %d %d %s", iMidiDevice, iMidiPort, pszParam); |
920 |
return _lscp_param_info_query(pClient, &(pClient->midi_port_param_info), szQuery, sizeof(szQuery), NULL); |
921 |
} |
922 |
|
923 |
|
924 |
/** |
925 |
* Changing settings of MIDI input ports. |
926 |
* SET MIDI_INPUT_PORT_PARAMETER <midi-device-id> <midi-port> <param> <value> |
927 |
* |
928 |
* @param pClient Pointer to client instance structure. |
929 |
* @param iMidiDevice MIDI device number identifier. |
930 |
* @param iMidiPort MIDI port number. |
931 |
* @param pParam Pointer to a key-valued MIDI port parameter. |
932 |
* |
933 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
934 |
*/ |
935 |
lscp_status_t lscp_set_midi_port_param ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort, lscp_param_t *pParam ) |
936 |
{ |
937 |
char szQuery[LSCP_BUFSIZ]; |
938 |
|
939 |
if (pClient == NULL) |
940 |
return LSCP_FAILED; |
941 |
if (iMidiDevice < 0) |
942 |
return LSCP_FAILED; |
943 |
if (iMidiPort < 0) |
944 |
return LSCP_FAILED; |
945 |
if (pParam == NULL) |
946 |
return LSCP_FAILED; |
947 |
|
948 |
sprintf(szQuery, "SET MIDI_INPUT_PORT_PARAMETER %d %d", iMidiDevice, iMidiPort); |
949 |
lscp_param_concat(szQuery, sizeof(szQuery), pParam); |
950 |
return lscp_client_query(pClient, szQuery); |
951 |
} |
952 |
|
953 |
|
954 |
//------------------------------------------------------------------------- |
955 |
// Generic parameter list functions. |
956 |
|
957 |
const char *lscp_get_param_value ( lscp_param_t *pParams, const char *pszParam ) |
958 |
{ |
959 |
int i; |
960 |
|
961 |
for (i = 0; pParams && pParams[i].key; i++) { |
962 |
if (strcasecmp(pParams[i].key, pszParam) == 0) |
963 |
return (const char *) pParams[i].value; |
964 |
} |
965 |
return NULL; |
966 |
} |
967 |
|
968 |
|
969 |
// end of device.c |
970 |
|