/[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 132 by capela, Fri Jun 18 14:19:19 2004 UTC revision 167 by capela, Fri Jul 2 14:36:43 2004 UTC
# Line 28  Line 28 
28    
29  // Local prototypes.  // Local prototypes.
30    
31  static void _lscp_client_evt_proc   (void *pvClient);  static void             _lscp_client_evt_proc       (void *pvClient);
32    
33    static lscp_status_t    _lscp_client_evt_connect    (lscp_client_t *pClient);
34    static lscp_status_t    _lscp_client_evt_request    (lscp_client_t *pClient, int iSubscribe, lscp_event_t event);
35    
36    
37  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
# Line 37  static void _lscp_client_evt_proc   (voi Line 40  static void _lscp_client_evt_proc   (voi
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;
     struct sockaddr_in addr;  
     int   cAddr;  
43      char  achBuffer[LSCP_BUFSIZ];      char  achBuffer[LSCP_BUFSIZ];
44      int   cchBuffer;      int   cchBuffer;
45      const char *pszSeps = " \r\n";      const char *pszSeps = ":\r\n";
46      char *pszToken;      char *pszToken;
47      char *pch;      char *pch;
48        int   cchToken;
49        lscp_event_t event;
50    
51  #ifdef DEBUG  #ifdef DEBUG
52      fprintf(stderr, "_lscp_client_evt_proc: Client waiting for events.\n");      fprintf(stderr, "_lscp_client_evt_proc: Client waiting for events.\n");
53  #endif  #endif
54    
55      while (pClient->evt.iState) {      while (pClient->evt.iState) {
56          cAddr = sizeof(struct sockaddr_in);          // Wait for event...
57          cchBuffer = recvfrom(pClient->evt.sock, achBuffer, sizeof(achBuffer), 0, (struct sockaddr *) &addr, &cAddr);          cchBuffer = recv(pClient->evt.sock, achBuffer, sizeof(achBuffer), 0);
58          if (cchBuffer > 0) {          if (cchBuffer > 0) {
59  #ifdef DEBUG              // Make sure received buffer it's null terminated.
60              lscp_socket_trace("_lscp_client_evt_proc: recvfrom", &addr, achBuffer, cchBuffer);              achBuffer[cchBuffer] = (char) 0;
61  #endif              // Parse for the notification event message...
62              if (strncasecmp(achBuffer, "PING ", 5) == 0) {              pszToken = lscp_strtok(achBuffer, pszSeps, &(pch)); // Have "NOTIFY".
63                  // Make sure received buffer it's null terminated.              if (strcasecmp(pszToken, "NOTIFY") == 0) {
64                  achBuffer[cchBuffer] = (char) 0;                  pszToken = lscp_strtok(NULL, pszSeps, &(pch));
65                  lscp_strtok(achBuffer, pszSeps, &(pch));       // Skip "PING"                  event    = lscp_event_from_text(pszToken);
66                  lscp_strtok(NULL, pszSeps, &(pch));            // Skip port (must be the same as in addr)                  // And pick the rest of data...
67                  pszToken = lscp_strtok(NULL, pszSeps, &(pch)); // Have session-id.                  pszToken = lscp_strtok(NULL, pszSeps, &(pch));
68                  if (pszToken) {                  cchToken = (pszToken == NULL ? 0 : strlen(pszToken));
69                      // Set now client's session-id, if not already                  // Double-check if we're really up to it...
70                      if (pClient->sessid == NULL)                  if (pClient->events & event) {
71                          pClient->sessid = strdup(pszToken);                      // Invoke the client event callback...
72                      if (pClient->sessid && strcmp(pszToken, pClient->sessid) == 0) {                      if ((*pClient->pfnCallback)(
73                          sprintf(achBuffer, "PONG %s\r\n", pClient->sessid);                              pClient,
74                          cchBuffer = strlen(achBuffer);                              event,
75                          if (sendto(pClient->evt.sock, achBuffer, cchBuffer, 0, (struct sockaddr *) &addr, cAddr) < cchBuffer)                              pszToken,
76                              lscp_socket_perror("_lscp_client_evt_proc: sendto");                              cchToken,
77  #ifdef DEBUG                              pClient->pvData) != LSCP_OK) {
78                          fprintf(stderr, "> %s", achBuffer);                          pClient->evt.iState = 0;
 #endif  
79                      }                      }
80                  }                  }
                 // Done with life proof.  
             } else {  
                 //  
                 if ((*pClient->pfnCallback)(  
                         pClient,  
                         achBuffer,  
                         cchBuffer,  
                         pClient->pvData) != LSCP_OK) {  
                     pClient->evt.iState = 0;  
                 }  
81              }              }
82          } else {          } else {
83              lscp_socket_perror("_lscp_client_evt_proc: recvfrom");              lscp_socket_perror("_lscp_client_evt_proc: recv");
84              pClient->evt.iState = 0;              pClient->evt.iState = 0;
85          }          }
86      }      }
# Line 100  static void _lscp_client_evt_proc ( void Line 92  static void _lscp_client_evt_proc ( void
92    
93    
94  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
95    // Event subscription helpers.
96    
97    // Open the event service socket connection.
98    static lscp_status_t _lscp_client_evt_connect ( lscp_client_t *pClient )
99    {
100        lscp_socket_t sock;
101        struct sockaddr_in addr;
102        int cAddr;
103    #if defined(WIN32)
104        int iSockOpt = (-1);
105    #endif
106    
107        // Prepare the event connection socket...
108        sock = socket(AF_INET, SOCK_STREAM, 0);
109        if (sock == INVALID_SOCKET) {
110            lscp_socket_perror("_lscp_client_evt_connect: socket");
111            return LSCP_FAILED;
112        }
113    
114    #if defined(WIN32)
115        if (setsockopt(sock, SOL_SOCKET, SO_DONTLINGER, (char *) &iSockOpt, sizeof(int)) == SOCKET_ERROR)
116            lscp_socket_perror("lscp_client_evt_connect: setsockopt(SO_DONTLINGER)");
117    #endif
118    
119    #ifdef DEBUG
120        lscp_socket_getopts("_lscp_client_evt_connect:", sock);
121    #endif
122    
123        // Use same address of the command connection.
124        cAddr = sizeof(struct sockaddr_in);
125        memmove((char *) &addr, &(pClient->cmd.addr), cAddr);
126    
127        // Start the connection...
128        if (connect(sock, (struct sockaddr *) &addr, cAddr) == SOCKET_ERROR) {
129            lscp_socket_perror("_lscp_client_evt_connect: connect");
130            closesocket(sock);
131            return LSCP_FAILED;
132        }
133        
134        // Set our socket agent struct...
135        lscp_socket_agent_init(&(pClient->evt), sock, &addr, cAddr);
136        
137        // And finally the service thread...
138        return lscp_socket_agent_start(&(pClient->evt), _lscp_client_evt_proc, pClient, 0);
139    }
140    
141    
142    // Subscribe to a single event.
143    static lscp_status_t _lscp_client_evt_request ( lscp_client_t *pClient, int iSubscribe, lscp_event_t event )
144    {
145        const char *pszEvent;
146        char  szQuery[LSCP_BUFSIZ];
147        int   cchQuery;
148    
149        if (pClient == NULL)
150            return LSCP_FAILED;
151    
152        // Which (single) event?
153        pszEvent = lscp_event_to_text(event);
154        if (pszEvent == NULL)
155            return LSCP_FAILED;
156    
157        // Build the query string...
158        cchQuery = sprintf(szQuery, "%sSUBSCRIBE %s\n\n", (iSubscribe == 0 ? "UN" : ""), pszEvent);
159        // Just send data, forget result...
160        if (send(pClient->evt.sock, szQuery, cchQuery, 0) < cchQuery) {
161            lscp_socket_perror("_lscp_client_evt_request: send");
162            return LSCP_FAILED;
163        }
164    
165        // Update as naively as we can...
166        if (iSubscribe)
167            pClient->events |=  event;
168        else
169            pClient->events &= ~event;
170    
171        return LSCP_OK;
172    }
173    
174    
175    //-------------------------------------------------------------------------
176  // Client versioning teller fuunction.  // Client versioning teller fuunction.
177    
178    
# Line 137  lscp_client_t* lscp_client_create ( cons Line 210  lscp_client_t* lscp_client_create ( cons
210      lscp_socket_t sock;      lscp_socket_t sock;
211      struct sockaddr_in addr;      struct sockaddr_in addr;
212      int cAddr;      int cAddr;
213    #if defined(WIN32)
214      int iSockOpt = (-1);      int iSockOpt = (-1);
215    #endif
216    
217      if (pfnCallback == NULL) {      if (pfnCallback == NULL) {
218          fprintf(stderr, "lscp_client_create: Invalid client callback function.\n");          fprintf(stderr, "lscp_client_create: Invalid client callback function.\n");
# Line 197  lscp_client_t* lscp_client_create ( cons Line 272  lscp_client_t* lscp_client_create ( cons
272          return NULL;          return NULL;
273      }      }
274    
275        // Initialize the command socket agent struct...
276      lscp_socket_agent_init(&(pClient->cmd), sock, &addr, cAddr);      lscp_socket_agent_init(&(pClient->cmd), sock, &addr, cAddr);
277    
278  #ifdef DEBUG  #ifdef DEBUG
279      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));
280  #endif  #endif
281    
282      // Prepare the event datagram service socket...      // Initialize the event service socket struct...
283        lscp_socket_agent_init(&(pClient->evt), INVALID_SOCKET, NULL, 0);
284      sock = socket(AF_INET, SOCK_DGRAM, 0);      // No events subscribed, yet.
285      if (sock == INVALID_SOCKET) {      pClient->events = LSCP_EVENT_NONE;
         lscp_socket_perror("lscp_client_create: evt: socket");  
         lscp_socket_agent_free(&(pClient->cmd));  
         free(pClient);  
         return NULL;  
     }  
   
     if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &iSockOpt, sizeof(int)) == SOCKET_ERROR)  
         lscp_socket_perror("lscp_client_create: evt: setsockopt(SO_REUSEADDR)");  
   
 #ifdef DEBUG  
     lscp_socket_getopts("lscp_client_create: evt", sock);  
 #endif  
   
     cAddr = sizeof(struct sockaddr_in);  
     memset((char *) &addr, 0, cAddr);  
     addr.sin_family = AF_INET;  
     addr.sin_addr.s_addr = htonl(INADDR_ANY);  
     addr.sin_port = htons(0);  
   
     if (bind(sock, (const struct sockaddr *) &addr, cAddr) == SOCKET_ERROR) {  
         lscp_socket_perror("lscp_client_create: evt: bind");  
         lscp_socket_agent_free(&(pClient->cmd));  
         closesocket(sock);  
         free(pClient);  
         return NULL;  
     }  
   
     if (getsockname(sock, (struct sockaddr *) &addr, &cAddr) == SOCKET_ERROR) {  
         lscp_socket_perror("lscp_client_create: evt: getsockname");  
         lscp_socket_agent_free(&(pClient->cmd));  
         closesocket(sock);  
         free(pClient);  
         return NULL;  
     }  
   
     lscp_socket_agent_init(&(pClient->evt), sock, &addr, cAddr);  
   
 #ifdef DEBUG  
     fprintf(stderr, "lscp_client_create: evt: pClient=%p: sock=%d addr=%s port=%d.\n", pClient, pClient->evt.sock, inet_ntoa(pClient->evt.addr.sin_addr), ntohs(pClient->evt.addr.sin_port));  
 #endif  
   
     // No session id, yet.  
     pClient->sessid = NULL;  
