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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 107 by capela, Fri Jun 4 21:06:59 2004 UTC revision 523 by capela, Mon May 9 10:17:12 2005 UTC
# Line 2  Line 2 
2  //  //
3  /****************************************************************************  /****************************************************************************
4     liblscp - LinuxSampler Control Protocol API     liblscp - LinuxSampler Control Protocol API
5     Copyright (C) 2004, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2005, rncbc aka Rui Nuno Capela. All rights reserved.
6    
7     This library is free software; you can redistribute it and/or     This library is free software; you can redistribute it and/or
8     modify it under the terms of the GNU Lesser General Public     modify it under the terms of the GNU Lesser General Public
# Line 25  Line 25 
25    
26  // Local prototypes.  // Local prototypes.
27    
28  static lscp_driver_info_t *_lscp_driver_info_query (lscp_client_t *pClient, lscp_driver_info_t *pDriverInfo, const char *pszQuery);  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.  // Local funtions.
37    
38  // Common driver type query command.  // Common driver type query command.
39  static lscp_driver_info_t *_lscp_driver_info_query ( lscp_client_t *pClient, lscp_driver_info_t *pDriverInfo, const char *pszQuery )  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;      const char *pszResult;
42      const char *pszSeps = ":";      const char *pszSeps = ":";
# Line 40  static lscp_driver_info_t *_lscp_driver_ Line 44  static lscp_driver_info_t *_lscp_driver_
44      char *pszToken;      char *pszToken;
45      char *pch;      char *pch;
46    
47        // Lock this section up.
48        lscp_mutex_lock(pClient->mutex);
49    
50      lscp_driver_info_reset(pDriverInfo);      lscp_driver_info_reset(pDriverInfo);
51        if (lscp_client_call(pClient, pszQuery) == LSCP_OK) {
52            pszResult = lscp_client_get_result(pClient);
53            pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
54            while (pszToken) {
55                if (strcasecmp(pszToken, "DESCRIPTION") == 0) {
56                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
57                    if (pszToken)
58                        lscp_unquote_dup(&(pDriverInfo->description), &pszToken);
59                }
60                else if (strcasecmp(pszToken, "VERSION") == 0) {
61                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
62                    if (pszToken)
63                        lscp_unquote_dup(&(pDriverInfo->version), &pszToken);
64                }
65                else if (strcasecmp(pszToken, "PARAMETERS") == 0) {
66                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
67                    if (pszToken) {
68                        if (pDriverInfo->parameters)
69                            lscp_szsplit_destroy(pDriverInfo->parameters);
70                        pDriverInfo->parameters = lscp_szsplit_create(pszToken, ",");
71                    }
72                }
73                pszToken = lscp_strtok(NULL, pszSeps, &(pch));
74            }
75        }
76        else pDriverInfo = NULL;
77        
78        // Unlock this section down.
79        lscp_mutex_unlock(pClient->mutex);
80    
81      if (lscp_client_query(pClient, pszQuery) != LSCP_OK)      return pDriverInfo;
82          return NULL;  }
83    
84    
85    // Common device info query command.
86    static lscp_device_info_t *_lscp_device_info_query ( lscp_client_t *pClient, lscp_device_info_t *pDeviceInfo, char *pszQuery )
87    {
88        const char *pszResult;
89        const char *pszSeps = ":";
90        const char *pszCrlf = "\r\n";
91        char *pszToken;
92        char *pch;
93        char *pszKey;
94    
95        // Lock this section up.
96        lscp_mutex_lock(pClient->mutex);
97    
98      pszResult = lscp_client_get_result(pClient);      lscp_device_info_reset(pDeviceInfo);
99      pszToken = lscp_strtok(pszResult, pszSeps, &(pch));      if (lscp_client_call(pClient, pszQuery) == LSCP_OK) {
100      while (pszToken) {          pszResult = lscp_client_get_result(pClient);
101          if (strcasecmp(pszToken, "DESCRIPTION") == 0) {          pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
102              pszToken = lscp_strtok(NULL, pszCrlf, &(pch));          while (pszToken) {
103              if (pszToken)              if (strcasecmp(pszToken, "DRIVER") == 0) {
104                  pDriverInfo->description = lscp_unquote(&pszToken, 1);                  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          else if (strcasecmp(pszToken, "VERSION") == 0) {      }
117              pszToken = lscp_strtok(NULL, pszCrlf, &(pch));      else pDeviceInfo = NULL;
118              if (pszToken)  
119                  pDriverInfo->version = lscp_unquote(&pszToken, 1);      // Unlock this section down.
120        lscp_mutex_unlock(pClient->mutex);
121    
122        return pDeviceInfo;
123    }
124    
125    
126    // Common device channel/port info query command.
127    static lscp_device_port_info_t *_lscp_device_port_info_query ( lscp_client_t *pClient, lscp_device_port_info_t *pDevicePortInfo, char *pszQuery )
128    {
129        const char *pszResult;
130        const char *pszSeps = ":";
131        const char *pszCrlf = "\r\n";
132        char *pszToken;
133        char *pch;
134        char *pszKey;
135    
136        // Lock this section up.
137        lscp_mutex_lock(pClient->mutex);
138    
139        lscp_device_port_info_reset(pDevicePortInfo);
140        if (lscp_client_call(pClient, pszQuery) == LSCP_OK) {
141            pszResult = lscp_client_get_result(pClient);
142            pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
143            while (pszToken) {
144                if (strcasecmp(pszToken, "NAME") == 0) {
145                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
146                    if (pszToken)
147                        lscp_unquote_dup(&(pDevicePortInfo->name), &pszToken);
148                }
149                else {
150                    pszKey = pszToken;
151                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
152                    if (pszToken)
153                        lscp_plist_append(&(pDevicePortInfo->params), pszKey, lscp_unquote(&pszToken, 0));
154                }
155                pszToken = lscp_strtok(NULL, pszSeps, &(pch));
156          }          }
157          else if (strcasecmp(pszToken, "PARAMETERS") == 0) {      }
158              pszToken = lscp_strtok(NULL, pszCrlf, &(pch));      else pDevicePortInfo = NULL;
159              if (pszToken)  
160                  pDriverInfo->parameters = lscp_szsplit_create(pszToken, ",");      // Unlock this section down.
161        lscp_mutex_unlock(pClient->mutex);
162    
163        return pDevicePortInfo;
164    }
165    
166    
167    // Common parameter info query command.
168    static lscp_param_info_t *_lscp_param_info_query ( lscp_client_t *pClient, lscp_param_info_t *pParamInfo, char *pszQuery, int cchMaxQuery, lscp_param_t *pDepList )
169    {
170        const char *pszResult;
171        const char *pszSeps = ":";
172        const char *pszCrlf = "\r\n";
173        char *pszToken;
174        char *pch;
175    
176        // Lock this section up.
177        lscp_mutex_lock(pClient->mutex);
178    
179        lscp_param_info_reset(pParamInfo);
180        lscp_param_concat(pszQuery, cchMaxQuery, pDepList);
181        if (lscp_client_call(pClient, pszQuery) == LSCP_OK) {
182            pszResult = lscp_client_get_result(pClient);
183            pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
184            while (pszToken) {
185                if (strcasecmp(pszToken, "TYPE") == 0) {
186                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
187                    if (pszToken) {
188                        pszToken = lscp_unquote(&pszToken, 0);
189                        if (strcasecmp(pszToken, "BOOL") == 0)
190                            pParamInfo->type = LSCP_TYPE_BOOL;
191                        else if (strcasecmp(pszToken, "INT") == 0)
192                            pParamInfo->type = LSCP_TYPE_INT;
193                        else if (strcasecmp(pszToken, "FLOAT") == 0)
194                            pParamInfo->type = LSCP_TYPE_FLOAT;
195                        else if (strcasecmp(pszToken, "STRING") == 0)
196                            pParamInfo->type = LSCP_TYPE_STRING;
197                    }
198                }
199                else if (strcasecmp(pszToken, "DESCRIPTION") == 0) {
200                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
201                    if (pszToken)
202                        lscp_unquote_dup(&(pParamInfo->description), &pszToken);
203                }
204                else if (strcasecmp(pszToken, "MANDATORY") == 0) {
205                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
206                    if (pszToken)
207                        pParamInfo->mandatory = (strcasecmp(lscp_unquote(&pszToken, 0), "TRUE") == 0);
208                }
209                else if (strcasecmp(pszToken, "FIX") == 0) {
210                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
211                    if (pszToken)
212                        pParamInfo->fix = (strcasecmp(lscp_unquote(&pszToken, 0), "TRUE") == 0);
213                }
214                else if (strcasecmp(pszToken, "MULTIPLICITY") == 0) {
215                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
216                    if (pszToken)
217                        pParamInfo->multiplicity = (strcasecmp(lscp_unquote(&pszToken, 0), "TRUE") == 0);
218                }
219                else if (strcasecmp(pszToken, "DEPENDS") == 0) {
220                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
221                    if (pszToken) {
222                        if (pParamInfo->depends)
223                            lscp_szsplit_destroy(pParamInfo->depends);
224                        pParamInfo->depends = lscp_szsplit_create(pszToken, ",");
225                    }
226                }
227                else if (strcasecmp(pszToken, "DEFAULT") == 0) {
228                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
229                    if (pszToken)
230                        lscp_unquote_dup(&(pParamInfo->defaultv), &pszToken);
231                }
232                else if (strcasecmp(pszToken, "RANGE_MIN") == 0) {
233                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
234                    if (pszToken)
235                        lscp_unquote_dup(&(pParamInfo->range_min), &pszToken);
236                }
237                else if (strcasecmp(pszToken, "RANGE_MAX") == 0) {
238                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
239                    if (pszToken)
240                        lscp_unquote_dup(&(pParamInfo->range_max), &pszToken);
241                }
242                else if (strcasecmp(pszToken, "POSSIBILITIES") == 0) {
243                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
244                    if (pszToken) {
245                        if (pParamInfo->possibilities)
246                            lscp_szsplit_destroy(pParamInfo->possibilities);
247                        pParamInfo->possibilities = lscp_szsplit_create(pszToken, ",");
248                    }
249                }
250                pszToken = lscp_strtok(NULL, pszSeps, &(pch));
251          }          }
         pszToken = lscp_strtok(NULL, pszSeps, &(pch));  
252      }      }
253        else pParamInfo = NULL;
254    
255      return pDriverInfo;      // Unlock this section down.
256        lscp_mutex_unlock(pClient->mutex);
257    
258        return pParamInfo;
259  }  }
260    
261    
# Line 74  static lscp_driver_info_t *_lscp_driver_ Line 263  static lscp_driver_info_t *_lscp_driver_
263  // Audio driver control functions.  // Audio driver control functions.
264    
265  /**  /**
266   *  Getting all available audio output drivers.   *  Getting all available audio output driver count.
267   *  GET AVAILABLE_AUDIO_OUTPUT_DRIVERS   *  GET AVAILABLE_AUDIO_OUTPUT_DRIVERS
268   *   *
269   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
270   *   *
271     *  @returns The current total number of audio output drivers on success,
272     *  -1 otherwise.
273     */
274    int lscp_get_available_audio_drivers ( lscp_client_t *pClient )
275    {
276        int iAudioDrivers = -1;
277    
278        // Lock this section up.
279        lscp_mutex_lock(pClient->mutex);
280    
281        if (lscp_client_call(pClient, "GET AVAILABLE_AUDIO_OUTPUT_DRIVERS\r\n") == LSCP_OK)
282            iAudioDrivers = atoi(lscp_client_get_result(pClient));
283    
284        // Unlock this section down.
285        lscp_mutex_unlock(pClient->mutex);
286    
287        return iAudioDrivers;
288    }
289    
290    
291    /**
292     *  Getting all available audio output drivers.
293     *  LIST AVAILABLE_AUDIO_OUTPUT_DRIVERS
294     *
295     *  @param pClient  Pointer to client instance structure.
296     *
297   *  @returns A NULL terminated array of audio output driver type   *  @returns A NULL terminated array of audio output driver type
298   *  name strings, or NULL in case of failure.   *  name strings, or NULL in case of failure.
299   */   */
300  const char ** lscp_get_available_audio_drivers ( lscp_client_t *pClient )  const char ** lscp_list_available_audio_drivers ( lscp_client_t *pClient )
301  {  {
302      const char *pszSeps = ",";      const char *pszSeps = ",";
303    
304        // Lock this section up.
305        lscp_mutex_lock(pClient->mutex);
306    
307      if (pClient->audio_drivers) {      if (pClient->audio_drivers) {
308          lscp_szsplit_destroy(pClient->audio_drivers);          lscp_szsplit_destroy(pClient->audio_drivers);
309          pClient->audio_drivers = NULL;          pClient->audio_drivers = NULL;
310      }      }
311    
312      if (lscp_client_query(pClient, "GET AVAILABLE_AUDIO_OUTPUT_DRIVERS\r\n") == LSCP_OK)      if (lscp_client_call(pClient, "LIST AVAILABLE_AUDIO_OUTPUT_DRIVERS\r\n") == LSCP_OK)
313          pClient->audio_drivers = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps);          pClient->audio_drivers = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps);
314    
315        // Unlock this section down.
316        lscp_mutex_unlock(pClient->mutex);
317    
318      return (const char **) pClient->audio_drivers;      return (const char **) pClient->audio_drivers;
319  }  }
320    
# Line 116  lscp_driver_info_t* lscp_get_audio_drive Line 337  lscp_driver_info_t* lscp_get_audio_drive
337          return NULL;          return NULL;
338    
339      sprintf(szQuery, "GET AUDIO_OUTPUT_DRIVER INFO %s\r\n", pszAudioDriver);      sprintf(szQuery, "GET AUDIO_OUTPUT_DRIVER INFO %s\r\n", pszAudioDriver);
340      return _lscp_driver_info_query(pClient, &(pClient->audio_info), szQuery);      return _lscp_driver_info_query(pClient, &(pClient->audio_driver_info), szQuery);
341  }  }
342    
343    
# Line 134  lscp_driver_info_t* lscp_get_audio_drive Line 355  lscp_driver_info_t* lscp_get_audio_drive
355   */   */
356  lscp_param_info_t *lscp_get_audio_driver_param_info ( lscp_client_t *pClient, const char *pszAudioDriver, const char *pszParam, lscp_param_t *pDepList )  lscp_param_info_t *lscp_get_audio_driver_param_info ( lscp_client_t *pClient, const char *pszAudioDriver, const char *pszParam, lscp_param_t *pDepList )
357  {  {
358      lscp_param_info_t *pParamInfo = NULL;      char szQuery[LSCP_BUFSIZ];
359    
360      if (pClient == NULL)      if (pClient == NULL)
361          return NULL;          return NULL;
# Line 142  lscp_param_info_t *lscp_get_audio_driver Line 363  lscp_param_info_t *lscp_get_audio_driver
363          return NULL;          return NULL;
364      if (pszParam == NULL)      if (pszParam == NULL)
365          return NULL;          return NULL;
     if (pDepList == NULL)  
         return NULL;  
366    
367      return pParamInfo;      sprintf(szQuery, "GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO %s %s", pszAudioDriver, pszParam);
368        return _lscp_param_info_query(pClient, &(pClient->audio_param_info), szQuery, sizeof(szQuery), pDepList);
369  }  }
370    
371    
# Line 165  lscp_param_info_t *lscp_get_audio_driver Line 385  lscp_param_info_t *lscp_get_audio_driver
385   */   */
386  int lscp_create_audio_device ( lscp_client_t *pClient, const char *pszAudioDriver, lscp_param_t *pParams )  int lscp_create_audio_device ( lscp_client_t *pClient, const char *pszAudioDriver, lscp_param_t *pParams )
387  {  {
388        char szQuery[LSCP_BUFSIZ];
389      int iAudioDevice = -1;      int iAudioDevice = -1;
390    
391      if (pClient == NULL)      if (pClient == NULL)
392          return -1;          return iAudioDevice;
393      if (pszAudioDriver == NULL)      if (pszAudioDriver == NULL)
394          return -1;          return iAudioDevice;
395      if (pParams == NULL)  
396          return -1;      // Lock this section up.
397        lscp_mutex_lock(pClient->mutex);
398    
399        sprintf(szQuery, "CREATE AUDIO_OUTPUT_DEVICE %s", pszAudioDriver);
400        lscp_param_concat(szQuery, sizeof(szQuery), pParams);
401        if (lscp_client_call(pClient, szQuery) == LSCP_OK)
402            iAudioDevice = atoi(lscp_client_get_result(pClient));
403    
404        // Unlock this section down.
405        lscp_mutex_unlock(pClient->mutex);
406    
407      return iAudioDevice;      return iAudioDevice;
408  }  }
# Line 190  int lscp_create_audio_device ( lscp_clie Line 420  int lscp_create_audio_device ( lscp_clie
420  lscp_status_t lscp_destroy_audio_device ( lscp_client_t *pClient, int iAudioDevice )  lscp_status_t lscp_destroy_audio_device ( lscp_client_t *pClient, int iAudioDevice )
421  {  {
422      lscp_status_t ret = LSCP_FAILED;      lscp_status_t ret = LSCP_FAILED;
423        char szQuery[LSCP_BUFSIZ];
424    
425      if (pClient == NULL)      if (pClient == NULL)
426          return ret;          return ret;
427      if (iAudioDevice < 0)      if (iAudioDevice < 0)
428          return ret;          return ret;
429    
430      return ret;      sprintf(szQuery, "DESTROY AUDIO_OUTPUT_DEVICE %d\r\n", iAudioDevice);
431        return lscp_client_query(pClient, szQuery);
432  }  }
433    
434    
435  /**  /**
436   *  Getting all created audio output devices.   *  Getting all created audio output device count.
437   *  GET AUDIO_OUTPUT_DEVICES   *  GET AUDIO_OUTPUT_DEVICES
438   *   *
439   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
440   *   *
441     *  @returns The current total number of audio devices on success,
442     *  -1 otherwise.
443     */
444    int lscp_get_audio_devices ( lscp_client_t *pClient )
445    {
446        int iAudioDevices = -1;
447    
448        // Lock this section up.
449        lscp_mutex_lock(pClient->mutex);
450    
451        if (lscp_client_call(pClient, "GET AUDIO_OUTPUT_DEVICES\r\n") == LSCP_OK)
452            iAudioDevices = atoi(lscp_client_get_result(pClient));
453    
454        // Unlock this section down.
455        lscp_mutex_unlock(pClient->mutex);
456    
457        return iAudioDevices;
458    }
459    
460    
461    /**
462     *  Getting all created audio output device list.
463     *  LIST AUDIO_OUTPUT_DEVICES
464     *
465     *  @param pClient  Pointer to client instance structure.
466     *
467   *  @returns An array of audio device number identifiers,   *  @returns An array of audio device number identifiers,
468   *  terminated with -1 on success, or NULL in case of failure.   *  terminated with -1 on success, or NULL in case of failure.
469   */   */
470  int *lscp_get_audio_devices ( lscp_client_t *pClient )  int *lscp_list_audio_devices ( lscp_client_t *pClient )
471  {  {
472      int *piAudioDevices = NULL;      const char *pszSeps = ",";
473    
474      if (pClient == NULL)      if (pClient == NULL)
475          return NULL;          return NULL;
476    
477      return piAudioDevices;      // Lock this section up.
478        lscp_mutex_lock(pClient->mutex);
479    
480        if (pClient->audio_devices) {
481            lscp_isplit_destroy(pClient->audio_devices);
482            pClient->audio_devices = NULL;
483        }
484    
485        if (lscp_client_call(pClient, "LIST AUDIO_OUTPUT_DEVICES\r\n") == LSCP_OK)
486            pClient->audio_devices = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps);
487    
488        // Unlock this section down.
489        lscp_mutex_unlock(pClient->mutex);
490    
491        return pClient->audio_devices;
492  }  }
493    
494    
# Line 232  int *lscp_get_audio_devices ( lscp_clien Line 504  int *lscp_get_audio_devices ( lscp_clien
504   */   */
505  lscp_device_info_t *lscp_get_audio_device_info ( lscp_client_t *pClient, int iAudioDevice )  lscp_device_info_t *lscp_get_audio_device_info ( lscp_client_t *pClient, int iAudioDevice )
506  {  {
507      lscp_device_info_t *pDeviceInfo = NULL;      char szQuery[LSCP_BUFSIZ];
508    
509      if (pClient == NULL)      if (pClient == NULL)
510          return NULL;          return NULL;
511      if (iAudioDevice < 0)      if (iAudioDevice < 0)
512          return NULL;          return NULL;
513    
514      return pDeviceInfo;      sprintf(szQuery, "GET AUDIO_OUTPUT_DEVICE INFO %d\r\n", iAudioDevice);
515        return _lscp_device_info_query(pClient, &(pClient->audio_device_info), szQuery);
516  }  }
517    
518    
519  /**  /**
520   *  Changing settings of audio output devices.   *  Changing settings of audio output devices.
521   *  SET AUDIO_OUTPUT_DEVICE_PARAMETER <audio-device-id> <param> <value>   *  SET AUDIO_OUTPUT_DEVICE_PARAMETER <audio-device-id> <param>=<value>
522   *   *
523   *  @param pClient      Pointer to client instance structure.   *  @param pClient      Pointer to client instance structure.
524   *  @param iAudioDevice Audio device number identifier.   *  @param iAudioDevice Audio device number identifier.
# Line 255  lscp_device_info_t *lscp_get_audio_devic Line 528  lscp_device_info_t *lscp_get_audio_devic
528   */   */
529  lscp_status_t lscp_set_audio_device_param ( lscp_client_t *pClient, int iAudioDevice, lscp_param_t *pParam )  lscp_status_t lscp_set_audio_device_param ( lscp_client_t *pClient, int iAudioDevice, lscp_param_t *pParam )
530  {  {
531      lscp_status_t ret = LSCP_FAILED;      char szQuery[LSCP_BUFSIZ];
532    
533      if (pClient == NULL)      if (pClient == NULL)
534          return ret;          return LSCP_FAILED;
535      if (iAudioDevice < 0)      if (iAudioDevice < 0)
536          return ret;          return LSCP_FAILED;
537      if (pParam == NULL)      if (pParam == NULL)
538          return ret;          return LSCP_FAILED;
539    
540      return ret;      sprintf(szQuery, "SET AUDIO_OUTPUT_DEVICE_PARAMETER %d %s='%s'\r\n", iAudioDevice, pParam->key, pParam->value);
541        return lscp_client_query(pClient, szQuery);
542  }  }
543    
544    
# Line 276  lscp_status_t lscp_set_audio_device_para Line 550  lscp_status_t lscp_set_audio_device_para
550   *  @param iAudioDevice     Audio device number identifier.   *  @param iAudioDevice     Audio device number identifier.
551   *  @param iAudioChannel    Audio channel number.   *  @param iAudioChannel    Audio channel number.
552   *   *
553   *  @returns A pointer to a @ref lscp_device_channel_info_t structure,   *  @returns A pointer to a @ref lscp_device_port_info_t structure,
554   *  with the given audio channel information, or NULL in case of failure.   *  with the given audio channel information, or NULL in case of failure.
555   */   */
556  lscp_device_channel_info_t* lscp_get_audio_channel_info ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel )  lscp_device_port_info_t* lscp_get_audio_channel_info ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel )
557  {  {
558      lscp_device_channel_info_t *pDevChannelInfo = NULL;      char szQuery[LSCP_BUFSIZ];
559    
560      if (pClient == NULL)      if (pClient == NULL)
561          return NULL;          return NULL;
# Line 290  lscp_device_channel_info_t* lscp_get_aud Line 564  lscp_device_channel_info_t* lscp_get_aud
564      if (iAudioChannel < 0)      if (iAudioChannel < 0)
565          return NULL;          return NULL;
566    
567      return pDevChannelInfo;      sprintf(szQuery, "GET AUDIO_OUTPUT_CHANNEL INFO %d %d\r\n", iAudioDevice, iAudioChannel);
568        return _lscp_device_port_info_query(pClient, &(pClient->audio_channel_info), szQuery);
569  }  }
570    
571    
# Line 308  lscp_device_channel_info_t* lscp_get_aud Line 583  lscp_device_channel_info_t* lscp_get_aud
583   */   */
584  lscp_param_info_t* lscp_get_audio_channel_param_info ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel, const char *pszParam )  lscp_param_info_t* lscp_get_audio_channel_param_info ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel, const char *pszParam )
585  {  {
586      lscp_param_info_t *pParamInfo = NULL;      char szQuery[LSCP_BUFSIZ];
587    
588      if (pClient == NULL)      if (pClient == NULL)
589          return NULL;          return NULL;
# Line 319  lscp_param_info_t* lscp_get_audio_channe Line 594  lscp_param_info_t* lscp_get_audio_channe
594      if (pszParam == NULL)      if (pszParam == NULL)
595          return NULL;          return NULL;
596    
597      return pParamInfo;      sprintf(szQuery, "GET AUDIO_OUTPUT_CHANNEL_PARAMETER INFO %d %d %s", iAudioDevice, iAudioChannel, pszParam);
598        return _lscp_param_info_query(pClient, &(pClient->audio_channel_param_info), szQuery, sizeof(szQuery), NULL);
599  }  }
600    
601    
# Line 336  lscp_param_info_t* lscp_get_audio_channe Line 612  lscp_param_info_t* lscp_get_audio_channe
612   */   */
613  lscp_status_t lscp_set_audio_channel_param ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel, lscp_param_t *pParam )  lscp_status_t lscp_set_audio_channel_param ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel, lscp_param_t *pParam )
614  {  {
615      lscp_status_t ret = LSCP_FAILED;      char szQuery[LSCP_BUFSIZ];
616    
617      if (pClient == NULL)      if (pClient == NULL)
618          return ret;          return LSCP_FAILED;
619      if (iAudioDevice < 0)      if (iAudioDevice < 0)
620          return ret;          return LSCP_FAILED;
621      if (iAudioChannel < 0)      if (iAudioChannel < 0)
622          return ret;          return LSCP_FAILED;
623      if (pParam == NULL)      if (pParam == NULL)
624          return ret;          return LSCP_FAILED;
625    
626      return ret;      sprintf(szQuery, "SET AUDIO_OUTPUT_CHANNEL_PARAMETER %d %d %s='%s'\r\n", iAudioDevice, iAudioChannel, pParam->key, pParam->value);
627        return lscp_client_query(pClient, szQuery);
628  }  }
629    
630    
# Line 355  lscp_status_t lscp_set_audio_channel_par Line 632  lscp_status_t lscp_set_audio_channel_par
632  // MIDI driver control functions.  // MIDI driver control functions.
633    
634  /**  /**
635   *  Getting all available MIDI input drivers.   *  Getting all available MIDI input driver count.
636   *  GET AVAILABLE_MIDI_INPUT_DRIVERS   *  GET AVAILABLE_MIDI_INPUT_DRIVERS
637   *   *
638   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
639   *   *
640     *  @returns The current total number of MIDI input drivers on success,
641     *  -1 otherwise.
642     */
643    int lscp_get_available_midi_drivers ( lscp_client_t *pClient )
644    {
645        int iMidiDrivers = -1;
646    
647        // Lock this section up.
648        lscp_mutex_lock(pClient->mutex);
649    
650        if (lscp_client_call(pClient, "GET AVAILABLE_MIDI_INPUT_DRIVERS\r\n") == LSCP_OK)
651            iMidiDrivers = atoi(lscp_client_get_result(pClient));
652    
653        // Unlock this section up.
654        lscp_mutex_unlock(pClient->mutex);
655    
656        return iMidiDrivers;
657    }
658    
659    
660    /**
661     *  Getting all available MIDI input drivers.
662     *  LIST AVAILABLE_MIDI_INPUT_DRIVERS
663     *
664     *  @param pClient  Pointer to client instance structure.
665     *
666   *  @returns A NULL terminated array of MIDI input driver type   *  @returns A NULL terminated array of MIDI input driver type
667   *  name strings, or NULL in case of failure.   *  name strings, or NULL in case of failure.
668   */   */
669  const char** lscp_get_available_midi_drivers ( lscp_client_t *pClient )  const char** lscp_list_available_midi_drivers ( lscp_client_t *pClient )
670  {  {
671      const char *pszSeps = ",";      const char *pszSeps = ",";
672    
673        // Lock this section up.
674        lscp_mutex_lock(pClient->mutex);
675    
676      if (pClient->midi_drivers) {      if (pClient->midi_drivers) {
677          lscp_szsplit_destroy(pClient->midi_drivers);          lscp_szsplit_destroy(pClient->midi_drivers);
678          pClient->midi_drivers = NULL;          pClient->midi_drivers = NULL;
679      }      }
680    
681      if (lscp_client_query(pClient, "GET AVAILABLE_MIDI_INPUT_DRIVERS\r\n") == LSCP_OK)      if (lscp_client_call(pClient, "LIST AVAILABLE_MIDI_INPUT_DRIVERS\r\n") == LSCP_OK)
682          pClient->midi_drivers = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps);          pClient->midi_drivers = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps);
683    
684        // Unlock this section up.
685        lscp_mutex_unlock(pClient->mutex);
686    
687      return (const char **) pClient->midi_drivers;      return (const char **) pClient->midi_drivers;
688  }  }
689    
# Line 397  lscp_driver_info_t* lscp_get_midi_driver Line 706  lscp_driver_info_t* lscp_get_midi_driver
706          return NULL;          return NULL;
707    
708      sprintf(szQuery, "GET MIDI_INPUT_DRIVER INFO %s\r\n", pszMidiDriver);      sprintf(szQuery, "GET MIDI_INPUT_DRIVER INFO %s\r\n", pszMidiDriver);
709      return _lscp_driver_info_query(pClient, &(pClient->midi_info), szQuery);      return _lscp_driver_info_query(pClient, &(pClient->midi_driver_info), szQuery);
710  }  }
711    
712    
# Line 417  lscp_driver_info_t* lscp_get_midi_driver Line 726  lscp_driver_info_t* lscp_get_midi_driver
726   */   */
727  lscp_param_info_t *lscp_get_midi_driver_param_info ( lscp_client_t *pClient, const char *pszMidiDriver, const char *pszParam, lscp_param_t *pDepList )  lscp_param_info_t *lscp_get_midi_driver_param_info ( lscp_client_t *pClient, const char *pszMidiDriver, const char *pszParam, lscp_param_t *pDepList )
728  {  {
729      lscp_param_info_t *pParamInfo = NULL;      char szQuery[LSCP_BUFSIZ];
730    
731      if (pClient == NULL)      if (pClient == NULL)
732          return NULL;          return NULL;
# Line 425  lscp_param_info_t *lscp_get_midi_driver_ Line 734  lscp_param_info_t *lscp_get_midi_driver_
734          return NULL;          return NULL;
735      if (pszParam == NULL)      if (pszParam == NULL)
736          return NULL;          return NULL;
     if (pDepList == NULL)  
         return NULL;  
737    
738      return pParamInfo;      sprintf(szQuery, "GET MIDI_INPUT_DRIVER_PARAMETER INFO %s %s", pszMidiDriver, pszParam);
739        return _lscp_param_info_query(pClient, &(pClient->midi_param_info), szQuery, sizeof(szQuery), pDepList);
740  }  }
741    
742    
# Line 448  lscp_param_info_t *lscp_get_midi_driver_ Line 756  lscp_param_info_t *lscp_get_midi_driver_
756   */   */
757  int lscp_create_midi_device ( lscp_client_t *pClient, const char *pszMidiDriver, lscp_param_t *pParams )  int lscp_create_midi_device ( lscp_client_t *pClient, const char *pszMidiDriver, lscp_param_t *pParams )
758  {  {
759        char szQuery[LSCP_BUFSIZ];
760      int iMidiDevice = -1;      int iMidiDevice = -1;
761    
762      if (pClient == NULL)      if (pClient == NULL)
763          return -1;          return iMidiDevice;
764      if (pszMidiDriver == NULL)      if (pszMidiDriver == NULL)
765          return -1;          return iMidiDevice;
766      if (pParams == NULL)  
767          return -1;      // Lock this section up.
768        lscp_mutex_lock(pClient->mutex);
769    
770        sprintf(szQuery, "CREATE MIDI_INPUT_DEVICE %s", pszMidiDriver);
771        lscp_param_concat(szQuery, sizeof(szQuery), pParams);
772        if (lscp_client_call(pClient, szQuery) == LSCP_OK)
773            iMidiDevice = atoi(lscp_client_get_result(pClient));
774    
775        // Unlock this section down.
776        lscp_mutex_unlock(pClient->mutex);
777    
778      return iMidiDevice;      return iMidiDevice;
779  }  }
# Line 473  int lscp_create_midi_device ( lscp_clien Line 791  int lscp_create_midi_device ( lscp_clien
791  lscp_status_t lscp_destroy_midi_device ( lscp_client_t *pClient, int iMidiDevice )  lscp_status_t lscp_destroy_midi_device ( lscp_client_t *pClient, int iMidiDevice )
792  {  {
793      lscp_status_t ret = LSCP_FAILED;      lscp_status_t ret = LSCP_FAILED;
794        char szQuery[LSCP_BUFSIZ];
795    
796      if (pClient == NULL)      if (pClient == NULL)
797          return ret;          return ret;
798      if (iMidiDevice < 0)      if (iMidiDevice < 0)
799          return ret;          return ret;
800    
801      return ret;      sprintf(szQuery, "DESTROY MIDI_INPUT_DEVICE %d\r\n", iMidiDevice);
802        return lscp_client_query(pClient, szQuery);
803  }  }
804    
805    
806  /**  /**
807   *  Getting all created MIDI input devices.   *  Getting all created MIDI intput device count.
808   *  GET MIDI_INPUT_DEVICES   *  GET MIDI_INPUT_DEVICES
809   *   *
810   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
811   *   *
812     *  @returns The current total number of MIDI devices on success,
813     *  -1 otherwise.
814     */
815    int lscp_get_midi_devices ( lscp_client_t *pClient )
816    {
817        int iMidiDevices = -1;
818    
819        // Lock this section up.
820        lscp_mutex_lock(pClient->mutex);
821    
822        if (lscp_client_call(pClient, "GET MIDI_INPUT_DEVICES\r\n") == LSCP_OK)
823            iMidiDevices = atoi(lscp_client_get_result(pClient));
824            
825        // Unlock this section down.
826        lscp_mutex_unlock(pClient->mutex);
827    
828        return iMidiDevices;
829    }
830    
831    
832    /**
833     *  Getting all created MIDI intput device list.
834     *  LIST MIDI_INPUT_DEVICES
835     *
836     *  @param pClient  Pointer to client instance structure.
837     *
838   *  @returns An array of MIDI device number identifiers,   *  @returns An array of MIDI device number identifiers,
839   *  terminated with -1 on success, or NULL in case of failure.   *  terminated with -1 on success, or NULL in case of failure.
840   */   */
841  int *lscp_get_midi_devices ( lscp_client_t *pClient )  int *lscp_list_midi_devices ( lscp_client_t *pClient )
842  {  {
843      int *piMidiDevices = NULL;      const char *pszSeps = ",";
844    
845      if (pClient == NULL)      if (pClient == NULL)
846          return NULL;          return NULL;
847    
848      return piMidiDevices;      // Lock this section up.
849        lscp_mutex_lock(pClient->mutex);
850    
851        if (pClient->midi_devices) {
852            lscp_isplit_destroy(pClient->midi_devices);
853            pClient->midi_devices = NULL;
854        }
855    
856        if (lscp_client_call(pClient, "LIST MIDI_INPUT_DEVICES\r\n") == LSCP_OK)
857            pClient->midi_devices = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps);
858    
859        // Unlock this section down.
860        lscp_mutex_unlock(pClient->mutex);
861    
862        return pClient->midi_devices;
863  }  }
864    
865    
# Line 515  int *lscp_get_midi_devices ( lscp_client Line 875  int *lscp_get_midi_devices ( lscp_client
875   */   */
876  lscp_device_info_t* lscp_get_midi_device_info ( lscp_client_t *pClient, int iMidiDevice )  lscp_device_info_t* lscp_get_midi_device_info ( lscp_client_t *pClient, int iMidiDevice )
877  {  {
878      lscp_device_info_t *pDeviceInfo = NULL;      char szQuery[LSCP_BUFSIZ];
879    
880      if (pClient == NULL)      if (pClient == NULL)
881          return NULL;          return NULL;
882      if (iMidiDevice < 0)      if (iMidiDevice < 0)
883          return NULL;          return NULL;
884    
885      return pDeviceInfo;      sprintf(szQuery, "GET MIDI_INPUT_DEVICE INFO %d\r\n", iMidiDevice);
886        return _lscp_device_info_query(pClient, &(pClient->midi_device_info), szQuery);
887  }  }
888    
889    
890  /**  /**
891   *  Changing settings of MIDI input devices.   *  Changing settings of MIDI input devices.
892   *  SET MIDI_INPUT_DEVICE_PARAMETER <midi-device-id> <param> <value>   *  SET MIDI_INPUT_DEVICE_PARAMETER <midi-device-id> <param>=<value>
893   *   *
894   *  @param pClient      Pointer to client instance structure.   *  @param pClient      Pointer to client instance structure.
895   *  @param iMidiDevice  MIDI device number identifier.   *  @param iMidiDevice  MIDI device number identifier.
# Line 538  lscp_device_info_t* lscp_get_midi_device Line 899  lscp_device_info_t* lscp_get_midi_device
899   */   */
900  lscp_status_t lscp_set_midi_device_param ( lscp_client_t *pClient, int iMidiDevice, lscp_param_t *pParam )  lscp_status_t lscp_set_midi_device_param ( lscp_client_t *pClient, int iMidiDevice, lscp_param_t *pParam )
901  {  {
902      lscp_status_t ret = LSCP_FAILED;      char szQuery[LSCP_BUFSIZ];
903    
904      if (pClient == NULL)      if (pClient == NULL)
905          return ret;          return LSCP_FAILED;
906      if (iMidiDevice < 0)      if (iMidiDevice < 0)
907          return ret;          return LSCP_FAILED;
908      if (pParam == NULL)      if (pParam == NULL)
909          return ret;          return LSCP_FAILED;
910    
911      return ret;      sprintf(szQuery, "SET MIDI_INPUT_DEVICE_PARAMETER %d %s='%s'\r\n", iMidiDevice, pParam->key, pParam->value);
912        return lscp_client_query(pClient, szQuery);
913  }  }
914    
915    
# Line 559  lscp_status_t lscp_set_midi_device_param Line 921  lscp_status_t lscp_set_midi_device_param
921   *  @param iMidiDevice  MIDI device number identifier.   *  @param iMidiDevice  MIDI device number identifier.
922   *  @param iMidiPort    MIDI port number.   *  @param iMidiPort    MIDI port number.
923   *   *
924   *  @returns A pointer to a @ref lscp_device_channel_info_t structure,   *  @returns A pointer to a @ref lscp_device_port_info_t structure,
925   *  with the given MIDI port information, or NULL in case of failure.   *  with the given MIDI port information, or NULL in case of failure.
926   */   */
927  lscp_device_channel_info_t* lscp_get_midi_port_info ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort )  lscp_device_port_info_t* lscp_get_midi_port_info ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort )
928  {  {
929      lscp_device_channel_info_t *pDevChannelInfo = NULL;      char szQuery[LSCP_BUFSIZ];
930    
931      if (pClient == NULL)      if (pClient == NULL)
932          return NULL;          return NULL;
# Line 573  lscp_device_channel_info_t* lscp_get_mid Line 935  lscp_device_channel_info_t* lscp_get_mid
935      if (iMidiPort < 0)      if (iMidiPort < 0)
936          return NULL;          return NULL;
937    
938      return pDevChannelInfo;      sprintf(szQuery, "GET MIDI_INPUT_PORT INFO %d %d\r\n", iMidiDevice, iMidiPort);
939        return _lscp_device_port_info_query(pClient, &(pClient->midi_port_info), szQuery);
940  }  }
941    
942    
# Line 591  lscp_device_channel_info_t* lscp_get_mid Line 954  lscp_device_channel_info_t* lscp_get_mid
954   */   */
955  lscp_param_info_t* lscp_get_midi_port_param_info ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort, const char *pszParam )  lscp_param_info_t* lscp_get_midi_port_param_info ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort, const char *pszParam )
956  {  {
957      lscp_param_info_t *pParamInfo = NULL;      char szQuery[LSCP_BUFSIZ];
958    
959      if (pClient == NULL)      if (pClient == NULL)
960          return NULL;          return NULL;
# Line 602  lscp_param_info_t* lscp_get_midi_port_pa Line 965  lscp_param_info_t* lscp_get_midi_port_pa
965      if (pszParam == NULL)      if (pszParam == NULL)
966          return NULL;          return NULL;
967    
968      return pParamInfo;      sprintf(szQuery, "GET MIDI_INPUT_PORT_PARAMETER INFO %d %d %s", iMidiDevice, iMidiPort, pszParam);
969        return _lscp_param_info_query(pClient, &(pClient->midi_port_param_info), szQuery, sizeof(szQuery), NULL);
970  }  }
971    
972    
# Line 619  lscp_param_info_t* lscp_get_midi_port_pa Line 983  lscp_param_info_t* lscp_get_midi_port_pa
983   */   */
984  lscp_status_t lscp_set_midi_port_param ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort, lscp_param_t *pParam )  lscp_status_t lscp_set_midi_port_param ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort, lscp_param_t *pParam )
985  {  {
986      lscp_status_t ret = LSCP_FAILED;      char szQuery[LSCP_BUFSIZ];
987    
988      if (pClient == NULL)      if (pClient == NULL)
989          return ret;          return LSCP_FAILED;
990      if (iMidiDevice < 0)      if (iMidiDevice < 0)
991          return ret;          return LSCP_FAILED;
992      if (iMidiPort < 0)      if (iMidiPort < 0)
993          return ret;          return LSCP_FAILED;
994      if (pParam == NULL)      if (pParam == NULL)
995          return ret;          return LSCP_FAILED;
996    
997      return ret;      sprintf(szQuery, "SET MIDI_INPUT_PORT_PARAMETER %d %d %s='%s'\r\n", iMidiDevice, iMidiPort, pParam->key, pParam->value);
998        return lscp_client_query(pClient, szQuery);
999  }  }
1000    
1001    
1002    //-------------------------------------------------------------------------
1003    // Generic parameter list functions.
1004    
1005    const char *lscp_get_param_value ( lscp_param_t *pParams, const char *pszParam )
1006    {
1007        int i;
1008    
1009        for (i = 0; pParams && pParams[i].key; i++) {
1010            if (strcasecmp(pParams[i].key, pszParam) == 0)
1011                return (const char *) pParams[i].value;
1012        }
1013        return NULL;
1014    }
1015    
1016    
1017  // end of device.c  // end of device.c
1018    

Legend:
Removed from v.107  
changed lines
  Added in v.523

  ViewVC Help
Powered by ViewVC