/[svn]/liblscp/trunk/src/device.c
ViewVC logotype

Contents of /liblscp/trunk/src/device.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1019 - (show annotations) (download)
Thu Jan 11 12:33:05 2007 UTC (17 years, 3 months ago) by capela
File MIME type: text/plain
File size: 31456 byte(s)
* Added new client interface functions, for sampler
  channel effect sends control:
	 lscp_create_fxsend();
	 lscp_destroy_fxsend();
	 lscp_get_fxsends();
	 lscp_list_fxsends();
	 lscp_get_fxsend_info();
	 lscp_set_fxsend_audio_channel();
  and for global volume:
	 lscp_get_volume();
	 lscp_set_volume();

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

  ViewVC Help
Powered by ViewVC