286      // Initialize cached members.      // Initialize cached members.
287      pClient->audio_drivers = NULL;      pClient->audio_drivers = NULL;
288      pClient->midi_drivers = NULL;      pClient->midi_drivers = NULL;
# Line 259  lscp_client_t* lscp_client_create ( cons Line 292  lscp_client_t* lscp_client_create ( cons
292      pClient->channels = NULL;      pClient->channels = NULL;
293      lscp_driver_info_init(&(pClient->audio_info));      lscp_driver_info_init(&(pClient->audio_info));
294      lscp_driver_info_init(&(pClient->midi_info));      lscp_driver_info_init(&(pClient->midi_info));
295        lscp_param_info_init(&(pClient->audio_param_info));
296        lscp_param_info_init(&(pClient->midi_param_info));
297      lscp_engine_info_init(&(pClient->engine_info));      lscp_engine_info_init(&(pClient->engine_info));
298      lscp_channel_info_init(&(pClient->channel_info));      lscp_channel_info_init(&(pClient->channel_info));
299      // Initialize error stuff.      // Initialize error stuff.
# Line 273  lscp_client_t* lscp_client_create ( cons Line 308  lscp_client_t* lscp_client_create ( cons
308      // Initialize the transaction mutex.      // Initialize the transaction mutex.
309      lscp_mutex_init(pClient->mutex);      lscp_mutex_init(pClient->mutex);
310    
     // Now's finally time to startup threads...  
     // Event service thread...  
     if (lscp_socket_agent_start(&(pClient->evt), _lscp_client_evt_proc, pClient, 0) != LSCP_OK) {  
         lscp_socket_agent_free(&(pClient->cmd));  
         lscp_socket_agent_free(&(pClient->evt));  
         lscp_mutex_destroy(pClient->mutex);  
         free(pClient);  
         return NULL;  
     }  
   
