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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 180 - (hide annotations) (download)
Tue Jul 6 20:20:51 2004 UTC (19 years, 10 months ago) by capela
File MIME type: text/plain
File size: 32022 byte(s)
Prepared for 0.2.0 release.

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

  ViewVC Help
Powered by ViewVC