/[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 435 by capela, Wed Mar 9 18:39:57 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        return pDriverInfo;
82    }
83    
     if (lscp_client_query(pClient, pszQuery) != LSCP_OK)  
         return NULL;  
84    
85      pszResult = lscp_client_get_result(pClient);  // Common device info query command.
86      pszToken = lscp_strtok(pszResult, pszSeps, &(pch));  static lscp_device_info_t *_lscp_device_info_query ( lscp_client_t *pClient, lscp_device_info_t *pDeviceInfo, char *pszQuery )
87      while (pszToken) {  {
88          if (strcasecmp(pszToken, "DESCRIPTION") == 0) {      const char *pszResult;
89              pszToken = lscp_strtok(NULL, pszCrlf, &(pch));      const char *pszSeps = ":";
90              if (pszToken)      const char *pszCrlf = "\r\n";
91                  pDriverInfo->description = lscp_unquote(&pszToken, 1);      char *pszToken;
92        char *pch;
93        char *pszKey;
94    
95        // Lock this section up.
96        lscp_mutex_lock(pClient->mutex);
97    
98        lscp_device_info_reset(pDeviceInfo);
99        if (lscp_client_call(pClient, pszQuery) == 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          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 86  const char ** lscp_get_available_audio_d Line 275  const char ** lscp_get_available_audio_d
275  {  {
276      const char *pszSeps = ",";      const char *pszSeps = ",";
277    
278        // Lock this section up.
279        lscp_mutex_lock(pClient->mutex);
280    
281      if (pClient->audio_drivers) {      if (pClient->audio_drivers) {
282          lscp_szsplit_destroy(pClient->audio_drivers);          lscp_szsplit_destroy(pClient->audio_drivers);
283          pClient->audio_drivers = NULL;          pClient->audio_drivers = NULL;
284      }      }
285    
286      if (lscp_client_query(pClient, "GET AVAILABLE_AUDIO_OUTPUT_DRIVERS\r\n") == LSCP_OK)      if (lscp_client_call(pClient, "GET AVAILABLE_AUDIO_OUTPUT_DRIVERS\r\n") == LSCP_OK)
287          pClient->audio_drivers = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps);          pClient->audio_drivers = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps);
288    
289        // Unlock this section down.
290        lscp_mutex_unlock(pClient->mutex);
291    
292      return (const char **) pClient->audio_drivers;      return (const char **) pClient->audio_drivers;
293  }  }
294    
# Line 116  lscp_driver_info_t* lscp_get_audio_drive Line 311  lscp_driver_info_t* lscp_get_audio_drive
311          return NULL;          return NULL;
312    
313      sprintf(szQuery, "GET AUDIO_OUTPUT_DRIVER INFO %s\r\n", pszAudioDriver);      sprintf(szQuery, "GET AUDIO_OUTPUT_DRIVER INFO %s\r\n", pszAudioDriver);
314      return _lscp_driver_info_query(pClient, &(pClient->audio_info), szQuery);      return _lscp_driver_info_query(pClient, &(pClient->audio_driver_info), szQuery);
315  }  }
316    
317    
# Line 134  lscp_driver_info_t* lscp_get_audio_drive Line 329  lscp_driver_info_t* lscp_get_audio_drive
329   */   */
330  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 )
331  {  {
332      lscp_param_info_t *pParamInfo = NULL;      char szQuery[LSCP_BUFSIZ];
333    
334      if (pClient == NULL)      if (pClient == NULL)
335          return NULL;          return NULL;
# Line 142  lscp_param_info_t *lscp_get_audio_driver Line 337  lscp_param_info_t *lscp_get_audio_driver
337          return NULL;          return NULL;
338      if (pszParam == NULL)      if (pszParam == NULL)
339          return NULL;          return NULL;
     if (pDepList == NULL)  
         return NULL;  
340    
341      return pParamInfo;      sprintf(szQuery, "GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO %s %s", pszAudioDriver, pszParam);
342        return _lscp_param_info_query(pClient, &(pClient->audio_param_info), szQuery, sizeof(szQuery), pDepList);
343  }  }
344    
345    
# Line 165  lscp_param_info_t *lscp_get_audio_driver Line 359  lscp_param_info_t *lscp_get_audio_driver
359   */   */
360  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 )
361  {  {
362        char szQuery[LSCP_BUFSIZ];
363      int iAudioDevice = -1;      int iAudioDevice = -1;
364    
365      if (pClient == NULL)      if (pClient == NULL)
366          return -1;          return iAudioDevice;
367      if (pszAudioDriver == NULL)      if (pszAudioDriver == NULL)
368          return -1;          return iAudioDevice;
369      if (pParams == NULL)  
370          return -1;      // Lock this section up.
371        lscp_mutex_lock(pClient->mutex);
372    
373        sprintf(szQuery, "CREATE AUDIO_OUTPUT_DEVICE %s", pszAudioDriver);
374        lscp_param_concat(szQuery, sizeof(szQuery), pParams);
375        if (lscp_client_call(pClient, szQuery) == LSCP_OK)
376            iAudioDevice = atoi(lscp_client_get_result(pClient));
377    
378        // Unlock this section down.
379        lscp_mutex_unlock(pClient->mutex);
380    
381      return iAudioDevice;      return iAudioDevice;
382  }  }
# Line 190  int lscp_create_audio_device ( lscp_clie Line 394  int lscp_create_audio_device ( lscp_clie
394  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 )
395  {  {
396      lscp_status_t ret = LSCP_FAILED;      lscp_status_t ret = LSCP_FAILED;
397        char szQuery[LSCP_BUFSIZ];
398    
399      if (pClient == NULL)      if (pClient == NULL)
400          return ret;          return ret;
401      if (iAudioDevice < 0)      if (iAudioDevice < 0)
402          return ret;          return ret;
403    
404      return ret;      sprintf(szQuery, "DESTROY AUDIO_OUTPUT_DEVICE %d\r\n", iAudioDevice);
405        return lscp_client_query(pClient, szQuery);
406  }  }
407    
408    
409  /**  /**
410   *  Getting all created audio output devices.   *  Getting all created audio output device count.
411   *  GET AUDIO_OUTPUT_DEVICES   *  GET AUDIO_OUTPUT_DEVICES
412   *   *
413   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
414   *   *
415     *  @returns The current total number of audio devices on success,
416     *  -1 otherwise.
417     */
418    int lscp_get_audio_devices ( lscp_client_t *pClient )
419    {
420        int iAudioDevices = -1;
421    
422        // Lock this section up.
423        lscp_mutex_lock(pClient->mutex);
424    
425        if (lscp_client_call(pClient, "GET AUDIO_OUTPUT_DEVICES\r\n") == LSCP_OK)
426            iAudioDevices = atoi(lscp_client_get_result(pClient));
427    
428        // Unlock this section down.
429        lscp_mutex_unlock(pClient->mutex);
430    
431        return iAudioDevices;
432    }
433    
434    
435    /**
436     *  Getting all created audio output device list.
437     *  LIST AUDIO_OUTPUT_DEVICES
438     *
439     *  @param pClient  Pointer to client instance structure.
440     *
441   *  @returns An array of audio device number identifiers,   *  @returns An array of audio device number identifiers,
442   *  terminated with -1 on success, or NULL in case of failure.   *  terminated with -1 on success, or NULL in case of failure.
443   */   */
444  int *lscp_get_audio_devices ( lscp_client_t *pClient )  int *lscp_list_audio_devices ( lscp_client_t *pClient )
445  {  {
446      int *piAudioDevices = NULL;      const char *pszSeps = ",";
447    
448      if (pClient == NULL)      if (pClient == NULL)
449          return NULL;          return NULL;
450    
451      return piAudioDevices;      // Lock this section up.
452        lscp_mutex_lock(pClient->mutex);
453    
454        if (pClient->audio_devices) {
455            lscp_isplit_destroy(pClient->audio_devices);
456            pClient->audio_devices = NULL;
457        }
458    
459        if (lscp_client_call(pClient, "LIST AUDIO_OUTPUT_DEVICES\r\n") == LSCP_OK)
460            pClient->audio_devices = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps);
461    
462        // Unlock this section down.
463        lscp_mutex_unlock(pClient->mutex);
464    
465        return pClient->audio_devices;
466  }  }
467    
468    
# Line 232  int *lscp_get_audio_devices ( lscp_clien Line 478  int *lscp_get_audio_devices ( lscp_clien
478   */   */
479  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 )
480  {  {
481      lscp_device_info_t *pDeviceInfo = NULL;      char szQuery[LSCP_BUFSIZ];
482    
483      if (pClient == NULL)      if (pClient == NULL)
484          return NULL;          return NULL;
485      if (iAudioDevice < 0)      if (iAudioDevice < 0)
486          return NULL;          return NULL;
487    
488      return pDeviceInfo;      sprintf(szQuery, "GET AUDIO_OUTPUT_DEVICE INFO %d\r\n", iAudioDevice);
489        return _lscp_device_info_query(pClient, &(pClient->audio_device_info), szQuery);
490  }  }
491    
492    
493  /**  /**
494   *  Changing settings of audio output devices.   *  Changing settings of audio output devices.
495   *  SET AUDIO_OUTPUT_DEVICE_PARAMETER <audio-device-id> <param> <value>   *  SET AUDIO_OUTPUT_DEVICE_PARAMETER <audio-device-id> <param>=<value>
496   *   *
497   *  @param pClient      Pointer to client instance structure.   *  @param pClient      Pointer to client instance structure.
498   *  @param iAudioDevice Audio device number identifier.   *  @param iAudioDevice Audio device number identifier.
# Line 255  lscp_device_info_t *lscp_get_audio_devic Line 502  lscp_device_info_t *lscp_get_audio_devic
502   */   */
503  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 )
504  {  {
505      lscp_status_t ret = LSCP_FAILED;      char szQuery[LSCP_BUFSIZ];
506    
507      if (pClient == NULL)      if (pClient == NULL)
508          return ret;          return LSCP_FAILED;
509      if (iAudioDevice < 0)      if (iAudioDevice < 0)
510          return ret;          return LSCP_FAILED;
511      if (pParam == NULL)      if (pParam == NULL)
512          return ret;          return LSCP_FAILED;
513    
514      return ret;      sprintf(szQuery, "SET AUDIO_OUTPUT_DEVICE_PARAMETER %d %s='%s'", iAudioDevice, pParam->key, pParam->value);
515        return lscp_client_query(pClient, szQuery);
516  }  }
517    
518    
# Line 276  lscp_status_t lscp_set_audio_device_para Line 524  lscp_status_t lscp_set_audio_device_para
524   *  @param iAudioDevice     Audio device number identifier.   *  @param iAudioDevice     Audio device number identifier.
525   *  @param iAudioChannel    Audio channel number.   *  @param iAudioChannel    Audio channel number.
526   *   *
527   *  @returns A pointer to a @ref lscp_device_channel_info_t structure,   *  @returns A pointer to a @ref lscp_device_port_info_t structure,
528   *  with the given audio channel information, or NULL in case of failure.   *  with the given audio channel information, or NULL in case of failure.
529   */   */
530  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 )
531  {  {
532      lscp_device_channel_info_t *pDevChannelInfo = NULL;      char szQuery[LSCP_BUFSIZ];
533    
534      if (pClient == NULL)      if (pClient == NULL)
535          return NULL;          return NULL;
# Line 290  lscp_device_channel_info_t* lscp_get_aud Line 538  lscp_device_channel_info_t* lscp_get_aud
538      if (iAudioChannel < 0)      if (iAudioChannel < 0)
539          return NULL;          return NULL;
540    
541      return pDevChannelInfo;      sprintf(szQuery, "GET AUDIO_OUTPUT_CHANNEL INFO %d %d\r\n", iAudioDevice, iAudioChannel);
542        return _lscp_device_port_info_query(pClient, &(pClient->audio_channel_info), szQuery);
543  }  }
544    
545    
# Line 308  lscp_device_channel_info_t* lscp_get_aud Line 557  lscp_device_channel_info_t* lscp_get_aud
557   */   */
558  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 )
559  {  {
560      lscp_param_info_t *pParamInfo = NULL;      char szQuery[LSCP_BUFSIZ];
561    
562      if (pClient == NULL)      if (pClient == NULL)
563          return NULL;          return NULL;
# Line 319  lscp_param_info_t* lscp_get_audio_channe Line 568  lscp_param_info_t* lscp_get_audio_channe
568      if (pszParam == NULL)      if (pszParam == NULL)
569          return NULL;          return NULL;
570    
571      return pParamInfo;      sprintf(szQuery, "GET AUDIO_OUTPUT_CHANNEL_PARAMETER INFO %d %d %s", iAudioDevice, iAudioChannel, pszParam);
572        return _lscp_param_info_query(pClient, &(pClient->audio_channel_param_info), szQuery, sizeof(szQuery), NULL);
573  }  }
574    
575    
# Line 336  lscp_param_info_t* lscp_get_audio_channe Line 586  lscp_param_info_t* lscp_get_audio_channe
586   */   */
587  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 )
588  {  {
589      lscp_status_t ret = LSCP_FAILED;      char szQuery[LSCP_BUFSIZ];
590    
591      if (pClient == NULL)      if (pClient == NULL)
592          return ret;          return LSCP_FAILED;
593      if (iAudioDevice < 0)      if (iAudioDevice < 0)
594          return ret;          return LSCP_FAILED;
595      if (iAudioChannel < 0)      if (iAudioChannel < 0)
596          return ret;          return LSCP_FAILED;
597      if (pParam == NULL)      if (pParam == NULL)
598          return ret;          return LSCP_FAILED;
599    
600      return ret;      sprintf(szQuery, "SET AUDIO_OUTPUT_CHANNEL_PARAMETER %d %d %s='%s'", iAudioDevice, iAudioChannel, pParam->key, pParam->value);
601        return lscp_client_query(pClient, szQuery);
602  }  }
603    
604    
# Line 367  const char** lscp_get_available_midi_dri Line 618  const char** lscp_get_available_midi_dri
618  {  {
619      const char *pszSeps = ",";      const char *pszSeps = ",";
620    
621        // Lock this section up.
622        lscp_mutex_lock(pClient->mutex);
623    
624      if (pClient->midi_drivers) {      if (pClient->midi_drivers) {
625          lscp_szsplit_destroy(pClient->midi_drivers);          lscp_szsplit_destroy(pClient->midi_drivers);
626          pClient->midi_drivers = NULL;          pClient->midi_drivers = NULL;
627      }      }
628    
629      if (lscp_client_query(pClient, "GET AVAILABLE_MIDI_INPUT_DRIVERS\r\n") == LSCP_OK)      if (lscp_client_call(pClient, "GET AVAILABLE_MIDI_INPUT_DRIVERS\r\n") == LSCP_OK)
630          pClient->midi_drivers = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps);          pClient->midi_drivers = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps);
631    
632        // Unlock this section up.
633        lscp_mutex_unlock(pClient->mutex);
634    
635      return (const char **) pClient->midi_drivers;      return (const char **) pClient->midi_drivers;
636  }  }
637    
# Line 397  lscp_driver_info_t* lscp_get_midi_driver Line 654  lscp_driver_info_t* lscp_get_midi_driver
654          return NULL;          return NULL;
655    
656      sprintf(szQuery, "GET MIDI_INPUT_DRIVER INFO %s\r\n", pszMidiDriver);      sprintf(szQuery, "GET MIDI_INPUT_DRIVER INFO %s\r\n", pszMidiDriver);
657      return _lscp_driver_info_query(pClient, &(pClient->midi_info), szQuery);      return _lscp_driver_info_query(pClient, &(pClient->midi_driver_info), szQuery);
658  }  }
659    
660    
# Line 417  lscp_driver_info_t* lscp_get_midi_driver Line 674  lscp_driver_info_t* lscp_get_midi_driver
674   */   */
675  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 )
676  {  {
677      lscp_param_info_t *pParamInfo = NULL;      char szQuery[LSCP_BUFSIZ];
678    
679      if (pClient == NULL)      if (pClient == NULL)
680          return NULL;          return NULL;
# Line 425  lscp_param_info_t *lscp_get_midi_driver_ Line 682  lscp_param_info_t *lscp_get_midi_driver_
682          return NULL;          return NULL;
683      if (pszParam == NULL)      if (pszParam == NULL)
684          return NULL;          return NULL;
     if (pDepList == NULL)  
         return NULL;  
685    
686      return pParamInfo;      sprintf(szQuery, "GET MIDI_INPUT_DRIVER_PARAMETER INFO %s %s", pszMidiDriver, pszParam);
687        return _lscp_param_info_query(pClient, &(pClient->midi_param_info), szQuery, sizeof(szQuery), pDepList);
688  }  }
689    
690    
# Line 448  lscp_param_info_t *lscp_get_midi_driver_ Line 704  lscp_param_info_t *lscp_get_midi_driver_
704   */   */
705  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 )
706  {  {
707        char szQuery[LSCP_BUFSIZ];
708      int iMidiDevice = -1;      int iMidiDevice = -1;
709    
710      if (pClient == NULL)      if (pClient == NULL)
711          return -1;          return iMidiDevice;
712      if (pszMidiDriver == NULL)      if (pszMidiDriver == NULL)
713          return -1;          return iMidiDevice;
714      if (pParams == NULL)  
715          return -1;      // Lock this section up.
716        lscp_mutex_lock(pClient->mutex);
717    
718        sprintf(szQuery, "CREATE MIDI_INPUT_DEVICE %s", pszMidiDriver);
719        lscp_param_concat(szQuery, sizeof(szQuery), pParams);
720        if (lscp_client_call(pClient, szQuery) == LSCP_OK)
721            iMidiDevice = atoi(lscp_client_get_result(pClient));
722    
723        // Unlock this section down.
724        lscp_mutex_unlock(pClient->mutex);
725    
726      return iMidiDevice;      return iMidiDevice;
727  }  }
# Line 473  int lscp_create_midi_device ( lscp_clien Line 739  int lscp_create_midi_device ( lscp_clien
739  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 )
740  {  {
741      lscp_status_t ret = LSCP_FAILED;      lscp_status_t ret = LSCP_FAILED;
742        char szQuery[LSCP_BUFSIZ];
743    
744      if (pClient == NULL)      if (pClient == NULL)
745          return ret;          return ret;
746      if (iMidiDevice < 0)      if (iMidiDevice < 0)
747          return ret;          return ret;
748    
749      return ret;      sprintf(szQuery, "DESTROY MIDI_INPUT_DEVICE %d\r\n", iMidiDevice);
750        return lscp_client_query(pClient, szQuery);
751  }  }
752    
753    
754  /**  /**
755   *  Getting all created MIDI input devices.   *  Getting all created MIDI intput device count.
756   *  GET MIDI_INPUT_DEVICES   *  GET MIDI_INPUT_DEVICES
757   *   *
758   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
759   *   *
760     *  @returns The current total number of MIDI devices on success,
761     *  -1 otherwise.
762     */
763    int lscp_get_midi_devices ( lscp_client_t *pClient )
764    {
765        int iMidiDevices = -1;
766    
767        // Lock this section up.
768        lscp_mutex_lock(pClient->mutex);
769    
770        if (lscp_client_call(pClient, "GET MIDI_INPUT_DEVICES\r\n") == LSCP_OK)
771            iMidiDevices = atoi(lscp_client_get_result(pClient));
772            
773        // Unlock this section down.
774        lscp_mutex_unlock(pClient->mutex);
775    
776        return iMidiDevices;
777    }
778    
779    
780    /**
781     *  Getting all created MIDI intput device list.
782     *  LIST MIDI_INPUT_DEVICES
783     *
784     *  @param pClient  Pointer to client instance structure.
785     *
786   *  @returns An array of MIDI device number identifiers,   *  @returns An array of MIDI device number identifiers,
787   *  terminated with -1 on success, or NULL in case of failure.   *  terminated with -1 on success, or NULL in case of failure.
788   */   */
789  int *lscp_get_midi_devices ( lscp_client_t *pClient )  int *lscp_list_midi_devices ( lscp_client_t *pClient )
790  {  {
791      int *piMidiDevices = NULL;      const char *pszSeps = ",";
792    
793      if (pClient == NULL)      if (pClient == NULL)
794          return NULL;          return NULL;
795    
796      return piMidiDevices;      // Lock this section up.
797        lscp_mutex_lock(pClient->mutex);
798    
799        if (pClient->midi_devices) {
800            lscp_isplit_destroy(pClient->midi_devices);
801            pClient->midi_devices = NULL;
802        }
803    
804        if (lscp_client_call(pClient, "LIST MIDI_INPUT_DEVICES\r\n") == LSCP_OK)
805            pClient->midi_devices = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps);
806    
807        // Unlock this section down.
808        lscp_mutex_unlock(pClient->mutex);
809    
810        return pClient->midi_devices;
811  }  }
812    
813    
# Line 515  int *lscp_get_midi_devices ( lscp_client Line 823  int *lscp_get_midi_devices ( lscp_client
823   */   */
824  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 )
825  {  {
826      lscp_device_info_t *pDeviceInfo = NULL;      char szQuery[LSCP_BUFSIZ];
827    
828      if (pClient == NULL)      if (pClient == NULL)
829          return NULL;          return NULL;
830      if (iMidiDevice < 0)      if (iMidiDevice < 0)
831          return NULL;          return NULL;
832    
833      return pDeviceInfo;      sprintf(szQuery, "GET MIDI_INPUT_DEVICE INFO %d\r\n", iMidiDevice);
834        return _lscp_device_info_query(pClient, &(pClient->midi_device_info), szQuery);
835  }  }
836    
837    
838  /**  /**
839   *  Changing settings of MIDI input devices.   *  Changing settings of MIDI input devices.
840   *  SET MIDI_INPUT_DEVICE_PARAMETER <midi-device-id> <param> <value>   *  SET MIDI_INPUT_DEVICE_PARAMETER <midi-device-id> <param>=<value>
841   *   *
842   *  @param pClient      Pointer to client instance structure.   *  @param pClient      Pointer to client instance structure.
843   *  @param iMidiDevice  MIDI device number identifier.   *  @param iMidiDevice  MIDI device number identifier.
# Line 538  lscp_device_info_t* lscp_get_midi_device Line 847  lscp_device_info_t* lscp_get_midi_device
847   */   */
848  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 )
849  {  {
850      lscp_status_t ret = LSCP_FAILED;      char szQuery[LSCP_BUFSIZ];
851    
852      if (pClient == NULL)      if (pClient == NULL)
853          return ret;          return LSCP_FAILED;
854      if (iMidiDevice < 0)      if (iMidiDevice < 0)
855          return ret;          return LSCP_FAILED;
856      if (pParam == NULL)      if (pParam == NULL)
857          return ret;          return LSCP_FAILED;
858    
859      return ret;      sprintf(szQuery, "SET MIDI_INPUT_DEVICE_PARAMETER %d %s='%s'", iMidiDevice, pParam->key, pParam->value);
860        return lscp_client_query(pClient, szQuery);
861  }  }
862    
863    
# Line 559  lscp_status_t lscp_set_midi_device_param Line 869  lscp_status_t lscp_set_midi_device_param
869   *  @param iMidiDevice  MIDI device number identifier.   *  @param iMidiDevice  MIDI device number identifier.
870   *  @param iMidiPort    MIDI port number.   *  @param iMidiPort    MIDI port number.
871   *   *
872   *  @returns A pointer to a @ref lscp_device_channel_info_t structure,   *  @returns A pointer to a @ref lscp_device_port_info_t structure,
873   *  with the given MIDI port information, or NULL in case of failure.   *  with the given MIDI port information, or NULL in case of failure.
874   */   */
875  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 )
876  {  {
877      lscp_device_channel_info_t *pDevChannelInfo = NULL;      char szQuery[LSCP_BUFSIZ];
878    
879      if (pClient == NULL)      if (pClient == NULL)
880          return NULL;          return NULL;
# Line 573  lscp_device_channel_info_t* lscp_get_mid Line 883  lscp_device_channel_info_t* lscp_get_mid
883      if (iMidiPort < 0)      if (iMidiPort < 0)
884          return NULL;          return NULL;
885    
886      return pDevChannelInfo;      sprintf(szQuery, "GET MIDI_INPUT_PORT INFO %d %d\r\n", iMidiDevice, iMidiPort);
887        return _lscp_device_port_info_query(pClient, &(pClient->midi_port_info), szQuery);
888  }  }
889    
890    
# Line 591  lscp_device_channel_info_t* lscp_get_mid Line 902  lscp_device_channel_info_t* lscp_get_mid
902   */   */
903  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 )
904  {  {
905      lscp_param_info_t *pParamInfo = NULL;      char szQuery[LSCP_BUFSIZ];
906    
907      if (pClient == NULL)      if (pClient == NULL)
908          return NULL;          return NULL;
# Line 602  lscp_param_info_t* lscp_get_midi_port_pa Line 913  lscp_param_info_t* lscp_get_midi_port_pa
913      if (pszParam == NULL)      if (pszParam == NULL)
914          return NULL;          return NULL;
915    
916      return pParamInfo;      sprintf(szQuery, "GET MIDI_INPUT_PORT_PARAMETER INFO %d %d %s", iMidiDevice, iMidiPort, pszParam);
917        return _lscp_param_info_query(pClient, &(pClient->midi_port_param_info), szQuery, sizeof(szQuery), NULL);
918  }  }
919    
920    
# Line 619  lscp_param_info_t* lscp_get_midi_port_pa Line 931  lscp_param_info_t* lscp_get_midi_port_pa
931   */   */
932  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 )
933  {  {
934      lscp_status_t ret = LSCP_FAILED;      char szQuery[LSCP_BUFSIZ];
935    
936      if (pClient == NULL)      if (pClient == NULL)
937          return ret;          return LSCP_FAILED;
938      if (iMidiDevice < 0)      if (iMidiDevice < 0)
939          return ret;          return LSCP_FAILED;
940      if (iMidiPort < 0)      if (iMidiPort < 0)
941          return ret;          return LSCP_FAILED;
942      if (pParam == NULL)      if (pParam == NULL)
943          return ret;          return LSCP_FAILED;
944    
945      return ret;      sprintf(szQuery, "SET MIDI_INPUT_PORT_PARAMETER %d %d %s='%s'", iMidiDevice, iMidiPort, pParam->key, pParam->value);
946        return lscp_client_query(pClient, szQuery);
947  }  }
948    
949    
950    //-------------------------------------------------------------------------
951    // Generic parameter list functions.
952    
953    const char *lscp_get_param_value ( lscp_param_t *pParams, const char *pszParam )
954    {
955        int i;
956        
957        for (i = 0; pParams && pParams[i].key; i++) {
958            if (strcasecmp(pParams[i].key, pszParam) == 0)
959                return (const char *) pParams[i].value;
960        }
961        return NULL;
962    }
963    
964    
965  // end of device.c  // end of device.c
966    

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

  ViewVC Help
Powered by ViewVC