311      // Finally we've some success...      // Finally we've some success...
312      return pClient;      return pClient;
313  }  }
# Line 328  lscp_status_t lscp_client_destroy ( lscp Line 353  lscp_status_t lscp_client_destroy ( lscp
353      // Lock this section up.      // Lock this section up.
354      lscp_mutex_lock(pClient->mutex);      lscp_mutex_lock(pClient->mutex);
355            
    // Free session-id, if any.  
     if (pClient->sessid)  
         free(pClient->sessid);  
     pClient->sessid = NULL;  
356      // Free up all cached members.      // Free up all cached members.
357      lscp_channel_info_reset(&(pClient->channel_info));      lscp_channel_info_reset(&(pClient->channel_info));
358      lscp_engine_info_reset(&(pClient->engine_info));      lscp_engine_info_reset(&(pClient->engine_info));
359        lscp_param_info_reset(&(pClient->midi_param_info));
360        lscp_param_info_reset(&(pClient->audio_param_info));
361      lscp_driver_info_reset(&(pClient->midi_info));      lscp_driver_info_reset(&(pClient->midi_info));
362      lscp_driver_info_reset(&(pClient->audio_info));      lscp_driver_info_reset(&(pClient->audio_info));
363      // Free available engine table.      // Free available engine table.
# Line 350  lscp_status_t lscp_client_destroy ( lscp Line 373  lscp_status_t lscp_client_destroy ( lscp
373      pClient->engines = NULL;      pClient->engines = NULL;
374      // Free result error stuff.      // Free result error stuff.
375      lscp_client_set_result(pClient, NULL, 0);      lscp_client_set_result(pClient, NULL, 0);
376      // Frre stream usage stuff.      // Free stream usage stuff.
377      if (pClient->buffer_fill)      if (pClient->buffer_fill)
378          free(pClient->buffer_fill);          free(pClient->buffer_fill);
379      pClient->buffer_fill = NULL;      pClient->buffer_fill = NULL;
# Line 478  int lscp_client_get_errno ( lscp_client_ Line 501  int lscp_client_get_errno ( lscp_client_
501  // Client registration protocol functions.  // Client registration protocol functions.
502    
503  /**  /**
504   *  Register frontend for receiving UDP event messages:   *  Register frontend for receiving event messages:
505   *  SUBSCRIBE NOTIFICATION <udp-port>   *  SUBSCRIBE CHANNELS | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL
506     *      | CHANNEL_INFO | MISCELLANEOUS
507   *   *
508   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
509     *  @param events   Bit-wise OR'ed event flags to subscribe.
510   *   *
511   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
512   */   */
513  lscp_status_t lscp_client_subscribe ( lscp_client_t *pClient )  lscp_status_t lscp_client_subscribe ( lscp_client_t *pClient, lscp_event_t events )
514  {  {
515      lscp_status_t ret;      lscp_status_t ret = LSCP_FAILED;
     char szQuery[LSCP_BUFSIZ];  
     const char *pszResult;  
     const char *pszSeps = "[]";  
     char *pszToken;  
     char *pch;  
516    
517      if (pClient == NULL || pClient->sessid)      if (pClient == NULL)
518          return LSCP_FAILED;          return LSCP_FAILED;
519    
520      // Lock this section up.      // Lock this section up.
521      lscp_mutex_lock(pClient->mutex);      lscp_mutex_lock(pClient->mutex);
522    
523        // If applicable, start the alternate connection...
524        if (pClient->events == LSCP_EVENT_NONE)
525            ret = _lscp_client_evt_connect(pClient);
526            
527      sprintf(szQuery, "SUBSCRIBE NOTIFICATION %d\r\n", ntohs(pClient->evt.addr.sin_port));      // Send the subscription commands.
528      ret = lscp_client_call(pClient, szQuery);      if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNELS))
529      if (ret == LSCP_OK) {          ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNELS);
530          pszResult = lscp_client_get_result(pClient);      if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT))
531  #ifdef DEBUG          ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_VOICE_COUNT);
532          fprintf(stderr, "lscp_client_subscribe: %s\n", pszResult);      if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT))
533  #endif          ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_STREAM_COUNT);
534          // Check for the session-id on "OK[sessid]" response.      if (ret == LSCP_OK && (events & LSCP_EVENT_BUFFER_FILL))
535          pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));          ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_BUFFER_FILL);
536          if (pszToken && strcasecmp(pszToken, "OK") == 0) {      if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))
537              pszToken = lscp_strtok(NULL, pszSeps, &(pch));          ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_INFO);
538              if (pszToken)      if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))
539                  pClient->sessid = strdup(pszToken);          ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MISCELLANEOUS);
         }  
     }  
