/[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 948 by capela, Tue Nov 28 15:31:20 2006 UTC revision 952 by capela, Tue Nov 28 22:46:32 2006 UTC
# 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...                                  // Parse for the notification event message...
88                  pszToken = lscp_strtok(achBuffer, pszSeps, &(pch)); // Have "NOTIFY".                                  pszToken = lscp_strtok(achBuffer, pszSeps, &(pch)); // Have "NOTIFY".
89                  if (strcasecmp(pszToken, "NOTIFY") == 0) {                                  if (strcasecmp(pszToken, "NOTIFY") == 0) {
90                      pszToken = lscp_strtok(NULL, pszSeps, &(pch));                                          pszToken = lscp_strtok(NULL, pszSeps, &(pch));
91                      event    = lscp_event_from_text(pszToken);                                          event    = lscp_event_from_text(pszToken);
92                      // And pick the rest of data...                                          // And pick the rest of data...
93                      pszToken = lscp_strtok(NULL, pszSeps, &(pch));                                          pszToken = lscp_strtok(NULL, pszSeps, &(pch));
94                      cchToken = (pszToken == NULL ? 0 : strlen(pszToken));                                          cchToken = (pszToken == NULL ? 0 : strlen(pszToken));
95                      // Double-check if we're really up to it...                                          // Double-check if we're really up to it...
96                      if (pClient->events & event) {                                          if (pClient->events & event) {
97                          // Invoke the client event callback...                                                  // Invoke the client event callback...
98                          if ((*pClient->pfnCallback)(                                                  if ((*pClient->pfnCallback)(
99                                  pClient,                                                                  pClient,
100                                  event,                                                                  event,
101                                  pszToken,                                                                  pszToken,
102                                  cchToken,                                                                  cchToken,
103                                  pClient->pvData) != LSCP_OK) {                                                                  pClient->pvData) != LSCP_OK) {
104                              pClient->evt.iState = 0;                                                          pClient->evt.iState = 0;
105                          }                                                  }
106                      }                                          }
107                  }                                  }
108              } else {                          } else {
109                  lscp_socket_perror("_lscp_client_evt_proc: recv");                                  lscp_socket_perror("_lscp_client_evt_proc: recv");
110                  pClient->evt.iState = 0;                                  pClient->evt.iState = 0;
111              }                          }
112          }   // Check if select has in error.                  }   // Check if select has in error.
113          else if (iSelect < 0) {                  else if (iSelect < 0) {
114              lscp_socket_perror("_lscp_client_evt_proc: select");                          lscp_socket_perror("_lscp_client_evt_proc: select");
115              pClient->evt.iState = 0;                          pClient->evt.iState = 0;
116          }                  }
117    
118          // Finally, always signal the event.                  // Finally, always signal the event.
119          lscp_cond_signal(pClient->cond);                  lscp_cond_signal(pClient->cond);
120      }          }
121    
122  #ifdef DEBUG  #ifdef DEBUG
123      fprintf(stderr, "_lscp_client_evt_proc: Client closing.\n");          fprintf(stderr, "_lscp_client_evt_proc: Client closing.\n");
124  #endif  #endif
125  }  }
126    
# Line 131  static void _lscp_client_evt_proc ( void Line 131  static void _lscp_client_evt_proc ( void
131  // Open the event service socket connection.  // Open the event service socket connection.
132  static lscp_status_t _lscp_client_evt_connect ( lscp_client_t *pClient )  static lscp_status_t _lscp_client_evt_connect ( lscp_client_t *pClient )
133  {  {
134      lscp_socket_t sock;          lscp_socket_t sock;
135      struct sockaddr_in addr;          struct sockaddr_in addr;
136      int cAddr;          int cAddr;
137  #if defined(WIN32)  #if defined(WIN32)
138      int iSockOpt = (-1);          int iSockOpt = (-1);
139  #endif  #endif
140    
141      // Prepare the event connection socket...          // Prepare the event connection socket...
142      sock = socket(AF_INET, SOCK_STREAM, 0);          sock = socket(AF_INET, SOCK_STREAM, 0);
143      if (sock == INVALID_SOCKET) {          if (sock == INVALID_SOCKET) {
144          lscp_socket_perror("_lscp_client_evt_connect: socket");                  lscp_socket_perror("_lscp_client_evt_connect: socket");
145          return LSCP_FAILED;                  return LSCP_FAILED;
146      }          }
147    
148  #if defined(WIN32)  #if defined(WIN32)
149      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)
150          lscp_socket_perror("lscp_client_evt_connect: setsockopt(SO_DONTLINGER)");                  lscp_socket_perror("lscp_client_evt_connect: setsockopt(SO_DONTLINGER)");
151  #endif  #endif
152    
153  #ifdef DEBUG  #ifdef DEBUG
154      lscp_socket_getopts("_lscp_client_evt_connect:", sock);          lscp_socket_getopts("_lscp_client_evt_connect:", sock);
155  #endif  #endif
156    
157      // Use same address of the command connection.          // Use same address of the command connection.
158      cAddr = sizeof(struct sockaddr_in);          cAddr = sizeof(struct sockaddr_in);
159      memmove((char *) &addr, &(pClient->cmd.addr), cAddr);          memmove((char *) &addr, &(pClient->cmd.addr), cAddr);
160    
161      // Start the connection...          // Start the connection...
162      if (connect(sock, (struct sockaddr *) &addr, cAddr) == SOCKET_ERROR) {          if (connect(sock, (struct sockaddr *) &addr, cAddr) == SOCKET_ERROR) {
163          lscp_socket_perror("_lscp_client_evt_connect: connect");                  lscp_socket_perror("_lscp_client_evt_connect: connect");
164          closesocket(sock);                  closesocket(sock);
165          return LSCP_FAILED;                  return LSCP_FAILED;
166      }          }
167    
168      // Set our socket agent struct...          // Set our socket agent struct...
169      lscp_socket_agent_init(&(pClient->evt), sock, &addr, cAddr);          lscp_socket_agent_init(&(pClient->evt), sock, &addr, cAddr);
170    
171      // And finally the service thread...          // And finally the service thread...
172      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);
173  }  }
174    
175    
176  // Subscribe to a single event.  // Subscribe to a single event.
177  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 )
178  {  {
179      const char *pszEvent;          const char *pszEvent;
180      char  szQuery[LSCP_BUFSIZ];          char  szQuery[LSCP_BUFSIZ];
181      int   cchQuery;          int   cchQuery;
182    
183      if (pClient == NULL)          if (pClient == NULL)
184          return LSCP_FAILED;                  return LSCP_FAILED;
185    
186      // Which (single) event?          // Which (single) event?
187      pszEvent = lscp_event_to_text(event);          pszEvent = lscp_event_to_text(event);
188      if (pszEvent == NULL)          if (pszEvent == NULL)
189          return LSCP_FAILED;                  return LSCP_FAILED;
190    
191      // Build the query string...          // Build the query string...
192      cchQuery = sprintf(szQuery, "%sSUBSCRIBE %s\n\n", (iSubscribe == 0 ? "UN" : ""), pszEvent);          cchQuery = sprintf(szQuery, "%sSUBSCRIBE %s\n\n", (iSubscribe == 0 ? "UN" : ""), pszEvent);
193      // Just send data, forget result...          // Just send data, forget result...
194      if (send(pClient->evt.sock, szQuery, cchQuery, 0) < cchQuery) {          if (send(pClient->evt.sock, szQuery, cchQuery, 0) < cchQuery) {
195          lscp_socket_perror("_lscp_client_evt_request: send");                  lscp_socket_perror("_lscp_client_evt_request: send");
196          return LSCP_FAILED;                  return LSCP_FAILED;
197      }          }
198    
199      // Wait on response.          // Wait on response.
200      lscp_cond_wait(pClient->cond, pClient->mutex);          lscp_cond_wait(pClient->cond, pClient->mutex);
201    
202      // Update as naively as we can...          // Update as naively as we can...
203      if (iSubscribe)          if (iSubscribe)
204          pClient->events |=  event;                  pClient->events |=  event;
205      else          else
206          pClient->events &= ~event;                  pClient->events &= ~event;
207    
208      return LSCP_OK;          return LSCP_OK;
209  }  }
210    
211    
# Line 242  const char* lscp_client_build   (void) { Line 242  const char* lscp_client_build   (void) {
242   */   */
243  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 )
244  {  {
245      lscp_client_t  *pClient;          lscp_client_t  *pClient;
246      struct hostent *pHost;          struct hostent *pHost;
247      lscp_socket_t sock;          lscp_socket_t sock;
248      struct sockaddr_in addr;          struct sockaddr_in addr;
249      int cAddr;          int cAddr;
250  #if defined(WIN32)  #if defined(WIN32)
251      int iSockOpt = (-1);          int iSockOpt = (-1);
252  #endif  #endif
253    
254      if (pfnCallback == NULL) {          if (pfnCallback == NULL) {
255          fprintf(stderr, "lscp_client_create: Invalid client callback function.\n");                  fprintf(stderr, "lscp_client_create: Invalid client callback function.\n");
256          return NULL;                  return NULL;
257      }          }
258    
259      pHost = gethostbyname(pszHost);          pHost = gethostbyname(pszHost);
260      if (pHost == NULL) {          if (pHost == NULL) {
261          lscp_socket_herror("lscp_client_create: gethostbyname");                  lscp_socket_herror("lscp_client_create: gethostbyname");
262          return NULL;                  return NULL;
263      }          }
264    
265      // Allocate client descriptor...          // Allocate client descriptor...
266    
267      pClient = (lscp_client_t *) malloc(sizeof(lscp_client_t));          pClient = (lscp_client_t *) malloc(sizeof(lscp_client_t));
268      if (pClient == NULL) {          if (pClient == NULL) {
269          fprintf(stderr, "lscp_client_create: Out of memory.\n");                  fprintf(stderr, "lscp_client_create: Out of memory.\n");
270          return NULL;                  return NULL;
271      }          }
272      memset(pClient, 0, sizeof(lscp_client_t));          memset(pClient, 0, sizeof(lscp_client_t));
273    
274      pClient->pfnCallback = pfnCallback;          pClient->pfnCallback = pfnCallback;
275      pClient->pvData = pvData;          pClient->pvData = pvData;
276    
277  #ifdef DEBUG  #ifdef DEBUG
278      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);
279  #endif  #endif
280    
281      // Prepare the command connection socket...          // Prepare the command connection socket...
282    
283      sock = socket(AF_INET, SOCK_STREAM, 0);          sock = socket(AF_INET, SOCK_STREAM, 0);
284      if (sock == INVALID_SOCKET) {          if (sock == INVALID_SOCKET) {
285          lscp_socket_perror("lscp_client_create: cmd: socket");                  lscp_socket_perror("lscp_client_create: cmd: socket");
286          free(pClient);                  free(pClient);
287          return NULL;                  return NULL;
288      }          }
289    
290  #if defined(WIN32)  #if defined(WIN32)
291      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)
292          lscp_socket_perror("lscp_client_create: cmd: setsockopt(SO_DONTLINGER)");                  lscp_socket_perror("lscp_client_create: cmd: setsockopt(SO_DONTLINGER)");
293  #endif  #endif
294    
295  #ifdef DEBUG  #ifdef DEBUG
296      lscp_socket_getopts("lscp_client_create: cmd", sock);          lscp_socket_getopts("lscp_client_create: cmd", sock);
297  #endif  #endif
298    
299      cAddr = sizeof(struct sockaddr_in);          cAddr = sizeof(struct sockaddr_in);
300      memset((char *) &addr, 0, cAddr);          memset((char *) &addr, 0, cAddr);
301      addr.sin_family = pHost->h_addrtype;          addr.sin_family = pHost->h_addrtype;
302      memmove((char *) &(addr.sin_addr), pHost->h_addr, pHost->h_length);          memmove((char *) &(addr.sin_addr), pHost->h_addr, pHost->h_length);
303      addr.sin_port = htons((short) iPort);          addr.sin_port = htons((short) iPort);
304    
305      if (connect(sock, (struct sockaddr *) &addr, cAddr) == SOCKET_ERROR) {          if (connect(sock, (struct sockaddr *) &addr, cAddr) == SOCKET_ERROR) {
306          lscp_socket_perror("lscp_client_create: cmd: connect");                  lscp_socket_perror("lscp_client_create: cmd: connect");
307          closesocket(sock);                  closesocket(sock);
308          free(pClient);                  free(pClient);
309          return NULL;                  return NULL;
310      }          }
311    
312      // Initialize the command socket agent struct...          // Initialize the command socket agent struct...
313      lscp_socket_agent_init(&(pClient->cmd), sock, &addr, cAddr);          lscp_socket_agent_init(&(pClient->cmd), sock, &addr, cAddr);
314    
315  #ifdef DEBUG  #ifdef DEBUG
316      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));
317  #endif  #endif
318    
319      // Initialize the event service socket struct...          // Initialize the event service socket struct...
320      lscp_socket_agent_init(&(pClient->evt), INVALID_SOCKET, NULL, 0);          lscp_socket_agent_init(&(pClient->evt), INVALID_SOCKET, NULL, 0);
321      // No events subscribed, yet.          // No events subscribed, yet.
322      pClient->events = LSCP_EVENT_NONE;          pClient->events = LSCP_EVENT_NONE;
323      // Initialize cached members.          // Initialize cached members.
324      pClient->audio_drivers = NULL;          pClient->audio_drivers = NULL;
325      pClient->midi_drivers = NULL;          pClient->midi_drivers = NULL;
326      pClient->audio_devices = NULL;          pClient->audio_devices = NULL;
327      pClient->midi_devices = NULL;          pClient->midi_devices = NULL;
328      pClient->engines = NULL;          pClient->engines = NULL;
329      pClient->channels = NULL;          pClient->channels = NULL;
330      pClient->midi_instruments = NULL;          pClient->midi_instruments = NULL;
331      lscp_driver_info_init(&(pClient->audio_driver_info));          lscp_driver_info_init(&(pClient->audio_driver_info));
332      lscp_driver_info_init(&(pClient->midi_driver_info));          lscp_driver_info_init(&(pClient->midi_driver_info));
333      lscp_device_info_init(&(pClient->audio_device_info));          lscp_device_info_init(&(pClient->audio_device_info));
334      lscp_device_info_init(&(pClient->midi_device_info));          lscp_device_info_init(&(pClient->midi_device_info));
335      lscp_param_info_init(&(pClient->audio_param_info));          lscp_param_info_init(&(pClient->audio_param_info));
336      lscp_param_info_init(&(pClient->midi_param_info));          lscp_param_info_init(&(pClient->midi_param_info));
337      lscp_device_port_info_init(&(pClient->audio_channel_info));          lscp_device_port_info_init(&(pClient->audio_channel_info));
338      lscp_device_port_info_init(&(pClient->midi_port_info));          lscp_device_port_info_init(&(pClient->midi_port_info));
339      lscp_param_info_init(&(pClient->audio_channel_param_info));          lscp_param_info_init(&(pClient->audio_channel_param_info));
340      lscp_param_info_init(&(pClient->midi_port_param_info));          lscp_param_info_init(&(pClient->midi_port_param_info));
341      lscp_server_info_init(&(pClient->server_info));          lscp_server_info_init(&(pClient->server_info));
342      lscp_engine_info_init(&(pClient->engine_info));          lscp_engine_info_init(&(pClient->engine_info));
343      lscp_channel_info_init(&(pClient->channel_info));          lscp_channel_info_init(&(pClient->channel_info));
344      lscp_midi_instrument_info_init(&(pClient->midi_instrument_info));          lscp_midi_instrument_info_init(&(pClient->midi_instrument_info));
345      // Initialize error stuff.          // Initialize error stuff.
346      pClient->pszResult = NULL;          pClient->pszResult = NULL;
347      pClient->iErrno = -1;          pClient->iErrno = -1;
348      // Stream usage stuff.          // Stream usage stuff.
349      pClient->buffer_fill = NULL;          pClient->buffer_fill = NULL;
350      pClient->iStreamCount = 0;          pClient->iStreamCount = 0;
351      // Default timeout value.          // Default timeout value.
352      pClient->iTimeout = LSCP_TIMEOUT_MSECS;          pClient->iTimeout = LSCP_TIMEOUT_MSECS;
353          pClient->iTimeoutCount = 0;          pClient->iTimeoutCount = 0;
354    
355      // Initialize the transaction mutex.          // Initialize the transaction mutex.
356      lscp_mutex_init(pClient->mutex);          lscp_mutex_init(pClient->mutex);
357      lscp_cond_init(pClient->cond);          lscp_cond_init(pClient->cond);
358    
359      // Finally we've some success...          // Finally we've some success...
360      return pClient;          return pClient;
361  }  }
362    
363    
# Line 368  lscp_client_t* lscp_client_create ( cons Line 368  lscp_client_t* lscp_client_create ( cons
368   */   */
369  lscp_status_t lscp_client_join ( lscp_client_t *pClient )  lscp_status_t lscp_client_join ( lscp_client_t *pClient )
370  {  {
371      if (pClient == NULL)          if (pClient == NULL)
372          return LSCP_FAILED;                  return LSCP_FAILED;
373    
374  #ifdef DEBUG  #ifdef DEBUG
375      fprintf(stderr, "lscp_client_join: pClient=%p.\n", pClient);          fprintf(stderr, "lscp_client_join: pClient=%p.\n", pClient);
376  #endif  #endif
377    
378  //  lscp_socket_agent_join(&(pClient->evt));  //  lscp_socket_agent_join(&(pClient->evt));
379      lscp_socket_agent_join(&(pClient->cmd));          lscp_socket_agent_join(&(pClient->cmd));
380    
381      return LSCP_OK;          return LSCP_OK;
382  }  }
383    
384    
# Line 391  lscp_status_t lscp_client_join ( lscp_cl Line 391  lscp_status_t lscp_client_join ( lscp_cl
391   */   */
392  lscp_status_t lscp_client_destroy ( lscp_client_t *pClient )  lscp_status_t lscp_client_destroy ( lscp_client_t *pClient )
393  {  {
394      if (pClient == NULL)          if (pClient == NULL)
395          return LSCP_FAILED;                  return LSCP_FAILED;
396    
397  #ifdef DEBUG  #ifdef DEBUG
398      fprintf(stderr, "lscp_client_destroy: pClient=%p.\n", pClient);          fprintf(stderr, "lscp_client_destroy: pClient=%p.\n", pClient);
399  #endif  #endif
400    
401      // Lock this section up.          // Lock this section up.
402      lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
403    
404      // Free up all cached members.          // Free up all cached members.
405      lscp_midi_instrument_info_free(&(pClient->midi_instrument_info));          lscp_midi_instrument_info_free(&(pClient->midi_instrument_info));
406      lscp_channel_info_free(&(pClient->channel_info));          lscp_channel_info_free(&(pClient->channel_info));
407      lscp_engine_info_free(&(pClient->engine_info));          lscp_engine_info_free(&(pClient->engine_info));
408      lscp_server_info_free(&(pClient->server_info));          lscp_server_info_free(&(pClient->server_info));
409      lscp_param_info_free(&(pClient->midi_port_param_info));          lscp_param_info_free(&(pClient->midi_port_param_info));
410      lscp_param_info_free(&(pClient->audio_channel_param_info));          lscp_param_info_free(&(pClient->audio_channel_param_info));
411      lscp_device_port_info_free(&(pClient->midi_port_info));          lscp_device_port_info_free(&(pClient->midi_port_info));
412      lscp_device_port_info_free(&(pClient->audio_channel_info));          lscp_device_port_info_free(&(pClient->audio_channel_info));
413      lscp_param_info_free(&(pClient->midi_param_info));          lscp_param_info_free(&(pClient->midi_param_info));
414      lscp_param_info_free(&(pClient->audio_param_info));          lscp_param_info_free(&(pClient->audio_param_info));
415      lscp_device_info_free(&(pClient->midi_device_info));          lscp_device_info_free(&(pClient->midi_device_info));
416      lscp_device_info_free(&(pClient->audio_device_info));          lscp_device_info_free(&(pClient->audio_device_info));
417      lscp_driver_info_free(&(pClient->midi_driver_info));          lscp_driver_info_free(&(pClient->midi_driver_info));
418      lscp_driver_info_free(&(pClient->audio_driver_info));          lscp_driver_info_free(&(pClient->audio_driver_info));
419      // Free available engine table.          // Free available engine table.
420      lscp_szsplit_destroy(pClient->audio_drivers);          lscp_szsplit_destroy(pClient->audio_drivers);
421      lscp_szsplit_destroy(pClient->midi_drivers);          lscp_szsplit_destroy(pClient->midi_drivers);
422      lscp_isplit_destroy(pClient->audio_devices);          lscp_isplit_destroy(pClient->audio_devices);
423      lscp_isplit_destroy(pClient->midi_devices);          lscp_isplit_destroy(pClient->midi_devices);
424      lscp_szsplit_destroy(pClient->engines);          lscp_szsplit_destroy(pClient->engines);
425      lscp_isplit_destroy(pClient->channels);          lscp_isplit_destroy(pClient->channels);
426      lscp_midi_instruments_destroy(pClient->midi_instruments);          lscp_midi_instruments_destroy(pClient->midi_instruments);
427      // Make them null.          // Make them null.
428      pClient->audio_drivers = NULL;          pClient->audio_drivers = NULL;
429      pClient->midi_drivers = NULL;          pClient->midi_drivers = NULL;
430      pClient->audio_devices = NULL;          pClient->audio_devices = NULL;
431      pClient->midi_devices = NULL;          pClient->midi_devices = NULL;
432      pClient->engines = NULL;          pClient->engines = NULL;
433      pClient->channels = NULL;          pClient->channels = NULL;
434      pClient->midi_instruments = NULL;          pClient->midi_instruments = NULL;
435      // Free result error stuff.          // Free result error stuff.
436      lscp_client_set_result(pClient, NULL, 0);          lscp_client_set_result(pClient, NULL, 0);
437      // Free stream usage stuff.          // Free stream usage stuff.
438      if (pClient->buffer_fill)          if (pClient->buffer_fill)
439          free(pClient->buffer_fill);                  free(pClient->buffer_fill);
440      pClient->buffer_fill = NULL;          pClient->buffer_fill = NULL;
441      pClient->iStreamCount = 0;          pClient->iStreamCount = 0;
442      pClient->iTimeout = 0;          pClient->iTimeout = 0;
443    
444      // Free socket agents.          // Free socket agents.
445      lscp_socket_agent_free(&(pClient->evt));          lscp_socket_agent_free(&(pClient->evt));
446      lscp_socket_agent_free(&(pClient->cmd));          lscp_socket_agent_free(&(pClient->cmd));
447    
448      // Last but not least, free good ol'transaction mutex.          // Last but not least, free good ol'transaction mutex.
449      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
450      lscp_mutex_destroy(pClient->mutex);          lscp_mutex_destroy(pClient->mutex);
451      lscp_cond_destroy(pClient->cond);          lscp_cond_destroy(pClient->cond);
452    
453      free(pClient);          free(pClient);
454    
455      return LSCP_OK;          return LSCP_OK;
456  }  }
457    
458    
# Line 466  lscp_status_t lscp_client_destroy ( lscp Line 466  lscp_status_t lscp_client_destroy ( lscp
466   */   */
467  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 )
468  {  {
469      if (pClient == NULL)          if (pClient == NULL)
470          return LSCP_FAILED;                  return LSCP_FAILED;
471      if (iTimeout < 0)          if (iTimeout < 0)
472          return LSCP_FAILED;                  return LSCP_FAILED;
473    
474      pClient->iTimeout = iTimeout;          pClient->iTimeout = iTimeout;
475      return LSCP_OK;          return LSCP_OK;
476  }  }
477    
478    
# Line 485  lscp_status_t lscp_client_set_timeout ( Line 485  lscp_status_t lscp_client_set_timeout (
485   */   */
486  int lscp_client_get_timeout ( lscp_client_t *pClient )  int lscp_client_get_timeout ( lscp_client_t *pClient )
487  {  {
488      if (pClient == NULL)          if (pClient == NULL)
489          return -1;                  return -1;
490    
491      return pClient->iTimeout;          return pClient->iTimeout;
492  }  }
493    
494    
# Line 510  int lscp_client_get_timeout ( lscp_clien Line 510  int lscp_client_get_timeout ( lscp_clien
510   */   */
511  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 )
512  {  {
513      lscp_status_t ret;          lscp_status_t ret;
514    
515      // Lock this section up.          // Lock this section up.
516      lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
517    
518      // Just make the now guarded call.          // Just make the now guarded call.
519      ret = lscp_client_call(pClient, pszQuery, 0);          ret = lscp_client_call(pClient, pszQuery, 0);
520    
521      // Unlock this section down.          // Unlock this section down.
522      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
523    
524      return ret;          return ret;
525  }  }
526    
527  /**  /**
# Line 535  lscp_status_t lscp_client_query ( lscp_c Line 535  lscp_status_t lscp_client_query ( lscp_c
535   */   */
536  const char *lscp_client_get_result ( lscp_client_t *pClient )  const char *lscp_client_get_result ( lscp_client_t *pClient )
537  {  {
538      if (pClient == NULL)          if (pClient == NULL)
539          return NULL;                  return NULL;
540    
541      return pClient->pszResult;          return pClient->pszResult;
542  }  }
543    
544    
# Line 552  const char *lscp_client_get_result ( lsc Line 552  const char *lscp_client_get_result ( lsc
552   */   */
553  int lscp_client_get_errno ( lscp_client_t *pClient )  int lscp_client_get_errno ( lscp_client_t *pClient )
554  {  {
555      if (pClient == NULL)          if (pClient == NULL)
556          return -1;                  return -1;
557    
558      return pClient->iErrno;          return pClient->iErrno;
559  }  }
560    
561    
# Line 574  int lscp_client_get_errno ( lscp_client_ Line 574  int lscp_client_get_errno ( lscp_client_
574   */   */
575  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 )
576  {  {
577      lscp_status_t ret = LSCP_FAILED;          lscp_status_t ret = LSCP_FAILED;
578    
579      if (pClient == NULL)          if (pClient == NULL)
580          return LSCP_FAILED;                  return LSCP_FAILED;
581    
582      // Lock this section up.          // Lock this section up.
583      lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
584    
585      // If applicable, start the alternate connection...          // If applicable, start the alternate connection...
586      if (pClient->events == LSCP_EVENT_NONE)          if (pClient->events == LSCP_EVENT_NONE)
587          ret = _lscp_client_evt_connect(pClient);                  ret = _lscp_client_evt_connect(pClient);
588    
589      // Send the subscription commands.          // Send the subscription commands.
590      if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_COUNT))          if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_COUNT))
591          ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_COUNT);                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_COUNT);
592      if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT))          if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT))
593          ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_VOICE_COUNT);                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_VOICE_COUNT);
594      if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT))          if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT))
595          ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_STREAM_COUNT);                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_STREAM_COUNT);
596      if (ret == LSCP_OK && (events & LSCP_EVENT_BUFFER_FILL))          if (ret == LSCP_OK && (events & LSCP_EVENT_BUFFER_FILL))
597          ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_BUFFER_FILL);                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_BUFFER_FILL);
598      if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))          if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))
599          ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_INFO);                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_INFO);
600      if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))          if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))
601          ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MISCELLANEOUS);                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MISCELLANEOUS);
602    
603      // Unlock this section down.          // Unlock this section down.
604      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
605    
606      return ret;          return ret;
607  }  }
608    
609    
# Line 619  lscp_status_t lscp_client_subscribe ( ls Line 619  lscp_status_t lscp_client_subscribe ( ls
619   */   */
620  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 )
621  {  {
622      lscp_status_t ret = LSCP_OK;          lscp_status_t ret = LSCP_OK;
623    
624      if (pClient == NULL)          if (pClient == NULL)
625          return LSCP_FAILED;                  return LSCP_FAILED;
626    
627      // Lock this section up.          // Lock this section up.
628      lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
629    
630      // Send the unsubscription commands.          // Send the unsubscription commands.
631      if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_COUNT))          if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_COUNT))
632          ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_COUNT);                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_COUNT);
633      if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT))          if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT))
634          ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_VOICE_COUNT);                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_VOICE_COUNT);
635      if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT))          if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT))
636          ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_STREAM_COUNT);                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_STREAM_COUNT);
637      if (ret == LSCP_OK && (events & LSCP_EVENT_BUFFER_FILL))          if (ret == LSCP_OK && (events & LSCP_EVENT_BUFFER_FILL))
638          ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_BUFFER_FILL);                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_BUFFER_FILL);
639      if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))          if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))
640          ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_INFO);                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_INFO);
641      if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))          if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))
642          ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MISCELLANEOUS);                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MISCELLANEOUS);
643    
644      // If necessary, close the alternate connection...          // If necessary, close the alternate connection...
645      if (pClient->events == LSCP_EVENT_NONE)          if (pClient->events == LSCP_EVENT_NONE)
646          lscp_socket_agent_free(&(pClient->evt));                  lscp_socket_agent_free(&(pClient->evt));
647    
648      // Unlock this section down.          // Unlock this section down.
649      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
650    
651      return ret;          return ret;
652  }  }
653    
654    
# Line 661  lscp_status_t lscp_client_unsubscribe ( Line 661  lscp_status_t lscp_client_unsubscribe (
661   */   */
662  lscp_event_t lscp_client_get_events ( lscp_client_t *pClient )  lscp_event_t lscp_client_get_events ( lscp_client_t *pClient )
663  {  {
664      if (pClient == NULL)          if (pClient == NULL)
665          return LSCP_EVENT_NONE;                  return LSCP_EVENT_NONE;
666    
667      return pClient->events;          return pClient->events;
668  }  }
669    
670    
# Line 684  lscp_event_t lscp_client_get_events ( ls Line 684  lscp_event_t lscp_client_get_events ( ls
684   */   */
685  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 )
686  {  {
687      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
688    
689      if (pszFileName == NULL || iSamplerChannel < 0)          if (pszFileName == NULL || iSamplerChannel < 0)
690          return LSCP_FAILED;                  return LSCP_FAILED;
691    
692      sprintf(szQuery, "LOAD INSTRUMENT '%s' %d %d\r\n", pszFileName, iInstrIndex, iSamplerChannel);          sprintf(szQuery, "LOAD INSTRUMENT '%s' %d %d\r\n", pszFileName, iInstrIndex, iSamplerChannel);
693      return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
694  }  }
695    
696    
# Line 707  lscp_status_t lscp_load_instrument ( lsc Line 707  lscp_status_t lscp_load_instrument ( lsc
707   */   */
708  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 )
709  {  {
710      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
711    
712      if (pszFileName == NULL || iSamplerChannel < 0)          if (pszFileName == NULL || iSamplerChannel < 0)
713          return LSCP_FAILED;                  return LSCP_FAILED;
714    
715      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);
716      return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
717  }  }
718    
719    
# Line 729  lscp_status_t lscp_load_instrument_non_m Line 729  lscp_status_t lscp_load_instrument_non_m
729   */   */
730  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 )
731  {  {
732      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
733    
734      if (pszEngineName == NULL || iSamplerChannel < 0)          if (pszEngineName == NULL || iSamplerChannel < 0)
735          return LSCP_FAILED;                  return LSCP_FAILED;
736    
737      sprintf(szQuery, "LOAD ENGINE %s %d\r\n", pszEngineName, iSamplerChannel);          sprintf(szQuery, "LOAD ENGINE %s %d\r\n", pszEngineName, iSamplerChannel);
738      return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
739  }  }
740    
741    
# Line 750  lscp_status_t lscp_load_engine ( lscp_cl Line 750  lscp_status_t lscp_load_engine ( lscp_cl
750   */   */
751  int lscp_get_channels ( lscp_client_t *pClient )  int lscp_get_channels ( lscp_client_t *pClient )
752  {  {
753      int iChannels = -1;          int iChannels = -1;
754    
755      // Lock this section up.          // Lock this section up.
756      lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
757    
758      if (lscp_client_call(pClient, "GET CHANNELS\r\n", 0) == LSCP_OK)          if (lscp_client_call(pClient, "GET CHANNELS\r\n", 0) == LSCP_OK)
759          iChannels = atoi(lscp_client_get_result(pClient));                  iChannels = atoi(lscp_client_get_result(pClient));
760    
761      // Unlock this section doen.          // Unlock this section doen.
762      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
763    
764      return iChannels;          return iChannels;
765  }  }
766    
767    
# Line 776  int lscp_get_channels ( lscp_client_t *p Line 776  int lscp_get_channels ( lscp_client_t *p
776   */   */
777  int *lscp_list_channels ( lscp_client_t *pClient )  int *lscp_list_channels ( lscp_client_t *pClient )
778  {  {
779      const char *pszSeps = ",";          const char *pszSeps = ",";
780    
781      if (pClient == NULL)          if (pClient == NULL)
782          return NULL;                  return NULL;
783    
784      // Lock this section up.          // Lock this section up.
785      lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
786    
787      if (pClient->channels) {          if (pClient->channels) {
788          lscp_isplit_destroy(pClient->channels);                  lscp_isplit_destroy(pClient->channels);
789          pClient->channels = NULL;                  pClient->channels = NULL;
790      }          }
791    
792      if (lscp_client_call(pClient, "LIST CHANNELS\r\n", 0) == LSCP_OK)          if (lscp_client_call(pClient, "LIST CHANNELS\r\n", 0) == LSCP_OK)
793          pClient->channels = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps);                  pClient->channels = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps);
794    
795      // Unlock this section down.          // Unlock this section down.
796      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
797    
798      return pClient->channels;          return pClient->channels;
799  }  }
800    
801    
# Line 810  int *lscp_list_channels ( lscp_client_t Line 810  int *lscp_list_channels ( lscp_client_t
810   */   */
811  int lscp_add_channel ( lscp_client_t *pClient )  int lscp_add_channel ( lscp_client_t *pClient )
812  {  {
813      int iSamplerChannel = -1;          int iSamplerChannel = -1;
814    
815      // Lock this section up.          // Lock this section up.
816      lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
817    
818      if (lscp_client_call(pClient, "ADD CHANNEL\r\n", 0) == LSCP_OK)          if (lscp_client_call(pClient, "ADD CHANNEL\r\n", 0) == LSCP_OK)
819          iSamplerChannel = atoi(lscp_client_get_result(pClient));                  iSamplerChannel = atoi(lscp_client_get_result(pClient));
820    
821      // Unlock this section down.          // Unlock this section down.
822      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
823    
824      return iSamplerChannel;          return iSamplerChannel;
825  }  }
826    
827    
# Line 836  int lscp_add_channel ( lscp_client_t *pC Line 836  int lscp_add_channel ( lscp_client_t *pC
836   */   */
837  lscp_status_t lscp_remove_channel ( lscp_client_t *pClient, int iSamplerChannel )  lscp_status_t lscp_remove_channel ( lscp_client_t *pClient, int iSamplerChannel )
838  {  {
839      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
840    
841      if (iSamplerChannel < 0)          if (iSamplerChannel < 0)
842          return LSCP_FAILED;                  return LSCP_FAILED;
843    
844      sprintf(szQuery, "REMOVE CHANNEL %d\r\n", iSamplerChannel);          sprintf(szQuery, "REMOVE CHANNEL %d\r\n", iSamplerChannel);
845      return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
846  }  }
847    
848    
# Line 857  lscp_status_t lscp_remove_channel ( lscp Line 857  lscp_status_t lscp_remove_channel ( lscp
857   */   */
858  int lscp_get_available_engines ( lscp_client_t *pClient )  int lscp_get_available_engines ( lscp_client_t *pClient )
859  {  {
860      int iAvailableEngines = -1;          int iAvailableEngines = -1;
861    
862      // Lock this section up.          // Lock this section up.
863      lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
864    
865      if (lscp_client_call(pClient, "GET AVAILABLE_ENGINES\r\n", 0) == LSCP_OK)          if (lscp_client_call(pClient, "GET AVAILABLE_ENGINES\r\n", 0) == LSCP_OK)
866          iAvailableEngines = atoi(lscp_client_get_result(pClient));                  iAvailableEngines = atoi(lscp_client_get_result(pClient));
867    
868      // Unlock this section down.          // Unlock this section down.
869      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
870    
871      return iAvailableEngines;          return iAvailableEngines;
872  }  }
873    
874    
# Line 883  int lscp_get_available_engines ( lscp_cl Line 883  int lscp_get_available_engines ( lscp_cl
883   */   */
884  const char **lscp_list_available_engines ( lscp_client_t *pClient )  const char **lscp_list_available_engines ( lscp_client_t *pClient )
885  {  {
886      const char *pszSeps = ",";          const char *pszSeps = ",";
887    
888      // Lock this section up.          // Lock this section up.
889      lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
890    
891      if (pClient->engines) {          if (pClient->engines) {
892          lscp_szsplit_destroy(pClient->engines);                  lscp_szsplit_destroy(pClient->engines);
893          pClient->engines = NULL;                  pClient->engines = NULL;
894      }          }
895    
896      if (lscp_client_call(pClient, "LIST AVAILABLE_ENGINES\r\n", 0) == LSCP_OK)          if (lscp_client_call(pClient, "LIST AVAILABLE_ENGINES\r\n", 0) == LSCP_OK)
897          pClient->engines = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps);                  pClient->engines = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps);
898    
899      // Unlock this section down.          // Unlock this section down.
900      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
901    
902      return (const char **) pClient->engines;          return (const char **) pClient->engines;
903  }  }
904    
905    
# Line 915  const char **lscp_list_available_engines Line 915  const char **lscp_list_available_engines
915   */   */
916  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 )
917  {  {
918      lscp_engine_info_t *pEngineInfo;          lscp_engine_info_t *pEngineInfo;
919      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
920      const char *pszResult;          const char *pszResult;
921      const char *pszSeps = ":";          const char *pszSeps = ":";
922      const char *pszCrlf = "\r\n";          const char *pszCrlf = "\r\n";
923      char *pszToken;          char *pszToken;
924      char *pch;          char *pch;
925    
926      if (pszEngineName == NULL)          if (pszEngineName == NULL)
927          return NULL;                  return NULL;
928    
929      // Lock this section up.          // Lock this section up.
930      lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
931    
932      pEngineInfo = &(pClient->engine_info);          pEngineInfo = &(pClient->engine_info);
933      lscp_engine_info_reset(pEngineInfo);          lscp_engine_info_reset(pEngineInfo);
934    
935      sprintf(szQuery, "GET ENGINE INFO %s\r\n", pszEngineName);          sprintf(szQuery, "GET ENGINE INFO %s\r\n", pszEngineName);
936      if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) {          if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) {
937          pszResult = lscp_client_get_result(pClient);                  pszResult = lscp_client_get_result(pClient);
938          pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));                  pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
939          while (pszToken) {                  while (pszToken) {
940              if (strcasecmp(pszToken, "DESCRIPTION") == 0) {                          if (strcasecmp(pszToken, "DESCRIPTION") == 0) {
941                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
942                  if (pszToken)                                  if (pszToken)
943                      lscp_unquote_dup(&(pEngineInfo->description), &pszToken);                                          lscp_unquote_dup(&(pEngineInfo->description), &pszToken);
944              }                          }
945              else if (strcasecmp(pszToken, "VERSION") == 0) {                          else if (strcasecmp(pszToken, "VERSION") == 0) {
946                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
947                  if (pszToken)                                  if (pszToken)
948                      lscp_unquote_dup(&(pEngineInfo->version), &pszToken);                                          lscp_unquote_dup(&(pEngineInfo->version), &pszToken);
949              }                          }
950              pszToken = lscp_strtok(NULL, pszSeps, &(pch));                          pszToken = lscp_strtok(NULL, pszSeps, &(pch));
951          }                  }
952      }          }
953      else pEngineInfo = NULL;          else pEngineInfo = NULL;
954    
955      // Unlock this section down.          // Unlock this section down.
956      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
957    
958      return pEngineInfo;          return pEngineInfo;
959  }  }
960    
961    
# Line 971  lscp_engine_info_t *lscp_get_engine_info Line 971  lscp_engine_info_t *lscp_get_engine_info
971   */   */
972  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 )
973  {  {
974      lscp_channel_info_t *pChannelInfo;          lscp_channel_info_t *pChannelInfo;
975      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
976      const char *pszResult;          const char *pszResult;
977      const char *pszSeps = ":";          const char *pszSeps = ":";
978      const char *pszCrlf = "\r\n";          const char *pszCrlf = "\r\n";
979      char *pszToken;          char *pszToken;
980      char *pch;          char *pch;
981    
982      if (iSamplerChannel < 0)          if (iSamplerChannel < 0)
983          return NULL;                  return NULL;
984    
985      // Lock this section up.          // Lock this section up.
986      lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
987    
988      pChannelInfo = &(pClient->channel_info);          pChannelInfo = &(pClient->channel_info);
989      lscp_channel_info_reset(pChannelInfo);          lscp_channel_info_reset(pChannelInfo);
990    
991      sprintf(szQuery, "GET CHANNEL INFO %d\r\n", iSamplerChannel);          sprintf(szQuery, "GET CHANNEL INFO %d\r\n", iSamplerChannel);
992      if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) {          if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) {
993          pszResult = lscp_client_get_result(pClient);                  pszResult = lscp_client_get_result(pClient);
994          pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));                  pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
995          while (pszToken) {                  while (pszToken) {
996              if (strcasecmp(pszToken, "ENGINE_NAME") == 0) {                          if (strcasecmp(pszToken, "ENGINE_NAME") == 0) {
997                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
998                  if (pszToken)                                  if (pszToken)
999                      lscp_unquote_dup(&(pChannelInfo->engine_name), &pszToken);                                          lscp_unquote_dup(&(pChannelInfo->engine_name), &pszToken);
1000              }                          }
1001              else if (strcasecmp(pszToken, "AUDIO_OUTPUT_DEVICE") == 0) {                          else if (strcasecmp(pszToken, "AUDIO_OUTPUT_DEVICE") == 0) {
1002                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1003                  if (pszToken)                                  if (pszToken)
1004                      pChannelInfo->audio_device = atoi(lscp_ltrim(pszToken));                                          pChannelInfo->audio_device = atoi(lscp_ltrim(pszToken));
1005              }                          }
1006              else if (strcasecmp(pszToken, "AUDIO_OUTPUT_CHANNELS") == 0) {                          else if (strcasecmp(pszToken, "AUDIO_OUTPUT_CHANNELS") == 0) {
1007                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1008                  if (pszToken)                                  if (pszToken)
1009                      pChannelInfo->audio_channels = atoi(lscp_ltrim(pszToken));                                          pChannelInfo->audio_channels = atoi(lscp_ltrim(pszToken));
1010              }                          }
1011              else if (strcasecmp(pszToken, "AUDIO_OUTPUT_ROUTING") == 0) {                          else if (strcasecmp(pszToken, "AUDIO_OUTPUT_ROUTING") == 0) {
1012                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1013                  if (pszToken) {                                  if (pszToken) {
1014                      if (pChannelInfo->audio_routing)                                          if (pChannelInfo->audio_routing)
1015                          lscp_szsplit_destroy(pChannelInfo->audio_routing);                                                  lscp_szsplit_destroy(pChannelInfo->audio_routing);
1016                      pChannelInfo->audio_routing = lscp_szsplit_create(pszToken, ",");                                          pChannelInfo->audio_routing = lscp_szsplit_create(pszToken, ",");
1017                  }                                  }
1018              }                          }
1019              else if (strcasecmp(pszToken, "INSTRUMENT_FILE") == 0) {                          else if (strcasecmp(pszToken, "INSTRUMENT_FILE") == 0) {
1020                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1021                  if (pszToken)                                  if (pszToken)
1022                      lscp_unquote_dup(&(pChannelInfo->instrument_file), &pszToken);                                          lscp_unquote_dup(&(pChannelInfo->instrument_file), &pszToken);
1023              }                          }
1024              else if (strcasecmp(pszToken, "INSTRUMENT_NR") == 0) {                          else if (strcasecmp(pszToken, "INSTRUMENT_NR") == 0) {
1025                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1026                  if (pszToken)                                  if (pszToken)
1027                      pChannelInfo->instrument_nr = atoi(lscp_ltrim(pszToken));                                          pChannelInfo->instrument_nr = atoi(lscp_ltrim(pszToken));
1028              }                          }
1029              else if (strcasecmp(pszToken, "INSTRUMENT_NAME") == 0) {                          else if (strcasecmp(pszToken, "INSTRUMENT_NAME") == 0) {
1030                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1031                  if (pszToken)                                  if (pszToken)
1032                      lscp_unquote_dup(&(pChannelInfo->instrument_name), &pszToken);                                          lscp_unquote_dup(&(pChannelInfo->instrument_name), &pszToken);
1033              }                          }
1034              else if (strcasecmp(pszToken, "INSTRUMENT_STATUS") == 0) {                          else if (strcasecmp(pszToken, "INSTRUMENT_STATUS") == 0) {
1035                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1036                  if (pszToken)                                  if (pszToken)
1037                      pChannelInfo->instrument_status = atoi(lscp_ltrim(pszToken));                                          pChannelInfo->instrument_status = atoi(lscp_ltrim(pszToken));
1038              }                          }
1039              else if (strcasecmp(pszToken, "MIDI_INPUT_DEVICE") == 0) {                          else if (strcasecmp(pszToken, "MIDI_INPUT_DEVICE") == 0) {
1040                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1041                  if (pszToken)                                  if (pszToken)
1042                      pChannelInfo->midi_device = atoi(lscp_ltrim(pszToken));                                          pChannelInfo->midi_device = atoi(lscp_ltrim(pszToken));
1043              }                          }
1044              else if (strcasecmp(pszToken, "MIDI_INPUT_PORT") == 0) {                          else if (strcasecmp(pszToken, "MIDI_INPUT_PORT") == 0) {
1045                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1046                  if (pszToken)                                  if (pszToken)
1047                      pChannelInfo->midi_port = atoi(lscp_ltrim(pszToken));                                          pChannelInfo->midi_port = atoi(lscp_ltrim(pszToken));
1048              }                          }
1049              else if (strcasecmp(pszToken, "MIDI_INPUT_CHANNEL") == 0) {                          else if (strcasecmp(pszToken, "MIDI_INPUT_CHANNEL") == 0) {
1050                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1051                  if (pszToken) {                                  if (pszToken) {
1052                      pszToken = lscp_ltrim(pszToken);                                          pszToken = lscp_ltrim(pszToken);
1053                      if (strcasecmp(pszToken, "ALL") == 0)                                          if (strcasecmp(pszToken, "ALL") == 0)
1054                          pChannelInfo->midi_channel = LSCP_MIDI_CHANNEL_ALL;                                                  pChannelInfo->midi_channel = LSCP_MIDI_CHANNEL_ALL;
1055                      else                                          else
1056                          pChannelInfo->midi_channel = atoi(pszToken);                                                  pChannelInfo->midi_channel = atoi(pszToken);
1057                  }                                  }
1058              }                          }
1059              else if (strcasecmp(pszToken, "VOLUME") == 0) {                          else if (strcasecmp(pszToken, "VOLUME") == 0) {
1060                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1061                  if (pszToken)                                  if (pszToken)
1062                      pChannelInfo->volume = (float) atof(lscp_ltrim(pszToken));                                          pChannelInfo->volume = (float) atof(lscp_ltrim(pszToken));
1063              }                          }
1064              else if (strcasecmp(pszToken, "MUTE") == 0) {                          else if (strcasecmp(pszToken, "MUTE") == 0) {
1065                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1066                  if (pszToken)                                  if (pszToken)
1067                      pChannelInfo->mute = (strcasecmp(lscp_unquote(&pszToken, 0), "TRUE") == 0);                                          pChannelInfo->mute = (strcasecmp(lscp_unquote(&pszToken, 0), "TRUE") == 0);
1068              }                          }
1069              else if (strcasecmp(pszToken, "SOLO") == 0) {                          else if (strcasecmp(pszToken, "SOLO") == 0) {
1070                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1071                  if (pszToken)                                  if (pszToken)
1072                      pChannelInfo->solo = (strcasecmp(lscp_unquote(&pszToken, 0), "TRUE") == 0);                                          pChannelInfo->solo = (strcasecmp(lscp_unquote(&pszToken, 0), "TRUE") == 0);
1073              }                          }
1074              pszToken = lscp_strtok(NULL, pszSeps, &(pch));                          pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1075          }                  }
1076      }          }
1077      else pChannelInfo = NULL;          else pChannelInfo = NULL;
1078    
1079      // Unlock this section up.          // Unlock this section up.
1080      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
1081    
1082      return pChannelInfo;          return pChannelInfo;
1083  }  }
1084    
1085    
# Line 1094  lscp_channel_info_t *lscp_get_channel_in Line 1094  lscp_channel_info_t *lscp_get_channel_in
1094   */   */
1095  int lscp_get_channel_voice_count ( lscp_client_t *pClient, int iSamplerChannel )  int lscp_get_channel_voice_count ( lscp_client_t *pClient, int iSamplerChannel )
1096  {  {
1097      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1098      int iVoiceCount = -1;          int iVoiceCount = -1;
1099    
1100      if (iSamplerChannel < 0)          if (iSamplerChannel < 0)
1101          return iVoiceCount;                  return iVoiceCount;
1102    
1103      // Lock this section up.          // Lock this section up.
1104      lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
1105    
1106      sprintf(szQuery, "GET CHANNEL VOICE_COUNT %d\r\n", iSamplerChannel);          sprintf(szQuery, "GET CHANNEL VOICE_COUNT %d\r\n", iSamplerChannel);
1107      if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)          if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
1108          iVoiceCount = atoi(lscp_client_get_result(pClient));                  iVoiceCount = atoi(lscp_client_get_result(pClient));
1109    
1110      // Unlock this section down.          // Unlock this section down.
1111      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
1112    
1113      return iVoiceCount;          return iVoiceCount;
1114  }  }
1115    
1116    
# Line 1125  int lscp_get_channel_voice_count ( lscp_ Line 1125  int lscp_get_channel_voice_count ( lscp_
1125   */   */
1126  int lscp_get_channel_stream_count ( lscp_client_t *pClient, int iSamplerChannel )  int lscp_get_channel_stream_count ( lscp_client_t *pClient, int iSamplerChannel )
1127  {  {
1128      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1129      int iStreamCount = -1;          int iStreamCount = -1;
1130    
1131      if (iSamplerChannel < 0)          if (iSamplerChannel < 0)
1132          return iStreamCount;                  return iStreamCount;
1133    
1134      // Lock this section up.          // Lock this section up.
1135      lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
1136    
1137      sprintf(szQuery, "GET CHANNEL STREAM_COUNT %d\r\n", iSamplerChannel);          sprintf(szQuery, "GET CHANNEL STREAM_COUNT %d\r\n", iSamplerChannel);
1138      if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)          if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
1139          iStreamCount = atoi(lscp_client_get_result(pClient));                  iStreamCount = atoi(lscp_client_get_result(pClient));
1140    
1141      // Unlock this section down.          // Unlock this section down.
1142      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
1143    
1144      return iStreamCount;          return iStreamCount;
1145  }  }
1146    
1147    
# Line 1156  int lscp_get_channel_stream_count ( lscp Line 1156  int lscp_get_channel_stream_count ( lscp
1156   */   */
1157  int lscp_get_channel_stream_usage ( lscp_client_t *pClient, int iSamplerChannel )  int lscp_get_channel_stream_usage ( lscp_client_t *pClient, int iSamplerChannel )
1158  {  {
1159      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1160      int  iStreamUsage = -1;          int  iStreamUsage = -1;
1161      const char *pszResult;          const char *pszResult;
1162      const char *pszSeps = "[]%,";          const char *pszSeps = "[]%,";
1163      char *pszToken;          char *pszToken;
1164      char *pch;          char *pch;
1165      int   iStream;          int   iStream;
1166      int   iPercent;          int   iPercent;
1167    
1168      if (iSamplerChannel < 0)          if (iSamplerChannel < 0)
1169          return iStreamUsage;                  return iStreamUsage;
1170    
1171      // Lock this section up.          // Lock this section up.
1172      lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
1173    
1174      iStream = 0;          iStream = 0;
1175      sprintf(szQuery, "GET CHANNEL BUFFER_FILL PERCENTAGE %d\r\n", iSamplerChannel);          sprintf(szQuery, "GET CHANNEL BUFFER_FILL PERCENTAGE %d\r\n", iSamplerChannel);
1176      if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK) {          if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK) {
1177          pszResult = lscp_client_get_result(pClient);                  pszResult = lscp_client_get_result(pClient);
1178          pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));                  pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
1179          while (pszToken) {                  while (pszToken) {
1180              if (*pszToken) {                          if (*pszToken) {
1181                  // Skip stream id.                                  // Skip stream id.
1182                  pszToken = lscp_strtok(NULL, pszSeps, &(pch));                                  pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1183                  if (pszToken == NULL)                                  if (pszToken == NULL)
1184                      break;                                          break;
1185                  // Get least buffer fill percentage.                                  // Get least buffer fill percentage.
1186                  iPercent = atol(pszToken);                                  iPercent = atol(pszToken);
1187                  if (iStreamUsage > iPercent || iStream == 0)                                  if (iStreamUsage > iPercent || iStream == 0)
1188                      iStreamUsage = iPercent;                                          iStreamUsage = iPercent;
1189                  iStream++;                                  iStream++;
1190              }                          }
1191              pszToken = lscp_strtok(NULL, pszSeps, &(pch));                          pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1192          }                  }
1193      }          }
1194    
1195      // Unlock this section down.          // Unlock this section down.
1196      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
1197    
1198      return iStreamUsage;          return iStreamUsage;
1199  }  }
1200    
1201    
# Line 1215  int lscp_get_channel_stream_usage ( lscp Line 1215  int lscp_get_channel_stream_usage ( lscp
1215   */   */
1216  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 )
1217  {  {
1218      lscp_buffer_fill_t *pBufferFill;          lscp_buffer_fill_t *pBufferFill;
1219      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1220      int iStreamCount;          int iStreamCount;
1221      const char *pszUsageType = (usage_type == LSCP_USAGE_BYTES ? "BYTES" : "PERCENTAGE");          const char *pszUsageType = (usage_type == LSCP_USAGE_BYTES ? "BYTES" : "PERCENTAGE");
1222      const char *pszResult;          const char *pszResult;
1223      const char *pszSeps = "[]%,";          const char *pszSeps = "[]%,";
1224      char *pszToken;          char *pszToken;
1225      char *pch;          char *pch;
1226      int   iStream;          int   iStream;
1227    
1228      // Retrieve a channel stream estimation.          // Retrieve a channel stream estimation.
1229      iStreamCount = lscp_get_channel_stream_count(pClient, iSamplerChannel);          iStreamCount = lscp_get_channel_stream_count(pClient, iSamplerChannel);
1230      if (pClient->iStreamCount < 0)          if (pClient->iStreamCount < 0)
1231          return NULL;                  return NULL;
1232    
1233      // Lock this section up.          // Lock this section up.
1234      lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
1235    
1236      // Check if we need to reallocate the stream usage array.          // Check if we need to reallocate the stream usage array.
1237      if (pClient->iStreamCount != iStreamCount) {          if (pClient->iStreamCount != iStreamCount) {
1238          if (pClient->buffer_fill)                  if (pClient->buffer_fill)
1239              free(pClient->buffer_fill);                          free(pClient->buffer_fill);
1240          if (iStreamCount > 0)                  if (iStreamCount > 0)
1241              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));
1242          else                  else
1243              pClient->buffer_fill = NULL;                          pClient->buffer_fill = NULL;
1244          pClient->iStreamCount = iStreamCount;                  pClient->iStreamCount = iStreamCount;
1245      }          }
1246    
1247      // Get buffer fill usage...          // Get buffer fill usage...
1248      pBufferFill = pClient->buffer_fill;          pBufferFill = pClient->buffer_fill;
1249      if (pBufferFill && iStreamCount > 0) {          if (pBufferFill && iStreamCount > 0) {
1250          iStream = 0;                  iStream = 0;
1251          pBufferFill = pClient->buffer_fill;                  pBufferFill = pClient->buffer_fill;
1252          sprintf(szQuery, "GET CHANNEL BUFFER_FILL %s %d\r\n", pszUsageType, iSamplerChannel);                  sprintf(szQuery, "GET CHANNEL BUFFER_FILL %s %d\r\n", pszUsageType, iSamplerChannel);
1253          if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK) {                  if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK) {
1254              pszResult = lscp_client_get_result(pClient);                          pszResult = lscp_client_get_result(pClient);
1255              pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));                          pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
1256              while (pszToken && iStream < pClient->iStreamCount) {                          while (pszToken && iStream < pClient->iStreamCount) {
1257                  if (*pszToken) {                                  if (*pszToken) {
1258                      pBufferFill[iStream].stream_id = atol(pszToken);                                          pBufferFill[iStream].stream_id = atol(pszToken);
1259                      pszToken = lscp_strtok(NULL, pszSeps, &(pch));                                          pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1260                      if (pszToken == NULL)                                          if (pszToken == NULL)
1261                          break;                                                  break;
1262                      pBufferFill[iStream].stream_usage = atol(pszToken);                                          pBufferFill[iStream].stream_usage = atol(pszToken);
1263                      iStream++;                                          iStream++;
1264                  }                                  }
1265                  pszToken = lscp_strtok(NULL, pszSeps, &(pch));                                  pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1266              }                          }
1267          }   // Reset the usage, whatever it was before.                  }   // Reset the usage, whatever it was before.
1268          else while (iStream < pClient->iStreamCount)                  else while (iStream < pClient->iStreamCount)
1269              pBufferFill[iStream++].stream_usage = 0;                          pBufferFill[iStream++].stream_usage = 0;
1270      }          }
1271    
1272      // Unlock this section down.          // Unlock this section down.
1273      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
1274    
1275      return pBufferFill;          return pBufferFill;
1276  }  }
1277    
1278    
# Line 1288  lscp_buffer_fill_t *lscp_get_channel_buf Line 1288  lscp_buffer_fill_t *lscp_get_channel_buf
1288   */   */
1289  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 )
1290  {  {
1291      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1292    
1293      if (iSamplerChannel < 0 || pszAudioDriver == NULL)          if (iSamplerChannel < 0 || pszAudioDriver == NULL)
1294          return LSCP_FAILED;                  return LSCP_FAILED;
1295    
1296      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);
1297      return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
1298  }  }
1299    
1300    
# Line 1310  lscp_status_t lscp_set_channel_audio_typ Line 1310  lscp_status_t lscp_set_channel_audio_typ
1310   */   */
1311  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 )
1312  {  {
1313      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1314    
1315      if (iSamplerChannel < 0 || iAudioDevice < 0)          if (iSamplerChannel < 0 || iAudioDevice < 0)
1316          return LSCP_FAILED;                  return LSCP_FAILED;
1317    
1318      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);
1319      return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
1320  }  }
1321    
1322    
# Line 1333  lscp_status_t lscp_set_channel_audio_dev Line 1333  lscp_status_t lscp_set_channel_audio_dev
1333   */   */
1334  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 )
1335  {  {
1336      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1337    
1338      if (iSamplerChannel < 0 || iAudioOut < 0 || iAudioIn < 0)          if (iSamplerChannel < 0 || iAudioOut < 0 || iAudioIn < 0)
1339          return LSCP_FAILED;                  return LSCP_FAILED;
1340    
1341      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);
1342      return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
1343  }  }
1344    
1345    
# Line 1355  lscp_status_t lscp_set_channel_audio_cha Line 1355  lscp_status_t lscp_set_channel_audio_cha
1355   */   */
1356  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 )
1357  {  {
1358      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1359    
1360      if (iSamplerChannel < 0 || pszMidiDriver == NULL)          if (iSamplerChannel < 0 || pszMidiDriver == NULL)
1361          return LSCP_FAILED;                  return LSCP_FAILED;
1362    
1363      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);
1364      return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
1365  }  }
1366    
1367    
# Line 1377  lscp_status_t lscp_set_channel_midi_type Line 1377  lscp_status_t lscp_set_channel_midi_type
1377   */   */
1378  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 )
1379  {  {
1380      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1381    
1382      if (iSamplerChannel < 0 || iMidiDevice < 0)          if (iSamplerChannel < 0 || iMidiDevice < 0)
1383          return LSCP_FAILED;                  return LSCP_FAILED;
1384    
1385      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);
1386      return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
1387  }  }
1388    
1389    
# Line 1399  lscp_status_t lscp_set_channel_midi_devi Line 1399  lscp_status_t lscp_set_channel_midi_devi
1399   */   */
1400  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 )
1401  {  {
1402      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1403    
1404      if (iSamplerChannel < 0 || iMidiPort < 0)          if (iSamplerChannel < 0 || iMidiPort < 0)
1405          return LSCP_FAILED;                  return LSCP_FAILED;
1406    
1407      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);
1408      return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
1409  }  }
1410    
1411    
# Line 1422  lscp_status_t lscp_set_channel_midi_port Line 1422  lscp_status_t lscp_set_channel_midi_port
1422   */   */
1423  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 )
1424  {  {
1425      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1426    
1427      if (iSamplerChannel < 0 || iMidiChannel < 0 || iMidiChannel > 16)          if (iSamplerChannel < 0 || iMidiChannel < 0 || iMidiChannel > 16)
1428          return LSCP_FAILED;                  return LSCP_FAILED;
1429    
1430      if (iMidiChannel == LSCP_MIDI_CHANNEL_ALL)          if (iMidiChannel == LSCP_MIDI_CHANNEL_ALL)
1431          sprintf(szQuery, "SET CHANNEL MIDI_INPUT_CHANNEL %d ALL\r\n", iSamplerChannel);                  sprintf(szQuery, "SET CHANNEL MIDI_INPUT_CHANNEL %d ALL\r\n", iSamplerChannel);
1432      else          else
1433          sprintf(szQuery, "SET CHANNEL MIDI_INPUT_CHANNEL %d %d\r\n", iSamplerChannel, iMidiChannel);                  sprintf(szQuery, "SET CHANNEL MIDI_INPUT_CHANNEL %d %d\r\n", iSamplerChannel, iMidiChannel);
1434      return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
1435  }  }
1436    
1437    
# Line 1449  lscp_status_t lscp_set_channel_midi_chan Line 1449  lscp_status_t lscp_set_channel_midi_chan
1449   */   */
1450  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 )
1451  {  {
1452      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1453    
1454      if (iSamplerChannel < 0 || fVolume < 0.0)          if (iSamplerChannel < 0 || fVolume < 0.0)
1455          return LSCP_FAILED;                  return LSCP_FAILED;
1456    
1457      sprintf(szQuery, "SET CHANNEL VOLUME %d %g\r\n", iSamplerChannel, fVolume);          sprintf(szQuery, "SET CHANNEL VOLUME %d %g\r\n", iSamplerChannel, fVolume);
1458      return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
1459  }  }
1460    
1461    
# Line 1473  lscp_status_t lscp_set_channel_volume ( Line 1473  lscp_status_t lscp_set_channel_volume (
1473   */   */
1474  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 )
1475  {  {
1476      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1477    
1478      if (iSamplerChannel < 0 || iMute < 0 || iMute > 1)          if (iSamplerChannel < 0 || iMute < 0 || iMute > 1)
1479          return LSCP_FAILED;                  return LSCP_FAILED;
1480    
1481      sprintf(szQuery, "SET CHANNEL MUTE %d %d\r\n", iSamplerChannel, iMute);          sprintf(szQuery, "SET CHANNEL MUTE %d %d\r\n", iSamplerChannel, iMute);
1482      return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
1483  }  }
1484    
1485    
# Line 1497  lscp_status_t lscp_set_channel_mute ( ls Line 1497  lscp_status_t lscp_set_channel_mute ( ls
1497   */   */
1498  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 )
1499  {  {
1500      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1501    
1502      if (iSamplerChannel < 0 || iSolo < 0 || iSolo > 1)          if (iSamplerChannel < 0 || iSolo < 0 || iSolo > 1)
1503          return LSCP_FAILED;                  return LSCP_FAILED;
1504    
1505      sprintf(szQuery, "SET CHANNEL SOLO %d %d\r\n", iSamplerChannel, iSolo);          sprintf(szQuery, "SET CHANNEL SOLO %d %d\r\n", iSamplerChannel, iSolo);
1506      return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
1507  }  }
1508    
1509    
# Line 1518  lscp_status_t lscp_set_channel_solo ( ls Line 1518  lscp_status_t lscp_set_channel_solo ( ls
1518   */   */
1519  lscp_status_t lscp_reset_channel ( lscp_client_t *pClient, int iSamplerChannel )  lscp_status_t lscp_reset_channel ( lscp_client_t *pClient, int iSamplerChannel )
1520  {  {
1521      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1522    
1523      if (iSamplerChannel < 0)          if (iSamplerChannel < 0)
1524          return LSCP_FAILED;                  return LSCP_FAILED;
1525    
1526      sprintf(szQuery, "RESET CHANNEL %d\r\n", iSamplerChannel);          sprintf(szQuery, "RESET CHANNEL %d\r\n", iSamplerChannel);
1527      return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
1528  }  }
1529    
1530    
# Line 1538  lscp_status_t lscp_reset_channel ( lscp_ Line 1538  lscp_status_t lscp_reset_channel ( lscp_
1538   */   */
1539  lscp_status_t lscp_reset_sampler ( lscp_client_t *pClient )  lscp_status_t lscp_reset_sampler ( lscp_client_t *pClient )
1540  {  {
1541      return lscp_client_query(pClient, "RESET\r\n");          return lscp_client_query(pClient, "RESET\r\n");
1542  }  }
1543    
1544    
# Line 1553  lscp_status_t lscp_reset_sampler ( lscp_ Line 1553  lscp_status_t lscp_reset_sampler ( lscp_
1553   */   */
1554  lscp_server_info_t *lscp_get_server_info ( lscp_client_t *pClient )  lscp_server_info_t *lscp_get_server_info ( lscp_client_t *pClient )
1555  {  {
1556      lscp_server_info_t *pServerInfo;          lscp_server_info_t *pServerInfo;
1557      const char *pszResult;          const char *pszResult;
1558      const char *pszSeps = ":";          const char *pszSeps = ":";
1559      const char *pszCrlf = "\r\n";          const char *pszCrlf = "\r\n";
1560      char *pszToken;          char *pszToken;
1561      char *pch;          char *pch;
1562    
1563      // Lock this section up.          // Lock this section up.
1564      lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
1565    
1566      pServerInfo = &(pClient->server_info);          pServerInfo = &(pClient->server_info);
1567      lscp_server_info_reset(pServerInfo);          lscp_server_info_reset(pServerInfo);
1568    
1569      if (lscp_client_call(pClient, "GET SERVER INFO\r\n", 1) == LSCP_OK) {          if (lscp_client_call(pClient, "GET SERVER INFO\r\n", 1) == LSCP_OK) {
1570          pszResult = lscp_client_get_result(pClient);                  pszResult = lscp_client_get_result(pClient);
1571          pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));                  pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
1572          while (pszToken) {                  while (pszToken) {
1573              if (strcasecmp(pszToken, "DESCRIPTION") == 0) {                          if (strcasecmp(pszToken, "DESCRIPTION") == 0) {
1574                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1575                  if (pszToken)                                  if (pszToken)
1576                      lscp_unquote_dup(&(pServerInfo->description), &pszToken);                                          lscp_unquote_dup(&(pServerInfo->description), &pszToken);
1577              }                          }
1578              else if (strcasecmp(pszToken, "VERSION") == 0) {                          else if (strcasecmp(pszToken, "VERSION") == 0) {
1579                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1580                  if (pszToken)                                  if (pszToken)
1581                      lscp_unquote_dup(&(pServerInfo->version), &pszToken);                                          lscp_unquote_dup(&(pServerInfo->version), &pszToken);
1582              }                          }
1583              pszToken = lscp_strtok(NULL, pszSeps, &(pch));                          pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1584          }                  }
1585      }          }
1586      else pServerInfo = NULL;          else pServerInfo = NULL;
1587    
1588      // Unlock this section down.          // Unlock this section down.
1589      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
1590    
1591      return pServerInfo;          return pServerInfo;
1592  }  }
1593    
1594    
# Line 1603  lscp_server_info_t *lscp_get_server_info Line 1603  lscp_server_info_t *lscp_get_server_info
1603   */   */
1604  int lscp_get_total_voice_count ( lscp_client_t *pClient )  int lscp_get_total_voice_count ( lscp_client_t *pClient )
1605  {  {
1606      int iVoiceCount = -1;          int iVoiceCount = -1;
1607    
1608      // Lock this section up.          // Lock this section up.
1609      lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
1610    
1611      if (lscp_client_call(pClient, "GET TOTAL_VOICE_COUNT\r\n", 0) == LSCP_OK)          if (lscp_client_call(pClient, "GET TOTAL_VOICE_COUNT\r\n", 0) == LSCP_OK)
1612          iVoiceCount = atoi(lscp_client_get_result(pClient));                  iVoiceCount = atoi(lscp_client_get_result(pClient));
1613    
1614      // Unlock this section down.          // Unlock this section down.
1615      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
1616    
1617      return iVoiceCount;          return iVoiceCount;
1618  }  }
1619    
1620    
# Line 1629  int lscp_get_total_voice_count ( lscp_cl Line 1629  int lscp_get_total_voice_count ( lscp_cl
1629   */   */
1630  int lscp_get_total_voice_count_max ( lscp_client_t *pClient )  int lscp_get_total_voice_count_max ( lscp_client_t *pClient )
1631  {  {
1632      int iVoiceCount = -1;          int iVoiceCount = -1;
1633    
1634      // Lock this section up.          // Lock this section up.
1635      lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
1636    
1637      if (lscp_client_call(pClient, "GET TOTAL_VOICE_COUNT_MAX\r\n", 0) == LSCP_OK)          if (lscp_client_call(pClient, "GET TOTAL_VOICE_COUNT_MAX\r\n", 0) == LSCP_OK)
1638          iVoiceCount = atoi(lscp_client_get_result(pClient));                  iVoiceCount = atoi(lscp_client_get_result(pClient));
1639    
1640      // Unlock this section down.          // Unlock this section down.
1641      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
1642    
1643      return iVoiceCount;          return iVoiceCount;
1644  }  }
1645    
1646    
# Line 1669  int lscp_get_total_voice_count_max ( lsc Line 1669  int lscp_get_total_voice_count_max ( lsc
1669   */   */
1670  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 )  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 )
1671  {  {
1672      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1673                
1674      if (pMidiInstr->bank_msb < 0 || pMidiInstr->bank_msb > 127)          if (pMidiInstr->bank_msb < 0 || pMidiInstr->bank_msb > 127)
1675          return LSCP_FAILED;                  return LSCP_FAILED;
1676      if (pMidiInstr->bank_lsb < 0 || pMidiInstr->bank_lsb > 127)          if (pMidiInstr->bank_lsb < 0 || pMidiInstr->bank_lsb > 127)
1677          return LSCP_FAILED;                  return LSCP_FAILED;
1678      if (pMidiInstr->program < 0 || pMidiInstr->program > 127)          if (pMidiInstr->program < 0 || pMidiInstr->program > 127)
1679          return LSCP_FAILED;                  return LSCP_FAILED;
1680      if (pszEngineName == NULL || pszFileName == NULL)          if (pszEngineName == NULL || pszFileName == NULL)
1681          return LSCP_FAILED;                  return LSCP_FAILED;
1682                
1683      if (fVolume < 0.0f)          if (fVolume < 0.0f)
1684          fVolume = 1.0f;                  fVolume = 1.0f;
1685                
1686      sprintf(szQuery, "MAP MIDI_INSTRUMENT %d %d %d %s '%s' %d %g",          sprintf(szQuery, "MAP MIDI_INSTRUMENT %d %d %d %s '%s' %d %g",
1687          pMidiInstr->bank_msb, pMidiInstr->bank_lsb, pMidiInstr->program,                  pMidiInstr->bank_msb, pMidiInstr->bank_lsb, pMidiInstr->program,
1688          pszEngineName, pszFileName, iInstrIndex, fVolume);                  pszEngineName, pszFileName, iInstrIndex, fVolume);
1689                
1690      switch (load_mode) {          switch (load_mode) {
1691      case LSCP_LOAD_PERSISTENT:          case LSCP_LOAD_PERSISTENT:
1692          strcat(szQuery, " PERSISTENT");                  strcat(szQuery, " PERSISTENT");
1693          break;                  break;
1694      case LSCP_LOAD_ON_DEMAND_HOLD:          case LSCP_LOAD_ON_DEMAND_HOLD:
1695          strcat(szQuery, " ON_DEMAND_HOLD");                  strcat(szQuery, " ON_DEMAND_HOLD");
1696          break;                  break;
1697      case LSCP_LOAD_ON_DEMAND:          case LSCP_LOAD_ON_DEMAND:
1698          strcat(szQuery, " ON_DEMAND_HOLD");                  strcat(szQuery, " ON_DEMAND_HOLD");
1699          break;                  break;
1700      case LSCP_LOAD_DEFAULT:          case LSCP_LOAD_DEFAULT:
1701      default:          default:
1702          break;                  break;
1703      }          }
1704                
1705      if (pszName)          if (pszName)
1706          sprintf(szQuery + strlen(szQuery), " '%s'", pszName);                  sprintf(szQuery + strlen(szQuery), " '%s'", pszName);
1707                
1708      strcat(szQuery, "\r\n");          strcat(szQuery, "\r\n");
1709                
1710      return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
1711  }  }
1712    
1713    
# Line 1722  lscp_status_t lscp_map_midi_instrument ( Line 1722  lscp_status_t lscp_map_midi_instrument (
1722   */   */
1723  lscp_status_t lscp_unmap_midi_instrument ( lscp_client_t *pClient, lscp_midi_instrument_t *pMidiInstr )  lscp_status_t lscp_unmap_midi_instrument ( lscp_client_t *pClient, lscp_midi_instrument_t *pMidiInstr )
1724  {  {
1725      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1726    
1727      if (pMidiInstr->bank_msb < 0 || pMidiInstr->bank_msb > 127)          if (pMidiInstr->bank_msb < 0 || pMidiInstr->bank_msb > 127)
1728          return LSCP_FAILED;                  return LSCP_FAILED;
1729      if (pMidiInstr->bank_lsb < 0 || pMidiInstr->bank_lsb > 127)          if (pMidiInstr->bank_lsb < 0 || pMidiInstr->bank_lsb > 127)
1730          return LSCP_FAILED;                  return LSCP_FAILED;
1731      if (pMidiInstr->program < 0 || pMidiInstr->program > 127)          if (pMidiInstr->program < 0 || pMidiInstr->program > 127)
1732          return LSCP_FAILED;                  return LSCP_FAILED;
1733    
1734      sprintf(szQuery, "UNMAP MIDI_INSTRUMENT %d %d %d\r\n",          sprintf(szQuery, "UNMAP MIDI_INSTRUMENT %d %d %d\r\n",
1735                  pMidiInstr->bank_msb, pMidiInstr->bank_lsb, pMidiInstr->program);                  pMidiInstr->bank_msb, pMidiInstr->bank_lsb, pMidiInstr->program);
1736    
1737      return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
1738  }  }
1739    
1740    
# Line 1749  lscp_status_t lscp_unmap_midi_instrument Line 1749  lscp_status_t lscp_unmap_midi_instrument
1749   */   */
1750  int lscp_get_midi_instruments ( lscp_client_t *pClient )  int lscp_get_midi_instruments ( lscp_client_t *pClient )
1751  {  {
1752      int iInstruments = -1;          int iInstruments = -1;
1753    
1754      // Lock this section up.          // Lock this section up.
1755      lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
1756    
1757      if (lscp_client_call(pClient, "GET MIDI_INSTRUMENTS\r\n", 0) == LSCP_OK)          if (lscp_client_call(pClient, "GET MIDI_INSTRUMENTS\r\n", 0) == LSCP_OK)
1758          iInstruments = atoi(lscp_client_get_result(pClient));                  iInstruments = atoi(lscp_client_get_result(pClient));
1759    
1760      // Unlock this section down.          // Unlock this section down.
1761      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
1762    
1763      return iInstruments;          return iInstruments;
1764  }  }
1765    
1766    
# Line 1775  int lscp_get_midi_instruments ( lscp_cli Line 1775  int lscp_get_midi_instruments ( lscp_cli
1775   */   */
1776  lscp_midi_instrument_t *lscp_list_midi_instruments ( lscp_client_t *pClient )  lscp_midi_instrument_t *lscp_list_midi_instruments ( lscp_client_t *pClient )
1777  {  {
1778      if (pClient == NULL)          if (pClient == NULL)
1779          return NULL;                  return NULL;
1780    
1781      // Lock this section up.          // Lock this section up.
1782      lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
1783    
1784      if (pClient->midi_instruments) {          if (pClient->midi_instruments) {
1785          lscp_midi_instruments_destroy(pClient->midi_instruments);                  lscp_midi_instruments_destroy(pClient->midi_instruments);
1786          pClient->midi_instruments = NULL;                  pClient->midi_instruments = NULL;
1787      }          }
1788    
1789      if (lscp_client_call(pClient, "LIST MIDI_INSTRUMENTS\r\n", 0) == LSCP_OK)          if (lscp_client_call(pClient, "LIST MIDI_INSTRUMENTS\r\n", 0) == LSCP_OK)
1790          pClient->midi_instruments = lscp_midi_instruments_create(lscp_client_get_result(pClient));                  pClient->midi_instruments = lscp_midi_instruments_create(lscp_client_get_result(pClient));
1791    
1792      // Unlock this section down.          // Unlock this section down.
1793      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
1794    
1795      return pClient->midi_instruments;          return pClient->midi_instruments;
1796  }  }
1797    
1798    
# Line 1809  lscp_midi_instrument_t *lscp_list_midi_i Line 1809  lscp_midi_instrument_t *lscp_list_midi_i
1809   */   */
1810  lscp_midi_instrument_info_t *lscp_get_midi_instrument_info ( lscp_client_t *pClient, lscp_midi_instrument_t *pMidiInstr )  lscp_midi_instrument_info_t *lscp_get_midi_instrument_info ( lscp_client_t *pClient, lscp_midi_instrument_t *pMidiInstr )
1811  {  {
1812      lscp_midi_instrument_info_t *pInstrInfo;          lscp_midi_instrument_info_t *pInstrInfo;
1813      char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1814      const char *pszResult;          const char *pszResult;
1815      const char *pszSeps = ":";          const char *pszSeps = ":";
1816      const char *pszCrlf = "\r\n";          const char *pszCrlf = "\r\n";
1817      char *pszToken;          char *pszToken;
1818      char *pch;          char *pch;
1819                
1820      if (pMidiInstr->bank_msb < 0 || pMidiInstr->bank_msb > 127)          if (pMidiInstr->bank_msb < 0 || pMidiInstr->bank_msb > 127)
1821          return NULL;                  return NULL;
1822      if (pMidiInstr->bank_lsb < 0 || pMidiInstr->bank_lsb > 127)          if (pMidiInstr->bank_lsb < 0 || pMidiInstr->bank_lsb > 127)
1823          return NULL;                  return NULL;
1824      if (pMidiInstr->program < 0 || pMidiInstr->program > 127)          if (pMidiInstr->program < 0 || pMidiInstr->program > 127)
1825          return NULL;                  return NULL;
1826                
1827      // Lock this section up.          // Lock this section up.
1828      lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
1829                
1830      pInstrInfo = &(pClient->midi_instrument_info);          pInstrInfo = &(pClient->midi_instrument_info);
1831      lscp_midi_instrument_info_reset(pInstrInfo);          lscp_midi_instrument_info_reset(pInstrInfo);
1832                
1833      sprintf(szQuery, "GET MIDI_INSTRUMENT INFO %d %d %d\r\n",          sprintf(szQuery, "GET MIDI_INSTRUMENT INFO %d %d %d\r\n",
1834          pMidiInstr->bank_msb, pMidiInstr->bank_lsb, pMidiInstr->program);                  pMidiInstr->bank_msb, pMidiInstr->bank_lsb, pMidiInstr->program);
1835      if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) {          if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) {
1836          pszResult = lscp_client_get_result(pClient);                  pszResult = lscp_client_get_result(pClient);
1837          pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));                  pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
1838          while (pszToken) {                  while (pszToken) {
1839              if (strcasecmp(pszToken, "NAME") == 0) {                          if (strcasecmp(pszToken, "NAME") == 0) {
1840                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1841                  if (pszToken)                                  if (pszToken)
1842                      lscp_unquote_dup(&(pInstrInfo->name), &pszToken);                                          lscp_unquote_dup(&(pInstrInfo->name), &pszToken);
1843              }                          }
1844              else if (strcasecmp(pszToken, "ENGINE_NAME") == 0) {                          else if (strcasecmp(pszToken, "ENGINE_NAME") == 0) {
1845                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1846                  if (pszToken)                                  if (pszToken)
1847                      lscp_unquote_dup(&(pInstrInfo->engine_name), &pszToken);                                          lscp_unquote_dup(&(pInstrInfo->engine_name), &pszToken);
1848              }                          }
1849              else if (strcasecmp(pszToken, "INSTRUMENT_FILE") == 0) {                          else if (strcasecmp(pszToken, "INSTRUMENT_FILE") == 0) {
1850                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1851                  if (pszToken)                                  if (pszToken)
1852                      lscp_unquote_dup(&(pInstrInfo->instrument_file), &pszToken);                                          lscp_unquote_dup(&(pInstrInfo->instrument_file), &pszToken);
1853              }                          }
1854              else if (strcasecmp(pszToken, "INSTRUMENT_NR") == 0) {                          else if (strcasecmp(pszToken, "INSTRUMENT_NR") == 0) {
1855                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1856                  if (pszToken)                                  if (pszToken)
1857                      pInstrInfo->instrument_nr = atoi(lscp_ltrim(pszToken));                                          pInstrInfo->instrument_nr = atoi(lscp_ltrim(pszToken));
1858              }                          }
1859              else if (strcasecmp(pszToken, "INSTRUMENT_NAME") == 0) {                          else if (strcasecmp(pszToken, "INSTRUMENT_NAME") == 0) {
1860                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1861                  if (pszToken)                                  if (pszToken)
1862                      lscp_unquote_dup(&(pInstrInfo->instrument_name), &pszToken);                                          lscp_unquote_dup(&(pInstrInfo->instrument_name), &pszToken);
1863              }                          }
1864              else if (strcasecmp(pszToken, "LOAD_MODE") == 0) {                          else if (strcasecmp(pszToken, "LOAD_MODE") == 0) {
1865                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1866                  if (pszToken) {                                  if (pszToken) {
1867                      pszToken = lscp_ltrim(pszToken);                                          pszToken = lscp_ltrim(pszToken);
1868                      if (strcasecmp(pszToken, "ON_DEMAND") == 0)                                          if (strcasecmp(pszToken, "ON_DEMAND") == 0)
1869                          pInstrInfo->load_mode = LSCP_LOAD_ON_DEMAND;                                                  pInstrInfo->load_mode = LSCP_LOAD_ON_DEMAND;
1870                      else                                          else
1871                      if (strcasecmp(pszToken, "ON_DEMAND_HOLD") == 0)                                          if (strcasecmp(pszToken, "ON_DEMAND_HOLD") == 0)
1872                          pInstrInfo->load_mode = LSCP_LOAD_ON_DEMAND_HOLD;                                                  pInstrInfo->load_mode = LSCP_LOAD_ON_DEMAND_HOLD;
1873                      else                                          else
1874                      if (strcasecmp(pszToken, "PERSISTENT") == 0)                                          if (strcasecmp(pszToken, "PERSISTENT") == 0)
1875                          pInstrInfo->load_mode = LSCP_LOAD_PERSISTENT;                                                  pInstrInfo->load_mode = LSCP_LOAD_PERSISTENT;
1876                      else                                          else
1877                          pInstrInfo->load_mode = LSCP_LOAD_DEFAULT;                                                  pInstrInfo->load_mode = LSCP_LOAD_DEFAULT;
1878                  }                                  }
1879              }                          }
1880              else if (strcasecmp(pszToken, "VOLUME") == 0) {                          else if (strcasecmp(pszToken, "VOLUME") == 0) {
1881                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1882                  if (pszToken)                                  if (pszToken)
1883                      pInstrInfo->volume = (float) atof(lscp_ltrim(pszToken));                                          pInstrInfo->volume = (float) atof(lscp_ltrim(pszToken));
1884              }                          }
1885              pszToken = lscp_strtok(NULL, pszSeps, &(pch));                          pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1886          }                  }
1887      }          }
1888      else pInstrInfo = NULL;          else pInstrInfo = NULL;
1889                
1890      // Unlock this section down.          // Unlock this section down.
1891      lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
1892                
1893      return pInstrInfo;          return pInstrInfo;
1894  }  }
1895    
1896    
# Line 1898  lscp_midi_instrument_info_t *lscp_get_mi Line 1898  lscp_midi_instrument_info_t *lscp_get_mi
1898   *  Clear the MIDI instrumnet map:   *  Clear the MIDI instrumnet map:
1899   *  CLEAR MIDI_INSTRUMENTS   *  CLEAR MIDI_INSTRUMENTS
1900   *   *
1901   *  @param pClient          Pointer to client instance structure.   *  @param pClient         Pointer to client instance structure.
1902   *  @param iSamplerChannel  Sampler channel number.   *  @param iSamplerChannel  Sampler channel number.
1903   *   *
1904   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1905   */   */
1906  lscp_status_t lscp_clear_midi_instruments  ( lscp_client_t *pClient )  lscp_status_t lscp_clear_midi_instruments  ( lscp_client_t *pClient )
1907  {  {
1908      return lscp_client_query(pClient, "CLEAR MIDI_INSTRUMENTS\r\n");          return lscp_client_query(pClient, "CLEAR MIDI_INSTRUMENTS\r\n");
1909  }  }
1910    
1911    

Legend:
Removed from v.948  
changed lines
  Added in v.952

  ViewVC Help
Powered by ViewVC