/[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 163 by capela, Wed Jun 30 15:16:03 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 26  Line 26 
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, 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_param_info_t  *_lscp_param_info_query  (lscp_client_t *pClient, lscp_param_info_t *pParamInfo, char *pszQuery, lscp_param_t *pDepList);  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  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
# Line 52  static lscp_driver_info_t *_lscp_driver_ Line 55  static lscp_driver_info_t *_lscp_driver_
55              if (strcasecmp(pszToken, "DESCRIPTION") == 0) {              if (strcasecmp(pszToken, "DESCRIPTION") == 0) {
56                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
57                  if (pszToken)                  if (pszToken)
58                      pDriverInfo->description = lscp_unquote(&pszToken, 1);                      lscp_unquote_dup(&(pDriverInfo->description), &pszToken);
59              }              }
60              else if (strcasecmp(pszToken, "VERSION") == 0) {              else if (strcasecmp(pszToken, "VERSION") == 0) {
61                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
62                  if (pszToken)                  if (pszToken)
63                      pDriverInfo->version = lscp_unquote(&pszToken, 1);                      lscp_unquote_dup(&(pDriverInfo->version), &pszToken);
64              }              }
65              else if (strcasecmp(pszToken, "PARAMETERS") == 0) {              else if (strcasecmp(pszToken, "PARAMETERS") == 0) {
66                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
67                  if (pszToken)                  if (pszToken) {
68                        if (pDriverInfo->parameters)
69                            lscp_szsplit_destroy(pDriverInfo->parameters);
70                      pDriverInfo->parameters = lscp_szsplit_create(pszToken, ",");                      pDriverInfo->parameters = lscp_szsplit_create(pszToken, ",");
71                    }
72              }              }
73              pszToken = lscp_strtok(NULL, pszSeps, &(pch));              pszToken = lscp_strtok(NULL, pszSeps, &(pch));
74          }          }
75      }      }
76        else pDriverInfo = NULL;
77            
78      // Unlock this section down.      // Unlock this section down.
79      lscp_mutex_unlock(pClient->mutex);      lscp_mutex_unlock(pClient->mutex);
# Line 75  static lscp_driver_info_t *_lscp_driver_ Line 82  static lscp_driver_info_t *_lscp_driver_
82  }  }
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        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        }
117        else pDeviceInfo = NULL;
118    
119        // 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        }
158        else pDevicePortInfo = NULL;
159    
160        // Unlock this section down.
161        lscp_mutex_unlock(pClient->mutex);
162    
163        return pDevicePortInfo;
164    }
165    
166    
167  // Common parameter info query command.  // 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, lscp_param_t *pDepList )  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;      const char *pszResult;
171      const char *pszSeps = ":";      const char *pszSeps = ":";
# Line 88  static lscp_param_info_t *_lscp_param_in Line 177  static lscp_param_info_t *_lscp_param_in
177      lscp_mutex_lock(pClient->mutex);      lscp_mutex_lock(pClient->mutex);
178    
179      lscp_param_info_reset(pParamInfo);      lscp_param_info_reset(pParamInfo);
180      lscp_param_concat(pszQuery, LSCP_BUFSIZ, pDepList);      lscp_param_concat(pszQuery, cchMaxQuery, pDepList);
181      if (lscp_client_call(pClient, pszQuery) == LSCP_OK) {      if (lscp_client_call(pClient, pszQuery) == LSCP_OK) {
182          pszResult = lscp_client_get_result(pClient);          pszResult = lscp_client_get_result(pClient);
183          pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));          pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
# Line 110  static lscp_param_info_t *_lscp_param_in Line 199  static lscp_param_info_t *_lscp_param_in
199              else if (strcasecmp(pszToken, "DESCRIPTION") == 0) {              else if (strcasecmp(pszToken, "DESCRIPTION") == 0) {
200                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
201                  if (pszToken)                  if (pszToken)
202                      pParamInfo->description = lscp_unquote(&pszToken, 1);                      lscp_unquote_dup(&(pParamInfo->description), &pszToken);
203              }              }
204              else if (strcasecmp(pszToken, "MANDATORY") == 0) {              else if (strcasecmp(pszToken, "MANDATORY") == 0) {
205                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
# Line 129  static lscp_param_info_t *_lscp_param_in Line 218  static lscp_param_info_t *_lscp_param_in
218              }              }
219              else if (strcasecmp(pszToken, "DEPENDS") == 0) {              else if (strcasecmp(pszToken, "DEPENDS") == 0) {
220                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
221                  if (pszToken)                  if (pszToken) {
222                        if (pParamInfo->depends)
223                            lscp_szsplit_destroy(pParamInfo->depends);
224                      pParamInfo->depends = lscp_szsplit_create(pszToken, ",");                      pParamInfo->depends = lscp_szsplit_create(pszToken, ",");
225                    }
226              }              }
227              else if (strcasecmp(pszToken, "DEFAULT") == 0) {              else if (strcasecmp(pszToken, "DEFAULT") == 0) {
228                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
229                  if (pszToken)                  if (pszToken)
230                      pParamInfo->defaultv = lscp_unquote(&pszToken, 1);                      lscp_unquote_dup(&(pParamInfo->defaultv), &pszToken);
231              }              }
232              else if (strcasecmp(pszToken, "RANGE_MIN") == 0) {              else if (strcasecmp(pszToken, "RANGE_MIN") == 0) {
233                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
234                  if (pszToken)                  if (pszToken)
235                      pParamInfo->range_min = lscp_unquote(&pszToken, 1);                      lscp_unquote_dup(&(pParamInfo->range_min), &pszToken);
236              }              }
237              else if (strcasecmp(pszToken, "RANGE_MAX") == 0) {              else if (strcasecmp(pszToken, "RANGE_MAX") == 0) {
238                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
239                  if (pszToken)                  if (pszToken)
240                      pParamInfo->range_max = lscp_unquote(&pszToken, 1);                      lscp_unquote_dup(&(pParamInfo->range_max), &pszToken);
241              }              }
242              else if (strcasecmp(pszToken, "POSSIBILITIES") == 0) {              else if (strcasecmp(pszToken, "POSSIBILITIES") == 0) {
243                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
244                  if (pszToken)                  if (pszToken) {
245                        if (pParamInfo->possibilities)
246                            lscp_szsplit_destroy(pParamInfo->possibilities);
247                      pParamInfo->possibilities = lscp_szsplit_create(pszToken, ",");                      pParamInfo->possibilities = lscp_szsplit_create(pszToken, ",");
248                    }
249              }              }
250              pszToken = lscp_strtok(NULL, pszSeps, &(pch));              pszToken = lscp_strtok(NULL, pszSeps, &(pch));
251          }          }
252      }      }
253        else pParamInfo = NULL;
254    
255      // Unlock this section down.      // Unlock this section down.
256      lscp_mutex_unlock(pClient->mutex);      lscp_mutex_unlock(pClient->mutex);
# Line 167  static lscp_param_info_t *_lscp_param_in Line 263  static lscp_param_info_t *_lscp_param_in
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    
# Line 187  const char ** lscp_get_available_audio_d Line 309  const char ** lscp_get_available_audio_d
309          pClient->audio_drivers = NULL;          pClient->audio_drivers = NULL;
310      }      }
311    
312      if (lscp_client_call(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.      // Unlock this section down.
# Line 215  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 242  lscp_param_info_t *lscp_get_audio_driver Line 364  lscp_param_info_t *lscp_get_audio_driver
364      if (pszParam == NULL)      if (pszParam == NULL)
365          return NULL;          return NULL;
366    
367      sprintf(szQuery, "GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO %s %s\r\n", pszAudioDriver, pszParam);      sprintf(szQuery, "GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO %s %s", pszAudioDriver, pszParam);
368      return _lscp_param_info_query(pClient, &(pClient->audio_param_info), szQuery, pDepList);      return _lscp_param_info_query(pClient, &(pClient->audio_param_info), szQuery, sizeof(szQuery), pDepList);
369  }  }
370    
371    
# Line 263  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 288  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    
# Line 370  int *lscp_list_audio_devices ( lscp_clie Line 504  int *lscp_list_audio_devices ( lscp_clie
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 393  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 414  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 428  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 446  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 457  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 474  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 493  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    
# Line 513  const char** lscp_get_available_midi_dri Line 678  const char** lscp_get_available_midi_dri
678          pClient->midi_drivers = NULL;          pClient->midi_drivers = NULL;
679      }      }
680    
681      if (lscp_client_call(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.      // Unlock this section up.
# Line 541  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 570  lscp_param_info_t *lscp_get_midi_driver_ Line 735  lscp_param_info_t *lscp_get_midi_driver_
735      if (pszParam == NULL)      if (pszParam == NULL)
736          return NULL;          return NULL;
737    
738      sprintf(szQuery, "GET MIDI_INPUT_DRIVER_PARAMETER INFO %s %s\r\n", pszMidiDriver, pszParam);      sprintf(szQuery, "GET MIDI_INPUT_DRIVER_PARAMETER INFO %s %s", pszMidiDriver, pszParam);
739      return _lscp_param_info_query(pClient, &(pClient->midi_param_info), szQuery, pDepList);      return _lscp_param_info_query(pClient, &(pClient->midi_param_info), szQuery, sizeof(szQuery), pDepList);
740  }  }
741    
742    
# Line 591  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 616  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    
# Line 698  int *lscp_list_midi_devices ( lscp_clien Line 875  int *lscp_list_midi_devices ( lscp_clien
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 721  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 742  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 756  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 774  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 785  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 802  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        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      return ret;      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.163  
changed lines
  Added in v.523

  ViewVC Help
Powered by ViewVC