/[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 1368 by capela, Tue Oct 2 07:16:59 2007 UTC revision 1692 by schoenebeck, Fri Feb 15 17:04:34 2008 UTC
# Line 2  Line 2 
2  //  //
3  /****************************************************************************  /****************************************************************************
4     liblscp - LinuxSampler Control Protocol API     liblscp - LinuxSampler Control Protocol API
5     Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2008, rncbc aka Rui Nuno Capela. All rights reserved.
6    
7     This library is free software; you can redistribute it and/or     This library is free software; you can redistribute it and/or
8     modify it under the terms of the GNU Lesser General Public     modify it under the terms of the GNU Lesser General Public
# Line 84  static void _lscp_client_evt_proc ( void Line 84  static void _lscp_client_evt_proc ( void
84                          if (cchBuffer > 0) {                          if (cchBuffer > 0) {
85                                  // Make sure received buffer it's null terminated.                                  // Make sure received buffer it's null terminated.
86                                  achBuffer[cchBuffer] = (char) 0;                                  achBuffer[cchBuffer] = (char) 0;
87                                  // Parse for the notification event message...                                  pch = achBuffer;
88                                  pszToken = lscp_strtok(achBuffer, pszSeps, &(pch)); // Have "NOTIFY".                                  do {
89                                  if (strcasecmp(pszToken, "NOTIFY") == 0) {                                          // Parse for the notification event message...
90                                          pszToken = lscp_strtok(NULL, pszSeps, &(pch));                                          pszToken = lscp_strtok(NULL, pszSeps, &(pch)); // Have "NOTIFY"
91                                          event    = lscp_event_from_text(pszToken);                                          if (strcasecmp(pszToken, "NOTIFY") == 0) {
92                                          // And pick the rest of data...                                                  pszToken = lscp_strtok(NULL, pszSeps, &(pch));
93                                          pszToken = lscp_strtok(NULL, pszSeps, &(pch));                                                  event    = lscp_event_from_text(pszToken);
94                                          cchToken = (pszToken == NULL ? 0 : strlen(pszToken));                                                  // And pick the rest of data...
95                                          // Double-check if we're really up to it...                                                  pszToken = lscp_strtok(NULL, pszSeps, &(pch));
96                                          if (pClient->events & event) {                                                  cchToken = (pszToken == NULL ? 0 : strlen(pszToken));
97                                                  // Invoke the client event callback...                                                  // Double-check if we're really up to it...
98                                                  if ((*pClient->pfnCallback)(                                                  if (pClient->events & event) {
99                                                                  pClient,                                                          // Invoke the client event callback...
100                                                                  event,                                                          if ((*pClient->pfnCallback)(
101                                                                  pszToken,                                                                          pClient,
102                                                                  cchToken,                                                                          event,
103                                                                  pClient->pvData) != LSCP_OK) {                                                                          pszToken,
104                                                          pClient->evt.iState = 0;                                                                          cchToken,
105                                                                            pClient->pvData) != LSCP_OK) {
106                                                                    pClient->evt.iState = 0;
107                                                            }
108                                                  }                                                  }
109                                          }                                          }
110                                  }                                  } while (*pch);
111                          } else {                          } else {
112                                  lscp_socket_perror("_lscp_client_evt_proc: recv");                                  lscp_socket_perror("_lscp_client_evt_proc: recv");
113                                  pClient->evt.iState = 0;                                  pClient->evt.iState = 0;
# Line 578  int lscp_client_get_errno ( lscp_client_ Line 581  int lscp_client_get_errno ( lscp_client_
581  // Client registration protocol functions.  // Client registration protocol functions.
582    
583  /**  /**
584   *  Register frontend for receiving event messages:   *  Register frontend for receiving event messages.
585     *  @e Caution: since liblscp v0.5.5.4 you have to call lscp_client_subscribe()
586     *  for @e each event you want to subscribe. That is the old bitflag approach
587     *  was abondoned at this point. You can however still register all older
588     *  events with one lscp_client_subscribe() call at once. Thus, the old
589     *  behavior of this functions was not broken. Those older events are namely:
590     *  @code
591   *  SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT   *  SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT
592   *      | BUFFER_FILL | CHANNEL_INFO | TOTAL_VOICE_COUNT   *      | BUFFER_FILL | CHANNEL_INFO | TOTAL_VOICE_COUNT
593   *      | AUDIO_OUTPUT_DEVICE_COUNT | AUDIO_OUTPUT_DEVICE_INFO   *      | AUDIO_OUTPUT_DEVICE_COUNT | AUDIO_OUTPUT_DEVICE_INFO
# Line 586  int lscp_client_get_errno ( lscp_client_ Line 595  int lscp_client_get_errno ( lscp_client_
595   *      | MIDI_INSTRUMENT_MAP_COUNT | MIDI_INSTRUMENT_MAP_INFO   *      | MIDI_INSTRUMENT_MAP_COUNT | MIDI_INSTRUMENT_MAP_INFO
596   *      | MIDI_INSTRUMENT_COUNT | MIDI_INSTRUMENT_INFO   *      | MIDI_INSTRUMENT_COUNT | MIDI_INSTRUMENT_INFO
597   *      | MISCELLANEOUS   *      | MISCELLANEOUS
598     *  @endcode
599     *  The old events occupy the lower 16 bits (as bit flags), and all younger
600     *  events enumerate the whole upper 16 bits range. The new, enumerated
601     *  events are namely:
602     *  @code
603     *  SUBSCRIBE CHANNEL_MIDI
604     *  @endcode
605   *   *
606   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
607   *  @param events   Bit-wise OR'ed event flags to subscribe.   *  @param events   Bit-wise OR'ed event flags to subscribe.
# Line 594  int lscp_client_get_errno ( lscp_client_ Line 610  int lscp_client_get_errno ( lscp_client_
610   */   */
611  lscp_status_t lscp_client_subscribe ( lscp_client_t *pClient, lscp_event_t events )  lscp_status_t lscp_client_subscribe ( lscp_client_t *pClient, lscp_event_t events )
612  {  {
613          lscp_status_t ret = LSCP_FAILED;          lscp_status_t ret = LSCP_OK;
614    
615          if (pClient == NULL)          if (pClient == NULL)
616                  return LSCP_FAILED;                  return LSCP_FAILED;
# Line 637  lscp_status_t lscp_client_subscribe ( ls Line 653  lscp_status_t lscp_client_subscribe ( ls
653                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_INFO);                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_INFO);
654          if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))          if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))
655                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MISCELLANEOUS);                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MISCELLANEOUS);
656            // Caution: for the upper 16 bits, we don't use bit flags anymore ...
657            if (ret == LSCP_OK && ((events & 0xffff0000) == LSCP_EVENT_CHANNEL_MIDI))
658                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_MIDI);
659    
660          // Unlock this section down.          // Unlock this section down.
661          lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
# Line 647  lscp_status_t lscp_client_subscribe ( ls Line 666  lscp_status_t lscp_client_subscribe ( ls
666    
667  /**  /**
668   *  Deregister frontend from receiving UDP event messages anymore:   *  Deregister frontend from receiving UDP event messages anymore:
669     *  @e Caution: since liblscp v0.5.5.4 you have to call
670     *  lscp_client_unsubscribe() for @e each event you want to unsubscribe.
671     *  That is the old bitflag approach was abondoned at this point. You can
672     *  however still register all older events with one lscp_client_subscribe()
673     *  call at once. Thus, the old behavior of this functions was not broken.
674     *  Those older events are namely:
675     *  @code
676   *  UNSUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT   *  UNSUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT
677   *      | BUFFER_FILL | CHANNEL_INFO | TOTAL_VOICE_COUNT   *      | BUFFER_FILL | CHANNEL_INFO | TOTAL_VOICE_COUNT
678   *      | AUDIO_OUTPUT_DEVICE_COUNT | AUDIO_OUTPUT_DEVICE_INFO   *      | AUDIO_OUTPUT_DEVICE_COUNT | AUDIO_OUTPUT_DEVICE_INFO
# Line 654  lscp_status_t lscp_client_subscribe ( ls Line 680  lscp_status_t lscp_client_subscribe ( ls
680   *      | MIDI_INSTRUMENT_MAP_COUNT | MIDI_INSTRUMENT_MAP_INFO   *      | MIDI_INSTRUMENT_MAP_COUNT | MIDI_INSTRUMENT_MAP_INFO
681   *      | MIDI_INSTRUMENT_COUNT | MIDI_INSTRUMENT_INFO   *      | MIDI_INSTRUMENT_COUNT | MIDI_INSTRUMENT_INFO
682   *      | MISCELLANEOUS   *      | MISCELLANEOUS
683     *  @endcode
684     *  The old events occupy the lower 16 bits (as bit flags), and all younger
685     *  events enumerate the whole upper 16 bits range. The new, enumerated
686     *  events are namely:
687     *  @code
688     *  UNSUBSCRIBE CHANNEL_MIDI
689     *  @endcode
690   *   *
691   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
692   *  @param events   Bit-wise OR'ed event flags to unsubscribe.   *  @param events   Bit-wise OR'ed event flags to unsubscribe.
# Line 701  lscp_status_t lscp_client_unsubscribe ( Line 734  lscp_status_t lscp_client_unsubscribe (
734                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_INFO);                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_INFO);
735          if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))          if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))
736                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MISCELLANEOUS);                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MISCELLANEOUS);
737            // Caution: for the upper 16 bits, we don't use bit flags anymore ...
738            if (ret == LSCP_OK && ((events & 0xffff0000) == LSCP_EVENT_CHANNEL_MIDI))
739                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_MIDI);
740    
741          // If necessary, close the alternate connection...          // If necessary, close the alternate connection...
742          if (pClient->events == LSCP_EVENT_NONE)          if (pClient->events == LSCP_EVENT_NONE)
# Line 2051  lscp_fxsend_info_t *lscp_get_fxsend_info Line 2087  lscp_fxsend_info_t *lscp_get_fxsend_info
2087          return pFxSendInfo;          return pFxSendInfo;
2088  }  }
2089    
2090    /**
2091     *  Alter effect send's name:
2092     *  @code
2093     *  SET FX_SEND NAME <sampler-chan> <fx-send-id> <name>
2094     *  @endcode
2095     *
2096     *  @param pClient          Pointer to client instance structure.
2097     *  @param iSamplerChannel  Sampler channel number.
2098     *  @param iFxSend          Effect send number.
2099     *  @param pszFxName        Effect send's new name.
2100     *
2101     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2102     */
2103    lscp_status_t lscp_set_fxsend_name ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, const char *pszFxName )
2104    {
2105            char szQuery[LSCP_BUFSIZ];
2106    
2107            if (!pClient || iSamplerChannel < 0 || iFxSend < 0 || !pszFxName)
2108                    return LSCP_FAILED;
2109    
2110            snprintf(szQuery, LSCP_BUFSIZ, "SET FX_SEND NAME %d %d '%s'\r\n", iSamplerChannel, iFxSend, pszFxName);
2111            return lscp_client_query(pClient, szQuery);
2112    }
2113    
2114  /**  /**
2115   *  Alter effect send's audio routing:   *  Alter effect send's audio routing:
# Line 2631  lscp_status_t lscp_clear_midi_instrument Line 2690  lscp_status_t lscp_clear_midi_instrument
2690  /**  /**
2691   * Open an instrument editor application for the instrument   * Open an instrument editor application for the instrument
2692   * on the given sampler channel:   * on the given sampler channel:
2693   * EDIT INSTRUMENT <sampler-channel>   * EDIT CHANNEL INSTRUMENT <sampler-channel>
2694   *   *
2695   * @param pClient         Pointer to client instance structure.   * @param pClient         Pointer to client instance structure.
2696   * @param iSamplerChannel Sampler Channel.   * @param iSamplerChannel Sampler Channel.
2697   *   *
2698   * @returns LSCP_OK on success, LSCP_FAILED otherwise.   * @returns LSCP_OK on success, LSCP_FAILED otherwise.
2699   */   */
2700  lscp_status_t lscp_edit_instrument ( lscp_client_t *pClient, int iSamplerChannel )  lscp_status_t lscp_edit_channel_instrument ( lscp_client_t *pClient, int iSamplerChannel )
2701  {  {
2702          char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
2703    
2704          if (iSamplerChannel < 0)          if (iSamplerChannel < 0)
2705                  return LSCP_FAILED;                  return LSCP_FAILED;
2706    
2707          sprintf(szQuery, "EDIT INSTRUMENT %d\r\n", iSamplerChannel);          sprintf(szQuery, "EDIT CHANNEL INSTRUMENT %d\r\n", iSamplerChannel);
2708    
2709          return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
2710  }  }

Legend:
Removed from v.1368  
changed lines
  Added in v.1692

  ViewVC Help
Powered by ViewVC