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

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

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

revision 921 by capela, Sun Sep 24 12:55:48 2006 UTC revision 1697 by schoenebeck, Sat Feb 16 19:31:32 2008 UTC
# Line 2  Line 2 
2  //  //
3  /****************************************************************************  /****************************************************************************
4     liblscp - LinuxSampler Control Protocol API     liblscp - LinuxSampler Control Protocol API
5     Copyright (C) 2004-2006, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2008, 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 39  static lscp_status_t    _lscp_client_evt Line 39  static lscp_status_t    _lscp_client_evt
39    
40  static void _lscp_client_evt_proc ( void *pvClient )  static void _lscp_client_evt_proc ( void *pvClient )
41  {  {
42      lscp_client_t *pClient = (lscp_client_t *) pvClient;          lscp_client_t *pClient = (lscp_client_t *) pvClient;
43    
44      fd_set fds;                         // File descriptor list for select().          fd_set fds;                         // File descriptor list for select().
45      int    fd, fdmax;                   // Maximum file descriptor number.          int    fd, fdmax;                   // Maximum file descriptor number.
46      struct timeval tv;                  // For specifying a timeout value.          struct timeval tv;                  // For specifying a timeout value.
47      int    iSelect;                     // Holds select return status.          int    iSelect;                     // Holds select return status.
48      int    iTimeout;          int    iTimeout;
49    
50      char   achBuffer[LSCP_BUFSIZ];          char   achBuffer[LSCP_BUFSIZ];
51      int    cchBuffer;          int    cchBuffer;
52      const char *pszSeps = ":\r\n";          const char *pszSeps = ":\r\n";
53      char * pszToken;          char * pszToken;
54      char * pch;          char * pch;
55      int     cchToken;          int     cchToken;
56      lscp_event_t event;          lscp_event_t event;
57    
58  #ifdef DEBUG  #ifdef DEBUG
59      fprintf(stderr, "_lscp_client_evt_proc: Client waiting for events.\n");          fprintf(stderr, "_lscp_client_evt_proc: Client waiting for events.\n");
60  #endif  #endif
61    
62      while (pClient->evt.iState) {          while (pClient->evt.iState) {
63    
64          // Prepare for waiting on select...                  // Prepare for waiting on select...
65          fd = (int) pClient->evt.sock;                  fd = (int) pClient->evt.sock;
66          FD_ZERO(&fds);                  FD_ZERO(&fds);
67          FD_SET((unsigned int) fd, &fds);                  FD_SET((unsigned int) fd, &fds);
68          fdmax = fd;                  fdmax = fd;
69    
70          // Use the timeout (x10) select feature ...                  // Use the timeout (x10) select feature ...
71          iTimeout = 10 * pClient->iTimeout;                  iTimeout = 10 * pClient->iTimeout;
72          if (iTimeout >= 1000) {                  if (iTimeout >= 1000) {
73              tv.tv_sec = iTimeout / 1000;                          tv.tv_sec = iTimeout / 1000;
74              iTimeout -= tv.tv_sec * 1000;                          iTimeout -= tv.tv_sec * 1000;
75          }                  }
76          else tv.tv_sec = 0;                  else tv.tv_sec = 0;
77          tv.tv_usec = iTimeout * 1000;                  tv.tv_usec = iTimeout * 1000;
78    
79          // Wait for event...                  // Wait for event...
80          iSelect = select(fdmax + 1, &fds, NULL, NULL, &tv);                  iSelect = select(fdmax + 1, &fds, NULL, NULL, &tv);
81          if (iSelect > 0 && FD_ISSET(fd, &fds)) {                  if (iSelect > 0 && FD_ISSET(fd, &fds)) {
82              // May recv now...                          // May recv now...
83              cchBuffer = recv(pClient->evt.sock, achBuffer, sizeof(achBuffer), 0);                          cchBuffer = recv(pClient->evt.sock, achBuffer, sizeof(achBuffer), 0);
84              if (cchBuffer > 0) {                          if (cchBuffer > 0) {
85                  // Make sure received buffer it's null terminated.                                  // Make sure received buffer it's null terminated.
86                  achBuffer[cchBuffer] = (char) 0;                                  achBuffer[cchBuffer] = (char) 0;
87                  // Parse for the notification event message...                                  pch = achBuffer;
88                  pszToken = lscp_strtok(achBuffer, pszSeps, &(pch)); // Have "NOTIFY".                                  do {
89                  if (strcasecmp(pszToken, "NOTIFY") == 0) {                                          // Parse for the notification event message...
90                      pszToken = lscp_strtok(NULL, pszSeps, &(pch));                                          pszToken = lscp_strtok(NULL, pszSeps, &(pch)); // Have "NOTIFY"
91                      event    = lscp_event_from_text(pszToken);                                          if (strcasecmp(pszToken, "NOTIFY") == 0) {
92                      // And pick the rest of data...                                                  pszToken = lscp_strtok(NULL, pszSeps, &(pch));
93                      pszToken = lscp_strtok(NULL, pszSeps, &(pch));                                                  event    = lscp_event_from_text(pszToken);
94                      cchToken = (pszToken == NULL ? 0 : strlen(pszToken));                                                  // And pick the rest of data...
95                      // Double-check if we're really up to it...                                                  pszToken = lscp_strtok(NULL, pszSeps, &(pch));
96                      if (pClient->events & event) {                                                  cchToken = (pszToken == NULL ? 0 : strlen(pszToken));
97                          // Invoke the client event callback...                                                  // Double-check if we're really up to it...
98                          if ((*pClient->pfnCallback)(                                                  if (pClient->events & event) {
99                                  pClient,                                                          // Invoke the client event callback...
100                                  event,                                                          if ((*pClient->pfnCallback)(
101                                  pszToken,                                                                          pClient,
102                                  cchToken,                                                                          event,
103                                  pClient->pvData) != LSCP_OK) {                                                                          pszToken,
104                              pClient->evt.iState = 0;                                                                          cchToken,
105                          }                                                                          pClient->pvData) != LSCP_OK) {
106                      }                                                                  pClient->evt.iState = 0;
107                  }                                                          }
108              } else {                                                  }
109                  lscp_socket_perror("_lscp_client_evt_proc: recv");                                          }
110                  pClient->evt.iState = 0;                                  } while (*pch);
111              }                          } else {
112          }   // Check if select has in error.                                  lscp_socket_perror("_lscp_client_evt_proc: recv");
113          else if (iSelect < 0) {                                  pClient->evt.iState = 0;
114              lscp_socket_perror("_lscp_client_evt_proc: select");                          }
115              pClient->evt.iState = 0;                  }   // Check if select has in error.
116          }                  else if (iSelect < 0) {
117                            lscp_socket_perror("_lscp_client_evt_proc: select");
118          // Finally, always signal the event.                          pClient->evt.iState = 0;
119          lscp_cond_signal(pClient->cond);                  }
120      }  
121                    // Finally, always signal the event.
122                    lscp_cond_signal(pClient->cond);
123            }
124    
125  #ifdef DEBUG  #ifdef DEBUG
126      fprintf(stderr, "_lscp_client_evt_proc: Client closing.\n");          fprintf(stderr, "_lscp_client_evt_proc: Client closing.\n");
127  #endif  #endif
128  }  }
129    
# Line 131  static void _lscp_client_evt_proc ( void Line 134  static void _lscp_client_evt_proc ( void
134  // Open the event service socket connection.  // Open the event service socket connection.
135  static lscp_status_t _lscp_client_evt_connect ( lscp_client_t *pClient )  static lscp_status_t _lscp_client_evt_connect ( lscp_client_t *pClient )
136  {  {
137      lscp_socket_t sock;          lscp_socket_t sock;
138      struct sockaddr_in addr;          struct sockaddr_in addr;
139      int cAddr;          int cAddr;
140  #if defined(WIN32)  #if defined(WIN32)
141      int iSockOpt = (-1);          int iSockOpt = (-1);
142  #endif  #endif
143    
144      // Prepare the event connection socket...          // Prepare the event connection socket...
145      sock = socket(AF_INET, SOCK_STREAM, 0);          sock = socket(AF_INET, SOCK_STREAM, 0);
146      if (sock == INVALID_SOCKET) {          if (sock == INVALID_SOCKET) {
147          lscp_socket_perror("_lscp_client_evt_connect: socket");                  lscp_socket_perror("_lscp_client_evt_connect: socket");
148          return LSCP_FAILED;                  return LSCP_FAILED;
149      }          }
150    
151  #if defined(WIN32)  #if defined(WIN32)
152      if (setsockopt(sock, SOL_SOCKET, SO_DONTLINGER, (char *) &iSockOpt, sizeof(int)) == SOCKET_ERROR)          if (setsockopt(sock, SOL_SOCKET, SO_DONTLINGER, (char *) &iSockOpt, sizeof(int)) == SOCKET_ERROR)
153          lscp_socket_perror("lscp_client_evt_connect: setsockopt(SO_DONTLINGER)");                  lscp_socket_perror("lscp_client_evt_connect: setsockopt(SO_DONTLINGER)");
154  #endif  #endif
155    
156  #ifdef DEBUG  #ifdef DEBUG
157      lscp_socket_getopts("_lscp_client_evt_connect:", sock);          lscp_socket_getopts("_lscp_client_evt_connect:", sock);
158  #endif  #endif
159    
160      // Use same address of the command connection.          // Use same address of the command connection.
161      cAddr = sizeof(struct sockaddr_in);          cAddr = sizeof(struct sockaddr_in);
162      memmove((char *) &addr, &(pClient->cmd.addr), cAddr);          memmove((char *) &addr, &(pClient->cmd.addr), cAddr);
163    
164      // Start the connection...          // Start the connection...
165      if (connect(sock, (struct sockaddr *) &addr, cAddr) == SOCKET_ERROR) {          if (connect(sock, (struct sockaddr *) &addr, cAddr) == SOCKET_ERROR) {
166          lscp_socket_perror("_lscp_client_evt_connect: connect");                  lscp_socket_perror("_lscp_client_evt_connect: connect");
167          closesocket(sock);                  closesocket(sock);
168          return LSCP_FAILED;                  return LSCP_FAILED;
169      }          }
170    
171      // Set our socket agent struct...          // Set our socket agent struct...
172      lscp_socket_agent_init(&(pClient->evt), sock, &addr, cAddr);          lscp_socket_agent_init(&(pClient->evt), sock, &addr, cAddr);
173    
174      // And finally the service thread...          // And finally the service thread...
175      return lscp_socket_agent_start(&(pClient->evt), _lscp_client_evt_proc, pClient, 0);          return lscp_socket_agent_start(&(pClient->evt), _lscp_client_evt_proc, pClient, 0);
176  }  }
177    
178    
179  // Subscribe to a single event.  // Subscribe to a single event.
180  static lscp_status_t _lscp_client_evt_request ( lscp_client_t *pClient, int iSubscribe, lscp_event_t event )  static lscp_status_t _lscp_client_evt_request ( lscp_client_t *pClient, int iSubscribe, lscp_event_t event )
181  {  {
182      const char *pszEvent;          const char *pszEvent;
183      char  szQuery[LSCP_BUFSIZ];          char  szQuery[LSCP_BUFSIZ];
184      int   cchQuery;          int   cchQuery;
185    
186      if (pClient == NULL)          if (pClient == NULL)
187          return LSCP_FAILED;                  return LSCP_FAILED;
188    
189      // Which (single) event?          // Which (single) event?
190      pszEvent = lscp_event_to_text(event);          pszEvent = lscp_event_to_text(event);
191      if (pszEvent == NULL)          if (pszEvent == NULL)
192          return LSCP_FAILED;                  return LSCP_FAILED;
193    
194      // Build the query string...          // Build the query string...
195      cchQuery = sprintf(szQuery, "%sSUBSCRIBE %s\n\n", (iSubscribe == 0 ? "UN" : ""), pszEvent);          cchQuery = sprintf(szQuery, "%sSUBSCRIBE %s\n\n", (iSubscribe == 0 ? "UN" : ""), pszEvent);
196      // Just send data, forget result...          // Just send data, forget result...
197      if (send(pClient->evt.sock, szQuery, cchQuery, 0) < cchQuery) {          if (send(pClient->evt.sock, szQuery, cchQuery, 0) < cchQuery) {
198          lscp_socket_perror("_lscp_client_evt_request: send");                  lscp_socket_perror("_lscp_client_evt_request: send");
199          return LSCP_FAILED;                  return LSCP_FAILED;
200      }          }
201    
202      // Wait on response.          // Wait on response.
203      lscp_cond_wait(pClient->cond, pClient->mutex);          lscp_cond_wait(pClient->cond, pClient->mutex);
204    
205      // Update as naively as we can...          // Update as naively as we can...
206      if (iSubscribe)          if (iSubscribe)
207          pClient->events |=  event;                  pClient->events |=  event;
208      else          else
209          pClient->events &= ~event;                  pClient->events &= ~event;
210    
211      return LSCP_OK;          return LSCP_OK;
212  }  }
213    
214    
# Line 242  const char* lscp_client_build   (void) { Line 245  const char* lscp_client_build   (void) {
245   */   */
246  lscp_client_t* lscp_client_create ( const char *pszHost, int iPort, lscp_client_proc_t pfnCallback, void *pvData )  lscp_client_t* lscp_client_create ( const char *pszHost, int iPort, lscp_client_proc_t pfnCallback, void *pvData )
247  {  {
248      lscp_client_t  *pClient;          lscp_client_t  *pClient;
249      struct hostent *pHost;          struct hostent *pHost;
250      lscp_socket_t sock;          lscp_socket_t sock;
251      struct sockaddr_in addr;          struct sockaddr_in addr;
252      int cAddr;          int cAddr;
253  #if defined(WIN32)  #if defined(WIN32)
254      int iSockOpt = (-1);          int iSockOpt = (-1);
255  #endif  #endif
256    
257      if (pfnCallback == NULL) {          if (pfnCallback == NULL) {
258          fprintf(stderr, "lscp_client_create: Invalid client callback function.\n");                  fprintf(stderr, "lscp_client_create: Invalid client callback function.\n");
259          return NULL;                  return NULL;
260      }          }
261    
262      pHost = gethostbyname(pszHost);          pHost = gethostbyname(pszHost);
263      if (pHost == NULL) {          if (pHost == NULL) {
264          lscp_socket_herror("lscp_client_create: gethostbyname");                  lscp_socket_herror("lscp_client_create: gethostbyname");
265          return NULL;                  return NULL;
266      }          }
267    
268      // Allocate client descriptor...          // Allocate client descriptor...
269    
270      pClient = (lscp_client_t *) malloc(sizeof(lscp_client_t));          pClient = (lscp_client_t *) malloc(sizeof(lscp_client_t));
271      if (pClient == NULL) {          if (pClient == NULL) {
272          fprintf(stderr, "lscp_client_create: Out of memory.\n");                  fprintf(stderr, "lscp_client_create: Out of memory.\n");
273          return NULL;                  return NULL;
274      }          }
275      memset(pClient, 0, sizeof(lscp_client_t));          memset(pClient, 0, sizeof(lscp_client_t));
276    
277      pClient->pfnCallback = pfnCallback;          pClient->pfnCallback = pfnCallback;
278      pClient->pvData = pvData;          pClient->pvData = pvData;
279    
280  #ifdef DEBUG  #ifdef DEBUG
281      fprintf(stderr, "lscp_client_create: pClient=%p: pszHost=%s iPort=%d.\n", pClient, pszHost, iPort);          fprintf(stderr, "lscp_client_create: pClient=%p: pszHost=%s iPort=%d.\n", pClient, pszHost, iPort);
282  #endif  #endif
283    
284      // Prepare the command connection socket...          // Prepare the command connection socket...
285    
286      sock = socket(AF_INET, SOCK_STREAM, 0);          sock = socket(AF_INET, SOCK_STREAM, 0);
287      if (sock == INVALID_SOCKET) {          if (sock == INVALID_SOCKET) {
288          lscp_socket_perror("lscp_client_create: cmd: socket");                  lscp_socket_perror("lscp_client_create: cmd: socket");
289          free(pClient);                  free(pClient);
290          return NULL;                  return NULL;
291      }          }
292    
293  #if defined(WIN32)  #if defined(WIN32)
294      if (setsockopt(sock, SOL_SOCKET, SO_DONTLINGER, (char *) &iSockOpt, sizeof(int)) == SOCKET_ERROR)          if (setsockopt(sock, SOL_SOCKET, SO_DONTLINGER, (char *) &iSockOpt, sizeof(int)) == SOCKET_ERROR)
295          lscp_socket_perror("lscp_client_create: cmd: setsockopt(SO_DONTLINGER)");                  lscp_socket_perror("lscp_client_create: cmd: setsockopt(SO_DONTLINGER)");
296  #endif  #endif
297    
298  #ifdef DEBUG  #ifdef DEBUG
299      lscp_socket_getopts("lscp_client_create: cmd", sock);          lscp_socket_getopts("lscp_client_create: cmd", sock);
300  #endif  #endif
301    
302      cAddr = sizeof(struct sockaddr_in);          cAddr = sizeof(struct sockaddr_in);
303      memset((char *) &addr, 0, cAddr);          memset((char *) &addr, 0, cAddr);
304      addr.sin_family = pHost->h_addrtype;          addr.sin_family = pHost->h_addrtype;
305      memmove((char *) &(addr.sin_addr), pHost->h_addr, pHost->h_length);          memmove((char *) &(addr.sin_addr), pHost->h_addr, pHost->h_length);
306      addr.sin_port = htons((short) iPort);          addr.sin_port = htons((short) iPort);
307    
308      if (connect(sock, (struct sockaddr *) &addr, cAddr) == SOCKET_ERROR) {          if (connect(sock, (struct sockaddr *) &addr, cAddr) == SOCKET_ERROR) {
309          lscp_socket_perror("lscp_client_create: cmd: connect");                  lscp_socket_perror("lscp_client_create: cmd: connect");
310          closesocket(sock);                  closesocket(sock);
311          free(pClient);                  free(pClient);
312          return NULL;                  return NULL;
313      }          }
314    
315      // Initialize the command socket agent struct...          // Initialize the command socket agent struct...
316      lscp_socket_agent_init(&(pClient->cmd), sock, &addr, cAddr);          lscp_socket_agent_init(&(pClient->cmd), sock, &addr, cAddr);
317    
318  #ifdef DEBUG  #ifdef DEBUG
319      fprintf(stderr, "lscp_client_create: cmd: pClient=%p: sock=%d addr=%s port=%d.\n", pClient, pClient->cmd.sock, inet_ntoa(pClient->cmd.addr.sin_addr), ntohs(pClient->cmd.addr.sin_port));          fprintf(stderr, "lscp_client_create: cmd: pClient=%p: sock=%d addr=%s port=%d.\n", pClient, pClient->cmd.sock, inet_ntoa(pClient->cmd.addr.sin_addr), ntohs(pClient->cmd.addr.sin_port));
320  #endif  #endif
321    
322      // Initialize the event service socket struct...          // Initialize the event service socket struct...
323      lscp_socket_agent_init(&(pClient->evt), INVALID_SOCKET, NULL, 0);          lscp_socket_agent_init(&(pClient->evt), INVALID_SOCKET, NULL, 0);
324      // No events subscribed, yet.          // No events subscribed, yet.
325      pClient->events = LSCP_EVENT_NONE;          pClient->events = LSCP_EVENT_NONE;
326      // Initialize cached members.          // Initialize cached members.
327      pClient->audio_drivers = NULL;          pClient->audio_drivers = NULL;
328      pClient->midi_drivers = NULL;          pClient->midi_drivers = NULL;
329      pClient->audio_devices = NULL;          pClient->audio_devices = NULL;
330      pClient->midi_devices = NULL;          pClient->midi_devices = NULL;
331      pClient->engines = NULL;          pClient->engines = NULL;
332      pClient->channels = NULL;          pClient->channels = NULL;
333      lscp_driver_info_init(&(pClient->audio_driver_info));          pClient->fxsends = NULL;
334      lscp_driver_info_init(&(pClient->midi_driver_info));          pClient->midi_instruments = NULL;
335      lscp_device_info_init(&(pClient->audio_device_info));          pClient->midi_maps = NULL;
336      lscp_device_info_init(&(pClient->midi_device_info));          pClient->midi_map_name = NULL;
337      lscp_param_info_init(&(pClient->audio_param_info));          lscp_driver_info_init(&(pClient->audio_driver_info));
338      lscp_param_info_init(&(pClient->midi_param_info));          lscp_driver_info_init(&(pClient->midi_driver_info));
339      lscp_device_port_info_init(&(pClient->audio_channel_info));          lscp_device_info_init(&(pClient->audio_device_info));
340      lscp_device_port_info_init(&(pClient->midi_port_info));          lscp_device_info_init(&(pClient->midi_device_info));
341      lscp_param_info_init(&(pClient->audio_channel_param_info));          lscp_param_info_init(&(pClient->audio_param_info));
342      lscp_param_info_init(&(pClient->midi_port_param_info));          lscp_param_info_init(&(pClient->midi_param_info));
343      lscp_server_info_init(&(pClient->server_info));          lscp_device_port_info_init(&(pClient->audio_channel_info));
344      lscp_engine_info_init(&(pClient->engine_info));          lscp_device_port_info_init(&(pClient->midi_port_info));
345      lscp_channel_info_init(&(pClient->channel_info));          lscp_param_info_init(&(pClient->audio_channel_param_info));
346      // Initialize error stuff.          lscp_param_info_init(&(pClient->midi_port_param_info));
347      pClient->pszResult = NULL;          lscp_server_info_init(&(pClient->server_info));
348      pClient->iErrno = -1;          lscp_engine_info_init(&(pClient->engine_info));
349      // Stream usage stuff.          lscp_channel_info_init(&(pClient->channel_info));
350      pClient->buffer_fill = NULL;          lscp_fxsend_info_init(&(pClient->fxsend_info));
351      pClient->iStreamCount = 0;          lscp_midi_instrument_info_init(&(pClient->midi_instrument_info));
352      // Default timeout value.          // Initialize error stuff.
353      pClient->iTimeout = LSCP_TIMEOUT_MSECS;          pClient->pszResult = NULL;
354            pClient->iErrno = -1;
355            // Stream usage stuff.
356            pClient->buffer_fill = NULL;
357            pClient->iStreamCount = 0;
358            // Default timeout value.
359            pClient->iTimeout = LSCP_TIMEOUT_MSECS;
360          pClient->iTimeoutCount = 0;          pClient->iTimeoutCount = 0;
361    
362      // Initialize the transaction mutex.          // Initialize the transaction mutex.
363      lscp_mutex_init(pClient->mutex);          lscp_mutex_init(pClient->mutex);
364      lscp_cond_init(pClient->cond);          lscp_cond_init(pClient->cond);
365    
366      // Finally we've some success...          // Finally we've some success...
367      return pClient;          return pClient;
368  }  }
369    
370    
# Line 366  lscp_client_t* lscp_client_create ( cons Line 375  lscp_client_t* lscp_client_create ( cons
375   */   */
376  lscp_status_t lscp_client_join ( lscp_client_t *pClient )  lscp_status_t lscp_client_join ( lscp_client_t *pClient )
377  {  {
378      if (pClient == NULL)          if (pClient == NULL)
379          return LSCP_FAILED;                  return LSCP_FAILED;
380    
381  #ifdef DEBUG  #ifdef DEBUG
382      fprintf(stderr, "lscp_client_join: pClient=%p.\n", pClient);          fprintf(stderr, "lscp_client_join: pClient=%p.\n", pClient);
383  #endif  #endif
384    
385  //  lscp_socket_agent_join(&(pClient->evt));  //  lscp_socket_agent_join(&(pClient->evt));
386      lscp_socket_agent_join(&(pClient->cmd));          lscp_socket_agent_join(&(pClient->cmd));
387    
388      return LSCP_OK;          return LSCP_OK;
389  }  }
390    
391    
# Line 389  lscp_status_t lscp_client_join ( lscp_cl Line 398  lscp_status_t lscp_client_join ( lscp_cl
398   */   */
399  lscp_status_t lscp_client_destroy ( lscp_client_t *pClient )  lscp_status_t lscp_client_destroy ( lscp_client_t *pClient )
400  {  {
401      if (pClient == NULL)          if (pClient == NULL)
402          return LSCP_FAILED;                  return LSCP_FAILED;
403    
404  #ifdef DEBUG  #ifdef DEBUG
405      fprintf(stderr, "lscp_client_destroy: pClient=%p.\n", pClient);          fprintf(stderr, "lscp_client_destroy: pClient=%p.\n", pClient);
406  #endif  #endif
407    
408      // Lock this section up.          // Lock this section up.
409      lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
410    
411      // Free up all cached members.          // Free up all cached members.
412      lscp_channel_info_free(&(pClient->channel_info));          lscp_midi_instrument_info_free(&(pClient->midi_instrument_info));
413      lscp_engine_info_free(&(pClient->engine_info));          lscp_fxsend_info_free(&(pClient->fxsend_info));
414      lscp_server_info_free(&(pClient->server_info));          lscp_channel_info_free(&(pClient->channel_info));
415      lscp_param_info_free(&(pClient->midi_port_param_info));          lscp_engine_info_free(&(pClient->engine_info));
416      lscp_param_info_free(&(pClient->audio_channel_param_info));          lscp_server_info_free(&(pClient->server_info));
417      lscp_device_port_info_free(&(pClient->midi_port_info));          lscp_param_info_free(&(pClient->midi_port_param_info));
418      lscp_device_port_info_free(&(pClient->audio_channel_info));          lscp_param_info_free(&(pClient->audio_channel_param_info));
419      lscp_param_info_free(&(pClient->midi_param_info));          lscp_device_port_info_free(&(pClient->midi_port_info));
420      lscp_param_info_free(&(pClient->audio_param_info));          lscp_device_port_info_free(&(pClient->audio_channel_info));
421      lscp_device_info_free(&(pClient->midi_device_info));          lscp_param_info_free(&(pClient->midi_param_info));
422      lscp_device_info_free(&(pClient->audio_device_info));          lscp_param_info_free(&(pClient->audio_param_info));
423      lscp_driver_info_free(&(pClient->midi_driver_info));          lscp_device_info_free(&(pClient->midi_device_info));
424      lscp_driver_info_free(&(pClient->audio_driver_info));          lscp_device_info_free(&(pClient->audio_device_info));
425      // Free available engine table.          lscp_driver_info_free(&(pClient->midi_driver_info));
426      lscp_szsplit_destroy(pClient->audio_drivers);          lscp_driver_info_free(&(pClient->audio_driver_info));
427      lscp_szsplit_destroy(pClient->midi_drivers);          // Free available engine table.
428      lscp_isplit_destroy(pClient->audio_devices);          lscp_szsplit_destroy(pClient->audio_drivers);
429      lscp_isplit_destroy(pClient->midi_devices);          lscp_szsplit_destroy(pClient->midi_drivers);
430      lscp_szsplit_destroy(pClient->engines);          lscp_isplit_destroy(pClient->audio_devices);
431      lscp_isplit_destroy(pClient->channels);          lscp_isplit_destroy(pClient->midi_devices);
432      // Make them null.          lscp_szsplit_destroy(pClient->engines);
433      pClient->audio_drivers = NULL;          lscp_isplit_destroy(pClient->channels);
434      pClient->midi_drivers = NULL;          lscp_isplit_destroy(pClient->fxsends);
435      pClient->engines = NULL;          lscp_midi_instruments_destroy(pClient->midi_instruments);
436      // Free result error stuff.          lscp_isplit_destroy(pClient->midi_maps);
437      lscp_client_set_result(pClient, NULL, 0);          if (pClient->midi_map_name)
438      // Free stream usage stuff.                  free(pClient->midi_map_name);
439      if (pClient->buffer_fill)          // Make them null.
440          free(pClient->buffer_fill);          pClient->audio_drivers = NULL;
441      pClient->buffer_fill = NULL;          pClient->midi_drivers = NULL;
442      pClient->iStreamCount = 0;          pClient->audio_devices = NULL;
443      pClient->iTimeout = 0;          pClient->midi_devices = NULL;
444            pClient->engines = NULL;
445      // Free socket agents.          pClient->channels = NULL;
446      lscp_socket_agent_free(&(pClient->evt));          pClient->fxsends = NULL;
447      lscp_socket_agent_free(&(pClient->cmd));          pClient->midi_instruments = NULL;
448            pClient->midi_maps = NULL;
449      // Last but not least, free good ol'transaction mutex.          pClient->midi_map_name = NULL;
450      lscp_mutex_unlock(pClient->mutex);          // Free result error stuff.
451      lscp_mutex_destroy(pClient->mutex);          lscp_client_set_result(pClient, NULL, 0);
452      lscp_cond_destroy(pClient->cond);          // Free stream usage stuff.
453            if (pClient->buffer_fill)
454                    free(pClient->buffer_fill);
455            pClient->buffer_fill = NULL;
456            pClient->iStreamCount = 0;
457            pClient->iTimeout = 0;
458    
459            // Free socket agents.
460            lscp_socket_agent_free(&(pClient->evt));
461            lscp_socket_agent_free(&(pClient->cmd));
462    
463            // Last but not least, free good ol'transaction mutex.
464            lscp_mutex_unlock(pClient->mutex);
465            lscp_mutex_destroy(pClient->mutex);
466            lscp_cond_destroy(pClient->cond);
467    
468      free(pClient);          free(pClient);
469    
470      return LSCP_OK;          return LSCP_OK;
471  }  }
472    
473    
# Line 458  lscp_status_t lscp_client_destroy ( lscp Line 481  lscp_status_t lscp_client_destroy ( lscp
481   */   */
482  lscp_status_t lscp_client_set_timeout ( lscp_client_t *pClient, int iTimeout )  lscp_status_t lscp_client_set_timeout ( lscp_client_t *pClient, int iTimeout )
483  {  {
484      if (pClient == NULL)          if (pClient == NULL)
485          return LSCP_FAILED;                  return LSCP_FAILED;
486      if (iTimeout < 0)          if (iTimeout < 0)
487          return LSCP_FAILED;                  return LSCP_FAILED;
488    
489      pClient->iTimeout = iTimeout;          pClient->iTimeout = iTimeout;
490      return LSCP_OK;          return LSCP_OK;
491  }  }
492    
493    
# Line 477  lscp_status_t lscp_client_set_timeout ( Line 500  lscp_status_t lscp_client_set_timeout (
500   */   */
501  int lscp_client_get_timeout ( lscp_client_t *pClient )  int lscp_client_get_timeout ( lscp_client_t *pClient )
502  {  {
503      if (pClient == NULL)          if (pClient == NULL)
504          return -1;                  return -1;
505    
506      return pClient->iTimeout;          return pClient->iTimeout;
507  }  }
508    
509    
# Line 502  int lscp_client_get_timeout ( lscp_clien Line 525  int lscp_client_get_timeout ( lscp_clien
525   */   */
526  lscp_status_t lscp_client_query ( lscp_client_t *pClient, const char *pszQuery )  lscp_status_t lscp_client_query ( lscp_client_t *pClient, const char *pszQuery )
527  {  {
528      lscp_status_t ret;          lscp_status_t ret;
529    
530      // Lock this section up.          if (pClient == NULL)
531      lscp_mutex_lock(pClient->mutex);                  return LSCP_FAILED;
532    
533      // Just make the now guarded call.          // Lock this section up.
534      ret = lscp_client_call(pClient, pszQuery);          lscp_mutex_lock(pClient->mutex);
535    
536      // Unlock this section down.          // Just make the now guarded call.
537      lscp_mutex_unlock(pClient->mutex);          ret = lscp_client_call(pClient, pszQuery, 0);
538    
539      return ret;          // Unlock this section down.
540            lscp_mutex_unlock(pClient->mutex);
541    
542            return ret;
543  }  }
544    
545  /**  /**
# Line 527  lscp_status_t lscp_client_query ( lscp_c Line 553  lscp_status_t lscp_client_query ( lscp_c
553   */   */
554  const char *lscp_client_get_result ( lscp_client_t *pClient )  const char *lscp_client_get_result ( lscp_client_t *pClient )
555  {  {
556      if (pClient == NULL)          if (pClient == NULL)
557          return NULL;                  return NULL;
558    
559      return pClient->pszResult;          return pClient->pszResult;
560  }  }
561    
562    
# Line 544  const char *lscp_client_get_result ( lsc Line 570  const char *lscp_client_get_result ( lsc
570   */   */
571  int lscp_client_get_errno ( lscp_client_t *pClient )  int lscp_client_get_errno ( lscp_client_t *pClient )
572  {  {
573      if (pClient == NULL)          if (pClient == NULL)
574          return -1;                  return -1;
575    
576      return pClient->iErrno;          return pClient->iErrno;
577  }  }
578    
579    
# Line 555  int lscp_client_get_errno ( lscp_client_ Line 581  int lscp_client_get_errno ( lscp_client_
581  // Client registration protocol functions.  // Client registration protocol functions.
582    
583  /**  /**
584   *  Register frontend for receiving event messages:   *  Register frontend for receiving event messages by the sampler backend.
585   *  SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL   *  @e Caution: since liblscp v0.5.5.4 you have to call lscp_client_subscribe()
586   *      | CHANNEL_INFO | MISCELLANEOUS   *  for @e each event you want to subscribe. That is the old bitflag approach
587     *  was abondoned at this point. You can however still register all older
588     *  events with one lscp_client_subscribe() call at once. Thus, the old
589     *  behavior of this functions was not broken. Those older events are namely:
590     *  @code
591     *  SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT
592     *      | BUFFER_FILL | CHANNEL_INFO | TOTAL_VOICE_COUNT
593     *      | AUDIO_OUTPUT_DEVICE_COUNT | AUDIO_OUTPUT_DEVICE_INFO
594     *      | MIDI_INPUT_DEVICE_COUNT | MIDI_INPUT_DEVICE_INFO
595     *      | MIDI_INSTRUMENT_MAP_COUNT | MIDI_INSTRUMENT_MAP_INFO
596     *      | MIDI_INSTRUMENT_COUNT | MIDI_INSTRUMENT_INFO
597     *      | MISCELLANEOUS
598     *  @endcode
599     *  The old events occupy the lower 16 bits (as bit flags), and all younger
600     *  events enumerate the whole upper 16 bits range. The new, enumerated
601     *  events are namely:
602     *  @code
603     *  SUBSCRIBE CHANNEL_MIDI
604     *  @endcode
605   *   *
606   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
607   *  @param events   Bit-wise OR'ed event flags to subscribe.   *  @param events   LSCP event to subscribe.
608   *   *
609   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
610   */   */
611  lscp_status_t lscp_client_subscribe ( lscp_client_t *pClient, lscp_event_t events )  lscp_status_t lscp_client_subscribe ( lscp_client_t *pClient, lscp_event_t events )
612  {  {
613      lscp_status_t ret = LSCP_FAILED;          lscp_status_t ret = LSCP_OK;
614            lscp_event_t currentEvent;
     if (pClient == NULL)  
         return LSCP_FAILED;  
   
     // Lock this section up.  
     lscp_mutex_lock(pClient->mutex);  
   
     // If applicable, start the alternate connection...  
     if (pClient->events == LSCP_EVENT_NONE)  
         ret = _lscp_client_evt_connect(pClient);  
615    
616      // Send the subscription commands.          if (pClient == NULL)
617      if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_COUNT))                  return LSCP_FAILED;
         ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_COUNT);  
     if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT))  
         ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_VOICE_COUNT);  
     if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT))  
         ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_STREAM_COUNT);  
     if (ret == LSCP_OK && (events & LSCP_EVENT_BUFFER_FILL))  
         ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_BUFFER_FILL);  
     if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))  
         ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_INFO);  
     if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))  
         ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MISCELLANEOUS);  
   
     // Unlock this section down.  
     lscp_mutex_unlock(pClient->mutex);  
   
     return ret;  
 }  
