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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 171 - (show annotations) (download)
Mon Jul 5 16:26:44 2004 UTC (19 years, 9 months ago) by capela
File MIME type: text/plain
File size: 31582 byte(s)
Milestone for integral implementation of draft-protocol v.11.

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

  ViewVC Help
Powered by ViewVC