540    
541      // Unlock this section down.      // Unlock this section down.
542      lscp_mutex_unlock(pClient->mutex);      lscp_mutex_unlock(pClient->mutex);
# Line 524  lscp_status_t lscp_client_subscribe ( ls Line 546  lscp_status_t lscp_client_subscribe ( ls
546    
547    
548  /**  /**
549   *  Deregister frontend for not receiving UDP event messages anymore:   *  Deregister frontend from receiving UDP event messages anymore:
550   *  UNSUBSCRIBE NOTIFICATION <session-id>   *  SUBSCRIBE CHANNELS | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL
551     *      | CHANNEL_INFO | MISCELLANEOUS
552   *   *
553   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
554     *  @param events   Bit-wise OR'ed event flags to unsubscribe.
555   *   *
556   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
557   */   */
558  lscp_status_t lscp_client_unsubscribe ( lscp_client_t *pClient )  lscp_status_t lscp_client_unsubscribe ( lscp_client_t *pClient, lscp_event_t events )
559  {  {
560      lscp_status_t ret;      lscp_status_t ret = LSCP_OK;
     char szQuery[LSCP_BUFSIZ];  
561    
562      if (pClient == NULL)      if (pClient == NULL)
563          return LSCP_FAILED;          return LSCP_FAILED;
     if (pClient->sessid == NULL)  
         return LSCP_FAILED;  
564    
565      // Lock this section up.      // Lock this section up.
566      lscp_mutex_lock(pClient->mutex);      lscp_mutex_lock(pClient->mutex);
567    
568      sprintf(szQuery, "UNSUBSCRIBE NOTIFICATION %s\n\n", pClient->sessid);      // Send the unsubscription commands.
569      ret = lscp_client_call(pClient, szQuery);      if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNELS))
570      if (ret == LSCP_OK) {          ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNELS);
571  #ifdef DEBUG      if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT))
572          fprintf(stderr, "lscp_client_unsubscribe: %s\n", lscp_client_get_result(pClient));          ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_VOICE_COUNT);
573  #endif      if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT))
574          // Bail out session-id string.          ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_STREAM_COUNT);
575          free(pClient->sessid);      if (ret == LSCP_OK && (events & LSCP_EVENT_BUFFER_FILL))
576          pClient->sessid = NULL;          ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_BUFFER_FILL);
577      }      if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))
578            ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_INFO);
579        if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))
580            ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MISCELLANEOUS);
581    
582        // If necessary, close the alternate connection...
583        if (pClient->events == LSCP_EVENT_NONE)
584            lscp_socket_agent_free(&(pClient->evt));
585    
586      // Unlock this section down.      // Unlock this section down.
587      lscp_mutex_unlock(pClient->mutex);      lscp_mutex_unlock(pClient->mutex);
# Line 583  lscp_status_t lscp_load_instrument ( lsc Line 611  lscp_status_t lscp_load_instrument ( lsc
611      if (pszFileName == NULL || iSamplerChannel < 0)      if (pszFileName == NULL || iSamplerChannel < 0)
612          return LSCP_FAILED;          return LSCP_FAILED;
613    
614      sprintf(szQuery, "LOAD INSTRUMENT %s %d %d\r\n", pszFileName, iInstrIndex, iSamplerChannel);      sprintf(szQuery, "LOAD INSTRUMENT '%s' %d %d\r\n", pszFileName, iInstrIndex, iSamplerChannel);
615        return lscp_client_query(pClient, szQuery);
616    }
617    
618    
619    /**
620     *  Loading an instrument in the background (non modal):
621     *  LOAD INSTRUMENT NON_MODAL <filename> <instr-index> <sampler-channel>
622     *
623     *  @param pClient          Pointer to client instance structure.
624     *  @param pszFileName      Instrument file name.
625     *  @param iInstrIndex      Instrument index number.
626     *  @param iSamplerChannel  Sampler Channel.
627     *
628     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
629     */
630    lscp_status_t lscp_load_instrument_non_modal ( lscp_client_t *pClient, const char *pszFileName, int iInstrIndex, int iSamplerChannel )
631    {
632        char szQuery[LSCP_BUFSIZ];
633    
634        if (pszFileName == NULL || iSamplerChannel < 0)
635            return LSCP_FAILED;
636    
637        sprintf(szQuery, "LOAD INSTRUMENT NON_MODAL '%s' %d %d\r\n", pszFileName, iInstrIndex, iSamplerChannel);
638      return lscp_client_query(pClient, szQuery);      return lscp_client_query(pClient, szQuery);
639  }  }
640    
# Line 940  int lscp_get_channel_voice_count ( lscp_ Line 991  int lscp_get_channel_voice_count ( lscp_
991   *  Current number of active disk streams:   *  Current number of active disk streams:
992   *  GET CHANNEL STREAM_COUNT <sampler-channel>   *  GET CHANNEL STREAM_COUNT <sampler-channel>
993   *   *
994     *  @param pClient          Pointer to client instance structure.
995     *  @param iSamplerChannel  Sampler channel number.
996     *
997   *  @returns The number of active disk streams on success, -1 otherwise.   *  @returns The number of active disk streams on success, -1 otherwise.
998   */   */
999  int lscp_get_channel_stream_count ( lscp_client_t *pClient, int iSamplerChannel )  int lscp_get_channel_stream_count ( lscp_client_t *pClient, int iSamplerChannel )
# Line 965  int lscp_get_channel_stream_count ( lscp Line 1019  int lscp_get_channel_stream_count ( lscp
1019    
1020    
1021  /**  /**
1022     *  Current least usage of active disk streams.
1023     *
1024     *  @param pClient          Pointer to client instance structure.
1025     *  @param iSamplerChannel  Sampler channel number.
1026     *
1027     *  @returns The usage percentage of the least filled active disk stream
1028     *  on success, -1 otherwise.
1029     */
1030    int lscp_get_channel_stream_usage ( lscp_client_t *pClient, int iSamplerChannel )
1031    {
1032        char szQuery[LSCP_BUFSIZ];
1033        int  iStreamUsage = -1;
1034        const char *pszResult;
1035        const char *pszSeps = "[]%,";
1036        char *pszToken;
1037        char *pch;
1038        int   iStream;
1039        int   iPercent;
1040    
1041        if (iSamplerChannel < 0)
1042            return iStreamUsage;
1043    
1044        // Lock this section up.
1045        lscp_mutex_lock(pClient->mutex);
1046    
1047        iStream = 0;
1048        sprintf(szQuery, "GET CHANNEL BUFFER_FILL PERCENTAGE %d\r\n", iSamplerChannel);
1049        if (lscp_client_call(pClient, szQuery) == LSCP_OK) {
1050            pszResult = lscp_client_get_result(pClient);
1051            pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
1052            while (pszToken) {
1053                if (*pszToken) {
1054                    // Skip stream id.
1055                    pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1056                    if (pszToken == NULL)
1057                        break;
1058                    // Get least buffer fill percentage.
1059                    iPercent = atol(pszToken);
1060                    if (iStreamUsage > iPercent || iStream == 0)
1061                        iStreamUsage = iPercent;
1062                    iStream++;
1063                }
1064                pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1065            }
1066        }
1067    
1068        // Unlock this section down.
1069        lscp_mutex_unlock(pClient->mutex);
1070    
1071        return iStreamUsage;
1072    }
1073    
1074    
1075    /**
1076   *  Current fill state of disk stream buffers:   *  Current fill state of disk stream buffers:
1077   *  GET CHANNEL BUFFER_FILL {BYTES|PERCENTAGE} <sampler-channel>   *  GET CHANNEL BUFFER_FILL {BYTES|PERCENTAGE} <sampler-channel>
1078   *   *
# Line 1062  lscp_status_t lscp_set_channel_audio_typ Line 1170  lscp_status_t lscp_set_channel_audio_typ
1170    
1171    
1172  /**  /**
1173     *  Setting audio output device:
1174     *  SET CHANNEL AUDIO_OUTPUT_DEVICE <sampler-channel> <device-id>
1175     *
1176     *  @param pClient          Pointer to client instance structure.
1177     *  @param iSamplerChannel  Sampler channel number.
1178     *  @param iAudioDevice     Audio output device number identifier.
1179     */
1180    lscp_status_t lscp_set_channel_audio_device ( lscp_client_t *pClient, int iSamplerChannel, int iAudioDevice )
1181    {
1182        char szQuery[LSCP_BUFSIZ];
1183    
1184        if (iSamplerChannel < 0 || iAudioDevice < 0)
1185            return LSCP_FAILED;
1186    
1187        sprintf(szQuery, "SET CHANNEL AUDIO_OUTPUT_DEVICE %d %d\r\n", iSamplerChannel, iAudioDevice);
1188        return lscp_client_query(pClient, szQuery);
1189    }
1190    
1191    
1192    /**
1193   *  Setting audio output channel:   *  Setting audio output channel:
1194   *  SET CHANNEL AUDIO_OUTPUT_CHANNEL <sampler-channel> <audio-output-chan> <audio-input-chan>   *  SET CHANNEL AUDIO_OUTPUT_CHANNEL <sampler-channel> <audio-output-chan> <audio-input-chan>
1195   *   *
# Line 1105  lscp_status_t lscp_set_channel_midi_type Line 1233  lscp_status_t lscp_set_channel_midi_type
1233      return lscp_client_query(pClient, szQuery);      return lscp_client_query(pClient, szQuery);
1234  }  }
1235    
1236    
1237    /**
1238     *  Setting MIDI input device:
1239     *  SET CHANNEL MIDI_INPUT_DEVICE <sampler-channel> <device-id>
1240     *
1241     *  @param pClient          Pointer to client instance structure.
1242     *  @param iSamplerChannel  Sampler channel number.
1243     *  @param iMidiDevice      MIDI input device number identifier.
1244     */
1245    lscp_status_t lscp_set_channel_midi_device ( lscp_client_t *pClient, int iSamplerChannel, int iMidiDevice )
1246    {
1247        char szQuery[LSCP_BUFSIZ];
1248    
1249        if (iSamplerChannel < 0 || iMidiDevice < 0)
1250            return LSCP_FAILED;
1251    
1252        sprintf(szQuery, "SET CHANNEL MIDI_INPUT_DEVICE %d %d\r\n", iSamplerChannel, iMidiDevice);
1253        return lscp_client_query(pClient, szQuery);
1254    }
1255    
1256    
1257  /**  /**
1258   *  Setting MIDI input port:   *  Setting MIDI input port:

Legend:
Removed from v.132  
changed lines
  Added in v.167

  ViewVC Help
Powered by ViewVC