618    
619            // Lock this section up.
620            lscp_mutex_lock(pClient->mutex);
621    
622  /**          // If applicable, start the alternate connection...
623   *  Deregister frontend from receiving UDP event messages anymore:          if (pClient->events == LSCP_EVENT_NONE)
624   *  SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL                  ret = _lscp_client_evt_connect(pClient);
625   *      | CHANNEL_INFO | MISCELLANEOUS  
626            // Send the subscription commands.
627            if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_COUNT))
628                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_COUNT);
629            if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT))
630                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_VOICE_COUNT);
631            if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT))
632                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_STREAM_COUNT);
633            if (ret == LSCP_OK && (events & LSCP_EVENT_BUFFER_FILL))
634                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_BUFFER_FILL);
635            if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))
636                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_INFO);
637            if (ret == LSCP_OK && (events & LSCP_EVENT_TOTAL_VOICE_COUNT))
638                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_TOTAL_VOICE_COUNT);
639            if (ret == LSCP_OK && (events & LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT))
640                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT);
641            if (ret == LSCP_OK && (events & LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO))
642                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO);
643            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT))
644                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT);
645            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INPUT_DEVICE_INFO))
646                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INPUT_DEVICE_INFO);
647            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_MAP_COUNT))
648                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_MAP_COUNT);
649            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_MAP_INFO))
650                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_MAP_INFO);
651            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_COUNT))
652                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_COUNT);
653            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_INFO))
654                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_INFO);
655            if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))
656                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MISCELLANEOUS);
657            // Caution: for the upper 16 bits, we don't use bit flags anymore ...
658            currentEvent = events & 0xffff0000;
659            if (ret == LSCP_OK && currentEvent) {
660                    switch (currentEvent) {
661                            case LSCP_EVENT_CHANNEL_MIDI:
662                            case LSCP_EVENT_DEVICE_MIDI:
663                                    ret = _lscp_client_evt_request(pClient, 1, currentEvent);
664                                    break;
665                            default: // unknown "upper" event type
666                                    ret = LSCP_FAILED;
667                                    break;
668                    }
669            }
670    
671            // Unlock this section down.
672            lscp_mutex_unlock(pClient->mutex);
673    
674            return ret;
675    }
676    
677    
678    /**
679     *  Deregister frontend from receiving UDP event messages anymore.
680     *  @e Caution: since liblscp v0.5.5.4 you have to call
681     *  lscp_client_unsubscribe() for @e each event you want to unsubscribe.
682     *  That is the old bitflag approach was abondoned at this point. You can
683     *  however still register all older events with one lscp_client_subscribe()
684     *  call at once. Thus, the old behavior of this functions was not broken.
685     *  Those older events are namely:
686     *  @code
687     *  UNSUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT
688     *      | BUFFER_FILL | CHANNEL_INFO | TOTAL_VOICE_COUNT
689     *      | AUDIO_OUTPUT_DEVICE_COUNT | AUDIO_OUTPUT_DEVICE_INFO
690     *      | MIDI_INPUT_DEVICE_COUNT | MIDI_INPUT_DEVICE_INFO
691     *      | MIDI_INSTRUMENT_MAP_COUNT | MIDI_INSTRUMENT_MAP_INFO
692     *      | MIDI_INSTRUMENT_COUNT | MIDI_INSTRUMENT_INFO
693     *      | MISCELLANEOUS
694     *  @endcode
695     *  The old events occupy the lower 16 bits (as bit flags), and all younger
696     *  events enumerate the whole upper 16 bits range. The new, enumerated
697     *  events are namely:
698     *  @code
699     *  UNSUBSCRIBE CHANNEL_MIDI
700     *  @endcode
701   *   *
702   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
703   *  @param events   Bit-wise OR'ed event flags to unsubscribe.   *  @param events   LSCP event to unsubscribe.
704   *   *
705   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
706   */   */
707  lscp_status_t lscp_client_unsubscribe ( lscp_client_t *pClient, lscp_event_t events )  lscp_status_t lscp_client_unsubscribe ( lscp_client_t *pClient, lscp_event_t events )
708  {  {
709      lscp_status_t ret = LSCP_OK;          lscp_status_t ret = LSCP_OK;
710            lscp_event_t currentEvent;
711    
712      if (pClient == NULL)          if (pClient == NULL)
713          return LSCP_FAILED;                  return LSCP_FAILED;
714    
715      // Lock this section up.          // Lock this section up.
716      lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
717    
718      // Send the unsubscription commands.          // Send the unsubscription commands.
719      if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_COUNT))          if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_COUNT))
720          ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_COUNT);                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_COUNT);
721      if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT))          if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT))
722          ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_VOICE_COUNT);                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_VOICE_COUNT);
723      if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT))          if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT))
724          ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_STREAM_COUNT);                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_STREAM_COUNT);
725      if (ret == LSCP_OK && (events & LSCP_EVENT_BUFFER_FILL))          if (ret == LSCP_OK && (events & LSCP_EVENT_BUFFER_FILL))
726          ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_BUFFER_FILL);                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_BUFFER_FILL);
727      if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))          if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))
728          ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_INFO);                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_INFO);
729      if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))          if (ret == LSCP_OK && (events & LSCP_EVENT_TOTAL_VOICE_COUNT))
730          ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MISCELLANEOUS);                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_TOTAL_VOICE_COUNT);
731            if (ret == LSCP_OK && (events & LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT))
732      // If necessary, close the alternate connection...                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT);
733      if (pClient->events == LSCP_EVENT_NONE)          if (ret == LSCP_OK && (events & LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO))
734          lscp_socket_agent_free(&(pClient->evt));                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO);
735            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT))
736                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT);
737            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INPUT_DEVICE_INFO))
738                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INPUT_DEVICE_INFO);
739            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_MAP_COUNT))
740                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_MAP_COUNT);
741            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_MAP_INFO))
742                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_MAP_INFO);
743            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_COUNT))
744                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_COUNT);
745            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_INFO))
746                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_INFO);
747            if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))
748                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MISCELLANEOUS);
749            // Caution: for the upper 16 bits, we don't use bit flags anymore ...
750            currentEvent = events & 0xffff0000;
751            if (ret == LSCP_OK && currentEvent) {
752                    switch (currentEvent) {
753                            case LSCP_EVENT_CHANNEL_MIDI:
754                            case LSCP_EVENT_DEVICE_MIDI:
755                                    ret = _lscp_client_evt_request(pClient, 0, currentEvent);
756                                    break;
757                            default: // unknown "upper" event type
758                                    ret = LSCP_FAILED;
759                                    break;
760                    }
761            }
762    
763            // If necessary, close the alternate connection...
764            if (pClient->events == LSCP_EVENT_NONE)
765                    lscp_socket_agent_free(&(pClient->evt));
766    
767      // Unlock this section down.          // Unlock this section down.
768      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
769    
770      return ret;          return ret;
771  }  }
772    
773    
# Line 653  lscp_status_t lscp_client_unsubscribe ( Line 780  lscp_status_t lscp_client_unsubscribe (
780   */   */
781  lscp_event_t lscp_client_get_events ( lscp_client_t *pClient )  lscp_event_t lscp_client_get_events ( lscp_client_t *pClient )
782  {  {
783      if (pClient == NULL)          if (pClient == NULL)
784          return LSCP_EVENT_NONE;                  return LSCP_EVENT_NONE;
785    
786      return pClient->events;          return pClient->events;
787  }  }
788    
789    
# Line 676  lscp_event_t lscp_client_get_events ( ls Line 803  lscp_event_t lscp_client_get_events ( ls
803   */   */
804  lscp_status_t lscp_load_instrument ( lscp_client_t *pClient, const char *pszFileName, int iInstrIndex, int iSamplerChannel )  lscp_status_t lscp_load_instrument ( lscp_client_t *pClient, const char *pszFileName, int iInstrIndex, int iSamplerChannel )
805  {  {
806      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
807    
808      if (pszFileName == NULL || iSamplerChannel < 0)          if (pszFileName == NULL || iSamplerChannel < 0)
809          return LSCP_FAILED;                  return LSCP_FAILED;
810    
811      sprintf(szQuery, "LOAD INSTRUMENT '%s' %d %d\r\n", pszFileName, iInstrIndex, iSamplerChannel);          sprintf(szQuery, "LOAD INSTRUMENT '%s' %d %d\r\n", pszFileName, iInstrIndex, iSamplerChannel);
812      return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
813  }  }
814    
815    
# Line 699  lscp_status_t lscp_load_instrument ( lsc Line 826  lscp_status_t lscp_load_instrument ( lsc
826   */   */
827  lscp_status_t lscp_load_instrument_non_modal ( lscp_client_t *pClient, const char *pszFileName, int iInstrIndex, int iSamplerChannel )  lscp_status_t lscp_load_instrument_non_modal ( lscp_client_t *pClient, const char *pszFileName, int iInstrIndex, int iSamplerChannel )
828  {  {
829      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
830    
831      if (pszFileName == NULL || iSamplerChannel < 0)          if (pszFileName == NULL || iSamplerChannel < 0)
832          return LSCP_FAILED;                  return LSCP_FAILED;
833    
834      sprintf(szQuery, "LOAD INSTRUMENT NON_MODAL '%s' %d %d\r\n", pszFileName, iInstrIndex, iSamplerChannel);          sprintf(szQuery, "LOAD INSTRUMENT NON_MODAL '%s' %d %d\r\n", pszFileName, iInstrIndex, iSamplerChannel);
835      return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
836  }  }
837    
838    
# Line 721  lscp_status_t lscp_load_instrument_non_m Line 848  lscp_status_t lscp_load_instrument_non_m
848   */   */
849  lscp_status_t lscp_load_engine ( lscp_client_t *pClient, const char *pszEngineName, int iSamplerChannel )  lscp_status_t lscp_load_engine ( lscp_client_t *pClient, const char *pszEngineName, int iSamplerChannel )
850  {  {
851      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
852    
853      if (pszEngineName == NULL || iSamplerChannel < 0)          if (pszEngineName == NULL || iSamplerChannel < 0)
854          return LSCP_FAILED;                  return LSCP_FAILED;
855    
856      sprintf(szQuery, "LOAD ENGINE %s %d\r\n", pszEngineName, iSamplerChannel);          sprintf(szQuery, "LOAD ENGINE %s %d\r\n", pszEngineName, iSamplerChannel);
857      return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
858  }  }
859    
860    
# Line 742  lscp_status_t lscp_load_engine ( lscp_cl Line 869  lscp_status_t lscp_load_engine ( lscp_cl
869   */   */
870  int lscp_get_channels ( lscp_client_t *pClient )  int lscp_get_channels ( lscp_client_t *pClient )
871  {  {
872      int iChannels = -1;          int iChannels = -1;
873    
874            if (pClient == NULL)
875                    return -1;
876    
877      // Lock this section up.          // Lock this section up.
878      lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
879    
880      if (lscp_client_call(pClient, "GET CHANNELS\r\n") == LSCP_OK)          if (lscp_client_call(pClient, "GET CHANNELS\r\n", 0) == LSCP_OK)
881          iChannels = atoi(lscp_client_get_result(pClient));                  iChannels = atoi(lscp_client_get_result(pClient));
882    
883      // Unlock this section doen.          // Unlock this section doen.
884      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
885    
886      return iChannels;          return iChannels;
887  }  }
888    
889    
# Line 768  int lscp_get_channels ( lscp_client_t *p Line 898  int lscp_get_channels ( lscp_client_t *p
898   */   */
899  int *lscp_list_channels ( lscp_client_t *pClient )  int *lscp_list_channels ( lscp_client_t *pClient )
900  {  {
901      const char *pszSeps = ",";          const char *pszSeps = ",";
902    
903      if (pClient == NULL)          if (pClient == NULL)
904          return NULL;                  return NULL;
905    
906      // Lock this section up.          // Lock this section up.
907      lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
908    
909      if (pClient->channels) {          if (pClient->channels) {
910          lscp_isplit_destroy(pClient->channels);                  lscp_isplit_destroy(pClient->channels);
911          pClient->channels = NULL;                  pClient->channels = NULL;
912      }          }
913    
914      if (lscp_client_call(pClient, "LIST CHANNELS\r\n") == LSCP_OK)          if (lscp_client_call(pClient, "LIST CHANNELS\r\n", 0) == LSCP_OK)
915          pClient->channels = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps);                  pClient->channels = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps);
916    
917      // Unlock this section down.          // Unlock this section down.
918      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
919    
920      return pClient->channels;          return pClient->channels;
921  }  }
922    
923    
# Line 802  int *lscp_list_channels ( lscp_client_t Line 932  int *lscp_list_channels ( lscp_client_t
932   */   */
933  int lscp_add_channel ( lscp_client_t *pClient )  int lscp_add_channel ( lscp_client_t *pClient )
934  {  {
935      int iSamplerChannel = -1;          int iSamplerChannel = -1;
936    
937            if (pClient == NULL)
938                    return -1;
939    
940      // Lock this section up.          // Lock this section up.
941      lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
942    
943      if (lscp_client_call(pClient, "ADD CHANNEL\r\n") == LSCP_OK)          if (lscp_client_call(pClient, "ADD CHANNEL\r\n", 0) == LSCP_OK)
944          iSamplerChannel = atoi(lscp_client_get_result(pClient));                  iSamplerChannel = atoi(lscp_client_get_result(pClient));
945    
946      // Unlock this section down.          // Unlock this section down.
947      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
948    
949      return iSamplerChannel;          return iSamplerChannel;
950  }  }
951    
952    
# Line 828  int lscp_add_channel ( lscp_client_t *pC Line 961  int lscp_add_channel ( lscp_client_t *pC
961   */   */
962  lscp_status_t lscp_remove_channel ( lscp_client_t *pClient, int iSamplerChannel )  lscp_status_t lscp_remove_channel ( lscp_client_t *pClient, int iSamplerChannel )
963  {  {
964      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
965    
966      if (iSamplerChannel < 0)          if (iSamplerChannel < 0)
967          return LSCP_FAILED;                  return LSCP_FAILED;
968    
969      sprintf(szQuery, "REMOVE CHANNEL %d\r\n", iSamplerChannel);          sprintf(szQuery, "REMOVE CHANNEL %d\r\n", iSamplerChannel);
970      return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
971  }  }
972    
973    
# Line 849  lscp_status_t lscp_remove_channel ( lscp Line 982  lscp_status_t lscp_remove_channel ( lscp
982   */   */
983  int lscp_get_available_engines ( lscp_client_t *pClient )  int lscp_get_available_engines ( lscp_client_t *pClient )
984  {  {
985      int iAvailableEngines = -1;          int iAvailableEngines = -1;
986    
987      // Lock this section up.          if (pClient == NULL)
988      lscp_mutex_lock(pClient->mutex);                  return -1;
989    
990      if (lscp_client_call(pClient, "GET AVAILABLE_ENGINES\r\n") == LSCP_OK)          // Lock this section up.
991          iAvailableEngines = atoi(lscp_client_get_result(pClient));          lscp_mutex_lock(pClient->mutex);
992    
993      // Unlock this section down.          if (lscp_client_call(pClient, "GET AVAILABLE_ENGINES\r\n", 0) == LSCP_OK)
994      lscp_mutex_unlock(pClient->mutex);                  iAvailableEngines = atoi(lscp_client_get_result(pClient));
995    
996      return iAvailableEngines;          // Unlock this section down.
997            lscp_mutex_unlock(pClient->mutex);
998    
999            return iAvailableEngines;
1000  }  }
1001    
1002    
# Line 875  int lscp_get_available_engines ( lscp_cl Line 1011  int lscp_get_available_engines ( lscp_cl
1011   */   */
1012  const char **lscp_list_available_engines ( lscp_client_t *pClient )  const char **lscp_list_available_engines ( lscp_client_t *pClient )
1013  {  {
1014      const char *pszSeps = ",";          const char *pszSeps = ",";
1015    
1016            if (pClient == NULL)
1017                    return NULL;
1018    
1019      // Lock this section up.          // Lock this section up.
1020      lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
1021    
1022      if (pClient->engines) {          if (pClient->engines) {
1023          lscp_szsplit_destroy(pClient->engines);                  lscp_szsplit_destroy(pClient->engines);
1024          pClient->engines = NULL;                  pClient->engines = NULL;
1025      }          }
1026    
1027      if (lscp_client_call(pClient, "LIST AVAILABLE_ENGINES\r\n") == LSCP_OK)          if (lscp_client_call(pClient, "LIST AVAILABLE_ENGINES\r\n", 0) == LSCP_OK)
1028          pClient->engines = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps);                  pClient->engines = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps);
1029    
1030      // Unlock this section down.          // Unlock this section down.
1031      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
1032    
1033      return (const char **) pClient->engines;          return (const char **) pClient->engines;
1034  }  }
1035    
1036    
# Line 907  const char **lscp_list_available_engines Line 1046  const char **lscp_list_available_engines
1046   */   */
1047  lscp_engine_info_t *lscp_get_engine_info ( lscp_client_t *pClient, const char *pszEngineName )  lscp_engine_info_t *lscp_get_engine_info ( lscp_client_t *pClient, const char *pszEngineName )
1048  {  {
1049      lscp_engine_info_t *pEngineInfo;          lscp_engine_info_t *pEngineInfo;
1050      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1051      const char *pszResult;          const char *pszResult;
1052      const char *pszSeps = ":";          const char *pszSeps = ":";
1053      const char *pszCrlf = "\r\n";          const char *pszCrlf = "\r\n";
1054      char *pszToken;          char *pszToken;
1055      char *pch;          char *pch;
1056    
1057      if (pszEngineName == NULL)          if (pClient == NULL)
1058          return NULL;                  return NULL;
1059            if (pszEngineName == NULL)
1060      // Lock this section up.                  return NULL;
1061      lscp_mutex_lock(pClient->mutex);  
1062            // Lock this section up.
1063      pEngineInfo = &(pClient->engine_info);          lscp_mutex_lock(pClient->mutex);
1064      lscp_engine_info_reset(pEngineInfo);  
1065            pEngineInfo = &(pClient->engine_info);
1066      sprintf(szQuery, "GET ENGINE INFO %s\r\n", pszEngineName);          lscp_engine_info_reset(pEngineInfo);
1067      if (lscp_client_call(pClient, szQuery) == LSCP_OK) {  
1068          pszResult = lscp_client_get_result(pClient);          sprintf(szQuery, "GET ENGINE INFO %s\r\n", pszEngineName);
1069          pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));          if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) {
1070          while (pszToken) {                  pszResult = lscp_client_get_result(pClient);
1071              if (strcasecmp(pszToken, "DESCRIPTION") == 0) {                  pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
1072                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                  while (pszToken) {
1073                  if (pszToken)                          if (strcasecmp(pszToken, "DESCRIPTION") == 0) {
1074                      lscp_unquote_dup(&(pEngineInfo->description), &pszToken);                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1075              }                                  if (pszToken)
1076              else if (strcasecmp(pszToken, "VERSION") == 0) {                                          lscp_unquote_dup(&(pEngineInfo->description), &pszToken);
1077                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                          }
1078                  if (pszToken)                          else if (strcasecmp(pszToken, "VERSION") == 0) {
1079                      lscp_unquote_dup(&(pEngineInfo->version), &pszToken);                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1080              }                                  if (pszToken)
1081              pszToken = lscp_strtok(NULL, pszSeps, &(pch));                                          lscp_unquote_dup(&(pEngineInfo->version), &pszToken);
1082          }                          }
1083      }                          pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1084      else pEngineInfo = NULL;                  }
1085            }
1086            else pEngineInfo = NULL;
1087    
1088      // Unlock this section down.          // Unlock this section down.
1089      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
1090    
1091      return pEngineInfo;          return pEngineInfo;
1092  }  }
1093    
1094    
# Line 963  lscp_engine_info_t *lscp_get_engine_info Line 1104  lscp_engine_info_t *lscp_get_engine_info
1104   */   */
1105  lscp_channel_info_t *lscp_get_channel_info ( lscp_client_t *pClient, int iSamplerChannel )  lscp_channel_info_t *lscp_get_channel_info ( lscp_client_t *pClient, int iSamplerChannel )
1106  {  {
1107      lscp_channel_info_t *pChannelInfo;          lscp_channel_info_t *pChannelInfo;
1108      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1109      const char *pszResult;          const char *pszResult;
1110      const char *pszSeps = ":";          const char *pszSeps = ":";
1111      const char *pszCrlf = "\r\n";          const char *pszCrlf = "\r\n";
1112      char *pszToken;          char *pszToken;
1113      char *pch;          char *pch;
1114    
1115      if (iSamplerChannel < 0)          if (pClient == NULL)
1116          return NULL;                  return NULL;
1117            if (iSamplerChannel < 0)
1118      // Lock this section up.                  return NULL;
1119      lscp_mutex_lock(pClient->mutex);  
1120            // Lock this section up.
1121      pChannelInfo = &(pClient->channel_info);          lscp_mutex_lock(pClient->mutex);
1122      lscp_channel_info_reset(pChannelInfo);  
1123            pChannelInfo = &(pClient->channel_info);
1124      sprintf(szQuery, "GET CHANNEL INFO %d\r\n", iSamplerChannel);          lscp_channel_info_reset(pChannelInfo);
1125      if (lscp_client_call(pClient, szQuery) == LSCP_OK) {  
1126          pszResult = lscp_client_get_result(pClient);          sprintf(szQuery, "GET CHANNEL INFO %d\r\n", iSamplerChannel);
1127          pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));          if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) {
1128          while (pszToken) {                  pszResult = lscp_client_get_result(pClient);
1129              if (strcasecmp(pszToken, "ENGINE_NAME") == 0) {                  pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
1130                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                  while (pszToken) {
1131                  if (pszToken)                          if (strcasecmp(pszToken, "ENGINE_NAME") == 0) {
1132                      lscp_unquote_dup(&(pChannelInfo->engine_name), &pszToken);                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1133              }                                  if (pszToken)
1134              else if (strcasecmp(pszToken, "AUDIO_OUTPUT_DEVICE") == 0) {                                          lscp_unquote_dup(&(pChannelInfo->engine_name), &pszToken);
1135                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                          }
1136                  if (pszToken)                          else if (strcasecmp(pszToken, "AUDIO_OUTPUT_DEVICE") == 0) {
1137                      pChannelInfo->audio_device = atoi(lscp_ltrim(pszToken));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1138              }                                  if (pszToken)
1139              else if (strcasecmp(pszToken, "AUDIO_OUTPUT_CHANNELS") == 0) {                                          pChannelInfo->audio_device = atoi(lscp_ltrim(pszToken));
1140                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                          }
1141                  if (pszToken)                          else if (strcasecmp(pszToken, "AUDIO_OUTPUT_CHANNELS") == 0) {
1142                      pChannelInfo->audio_channels = atoi(lscp_ltrim(pszToken));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1143              }                                  if (pszToken)
1144              else if (strcasecmp(pszToken, "AUDIO_OUTPUT_ROUTING") == 0) {                                          pChannelInfo->audio_channels = atoi(lscp_ltrim(pszToken));
1145                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                          }
1146                  if (pszToken) {                          else if (strcasecmp(pszToken, "AUDIO_OUTPUT_ROUTING") == 0) {
1147                      if (pChannelInfo->audio_routing)                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1148                          lscp_szsplit_destroy(pChannelInfo->audio_routing);                                  if (pszToken) {
1149                      pChannelInfo->audio_routing = lscp_szsplit_create(pszToken, ",");                                          if (pChannelInfo->audio_routing)
1150                  }                                                  lscp_isplit_destroy(pChannelInfo->audio_routing);
1151              }                                          pChannelInfo->audio_routing = lscp_isplit_create(pszToken, ",");
1152              else if (strcasecmp(pszToken, "INSTRUMENT_FILE") == 0) {                                  }
1153                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                          }
1154                  if (pszToken)                          else if (strcasecmp(pszToken, "INSTRUMENT_FILE") == 0) {
1155                      lscp_unquote_dup(&(pChannelInfo->instrument_file), &pszToken);                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1156              }                                  if (pszToken)
1157              else if (strcasecmp(pszToken, "INSTRUMENT_NR") == 0) {                                          lscp_unquote_dup(&(pChannelInfo->instrument_file), &pszToken);
1158                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                          }
1159                  if (pszToken)                          else if (strcasecmp(pszToken, "INSTRUMENT_NR") == 0) {
1160                      pChannelInfo->instrument_nr = atoi(lscp_ltrim(pszToken));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1161              }                                  if (pszToken)
1162              else if (strcasecmp(pszToken, "INSTRUMENT_NAME") == 0) {                                          pChannelInfo->instrument_nr = atoi(lscp_ltrim(pszToken));
1163                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                          }
1164                  if (pszToken)                          else if (strcasecmp(pszToken, "INSTRUMENT_NAME") == 0) {
1165                      lscp_unquote_dup(&(pChannelInfo->instrument_name), &pszToken);                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1166              }                                  if (pszToken)
1167              else if (strcasecmp(pszToken, "INSTRUMENT_STATUS") == 0) {                                          lscp_unquote_dup(&(pChannelInfo->instrument_name), &pszToken);
1168                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                          }
1169                  if (pszToken)                          else if (strcasecmp(pszToken, "INSTRUMENT_STATUS") == 0) {
1170                      pChannelInfo->instrument_status = atoi(lscp_ltrim(pszToken));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1171              }                                  if (pszToken)
1172              else if (strcasecmp(pszToken, "MIDI_INPUT_DEVICE") == 0) {                                          pChannelInfo->instrument_status = atoi(lscp_ltrim(pszToken));
1173                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                          }
1174                  if (pszToken)                          else if (strcasecmp(pszToken, "MIDI_INPUT_DEVICE") == 0) {
1175                      pChannelInfo->midi_device = atoi(lscp_ltrim(pszToken));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1176              }                                  if (pszToken)
1177              else if (strcasecmp(pszToken, "MIDI_INPUT_PORT") == 0) {                                          pChannelInfo->midi_device = atoi(lscp_ltrim(pszToken));
1178                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                          }
1179                  if (pszToken)                          else if (strcasecmp(pszToken, "MIDI_INPUT_PORT") == 0) {
1180                      pChannelInfo->midi_port = atoi(lscp_ltrim(pszToken));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1181              }                                  if (pszToken)
1182              else if (strcasecmp(pszToken, "MIDI_INPUT_CHANNEL") == 0) {                                          pChannelInfo->midi_port = atoi(lscp_ltrim(pszToken));
1183                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                          }
1184                  if (pszToken) {                          else if (strcasecmp(pszToken, "MIDI_INPUT_CHANNEL") == 0) {
1185                      pszToken = lscp_ltrim(pszToken);                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1186                      if (strcasecmp(pszToken, "ALL") == 0)                                  if (pszToken) {
1187                          pChannelInfo->midi_channel = LSCP_MIDI_CHANNEL_ALL;                                          pszToken = lscp_ltrim(pszToken);
1188                      else                                          if (strcasecmp(pszToken, "ALL") == 0)
1189                          pChannelInfo->midi_channel = atoi(pszToken);                                                  pChannelInfo->midi_channel = LSCP_MIDI_CHANNEL_ALL;
1190                  }                                          else
1191              }                                                  pChannelInfo->midi_channel = atoi(pszToken);
1192              else if (strcasecmp(pszToken, "VOLUME") == 0) {                                  }
1193                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                          }
1194                  if (pszToken)                          else if (strcasecmp(pszToken, "MIDI_INSTRUMENT_MAP") == 0) {
1195                      pChannelInfo->volume = (float) atof(lscp_ltrim(pszToken));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1196              }                                  if (pszToken) {
1197              else if (strcasecmp(pszToken, "MUTE") == 0) {                                          pszToken = lscp_ltrim(pszToken);
1198                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                          if (strcasecmp(pszToken, "NONE") == 0)
1199                  if (pszToken)                                                  pChannelInfo->midi_map = LSCP_MIDI_MAP_NONE;
1200                      pChannelInfo->mute = (strcasecmp(lscp_unquote(&pszToken, 0), "TRUE") == 0);                                          else
1201              }                                          if (strcasecmp(pszToken, "DEFAULT") == 0)
1202              else if (strcasecmp(pszToken, "SOLO") == 0) {                                                  pChannelInfo->midi_map = LSCP_MIDI_MAP_DEFAULT;
1203                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                          else
1204                  if (pszToken)                                                  pChannelInfo->midi_map = atoi(pszToken);
1205                      pChannelInfo->solo = (strcasecmp(lscp_unquote(&pszToken, 0), "TRUE") == 0);                                  }
1206              }                          }
1207              pszToken = lscp_strtok(NULL, pszSeps, &(pch));                          else if (strcasecmp(pszToken, "VOLUME") == 0) {
1208          }                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1209      }                                  if (pszToken)
1210      else pChannelInfo = NULL;                                          pChannelInfo->volume = (float) atof(lscp_ltrim(pszToken));
1211                            }
1212                            else if (strcasecmp(pszToken, "MUTE") == 0) {
1213                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1214                                    if (pszToken)
1215                                            pChannelInfo->mute = (strcasecmp(lscp_unquote(&pszToken, 0), "TRUE") == 0);
1216                            }
1217                            else if (strcasecmp(pszToken, "SOLO") == 0) {
1218                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1219                                    if (pszToken)
1220                                            pChannelInfo->solo = (strcasecmp(lscp_unquote(&pszToken, 0), "TRUE") == 0);
1221                            }
1222                            pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1223                    }
1224            }
1225            else pChannelInfo = NULL;
1226    
1227      // Unlock this section up.          // Unlock this section up.
1228      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
1229    
1230      return pChannelInfo;          return pChannelInfo;
1231  }  }
1232    
1233    
# Line 1086  lscp_channel_info_t *lscp_get_channel_in Line 1242  lscp_channel_info_t *lscp_get_channel_in
1242   */   */
1243  int lscp_get_channel_voice_count ( lscp_client_t *pClient, int iSamplerChannel )  int lscp_get_channel_voice_count ( lscp_client_t *pClient, int iSamplerChannel )
1244  {  {
1245      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1246      int iVoiceCount = -1;          int iVoiceCount = -1;
1247    
1248      if (iSamplerChannel < 0)          if (pClient == NULL)
1249          return iVoiceCount;                  return -1;
1250            if (iSamplerChannel < 0)
1251                    return -1;
1252    
1253      // Lock this section up.          // Lock this section up.
1254      lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
1255    
1256      sprintf(szQuery, "GET CHANNEL VOICE_COUNT %d\r\n", iSamplerChannel);          sprintf(szQuery, "GET CHANNEL VOICE_COUNT %d\r\n", iSamplerChannel);
1257      if (lscp_client_call(pClient, szQuery) == LSCP_OK)          if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
1258          iVoiceCount = atoi(lscp_client_get_result(pClient));                  iVoiceCount = atoi(lscp_client_get_result(pClient));
1259    
1260      // Unlock this section down.          // Unlock this section down.
1261      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
1262    
1263      return iVoiceCount;          return iVoiceCount;
1264  }  }
1265    
1266    
# Line 1117  int lscp_get_channel_voice_count ( lscp_ Line 1275  int lscp_get_channel_voice_count ( lscp_
1275   */   */
1276  int lscp_get_channel_stream_count ( lscp_client_t *pClient, int iSamplerChannel )  int lscp_get_channel_stream_count ( lscp_client_t *pClient, int iSamplerChannel )
1277  {  {
1278      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1279      int iStreamCount = -1;          int iStreamCount = -1;
1280    
1281      if (iSamplerChannel < 0)          if (pClient == NULL)
1282          return iStreamCount;                  return -1;
1283            if (iSamplerChannel < 0)
1284                    return -1;
1285    
1286      // Lock this section up.          // Lock this section up.
1287      lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
1288    
1289      sprintf(szQuery, "GET CHANNEL STREAM_COUNT %d\r\n", iSamplerChannel);          sprintf(szQuery, "GET CHANNEL STREAM_COUNT %d\r\n", iSamplerChannel);
1290      if (lscp_client_call(pClient, szQuery) == LSCP_OK)          if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
1291          iStreamCount = atoi(lscp_client_get_result(pClient));                  iStreamCount = atoi(lscp_client_get_result(pClient));
1292    
1293      // Unlock this section down.          // Unlock this section down.
1294      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
1295    
1296      return iStreamCount;          return iStreamCount;
1297  }  }
1298    
1299    
# Line 1148  int lscp_get_channel_stream_count ( lscp Line 1308  int lscp_get_channel_stream_count ( lscp
1308   */   */
1309  int lscp_get_channel_stream_usage ( lscp_client_t *pClient, int iSamplerChannel )  int lscp_get_channel_stream_usage ( lscp_client_t *pClient, int iSamplerChannel )
1310  {  {
1311      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1312      int  iStreamUsage = -1;          int  iStreamUsage = -1;
1313      const char *pszResult;          const char *pszResult;
1314      const char *pszSeps = "[]%,";          const char *pszSeps = "[]%,";
1315      char *pszToken;          char *pszToken;
1316      char *pch;          char *pch;
1317      int   iStream;          int   iStream;
1318      int   iPercent;          int   iPercent;
1319    
1320      if (iSamplerChannel < 0)          if (pClient == NULL)
1321          return iStreamUsage;                  return -1;
1322            if (iSamplerChannel < 0)
1323      // Lock this section up.                  return -1;
1324      lscp_mutex_lock(pClient->mutex);  
1325            // Lock this section up.
1326      iStream = 0;          lscp_mutex_lock(pClient->mutex);
1327      sprintf(szQuery, "GET CHANNEL BUFFER_FILL PERCENTAGE %d\r\n", iSamplerChannel);  
1328      if (lscp_client_call(pClient, szQuery) == LSCP_OK) {          iStream = 0;
1329          pszResult = lscp_client_get_result(pClient);          sprintf(szQuery, "GET CHANNEL BUFFER_FILL PERCENTAGE %d\r\n", iSamplerChannel);
1330          pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));          if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK) {
1331          while (pszToken) {                  pszResult = lscp_client_get_result(pClient);
1332              if (*pszToken) {                  pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
1333                  // Skip stream id.                  while (pszToken) {
1334                  pszToken = lscp_strtok(NULL, pszSeps, &(pch));                          if (*pszToken) {
1335                  if (pszToken == NULL)                                  // Skip stream id.
1336                      break;                                  pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1337                  // Get least buffer fill percentage.                                  if (pszToken == NULL)
1338                  iPercent = atol(pszToken);                                          break;
1339                  if (iStreamUsage > iPercent || iStream == 0)                                  // Get least buffer fill percentage.
1340                      iStreamUsage = iPercent;                                  iPercent = atol(pszToken);
1341                  iStream++;                                  if (iStreamUsage > iPercent || iStream == 0)
1342              }                                          iStreamUsage = iPercent;
1343              pszToken = lscp_strtok(NULL, pszSeps, &(pch));                                  iStream++;
1344          }                          }
1345      }                          pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1346                    }
1347            }
1348    
1349      // Unlock this section down.          // Unlock this section down.
1350      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
1351    
1352      return iStreamUsage;          return iStreamUsage;
1353  }  }
1354    
1355    
# Line 1207  int lscp_get_channel_stream_usage ( lscp Line 1369  int lscp_get_channel_stream_usage ( lscp
1369   */   */
1370  lscp_buffer_fill_t *lscp_get_channel_buffer_fill ( lscp_client_t *pClient, lscp_usage_t usage_type, int iSamplerChannel )  lscp_buffer_fill_t *lscp_get_channel_buffer_fill ( lscp_client_t *pClient, lscp_usage_t usage_type, int iSamplerChannel )
1371  {  {
1372      lscp_buffer_fill_t *pBufferFill;          lscp_buffer_fill_t *pBufferFill;
1373      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1374      int iStreamCount;          int iStreamCount;
1375      const char *pszUsageType = (usage_type == LSCP_USAGE_BYTES ? "BYTES" : "PERCENTAGE");          const char *pszUsageType = (usage_type == LSCP_USAGE_BYTES ? "BYTES" : "PERCENTAGE");
1376      const char *pszResult;          const char *pszResult;
1377      const char *pszSeps = "[]%,";          const char *pszSeps = "[]%,";
1378      char *pszToken;          char *pszToken;
1379      char *pch;          char *pch;
1380      int   iStream;          int   iStream;
1381    
1382      // Retrieve a channel stream estimation.          // Retrieve a channel stream estimation.
1383      iStreamCount = lscp_get_channel_stream_count(pClient, iSamplerChannel);          iStreamCount = lscp_get_channel_stream_count(pClient, iSamplerChannel);
1384      if (pClient->iStreamCount < 0)          if (iStreamCount < 0)
1385          return NULL;                  return NULL;
1386    
1387      // Lock this section up.          // Lock this section up.
1388      lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
1389    
1390      // Check if we need to reallocate the stream usage array.          // Check if we need to reallocate the stream usage array.
1391      if (pClient->iStreamCount != iStreamCount) {          if (pClient->iStreamCount != iStreamCount) {
1392          if (pClient->buffer_fill)                  if (pClient->buffer_fill)
1393              free(pClient->buffer_fill);                          free(pClient->buffer_fill);
1394          if (iStreamCount > 0)                  if (iStreamCount > 0)
1395              pClient->buffer_fill = (lscp_buffer_fill_t *) malloc(iStreamCount * sizeof(lscp_buffer_fill_t));                          pClient->buffer_fill = (lscp_buffer_fill_t *) malloc(iStreamCount * sizeof(lscp_buffer_fill_t));
1396          else                  else
1397              pClient->buffer_fill = NULL;                          pClient->buffer_fill = NULL;
1398          pClient->iStreamCount = iStreamCount;                  pClient->iStreamCount = iStreamCount;
1399      }          }
1400    
1401      // Get buffer fill usage...          // Get buffer fill usage...
1402      pBufferFill = pClient->buffer_fill;          pBufferFill = pClient->buffer_fill;
1403      if (pBufferFill && iStreamCount > 0) {          if (pBufferFill && iStreamCount > 0) {
1404          iStream = 0;                  iStream = 0;
1405          pBufferFill = pClient->buffer_fill;                  pBufferFill = pClient->buffer_fill;
1406          sprintf(szQuery, "GET CHANNEL BUFFER_FILL %s %d\r\n", pszUsageType, iSamplerChannel);                  sprintf(szQuery, "GET CHANNEL BUFFER_FILL %s %d\r\n", pszUsageType, iSamplerChannel);
1407          if (lscp_client_call(pClient, szQuery) == LSCP_OK) {                  if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK) {
1408              pszResult = lscp_client_get_result(pClient);                          pszResult = lscp_client_get_result(pClient);
1409              pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));                          pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
1410              while (pszToken && iStream < pClient->iStreamCount) {                          while (pszToken && iStream < pClient->iStreamCount) {
1411                  if (*pszToken) {                                  if (*pszToken) {
1412                      pBufferFill[iStream].stream_id = atol(pszToken);                                          pBufferFill[iStream].stream_id = atol(pszToken);
1413                      pszToken = lscp_strtok(NULL, pszSeps, &(pch));                                          pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1414                      if (pszToken == NULL)                                          if (pszToken == NULL)
1415                          break;                                                  break;
1416                      pBufferFill[iStream].stream_usage = atol(pszToken);                                          pBufferFill[iStream].stream_usage = atol(pszToken);
1417                      iStream++;                                          iStream++;
1418                  }                                  }
1419                  pszToken = lscp_strtok(NULL, pszSeps, &(pch));                                  pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1420              }                          }
1421          }   // Reset the usage, whatever it was before.                  }   // Reset the usage, whatever it was before.
1422          else while (iStream < pClient->iStreamCount)                  else while (iStream < pClient->iStreamCount)
1423              pBufferFill[iStream++].stream_usage = 0;                          pBufferFill[iStream++].stream_usage = 0;
1424      }          }
1425    
1426      // Unlock this section down.          // Unlock this section down.
1427      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
1428    
1429      return pBufferFill;          return pBufferFill;
1430  }  }
1431    
1432    
# Line 1275  lscp_buffer_fill_t *lscp_get_channel_buf Line 1437  lscp_buffer_fill_t *lscp_get_channel_buf
1437   *  @param pClient          Pointer to client instance structure.   *  @param pClient          Pointer to client instance structure.
1438   *  @param iSamplerChannel  Sampler channel number.   *  @param iSamplerChannel  Sampler channel number.
1439   *  @param pszAudioDriver   Audio output driver type (e.g. "ALSA" or "JACK").   *  @param pszAudioDriver   Audio output driver type (e.g. "ALSA" or "JACK").
1440     *
1441     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1442   */   */
1443  lscp_status_t lscp_set_channel_audio_type ( lscp_client_t *pClient, int iSamplerChannel, const char *pszAudioDriver )  lscp_status_t lscp_set_channel_audio_type ( lscp_client_t *pClient, int iSamplerChannel, const char *pszAudioDriver )
1444  {  {
1445      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1446    
1447      if (iSamplerChannel < 0 || pszAudioDriver == NULL)          if (iSamplerChannel < 0 || pszAudioDriver == NULL)
1448          return LSCP_FAILED;                  return LSCP_FAILED;
1449    
1450      sprintf(szQuery, "SET CHANNEL AUDIO_OUTPUT_TYPE %d %s\r\n", iSamplerChannel, pszAudioDriver);          sprintf(szQuery, "SET CHANNEL AUDIO_OUTPUT_TYPE %d %s\r\n", iSamplerChannel, pszAudioDriver);
1451      return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
1452  }  }
1453    
1454    
# Line 1295  lscp_status_t lscp_set_channel_audio_typ Line 1459  lscp_status_t lscp_set_channel_audio_typ
1459   *  @param pClient          Pointer to client instance structure.   *  @param pClient          Pointer to client instance structure.
1460   *  @param iSamplerChannel  Sampler channel number.   *  @param iSamplerChannel  Sampler channel number.
1461   *  @param iAudioDevice     Audio output device number identifier.   *  @param iAudioDevice     Audio output device number identifier.
1462     *
1463     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1464   */   */
1465  lscp_status_t lscp_set_channel_audio_device ( lscp_client_t *pClient, int iSamplerChannel, int iAudioDevice )  lscp_status_t lscp_set_channel_audio_device ( lscp_client_t *pClient, int iSamplerChannel, int iAudioDevice )
1466  {  {
1467      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1468    
1469      if (iSamplerChannel < 0 || iAudioDevice < 0)          if (iSamplerChannel < 0 || iAudioDevice < 0)
1470          return LSCP_FAILED;                  return LSCP_FAILED;
1471    
1472      sprintf(szQuery, "SET CHANNEL AUDIO_OUTPUT_DEVICE %d %d\r\n", iSamplerChannel, iAudioDevice);          sprintf(szQuery, "SET CHANNEL AUDIO_OUTPUT_DEVICE %d %d\r\n", iSamplerChannel, iAudioDevice);
1473      return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
1474  }  }
1475    
1476    
# Line 1321  lscp_status_t lscp_set_channel_audio_dev Line 1487  lscp_status_t lscp_set_channel_audio_dev
1487   */   */
1488  lscp_status_t lscp_set_channel_audio_channel ( lscp_client_t *pClient, int iSamplerChannel, int iAudioOut, int iAudioIn )  lscp_status_t lscp_set_channel_audio_channel ( lscp_client_t *pClient, int iSamplerChannel, int iAudioOut, int iAudioIn )
1489  {  {
1490      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1491    
1492      if (iSamplerChannel < 0 || iAudioOut < 0 || iAudioIn < 0)          if (iSamplerChannel < 0 || iAudioOut < 0 || iAudioIn < 0)
1493          return LSCP_FAILED;                  return LSCP_FAILED;
1494    
1495      sprintf(szQuery, "SET CHANNEL AUDIO_OUTPUT_CHANNEL %d %d %d\r\n", iSamplerChannel, iAudioOut, iAudioIn);          sprintf(szQuery, "SET CHANNEL AUDIO_OUTPUT_CHANNEL %d %d %d\r\n", iSamplerChannel, iAudioOut, iAudioIn);
1496      return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
1497  }  }
1498    
1499    
# Line 1343  lscp_status_t lscp_set_channel_audio_cha Line 1509  lscp_status_t lscp_set_channel_audio_cha
1509   */   */
1510  lscp_status_t lscp_set_channel_midi_type ( lscp_client_t *pClient, int iSamplerChannel, const char *pszMidiDriver )  lscp_status_t lscp_set_channel_midi_type ( lscp_client_t *pClient, int iSamplerChannel, const char *pszMidiDriver )
1511  {  {
1512      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1513    
1514      if (iSamplerChannel < 0 || pszMidiDriver == NULL)          if (iSamplerChannel < 0 || pszMidiDriver == NULL)
1515          return LSCP_FAILED;                  return LSCP_FAILED;
1516    
1517      sprintf(szQuery, "SET CHANNEL MIDI_INPUT_TYPE %d %s\r\n", iSamplerChannel, pszMidiDriver);          sprintf(szQuery, "SET CHANNEL MIDI_INPUT_TYPE %d %s\r\n", iSamplerChannel, pszMidiDriver);
1518      return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
1519  }  }
1520    
1521    
# Line 1360  lscp_status_t lscp_set_channel_midi_type Line 1526  lscp_status_t lscp_set_channel_midi_type
1526   *  @param pClient          Pointer to client instance structure.   *  @param pClient          Pointer to client instance structure.
1527   *  @param iSamplerChannel  Sampler channel number.   *  @param iSamplerChannel  Sampler channel number.
1528   *  @param iMidiDevice      MIDI input device number identifier.   *  @param iMidiDevice      MIDI input device number identifier.
1529     *
1530     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1531   */   */
1532  lscp_status_t lscp_set_channel_midi_device ( lscp_client_t *pClient, int iSamplerChannel, int iMidiDevice )  lscp_status_t lscp_set_channel_midi_device ( lscp_client_t *pClient, int iSamplerChannel, int iMidiDevice )
1533  {  {
1534      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1535    
1536      if (iSamplerChannel < 0 || iMidiDevice < 0)          if (iSamplerChannel < 0 || iMidiDevice < 0)
1537          return LSCP_FAILED;                  return LSCP_FAILED;
1538    
1539      sprintf(szQuery, "SET CHANNEL MIDI_INPUT_DEVICE %d %d\r\n", iSamplerChannel, iMidiDevice);          sprintf(szQuery, "SET CHANNEL MIDI_INPUT_DEVICE %d %d\r\n", iSamplerChannel, iMidiDevice);
1540      return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
1541  }  }
1542    
1543    
# Line 1385  lscp_status_t lscp_set_channel_midi_devi Line 1553  lscp_status_t lscp_set_channel_midi_devi
1553   */   */
1554  lscp_status_t lscp_set_channel_midi_port ( lscp_client_t *pClient, int iSamplerChannel, int iMidiPort )  lscp_status_t lscp_set_channel_midi_port ( lscp_client_t *pClient, int iSamplerChannel, int iMidiPort )
1555  {  {
1556      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1557    
1558      if (iSamplerChannel < 0 || iMidiPort < 0)          if (iSamplerChannel < 0 || iMidiPort < 0)
1559          return LSCP_FAILED;                  return LSCP_FAILED;
1560    
1561      sprintf(szQuery, "SET CHANNEL MIDI_INPUT_PORT %d %d\r\n", iSamplerChannel, iMidiPort);          sprintf(szQuery, "SET CHANNEL MIDI_INPUT_PORT %d %d\r\n", iSamplerChannel, iMidiPort);
1562      return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
1563  }  }
1564    
1565    
# Line 1402  lscp_status_t lscp_set_channel_midi_port Line 1570  lscp_status_t lscp_set_channel_midi_port
1570   *  @param pClient          Pointer to client instance structure.   *  @param pClient          Pointer to client instance structure.
1571   *  @param iSamplerChannel  Sampler channel number.   *  @param iSamplerChannel  Sampler channel number.
1572   *  @param iMidiChannel     MIDI channel address number to listen (0-15) or   *  @param iMidiChannel     MIDI channel address number to listen (0-15) or
1573   *                          LSCP_MIDI_CHANNEL_ALL (16) to listen on all channels.   *                          @ref LSCP_MIDI_CHANNEL_ALL (16) to listen on all channels.
1574   *   *
1575   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1576   */   */
1577  lscp_status_t lscp_set_channel_midi_channel ( lscp_client_t *pClient, int iSamplerChannel, int iMidiChannel )  lscp_status_t lscp_set_channel_midi_channel ( lscp_client_t *pClient, int iSamplerChannel, int iMidiChannel )
1578  {  {
1579      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1580    
1581            if (iSamplerChannel < 0 || iMidiChannel < 0 || iMidiChannel > 16)
1582                    return LSCP_FAILED;
1583    
1584            if (iMidiChannel == LSCP_MIDI_CHANNEL_ALL)
1585                    sprintf(szQuery, "SET CHANNEL MIDI_INPUT_CHANNEL %d ALL\r\n", iSamplerChannel);
1586            else
1587                    sprintf(szQuery, "SET CHANNEL MIDI_INPUT_CHANNEL %d %d\r\n", iSamplerChannel, iMidiChannel);
1588            return lscp_client_query(pClient, szQuery);
1589    }
1590    
1591    
1592    /**
1593     *  Setting MIDI instrument map:
1594     *  SET CHANNEL MIDI_INSTRUMENT_MAP <sampler-channel> <midi-map>
1595     *
1596     *  @param pClient          Pointer to client instance structure.
1597     *  @param iSamplerChannel  Sampler channel number.
1598     *  @param iMidiMap         MIDI instrument map number, or either
1599     *                          @ref LSCP_MIDI_MAP_NONE or
1600     *                          @ref LSCP_MIDI_MAP_DEFAULT .
1601     *
1602     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1603     */
1604    lscp_status_t lscp_set_channel_midi_map ( lscp_client_t *pClient, int iSamplerChannel, int iMidiMap )
1605    {
1606            char szQuery[LSCP_BUFSIZ];
1607    
1608            if (iSamplerChannel < 0)
1609                    return LSCP_FAILED;
1610    
1611      if (iSamplerChannel < 0 || iMidiChannel < 0 || iMidiChannel > 16)          sprintf(szQuery, "SET CHANNEL MIDI_INSTRUMENT_MAP %d ", iSamplerChannel);
1612          return LSCP_FAILED;          if (iMidiMap == LSCP_MIDI_MAP_NONE)
1613                    strcat(szQuery , "NONE");
1614            else
1615            if (iMidiMap == LSCP_MIDI_MAP_DEFAULT)
1616                    strcat(szQuery , "DEFAULT");
1617            else
1618                    sprintf(szQuery + strlen(szQuery), "%d", iMidiMap);
1619    
1620      if (iMidiChannel == LSCP_MIDI_CHANNEL_ALL)          strcat(szQuery, "\r\n");
1621          sprintf(szQuery, "SET CHANNEL MIDI_INPUT_CHANNEL %d ALL\r\n", iSamplerChannel);  
1622      else          return lscp_client_query(pClient, szQuery);
         sprintf(szQuery, "SET CHANNEL MIDI_INPUT_CHANNEL %d %d\r\n", iSamplerChannel, iMidiChannel);  
     return lscp_client_query(pClient, szQuery);  
1623  }  }
1624    
1625    
# Line 1435  lscp_status_t lscp_set_channel_midi_chan Line 1637  lscp_status_t lscp_set_channel_midi_chan
1637   */   */
1638  lscp_status_t lscp_set_channel_volume ( lscp_client_t *pClient, int iSamplerChannel, float fVolume )  lscp_status_t lscp_set_channel_volume ( lscp_client_t *pClient, int iSamplerChannel, float fVolume )
1639  {  {
1640      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1641    
1642      if (iSamplerChannel < 0 || fVolume < 0.0)          if (iSamplerChannel < 0 || fVolume < 0.0f)
1643          return LSCP_FAILED;                  return LSCP_FAILED;
1644    
1645      sprintf(szQuery, "SET CHANNEL VOLUME %d %g\r\n", iSamplerChannel, fVolume);          sprintf(szQuery, "SET CHANNEL VOLUME %d %g\r\n", iSamplerChannel, fVolume);
1646      return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
1647  }  }
1648    
1649    
# Line 1459  lscp_status_t lscp_set_channel_volume ( Line 1661  lscp_status_t lscp_set_channel_volume (
1661   */   */
1662  lscp_status_t lscp_set_channel_mute ( lscp_client_t *pClient, int iSamplerChannel, int iMute )  lscp_status_t lscp_set_channel_mute ( lscp_client_t *pClient, int iSamplerChannel, int iMute )
1663  {  {
1664      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1665    
1666      if (iSamplerChannel < 0 || iMute < 0 || iMute > 1)          if (iSamplerChannel < 0 || iMute < 0 || iMute > 1)
1667          return LSCP_FAILED;                  return LSCP_FAILED;
1668    
1669      sprintf(szQuery, "SET CHANNEL MUTE %d %d\r\n", iSamplerChannel, iMute);          sprintf(szQuery, "SET CHANNEL MUTE %d %d\r\n", iSamplerChannel, iMute);
1670      return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
1671  }  }
1672    
1673    
# Line 1483  lscp_status_t lscp_set_channel_mute ( ls Line 1685  lscp_status_t lscp_set_channel_mute ( ls
1685   */   */
1686  lscp_status_t lscp_set_channel_solo ( lscp_client_t *pClient, int iSamplerChannel, int iSolo )  lscp_status_t lscp_set_channel_solo ( lscp_client_t *pClient, int iSamplerChannel, int iSolo )
1687  {  {
1688      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1689    
1690      if (iSamplerChannel < 0 || iSolo < 0 || iSolo > 1)          if (iSamplerChannel < 0 || iSolo < 0 || iSolo > 1)
1691          return LSCP_FAILED;                  return LSCP_FAILED;
1692    
1693      sprintf(szQuery, "SET CHANNEL SOLO %d %d\r\n", iSamplerChannel, iSolo);          sprintf(szQuery, "SET CHANNEL SOLO %d %d\r\n", iSamplerChannel, iSolo);
1694      return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
1695  }  }
1696    
1697    
# Line 1504  lscp_status_t lscp_set_channel_solo ( ls Line 1706  lscp_status_t lscp_set_channel_solo ( ls
1706   */   */
1707  lscp_status_t lscp_reset_channel ( lscp_client_t *pClient, int iSamplerChannel )  lscp_status_t lscp_reset_channel ( lscp_client_t *pClient, int iSamplerChannel )
1708  {  {
1709      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1710    
1711      if (iSamplerChannel < 0)          if (iSamplerChannel < 0)
1712          return LSCP_FAILED;                  return LSCP_FAILED;
1713    
1714      sprintf(szQuery, "RESET CHANNEL %d\r\n", iSamplerChannel);          sprintf(szQuery, "RESET CHANNEL %d\r\n", iSamplerChannel);
1715      return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
1716  }  }
1717    
1718    
# Line 1524  lscp_status_t lscp_reset_channel ( lscp_ Line 1726  lscp_status_t lscp_reset_channel ( lscp_
1726   */   */
1727  lscp_status_t lscp_reset_sampler ( lscp_client_t *pClient )  lscp_status_t lscp_reset_sampler ( lscp_client_t *pClient )
1728  {  {
1729      return lscp_client_query(pClient, "RESET\r\n");          // Do actual whole sampler reset...
1730            return lscp_client_query(pClient, "RESET\r\n");
1731  }  }
1732    
1733    
# Line 1539  lscp_status_t lscp_reset_sampler ( lscp_ Line 1742  lscp_status_t lscp_reset_sampler ( lscp_
1742   */   */
1743  lscp_server_info_t *lscp_get_server_info ( lscp_client_t *pClient )  lscp_server_info_t *lscp_get_server_info ( lscp_client_t *pClient )
1744  {  {
1745      lscp_server_info_t *pServerInfo;          lscp_server_info_t *pServerInfo;
1746      const char *pszResult;          const char *pszResult;
1747      const char *pszSeps = ":";          const char *pszSeps = ":";
1748      const char *pszCrlf = "\r\n";          const char *pszCrlf = "\r\n";
1749      char *pszToken;          char *pszToken;
1750      char *pch;          char *pch;
1751    
1752      // Lock this section up.          if (pClient == NULL)
1753      lscp_mutex_lock(pClient->mutex);                  return NULL;
1754    
1755      pServerInfo = &(pClient->server_info);          // Lock this section up.
1756      lscp_server_info_reset(pServerInfo);          lscp_mutex_lock(pClient->mutex);
1757    
1758      if (lscp_client_call(pClient, "GET SERVER INFO\r\n") == LSCP_OK) {          pServerInfo = &(pClient->server_info);
1759          pszResult = lscp_client_get_result(pClient);          lscp_server_info_reset(pServerInfo);
1760          pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));  
1761          while (pszToken) {          if (lscp_client_call(pClient, "GET SERVER INFO\r\n", 1) == LSCP_OK) {
1762              if (strcasecmp(pszToken, "DESCRIPTION") == 0) {                  pszResult = lscp_client_get_result(pClient);
1763                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                  pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
1764                  if (pszToken)                  while (pszToken) {
1765                      lscp_unquote_dup(&(pServerInfo->description), &pszToken);                          if (strcasecmp(pszToken, "DESCRIPTION") == 0) {
1766              }                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1767              else if (strcasecmp(pszToken, "VERSION") == 0) {                                  if (pszToken)
1768                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                          lscp_unquote_dup(&(pServerInfo->description), &pszToken);
1769                  if (pszToken)                          }
1770                      lscp_unquote_dup(&(pServerInfo->version), &pszToken);                          else if (strcasecmp(pszToken, "VERSION") == 0) {
1771              }                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1772              pszToken = lscp_strtok(NULL, pszSeps, &(pch));                                  if (pszToken)
1773          }                                          lscp_unquote_dup(&(pServerInfo->version), &pszToken);
1774      }                          }
1775      else pServerInfo = NULL;                          else if (strcasecmp(pszToken, "PROTOCOL_VERSION") == 0) {
1776                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1777                                    if (pszToken)
1778                                            lscp_unquote_dup(&(pServerInfo->protocol_version), &pszToken);
1779                            }
1780                            pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1781                    }
1782            }
1783            else pServerInfo = NULL;
1784    
1785            // Unlock this section down.
1786            lscp_mutex_unlock(pClient->mutex);
1787    
1788            return pServerInfo;
1789    }
1790    
1791    
1792    /**
1793     *  Current total number of active voices:
1794     *  GET TOTAL_VOICE_COUNT
1795     *
1796     *  @param pClient  Pointer to client instance structure.
1797     *
1798     *  @returns The total number of voices currently active,
1799     *  -1 in case of failure.
1800     */
1801    int lscp_get_total_voice_count ( lscp_client_t *pClient )
1802    {
1803            int iVoiceCount = -1;
1804    
1805            if (pClient == NULL)
1806                    return -1;
1807    
1808            // Lock this section up.
1809            lscp_mutex_lock(pClient->mutex);
1810    
1811            if (lscp_client_call(pClient, "GET TOTAL_VOICE_COUNT\r\n", 0) == LSCP_OK)
1812                    iVoiceCount = atoi(lscp_client_get_result(pClient));
1813    
1814            // Unlock this section down.
1815            lscp_mutex_unlock(pClient->mutex);
1816    
1817            return iVoiceCount;
1818    }
1819    
1820    
1821    /**
1822     *  Maximum amount of active voices:
1823     *  GET TOTAL_VOICE_COUNT_MAX
1824     *
1825     *  @param pClient  Pointer to client instance structure.
1826     *
1827     *  @returns The maximum amount of voices currently active,
1828     *  -1 in case of failure.
1829     */
1830    int lscp_get_total_voice_count_max ( lscp_client_t *pClient )
1831    {
1832            int iVoiceCount = -1;
1833    
1834            if (pClient == NULL)
1835                    return -1;
1836    
1837            // Lock this section up.
1838            lscp_mutex_lock(pClient->mutex);
1839    
1840            if (lscp_client_call(pClient, "GET TOTAL_VOICE_COUNT_MAX\r\n", 0) == LSCP_OK)
1841                    iVoiceCount = atoi(lscp_client_get_result(pClient));
1842    
1843            // Unlock this section down.
1844            lscp_mutex_unlock(pClient->mutex);
1845    
1846            return iVoiceCount;
1847    }
1848    
1849    
1850    /**
1851     *  Get global volume attenuation:
1852     *  GET VOLUME
1853     *
1854     *  @param pClient  Pointer to client instance structure.
1855     *
1856     *  @returns The global volume as positive floating point value usually in
1857     *  the range between 0.0 and 1.0; in case of failure 0.0 is returned.
1858     */
1859    float lscp_get_volume ( lscp_client_t *pClient )
1860    {
1861            float fVolume = 0.0f;
1862    
1863            if (pClient == NULL)
1864                    return 0.0f;
1865    
1866            // Lock this section up.
1867            lscp_mutex_lock(pClient->mutex);
1868    
1869            if (lscp_client_call(pClient, "GET VOLUME\r\n", 0) == LSCP_OK)
1870                    fVolume = (float) atof(lscp_client_get_result(pClient));
1871    
1872            // Unlock this section down.
1873            lscp_mutex_unlock(pClient->mutex);
1874    
1875            return fVolume;
1876    }
1877    
1878    
1879    /**
1880     *  Setting global volume attenuation:
1881     *  SET VOLUME <volume>
1882     *
1883     *  @param pClient  Pointer to client instance structure.
1884     *  @param fVolume  Global volume parameter as positive floating point
1885     *                  value usually be in the range between 0.0 and 1.0,
1886     *                  that is for attenuating the overall volume.
1887     *
1888     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1889     */
1890    lscp_status_t lscp_set_volume ( lscp_client_t *pClient, float fVolume )
1891    {
1892            char szQuery[LSCP_BUFSIZ];
1893    
1894            if (fVolume < 0.0f)
1895                    return LSCP_FAILED;
1896    
1897            sprintf(szQuery, "SET VOLUME %g\r\n", fVolume);
1898            return lscp_client_query(pClient, szQuery);
1899    }
1900    
1901    
1902    /**
1903     *  Add an effect send to a sampler channel:
1904     *  CREATE FX_SEND <sampler-channel> <midi-ctrl> [<name>]
1905     *
1906     *  @param pClient          Pointer to client instance structure.
1907     *  @param iSamplerChannel  Sampler channel number.
1908     *  @param iMidiController  MIDI controller used to alter the effect,
1909     *                          usually a number between 0 and 127.
1910     *  @param pszName          Optional name for the effect send entity,
1911     *                          does not have to be unique.
1912     *
1913     *  @returns The new effect send number identifier, or -1 in case of failure.
1914     */
1915    int lscp_create_fxsend ( lscp_client_t *pClient, int iSamplerChannel, int iMidiController, const char *pszFxName )
1916    {
1917            int iFxSend = -1;
1918            char szQuery[LSCP_BUFSIZ];
1919    
1920            if (pClient == NULL)
1921                    return -1;
1922            if (iSamplerChannel < 0 || iMidiController < 0 || iMidiController > 127)
1923                    return -1;
1924    
1925            // Lock this section up.
1926            lscp_mutex_lock(pClient->mutex);
1927    
1928            sprintf(szQuery, "CREATE FX_SEND %d %d", iSamplerChannel, iMidiController);
1929            
1930            if (pszFxName)
1931                    sprintf(szQuery + strlen(szQuery), " '%s'", pszFxName);
1932    
1933            strcat(szQuery, "\r\n");
1934    
1935            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
1936                    iFxSend = atoi(lscp_client_get_result(pClient));
1937    
1938            // Unlock this section down.
1939            lscp_mutex_unlock(pClient->mutex);
1940    
1941            return iFxSend;
1942    }
1943    
1944    
1945    /**
1946     *  Remove an effect send from a sampler channel:
1947     *  DESTROY FX_SEND <sampler-channel> <fx-send-id>
1948     *
1949     *  @param pClient          Pointer to client instance structure.
1950     *  @param iSamplerChannel  Sampler channel number.
1951     *  @param iFxSend          Effect send number.
1952     *
1953     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1954     */
1955    lscp_status_t lscp_destroy_fxsend ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend )
1956    {
1957            char szQuery[LSCP_BUFSIZ];
1958    
1959            if (iSamplerChannel < 0 || iFxSend < 0)
1960                    return LSCP_FAILED;
1961    
1962            sprintf(szQuery, "DESTROY FX_SEND %d %d\r\n", iSamplerChannel, iFxSend);
1963    
1964            return lscp_client_query(pClient, szQuery);
1965    }
1966    
1967    
1968    /**
1969     *  Get amount of effect sends on a sampler channel:
1970     *  GET FX_SENDS <sampler-channel>
1971     *
1972     *  @param pClient          Pointer to client instance structure.
1973     *  @param iSamplerChannel  Sampler channel number.
1974     *
1975     *  @returns The current total number of effect sends of the sampler channel
1976     *  on success, -1 otherwise.
1977     */
1978    int lscp_get_fxsends ( lscp_client_t *pClient, int iSamplerChannel )
1979    {
1980            int iFxSends = -1;
1981            char szQuery[LSCP_BUFSIZ];
1982    
1983            if (pClient == NULL)
1984                    return -1;
1985            if (iSamplerChannel < 0)
1986                    return -1;
1987    
1988            // Lock this section up.
1989            lscp_mutex_lock(pClient->mutex);
1990    
1991            sprintf(szQuery, "GET FX_SENDS %d\r\n", iSamplerChannel);
1992    
1993            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
1994                    iFxSends = atoi(lscp_client_get_result(pClient));
1995    
1996            // Unlock this section doen.
1997            lscp_mutex_unlock(pClient->mutex);
1998    
1999            return iFxSends;
2000    }
2001    
2002    
2003    /**
2004     *  List all effect sends on a sampler channel:
2005     *  LIST FX_SENDS <sampler-channel>
2006     *
2007     *  @param pClient          Pointer to client instance structure.
2008     *  @param iSamplerChannel  Sampler channel number.
2009     *
2010     *  @returns An array of the effect sends identifiers as positive integers,
2011     *  terminated with -1 on success, NULL otherwise.
2012     */
2013    int *lscp_list_fxsends ( lscp_client_t *pClient, int iSamplerChannel )
2014    {
2015            const char *pszSeps = ",";
2016            char szQuery[LSCP_BUFSIZ];
2017    
2018            if (pClient == NULL)
2019                    return NULL;
2020    
2021            // Lock this section up.
2022            lscp_mutex_lock(pClient->mutex);
2023    
2024            if (pClient->fxsends) {
2025                    lscp_isplit_destroy(pClient->fxsends);
2026                    pClient->fxsends = NULL;
2027            }
2028    
2029            sprintf(szQuery, "LIST FX_SENDS %d\r\n", iSamplerChannel);
2030    
2031            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
2032                    pClient->fxsends = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps);
2033    
2034            // Unlock this section down.
2035            lscp_mutex_unlock(pClient->mutex);
2036    
2037            return pClient->fxsends;
2038    }
2039    
2040    
2041    /**
2042     *  Getting effect send information
2043     *  GET FX_SEND INFO <sampler-channel> <fx-send-id>
2044     *
2045     *  @param pClient          Pointer to client instance structure.
2046     *  @param iSamplerChannel  Sampler channel number.
2047     *  @param iFxSend          Effect send number.
2048     *
2049     *  @returns A pointer to a @ref lscp_fxsend_info_t structure, with the
2050     *  information of the given FX send, or NULL in case of failure.
2051     */
2052    lscp_fxsend_info_t *lscp_get_fxsend_info ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend )
2053    {
2054            lscp_fxsend_info_t *pFxSendInfo;
2055            char szQuery[LSCP_BUFSIZ];
2056            const char *pszResult;
2057            const char *pszSeps = ":";
2058            const char *pszCrlf = "\r\n";
2059            char *pszToken;
2060            char *pch;
2061    
2062            if (pClient == NULL)
2063                    return NULL;
2064            if (iSamplerChannel < 0 || iFxSend < 0)
2065                    return NULL;
2066    
2067            // Lock this section up.
2068            lscp_mutex_lock(pClient->mutex);
2069    
2070            pFxSendInfo = &(pClient->fxsend_info);
2071            lscp_fxsend_info_reset(pFxSendInfo);
2072    
2073            sprintf(szQuery, "GET FX_SEND INFO %d %d\r\n", iSamplerChannel, iFxSend);
2074            if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) {
2075                    pszResult = lscp_client_get_result(pClient);
2076                    pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
2077                    while (pszToken) {
2078                            if (strcasecmp(pszToken, "NAME") == 0) {
2079                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2080                                    if (pszToken)
2081                                            lscp_unquote_dup(&(pFxSendInfo->name), &pszToken);
2082                            }
2083                            else if (strcasecmp(pszToken, "MIDI_CONTROLLER") == 0) {
2084                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2085                                    if (pszToken)
2086                                            pFxSendInfo->midi_controller = atoi(lscp_ltrim(pszToken));
2087                            }
2088                            else if (strcasecmp(pszToken, "AUDIO_OUTPUT_ROUTING") == 0) {
2089                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2090                                    if (pszToken) {
2091                                            if (pFxSendInfo->audio_routing)
2092                                                    lscp_isplit_destroy(pFxSendInfo->audio_routing);
2093                                            pFxSendInfo->audio_routing = lscp_isplit_create(pszToken, ",");
2094                                    }
2095                            }
2096                            else if (strcasecmp(pszToken, "LEVEL") == 0) {
2097                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2098                                    if (pszToken)
2099                                            pFxSendInfo->level = (float) atof(lscp_ltrim(pszToken));
2100                            }
2101                            pszToken = lscp_strtok(NULL, pszSeps, &(pch));
2102                    }
2103            }
2104            else pFxSendInfo = NULL;
2105    
2106            // Unlock this section up.
2107            lscp_mutex_unlock(pClient->mutex);
2108    
2109            return pFxSendInfo;
2110    }
2111    
2112    /**
2113     *  Alter effect send's name:
2114     *  @code
2115     *  SET FX_SEND NAME <sampler-chan> <fx-send-id> <name>
2116     *  @endcode
2117     *
2118     *  @param pClient          Pointer to client instance structure.
2119     *  @param iSamplerChannel  Sampler channel number.
2120     *  @param iFxSend          Effect send number.
2121     *  @param pszFxName        Effect send's new name.
2122     *
2123     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2124     */
2125    lscp_status_t lscp_set_fxsend_name ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, const char *pszFxName )
2126    {
2127            char szQuery[LSCP_BUFSIZ];
2128    
2129            if (!pClient || iSamplerChannel < 0 || iFxSend < 0 || !pszFxName)
2130                    return LSCP_FAILED;
2131    
2132            snprintf(szQuery, LSCP_BUFSIZ, "SET FX_SEND NAME %d %d '%s'\r\n", iSamplerChannel, iFxSend, pszFxName);
2133            return lscp_client_query(pClient, szQuery);
2134    }
2135    
2136    /**
2137     *  Alter effect send's audio routing:
2138     *  SET FX_SEND AUDIO_OUTPUT_CHANNEL <sampler-chan> <fx-send-id>
2139     *    <audio-src> <audio-dst>
2140     *
2141     *  @param pClient          Pointer to client instance structure.
2142     *  @param iSamplerChannel  Sampler channel number.
2143     *  @param iFxSend          Effect send number.
2144     *  @param iAudioSrc        Audio output device channel to be routed from.
2145     *  @param iAudioDst        Audio output device channel to be routed into.
2146     *
2147     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2148     */
2149    lscp_status_t lscp_set_fxsend_audio_channel ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, int iAudioSrc, int iAudioDst )
2150    {
2151            char szQuery[LSCP_BUFSIZ];
2152    
2153            if (iSamplerChannel < 0 || iFxSend < 0 || iAudioSrc < 0 || iAudioDst < 0)
2154                    return LSCP_FAILED;
2155    
2156            sprintf(szQuery, "SET FX_SEND AUDIO_OUTPUT_CHANNEL %d %d %d %d\r\n", iSamplerChannel, iFxSend, iAudioSrc, iAudioDst);
2157            return lscp_client_query(pClient, szQuery);
2158    }
2159    
2160    
2161    /**
2162     *  Alter effect send's MIDI controller:
2163     *  SET FX_SEND MIDI_CONTROLLER <sampler-chan> <fx-send-id> <midi-ctrl>
2164     *
2165     *  @param pClient          Pointer to client instance structure.
2166     *  @param iSamplerChannel  Sampler channel number.
2167     *  @param iFxSend          Effect send number.
2168     *  @param iMidiController  MIDI controller used to alter the effect,
2169     *                          usually a number between 0 and 127.
2170     *
2171     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2172     */
2173    lscp_status_t lscp_set_fxsend_midi_controller ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, int iMidiController )
2174    {
2175            char szQuery[LSCP_BUFSIZ];
2176    
2177            if (iSamplerChannel < 0 || iFxSend < 0 || iMidiController < 0 || iMidiController > 127)
2178                    return LSCP_FAILED;
2179    
2180            sprintf(szQuery, "SET FX_SEND MIDI_CONTROLLER %d %d %d\r\n", iSamplerChannel, iFxSend, iMidiController);
2181            return lscp_client_query(pClient, szQuery);
2182    }
2183    
2184    
2185    /**
2186     *  Alter effect send's audio level:
2187     *  SET FX_SEND LEVEL <sampler-chan> <fx-send-id> <level>
2188     *
2189     *  @param pClient          Pointer to client instance structure.
2190     *  @param iSamplerChannel  Sampler channel number.
2191     *  @param iFxSend          Effect send number.
2192     *  @param fLevel           Effect send volume level.
2193     *
2194     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2195     */
2196    lscp_status_t lscp_set_fxsend_level ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, float fLevel )
2197    {
2198            char szQuery[LSCP_BUFSIZ];
2199    
2200            if (iSamplerChannel < 0 || iFxSend < 0 || fLevel < 0.0f)
2201                    return LSCP_FAILED;
2202    
2203            sprintf(szQuery, "SET FX_SEND LEVEL %d %d %f\r\n", iSamplerChannel, iFxSend, fLevel);
2204            return lscp_client_query(pClient, szQuery);
2205    }
2206    
2207    
2208    /**
2209     *  Create a new MIDI instrument map:
2210     *  ADD MIDI_INSTRUMENT_MAP [<name>]
2211     *
2212     *  @param pClient      Pointer to client instance structure.
2213     *  @param pszMapName   MIDI instrument map name (optional)
2214     *
2215     *  @returns The new MIDI instrument map number identifier,
2216     *  or -1 in case of failure.
2217     */
2218    int lscp_add_midi_instrument_map ( lscp_client_t *pClient, const char *pszMapName )
2219    {
2220            int iMidiMap = -1;
2221            char szQuery[LSCP_BUFSIZ];
2222    
2223            if (pClient == NULL)
2224                    return -1;
2225    
2226            // Lock this section up.
2227            lscp_mutex_lock(pClient->mutex);
2228    
2229            strcpy(szQuery, "ADD MIDI_INSTRUMENT_MAP");
2230            
2231            if (pszMapName)
2232                    sprintf(szQuery + strlen(szQuery), " '%s'", pszMapName);
2233    
2234            strcat(szQuery, "\r\n");
2235    
2236            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
2237                    iMidiMap = atoi(lscp_client_get_result(pClient));
2238    
2239            // Unlock this section down.
2240            lscp_mutex_unlock(pClient->mutex);
2241    
2242            return iMidiMap;
2243    }
2244    
2245    
2246    /**
2247     *  Delete one particular or all MIDI instrument maps:
2248     *  REMOVE MIDI_INSTRUMENT_MAP <midi-map>
2249     *
2250     *  @param pClient  Pointer to client instance structure.
2251     *  @param iMidiMap MIDI instrument map number.
2252     *
2253     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2254     */
2255    lscp_status_t lscp_remove_midi_instrument_map ( lscp_client_t *pClient, int iMidiMap )
2256    {
2257            char szQuery[LSCP_BUFSIZ];
2258    
2259            if (iMidiMap < 0)
2260                    return LSCP_FAILED;
2261    
2262            sprintf(szQuery, "REMOVE MIDI_INSTRUMENT_MAP %d\r\n", iMidiMap);
2263    
2264            return lscp_client_query(pClient, szQuery);
2265    }
2266    
2267    
2268    /**
2269     *  Get amount of existing MIDI instrument maps:
2270     *  GET MIDI_INSTRUMENT_MAPS
2271     *
2272     *  @param pClient  Pointer to client instance structure.
2273     *
2274     *  @returns The current total number of MIDI instrument maps
2275     *  on success, -1 otherwise.
2276     */
2277    int lscp_get_midi_instrument_maps ( lscp_client_t *pClient )
2278    {
2279            int iMidiMaps = -1;
2280    
2281            if (pClient == NULL)
2282                    return -1;
2283    
2284            // Lock this section up.
2285            lscp_mutex_lock(pClient->mutex);
2286    
2287            if (lscp_client_call(pClient, "GET MIDI_INSTRUMENT_MAPS\r\n", 0) == LSCP_OK)
2288                    iMidiMaps = atoi(lscp_client_get_result(pClient));
2289    
2290            // Unlock this section doen.
2291            lscp_mutex_unlock(pClient->mutex);
2292    
2293            return iMidiMaps;
2294    }
2295    
2296    
2297    /**
2298     *  Getting all created MIDI instrument maps:
2299     *  LIST MIDI_INSTRUMENT_MAPS
2300     *
2301     *  @param pClient  Pointer to client instance structure.
2302     *
2303     *  @returns An array of the MIDI instrument map identifiers as positive
2304     *  integers, terminated with -1 on success, NULL otherwise.
2305     */
2306    int *lscp_list_midi_instrument_maps ( lscp_client_t *pClient )
2307    {
2308            const char *pszSeps = ",";
2309    
2310            if (pClient == NULL)
2311                    return NULL;
2312    
2313            // Lock this section up.
2314            lscp_mutex_lock(pClient->mutex);
2315    
2316            if (pClient->midi_maps) {
2317                    lscp_isplit_destroy(pClient->midi_maps);
2318                    pClient->midi_maps = NULL;
2319            }
2320    
2321            if (lscp_client_call(pClient, "LIST MIDI_INSTRUMENT_MAPS\r\n", 0) == LSCP_OK)
2322                    pClient->midi_maps = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps);
2323    
2324            // Unlock this section down.
2325            lscp_mutex_unlock(pClient->mutex);
2326    
2327            return pClient->midi_maps;
2328    }
2329    
2330    
2331    /**
2332     *  Getting a MIDI instrument map name:
2333     *  GET MIDI_INSTRUMENT_MAP INFO <midi-map>
2334     *
2335     *  @param pClient  Pointer to client instance structure.
2336     *  @param iMidiMap MIDI instrument map number.
2337     *
2338     *  @returns The MIDI instrument map name on success, NULL on failure.
2339     */
2340    const char *lscp_get_midi_instrument_map_name ( lscp_client_t *pClient, int iMidiMap )
2341    {
2342            char szQuery[LSCP_BUFSIZ];
2343            const char *pszResult;
2344            const char *pszSeps = ":";
2345            const char *pszCrlf = "\r\n";
2346            char *pszToken;
2347            char *pch;
2348    
2349            if (pClient == NULL)
2350                    return NULL;
2351            if (iMidiMap < 0)
2352                    return NULL;
2353    
2354            // Lock this section up.
2355            lscp_mutex_lock(pClient->mutex);
2356            
2357            if (pClient->midi_map_name) {
2358                    free(pClient->midi_map_name);
2359                    pClient->midi_map_name = NULL;
2360            }
2361    
2362            sprintf(szQuery, "GET MIDI_INSTRUMENT_MAP INFO %d\r\n", iMidiMap);
2363            if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) {
2364                    pszResult = lscp_client_get_result(pClient);
2365                    pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
2366                    while (pszToken) {
2367                            if (strcasecmp(pszToken, "NAME") == 0) {
2368                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2369                                    if (pszToken)
2370                                            lscp_unquote_dup(&(pClient->midi_map_name), &pszToken);
2371                            }
2372                            pszToken = lscp_strtok(NULL, pszSeps, &(pch));
2373                    }
2374            }
2375    
2376            // Unlock this section down.
2377            lscp_mutex_unlock(pClient->mutex);
2378    
2379            return pClient->midi_map_name;
2380    }
2381    
2382    
2383    /**
2384     *  Renaming a MIDI instrument map:
2385     *  SET MIDI_INSTRUMENT_MAP NAME <midi-map> <map-name>
2386     *
2387     *  @param pClient      Pointer to client instance structure.
2388     *  @param iMidiMap     MIDI instrument map number.
2389     *  @param pszMapName   MIDI instrument map name.
2390     *
2391     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2392     */
2393    lscp_status_t lscp_set_midi_instrument_map_name ( lscp_client_t *pClient, int iMidiMap, const char *pszMapName )
2394    {
2395            char szQuery[LSCP_BUFSIZ];
2396    
2397            if (iMidiMap < 0)
2398                    return LSCP_FAILED;
2399            if (pszMapName == NULL)
2400                    return LSCP_FAILED;
2401    
2402            sprintf(szQuery, "SET MIDI_INSTRUMENT_MAP NAME %d '%s'\r\n",
2403                    iMidiMap, pszMapName);
2404    
2405            return lscp_client_query(pClient, szQuery);
2406    }
2407    
2408    
2409    /**
2410     *  Create or replace a MIDI instrumnet map entry:
2411     *  MAP MIDI_INSTRUMENT <midi-map> <midi-bank> <midi-prog>
2412     *      <engine-name> <filename> <instr-index> <volume> [<load-mode> [<name>]}
2413     *
2414     *  @param pClient          Pointer to client instance structure.
2415     *  @param pMidiInstr       MIDI instrument bank and program parameter key.
2416     *  @param pszEngineName    Engine name.
2417     *  @param pszFileName      Instrument file name.
2418     *  @param iInstrIndex      Instrument index number.
2419     *  @param fVolume          Reflects the master volume of the instrument as
2420     *                          a positive floating point number, where a value
2421     *                          less than 1.0 for attenuation, and greater than
2422     *                          1.0 for amplification.
2423     *  @param load_mode        Instrument load life-time strategy, either
2424     *                          @ref LSCP_LOAD_DEFAULT, or
2425     *                          @ref LSCP_LOAD_ON_DEMAND, or
2426     *                          @ref LSCP_LOAD_ON_DEMAND_HOLD, or
2427     *                          @ref LSCP_LOAD_PERSISTENT.
2428     *  @param pszName         Instrument custom name for the map entry (optional).
2429     *
2430     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2431     */
2432    lscp_status_t lscp_map_midi_instrument ( lscp_client_t *pClient, lscp_midi_instrument_t *pMidiInstr, const char *pszEngineName, const char *pszFileName, int iInstrIndex, float fVolume, lscp_load_mode_t load_mode, const char *pszName )
2433    {
2434            char szQuery[LSCP_BUFSIZ];
2435    
2436            if (pMidiInstr->map < 0)
2437                    return LSCP_FAILED;
2438            if (pMidiInstr->bank < 0 || pMidiInstr->bank > 16383)
2439                    return LSCP_FAILED;
2440            if (pMidiInstr->prog < 0 || pMidiInstr->prog > 127)
2441                    return LSCP_FAILED;
2442            if (pszEngineName == NULL || pszFileName == NULL)
2443                    return LSCP_FAILED;
2444    
2445            if (fVolume < 0.0f)
2446                    fVolume = 1.0f;
2447    
2448            sprintf(szQuery, "MAP MIDI_INSTRUMENT %d %d %d %s '%s' %d %g",
2449                    pMidiInstr->map, pMidiInstr->bank, pMidiInstr->prog,
2450                    pszEngineName, pszFileName, iInstrIndex, fVolume);
2451    
2452            switch (load_mode) {
2453            case LSCP_LOAD_PERSISTENT:
2454                    strcat(szQuery, " PERSISTENT");
2455                    break;
2456            case LSCP_LOAD_ON_DEMAND_HOLD:
2457                    strcat(szQuery, " ON_DEMAND_HOLD");
2458                    break;
2459            case LSCP_LOAD_ON_DEMAND:
2460                    strcat(szQuery, " ON_DEMAND");
2461                    break;
2462            case LSCP_LOAD_DEFAULT:
2463            default:
2464                    break;
2465            }
2466    
2467            if (pszName)
2468                    sprintf(szQuery + strlen(szQuery), " '%s'", pszName);
2469    
2470            strcat(szQuery, "\r\n");
2471    
2472            return lscp_client_query(pClient, szQuery);
2473    }
2474    
2475    
2476    /**
2477     *  Remove an entry from the MIDI instrument map:
2478     *  UNMAP MIDI_INSTRUMENT <midi-map> <midi-bank> <midi-prog>
2479     *
2480     *  @param pClient      Pointer to client instance structure.
2481     *  @param pMidiInstr   MIDI instrument bank and program parameter key.
2482     *
2483     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2484     */
2485    lscp_status_t lscp_unmap_midi_instrument ( lscp_client_t *pClient, lscp_midi_instrument_t *pMidiInstr )
2486    {
2487            char szQuery[LSCP_BUFSIZ];
2488    
2489            if (pMidiInstr->map < 0)
2490                    return LSCP_FAILED;
2491            if (pMidiInstr->bank < 0 || pMidiInstr->bank > 16383)
2492                    return LSCP_FAILED;
2493            if (pMidiInstr->prog < 0 || pMidiInstr->prog > 127)
2494                    return LSCP_FAILED;
2495    
2496            sprintf(szQuery, "UNMAP MIDI_INSTRUMENT %d %d %d\r\n",
2497                    pMidiInstr->map, pMidiInstr->bank, pMidiInstr->prog);
2498    
2499            return lscp_client_query(pClient, szQuery);
2500    }
2501    
2502    
2503    /**
2504     *  Get the total count of MIDI instrument map entries:
2505     *  GET MIDI_INSTRUMENTS ALL|<midi-map>
2506     *
2507     *  @param pClient  Pointer to client instance structure.
2508     *  @param iMidiMap MIDI instrument map number, or @ref LSCP_MIDI_MAP_ALL .
2509     *
2510     *  @returns The current total number of MIDI instrument map entries
2511     *  on success, -1 otherwise.
2512     */
2513    int lscp_get_midi_instruments ( lscp_client_t *pClient, int iMidiMap )
2514    {
2515            int iInstruments = -1;
2516            char szQuery[LSCP_BUFSIZ];
2517    
2518            if (pClient == NULL)
2519                    return -1;
2520    
2521            // Lock this section up.
2522            lscp_mutex_lock(pClient->mutex);
2523    
2524            strcpy(szQuery, "GET MIDI_INSTRUMENTS ");
2525    
2526            if (iMidiMap < 0)
2527                    strcat(szQuery, "ALL");
2528            else
2529                    sprintf(szQuery + strlen(szQuery), "%d", iMidiMap);
2530    
2531            strcat(szQuery, "\r\n");
2532    
2533            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
2534                    iInstruments = atoi(lscp_client_get_result(pClient));
2535    
2536            // Unlock this section down.
2537            lscp_mutex_unlock(pClient->mutex);
2538    
2539            return iInstruments;
2540    }
2541    
2542    
2543    /**
2544     *  Getting indeces of all MIDI instrument map entries:
2545     *  LIST MIDI_INSTRUMENTS ALL|<midi-map>
2546     *
2547     *  @param pClient  Pointer to client instance structure.
2548     *  @param iMidiMap MIDI instrument map number, or @ref LSCP_MIDI_MAP_ALL .
2549     *
2550     *  @returns An array of @ref lscp_midi_instrument_t, terminated with the
2551     *  {-1,-1,-1} triplet, NULL otherwise.
2552     */
2553    lscp_midi_instrument_t *lscp_list_midi_instruments ( lscp_client_t *pClient, int iMidiMap )
2554    {
2555            char szQuery[LSCP_BUFSIZ];
2556    
2557            if (pClient == NULL)
2558                    return NULL;
2559    
2560            // Lock this section up.
2561            lscp_mutex_lock(pClient->mutex);
2562    
2563            if (pClient->midi_instruments) {
2564                    lscp_midi_instruments_destroy(pClient->midi_instruments);
2565                    pClient->midi_instruments = NULL;
2566            }
2567    
2568            strcpy(szQuery, "LIST MIDI_INSTRUMENTS ");
2569    
2570            if (iMidiMap < 0)
2571                    strcat(szQuery, "ALL");
2572            else
2573                    sprintf(szQuery + strlen(szQuery), "%d", iMidiMap);
2574    
2575            strcat(szQuery, "\r\n");
2576    
2577            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
2578                    pClient->midi_instruments = lscp_midi_instruments_create(lscp_client_get_result(pClient));
2579    
2580            // Unlock this section down.
2581            lscp_mutex_unlock(pClient->mutex);
2582    
2583            return pClient->midi_instruments;
2584    }
2585    
2586    
2587    /**
2588     *  Getting information about a MIDI instrument map entry:
2589     *  GET MIDI_INSTRUMENT INFO <midi-map> <midi-bank> <midi-prog>
2590     *
2591     *  @param pClient      Pointer to client instance structure.
2592     *  @param pMidiInstr   MIDI instrument bank and program parameter key.
2593     *
2594     *  @returns A pointer to a @ref lscp_midi_instrument_info_t structure,
2595     *  with all the information of the given MIDI instrument map entry,
2596     *  or NULL in case of failure.
2597     */
2598    lscp_midi_instrument_info_t *lscp_get_midi_instrument_info ( lscp_client_t *pClient, lscp_midi_instrument_t *pMidiInstr )
2599    {
2600            lscp_midi_instrument_info_t *pInstrInfo;
2601            char szQuery[LSCP_BUFSIZ];
2602            const char *pszResult;
2603            const char *pszSeps = ":";
2604            const char *pszCrlf = "\r\n";
2605            char *pszToken;
2606            char *pch;
2607    
2608            if (pClient == NULL)
2609                    return NULL;
2610            if (pMidiInstr->map < 0)
2611                    return NULL;
2612            if (pMidiInstr->bank < 0 || pMidiInstr->bank > 16383)
2613                    return NULL;
2614            if (pMidiInstr->prog < 0 || pMidiInstr->prog > 127)
2615                    return NULL;
2616    
2617            // Lock this section up.
2618            lscp_mutex_lock(pClient->mutex);
2619            
2620            pInstrInfo = &(pClient->midi_instrument_info);
2621            lscp_midi_instrument_info_reset(pInstrInfo);
2622    
2623            sprintf(szQuery, "GET MIDI_INSTRUMENT INFO %d %d %d\r\n",
2624                    pMidiInstr->map, pMidiInstr->bank, pMidiInstr->prog);
2625            if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) {
2626                    pszResult = lscp_client_get_result(pClient);
2627                    pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
2628                    while (pszToken) {
2629                            if (strcasecmp(pszToken, "NAME") == 0) {
2630                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2631                                    if (pszToken)
2632                                            lscp_unquote_dup(&(pInstrInfo->name), &pszToken);
2633                            }
2634                            else if (strcasecmp(pszToken, "ENGINE_NAME") == 0) {
2635                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2636                                    if (pszToken)
2637                                            lscp_unquote_dup(&(pInstrInfo->engine_name), &pszToken);
2638                            }
2639                            else if (strcasecmp(pszToken, "INSTRUMENT_FILE") == 0) {
2640                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2641                                    if (pszToken)
2642                                            lscp_unquote_dup(&(pInstrInfo->instrument_file), &pszToken);
2643                            }
2644                            else if (strcasecmp(pszToken, "INSTRUMENT_NR") == 0) {
2645                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2646                                    if (pszToken)
2647                                            pInstrInfo->instrument_nr = atoi(lscp_ltrim(pszToken));
2648                            }
2649                            else if (strcasecmp(pszToken, "INSTRUMENT_NAME") == 0) {
2650                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2651                                    if (pszToken)
2652                                            lscp_unquote_dup(&(pInstrInfo->instrument_name), &pszToken);
2653                            }
2654                            else if (strcasecmp(pszToken, "LOAD_MODE") == 0) {
2655                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2656                                    if (pszToken) {
2657                                            pszToken = lscp_ltrim(pszToken);
2658                                            if (strcasecmp(pszToken, "ON_DEMAND") == 0)
2659                                                    pInstrInfo->load_mode = LSCP_LOAD_ON_DEMAND;
2660                                            else
2661                                            if (strcasecmp(pszToken, "ON_DEMAND_HOLD") == 0)
2662                                                    pInstrInfo->load_mode = LSCP_LOAD_ON_DEMAND_HOLD;
2663                                            else
2664                                            if (strcasecmp(pszToken, "PERSISTENT") == 0)
2665                                                    pInstrInfo->load_mode = LSCP_LOAD_PERSISTENT;
2666                                            else
2667                                                    pInstrInfo->load_mode = LSCP_LOAD_DEFAULT;
2668                                    }
2669                            }
2670                            else if (strcasecmp(pszToken, "VOLUME") == 0) {
2671                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2672                                    if (pszToken)
2673                                            pInstrInfo->volume = (float) atof(lscp_ltrim(pszToken));
2674                            }
2675                            pszToken = lscp_strtok(NULL, pszSeps, &(pch));
2676                    }
2677            }
2678            else pInstrInfo = NULL;
2679    
2680            // Unlock this section down.
2681            lscp_mutex_unlock(pClient->mutex);
2682    
2683            return pInstrInfo;
2684    }
2685    
2686    
2687    /**
2688     *  Clear the MIDI instrumnet map:
2689     *  CLEAR MIDI_INSTRUMENTS ALL|<midi-map>
2690     *
2691     *  @param pClient  Pointer to client instance structure.
2692     *  @param iMidiMap MIDI instrument map number, or @ref LSCP_MIDI_MAP_ALL .
2693     *
2694     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2695     */
2696    lscp_status_t lscp_clear_midi_instruments  ( lscp_client_t *pClient, int iMidiMap )
2697    {
2698            char szQuery[LSCP_BUFSIZ];
2699    
2700            strcpy(szQuery, "CLEAR MIDI_INSTRUMENTS ");
2701    
2702            if (iMidiMap < 0)
2703                    strcat(szQuery, "ALL");
2704            else
2705                    sprintf(szQuery + strlen(szQuery), "%d", iMidiMap);
2706    
2707            strcat(szQuery, "\r\n");
2708    
2709            return lscp_client_query(pClient, szQuery);
2710    }
2711    
2712    /**
2713     * Open an instrument editor application for the instrument
2714     * on the given sampler channel:
2715     * EDIT CHANNEL INSTRUMENT <sampler-channel>
2716     *
2717     * @param pClient         Pointer to client instance structure.
2718     * @param iSamplerChannel Sampler Channel.
2719     *
2720     * @returns LSCP_OK on success, LSCP_FAILED otherwise.
2721     */
2722    lscp_status_t lscp_edit_channel_instrument ( lscp_client_t *pClient, int iSamplerChannel )
2723    {
2724            char szQuery[LSCP_BUFSIZ];
2725    
2726            if (iSamplerChannel < 0)
2727                    return LSCP_FAILED;
2728    
2729      // Unlock this section down.          sprintf(szQuery, "EDIT CHANNEL INSTRUMENT %d\r\n", iSamplerChannel);
     lscp_mutex_unlock(pClient->mutex);  
2730    
2731      return pServerInfo;          return lscp_client_query(pClient, szQuery);
2732  }  }
2733    
2734    

Legend:
Removed from v.921  
changed lines
  Added in v.1697

  ViewVC Help
Powered by ViewVC