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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 975 - (hide annotations) (download)
Sun Dec 17 00:59:40 2006 UTC (17 years, 4 months ago) by capela
File MIME type: text/plain
File size: 31456 byte(s)
* MIDI instrument mapping, second round, according to
  LSCP 1.2 draft document as of December 15, 2006.

* New client interface functions:
     lscp_set_channel_midi_map();
     lscp_add_midi_instrument_map();
     lscp_remove_midi_instrument_map();
     lscp_get_midi_instrument_maps();
     lscp_list_midi_instrument_maps();
     lscp_get_midi_instrument_map_name();
     lscp_set_midi_instrument_map_name();

1 capela 107 // device.c
2     //
3     /****************************************************************************
4     liblscp - LinuxSampler Control Protocol API
5 capela 869 Copyright (C) 2004-2006, rncbc aka Rui Nuno Capela. All rights reserved.
6 capela 107
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 capela 921 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 capela 107
21     *****************************************************************************/
22    
23     #include "common.h"
24    
25    
26     // Local prototypes.
27    
28 capela 163 static lscp_driver_info_t *_lscp_driver_info_query (lscp_client_t *pClient, lscp_driver_info_t *pDriverInfo, char *pszQuery);
29 capela 171 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 capela 107
32 capela 171 static lscp_device_port_info_t *_lscp_device_port_info_query (lscp_client_t *pClient, lscp_device_port_info_t *pDevicePortInfo, char *pszQuery);
33 capela 107
34 capela 171
35 capela 107 //-------------------------------------------------------------------------
36     // Local funtions.
37    
38     // Common driver type query command.
39 capela 163 static lscp_driver_info_t *_lscp_driver_info_query ( lscp_client_t *pClient, lscp_driver_info_t *pDriverInfo, char *pszQuery )
40 capela 107 {
41 capela 952 const char *pszResult;
42     const char *pszSeps = ":";
43     const char *pszCrlf = "\r\n";
44     char *pszToken;
45     char *pch;
46 capela 107
47 capela 952 // Lock this section up.
48     lscp_mutex_lock(pClient->mutex);
49 capela 132
50 capela 952 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 capela 107
81 capela 952 return pDriverInfo;
82 capela 107 }
83    
84    
85 capela 171 // 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 capela 952 const char *pszResult;
89     const char *pszSeps = ":";
90     const char *pszCrlf = "\r\n";
91     char *pszToken;
92     char *pch;
93     char *pszKey;
94 capela 171
95 capela 952 // Lock this section up.
96     lscp_mutex_lock(pClient->mutex);
97 capela 171
98 capela 952 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 capela 171
119 capela 952 // Unlock this section down.
120     lscp_mutex_unlock(pClient->mutex);
121 capela 171
122 capela 952 return pDeviceInfo;
123 capela 171 }
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 capela 952 const char *pszResult;
130     const char *pszSeps = ":";
131     const char *pszCrlf = "\r\n";
132     char *pszToken;
133     char *pch;
134     char *pszKey;
135 capela 171
136 capela 952 // Lock this section up.
137     lscp_mutex_lock(pClient->mutex);
138 capela 171
139 capela 952 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 capela 171
160 capela 952 // Unlock this section down.
161     lscp_mutex_unlock(pClient->mutex);
162 capela 171
163 capela 952 return pDevicePortInfo;
164 capela 171 }
165    
166    
167 capela 163 // Common parameter info query command.
168 capela 171 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 capela 163 {
170 capela 952 const char *pszResult;
171     const char *pszSeps = ":";
172     const char *pszCrlf = "\r\n";
173     char *pszToken;
174     char *pch;
175 capela 163
176 capela 952 // Lock this section up.
177     lscp_mutex_lock(pClient->mutex);
178 capela 163
179 capela 952 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 capela 163
255 capela 952 // Unlock this section down.
256     lscp_mutex_unlock(pClient->mutex);
257 capela 163
258 capela 952 return pParamInfo;
259 capela 163 }
260    
261    
262 capela 107 //-------------------------------------------------------------------------
263     // Audio driver control functions.
264    
265     /**
266 capela 523 * Getting all available audio output driver count.
267 capela 107 * GET AVAILABLE_AUDIO_OUTPUT_DRIVERS
268     *
269     * @param pClient Pointer to client instance structure.
270     *
271 capela 523 * @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 capela 952 int iAudioDrivers = -1;
277 capela 523
278 capela 975 if (pClient == NULL)
279     return -1;
280    
281 capela 952 // Lock this section up.
282     lscp_mutex_lock(pClient->mutex);
283 capela 523
284 capela 952 if (lscp_client_call(pClient, "GET AVAILABLE_AUDIO_OUTPUT_DRIVERS\r\n", 0) == LSCP_OK)
285     iAudioDrivers = atoi(lscp_client_get_result(pClient));
286 capela 523
287 capela 952 // Unlock this section down.
288     lscp_mutex_unlock(pClient->mutex);
289 capela 523
290 capela 952 return iAudioDrivers;
291 capela 523 }
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 capela 107 * @returns A NULL terminated array of audio output driver type
301     * name strings, or NULL in case of failure.
302     */
303 capela 523 const char ** lscp_list_available_audio_drivers ( lscp_client_t *pClient )
304 capela 107 {
305 capela 952 const char *pszSeps = ",";
306 capela 107
307 capela 975 if (pClient == NULL)
308     return NULL;
309    
310 capela 952 // Lock this section up.
311     lscp_mutex_lock(pClient->mutex);
312 capela 132
313 capela 952 if (pClient->audio_drivers) {
314     lscp_szsplit_destroy(pClient->audio_drivers);
315     pClient->audio_drivers = NULL;
316     }
317 capela 107
318 capela 952 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 capela 107
321 capela 952 // Unlock this section down.
322     lscp_mutex_unlock(pClient->mutex);
323 capela 132
324 capela 952 return (const char **) pClient->audio_drivers;
325 capela 107 }
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 capela 952 char szQuery[LSCP_BUFSIZ];
341 capela 107
342 capela 952 if (pszAudioDriver == NULL)
343     return NULL;
344 capela 107
345 capela 952 sprintf(szQuery, "GET AUDIO_OUTPUT_DRIVER INFO %s\r\n", pszAudioDriver);
346     return _lscp_driver_info_query(pClient, &(pClient->audio_driver_info), szQuery);
347 capela 107 }
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 capela 952 char szQuery[LSCP_BUFSIZ];
365 capela 107
366 capela 952 if (pClient == NULL)
367     return NULL;
368     if (pszAudioDriver == NULL)
369     return NULL;
370     if (pszParam == NULL)
371     return NULL;
372 capela 107
373 capela 952 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 capela 107 }
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 capela 952 char szQuery[LSCP_BUFSIZ];
395     int iAudioDevice = -1;
396 capela 107
397 capela 952 if (pClient == NULL)
398 capela 975 return -1;
399 capela 952 if (pszAudioDriver == NULL)
400 capela 975 return -1;
401 capela 107
402 capela 952 // Lock this section up.
403     lscp_mutex_lock(pClient->mutex);
404 capela 171
405 capela 952 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 capela 171
410 capela 952 // Unlock this section down.
411     lscp_mutex_unlock(pClient->mutex);
412 capela 171
413 capela 952 return iAudioDevice;
414 capela 107 }
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 capela 952 lscp_status_t ret = LSCP_FAILED;
429     char szQuery[LSCP_BUFSIZ];
430 capela 107
431 capela 952 if (pClient == NULL)
432     return ret;
433     if (iAudioDevice < 0)
434     return ret;
435 capela 107
436 capela 952 sprintf(szQuery, "DESTROY AUDIO_OUTPUT_DEVICE %d\r\n", iAudioDevice);
437     return lscp_client_query(pClient, szQuery);
438 capela 107 }
439    
440    
441     /**
442 capela 125 * Getting all created audio output device count.
443 capela 107 * GET AUDIO_OUTPUT_DEVICES
444     *
445     * @param pClient Pointer to client instance structure.
446     *
447 capela 125 * @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 capela 952 int iAudioDevices = -1;
453 capela 132
454 capela 975 if (pClient == NULL)
455     return -1;
456    
457 capela 952 // Lock this section up.
458     lscp_mutex_lock(pClient->mutex);
459 capela 132
460 capela 952 if (lscp_client_call(pClient, "GET AUDIO_OUTPUT_DEVICES\r\n", 0) == LSCP_OK)
461     iAudioDevices = atoi(lscp_client_get_result(pClient));
462 capela 132
463 capela 952 // Unlock this section down.
464     lscp_mutex_unlock(pClient->mutex);
465 capela 132
466 capela 952 return iAudioDevices;
467 capela 125 }
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 capela 107 * @returns An array of audio device number identifiers,
477     * terminated with -1 on success, or NULL in case of failure.
478     */
479 capela 125 int *lscp_list_audio_devices ( lscp_client_t *pClient )
480 capela 107 {
481 capela 952 const char *pszSeps = ",";
482 capela 107
483 capela 952 if (pClient == NULL)
484     return NULL;
485 capela 107
486 capela 952 // Lock this section up.
487     lscp_mutex_lock(pClient->mutex);
488 capela 132
489 capela 952 if (pClient->audio_devices) {
490     lscp_isplit_destroy(pClient->audio_devices);
491     pClient->audio_devices = NULL;
492     }
493 capela 125
494 capela 952 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 capela 125
497 capela 952 // Unlock this section down.
498     lscp_mutex_unlock(pClient->mutex);
499 capela 132
500 capela 952 return pClient->audio_devices;
501 capela 107 }
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 capela 952 char szQuery[LSCP_BUFSIZ];
517 capela 107
518 capela 952 if (pClient == NULL)
519     return NULL;
520     if (iAudioDevice < 0)
521     return NULL;
522 capela 107
523 capela 952 sprintf(szQuery, "GET AUDIO_OUTPUT_DEVICE INFO %d\r\n", iAudioDevice);
524     return _lscp_device_info_query(pClient, &(pClient->audio_device_info), szQuery);
525 capela 107 }
526    
527    
528     /**
529     * Changing settings of audio output devices.
530 capela 171 * SET AUDIO_OUTPUT_DEVICE_PARAMETER <audio-device-id> <param>=<value>
531 capela 107 *
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 capela 952 char szQuery[LSCP_BUFSIZ];
541 capela 107
542 capela 952 if (pClient == NULL)
543     return LSCP_FAILED;
544     if (iAudioDevice < 0)
545     return LSCP_FAILED;
546     if (pParam == NULL)
547     return LSCP_FAILED;
548 capela 107
549 capela 952 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 capela 107 }
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 capela 171 * @returns A pointer to a @ref lscp_device_port_info_t structure,
563 capela 107 * with the given audio channel information, or NULL in case of failure.
564     */
565 capela 171 lscp_device_port_info_t* lscp_get_audio_channel_info ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel )
566 capela 107 {
567 capela 952 char szQuery[LSCP_BUFSIZ];
568 capela 107
569 capela 952 if (pClient == NULL)
570     return NULL;
571     if (iAudioDevice < 0)
572     return NULL;
573     if (iAudioChannel < 0)
574     return NULL;
575 capela 107
576 capela 952 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 capela 107 }
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 capela 952 char szQuery[LSCP_BUFSIZ];
596 capela 107
597 capela 952 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 capela 107
606 capela 952 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 capela 107 }
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 capela 952 char szQuery[LSCP_BUFSIZ];
625 capela 107
626 capela 952 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 capela 107
635 capela 952 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 capela 107 }
638    
639    
640     //-------------------------------------------------------------------------
641     // MIDI driver control functions.
642    
643     /**
644 capela 523 * Getting all available MIDI input driver count.
645 capela 107 * GET AVAILABLE_MIDI_INPUT_DRIVERS
646     *
647     * @param pClient Pointer to client instance structure.
648     *
649 capela 523 * @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 capela 952 int iMidiDrivers = -1;
655 capela 523
656 capela 975 if (pClient == NULL)
657     return -1;
658    
659 capela 952 // Lock this section up.
660     lscp_mutex_lock(pClient->mutex);
661 capela 523
662 capela 952 if (lscp_client_call(pClient, "GET AVAILABLE_MIDI_INPUT_DRIVERS\r\n", 0) == LSCP_OK)
663     iMidiDrivers = atoi(lscp_client_get_result(pClient));
664 capela 523
665 capela 952 // Unlock this section up.
666     lscp_mutex_unlock(pClient->mutex);
667 capela 523
668 capela 952 return iMidiDrivers;
669 capela 523 }
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 capela 107 * @returns A NULL terminated array of MIDI input driver type
679     * name strings, or NULL in case of failure.
680     */
681 capela 523 const char** lscp_list_available_midi_drivers ( lscp_client_t *pClient )
682 capela 107 {
683 capela 952 const char *pszSeps = ",";
684 capela 107
685 capela 975 if (pClient == NULL)
686     return NULL;
687    
688 capela 952 // Lock this section up.
689     lscp_mutex_lock(pClient->mutex);
690 capela 132
691 capela 952 if (pClient->midi_drivers) {
692     lscp_szsplit_destroy(pClient->midi_drivers);
693     pClient->midi_drivers = NULL;
694     }
695 capela 107
696 capela 952 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 capela 107
699 capela 952 // Unlock this section up.
700     lscp_mutex_unlock(pClient->mutex);
701 capela 132
702 capela 952 return (const char **) pClient->midi_drivers;
703 capela 107 }
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 capela 952 char szQuery[LSCP_BUFSIZ];
719 capela 107
720 capela 952 if (pszMidiDriver == NULL)
721     return NULL;
722 capela 107
723 capela 952 sprintf(szQuery, "GET MIDI_INPUT_DRIVER INFO %s\r\n", pszMidiDriver);
724     return _lscp_driver_info_query(pClient, &(pClient->midi_driver_info), szQuery);
725 capela 107 }
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 capela 952 char szQuery[LSCP_BUFSIZ];
745 capela 107
746 capela 952 if (pClient == NULL)
747     return NULL;
748     if (pszMidiDriver == NULL)
749     return NULL;
750     if (pszParam == NULL)
751     return NULL;
752 capela 107
753 capela 952 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 capela 107 }
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 capela 952 char szQuery[LSCP_BUFSIZ];
775     int iMidiDevice = -1;
776 capela 107
777 capela 952 if (pClient == NULL)
778 capela 975 return -1;
779 capela 952 if (pszMidiDriver == NULL)
780 capela 975 return -1;
781 capela 107
782 capela 952 // Lock this section up.
783     lscp_mutex_lock(pClient->mutex);
784 capela 171
785 capela 952 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 capela 171
790 capela 952 // Unlock this section down.
791     lscp_mutex_unlock(pClient->mutex);
792 capela 171
793 capela 952 return iMidiDevice;
794 capela 107 }
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 capela 952 lscp_status_t ret = LSCP_FAILED;
809     char szQuery[LSCP_BUFSIZ];
810 capela 107
811 capela 952 if (pClient == NULL)
812     return ret;
813     if (iMidiDevice < 0)
814     return ret;
815 capela 107
816 capela 952 sprintf(szQuery, "DESTROY MIDI_INPUT_DEVICE %d\r\n", iMidiDevice);
817     return lscp_client_query(pClient, szQuery);
818 capela 107 }
819    
820    
821     /**
822 capela 125 * Getting all created MIDI intput device count.
823 capela 107 * GET MIDI_INPUT_DEVICES
824     *
825     * @param pClient Pointer to client instance structure.
826     *
827 capela 125 * @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 capela 952 int iMidiDevices = -1;
833 capela 132
834 capela 975 if (pClient == NULL)
835     return -1;
836    
837 capela 952 // Lock this section up.
838     lscp_mutex_lock(pClient->mutex);
839 capela 132
840 capela 952 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 capela 132
846 capela 952 return iMidiDevices;
847 capela 125 }
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 capela 107 * @returns An array of MIDI device number identifiers,
857     * terminated with -1 on success, or NULL in case of failure.
858     */
859 capela 125 int *lscp_list_midi_devices ( lscp_client_t *pClient )
860 capela 107 {
861 capela 952 const char *pszSeps = ",";
862 capela 107
863 capela 952 if (pClient == NULL)
864     return NULL;
865 capela 107
866 capela 952 // Lock this section up.
867     lscp_mutex_lock(pClient->mutex);
868 capela 132
869 capela 952 if (pClient->midi_devices) {
870     lscp_isplit_destroy(pClient->midi_devices);
871     pClient->midi_devices = NULL;
872     }
873 capela 125
874 capela 952 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 capela 125
877 capela 952 // Unlock this section down.
878     lscp_mutex_unlock(pClient->mutex);
879 capela 132
880 capela 952 return pClient->midi_devices;
881 capela 107 }
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 capela 952 char szQuery[LSCP_BUFSIZ];
897 capela 107
898 capela 952 if (pClient == NULL)
899     return NULL;
900     if (iMidiDevice < 0)
901     return NULL;
902 capela 107
903 capela 952 sprintf(szQuery, "GET MIDI_INPUT_DEVICE INFO %d\r\n", iMidiDevice);
904     return _lscp_device_info_query(pClient, &(pClient->midi_device_info), szQuery);
905 capela 107 }
906    
907    
908     /**
909     * Changing settings of MIDI input devices.
910 capela 171 * SET MIDI_INPUT_DEVICE_PARAMETER <midi-device-id> <param>=<value>
911 capela 107 *
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 capela 952 char szQuery[LSCP_BUFSIZ];
921 capela 107
922 capela 952 if (pClient == NULL)
923     return LSCP_FAILED;
924     if (iMidiDevice < 0)
925     return LSCP_FAILED;
926     if (pParam == NULL)
927     return LSCP_FAILED;
928 capela 107
929 capela 952 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 capela 107 }
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 capela 171 * @returns A pointer to a @ref lscp_device_port_info_t structure,
943 capela 107 * with the given MIDI port information, or NULL in case of failure.
944     */
945 capela 171 lscp_device_port_info_t* lscp_get_midi_port_info ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort )
946 capela 107 {
947 capela 952 char szQuery[LSCP_BUFSIZ];
948 capela 107
949 capela 952 if (pClient == NULL)
950     return NULL;
951     if (iMidiDevice < 0)
952     return NULL;
953     if (iMidiPort < 0)
954     return NULL;
955 capela 107
956 capela 952 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 capela 107 }
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 capela 952 char szQuery[LSCP_BUFSIZ];
976 capela 107
977 capela 952 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 capela 107
986 capela 952 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 capela 107 }
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 capela 952 char szQuery[LSCP_BUFSIZ];
1005 capela 107
1006 capela 952 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 capela 107
1015 capela 952 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 capela 107 }
1018    
1019 capela 189
1020     //-------------------------------------------------------------------------
1021     // Generic parameter list functions.
1022    
1023     const char *lscp_get_param_value ( lscp_param_t *pParams, const char *pszParam )
1024     {
1025 capela 952 int i;
1026 capela 449
1027 capela 952 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 capela 189 }
1033    
1034    
1035 capela 107 // end of device.c
1036    

  ViewVC Help
Powered by ViewVC