/[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 1020 by capela, Thu Jan 11 15:25:04 2007 UTC revision 1697 by schoenebeck, Sat Feb 16 19:31:32 2008 UTC
# Line 2  Line 2 
2  //  //
3  /****************************************************************************  /****************************************************************************
4     liblscp - LinuxSampler Control Protocol API     liblscp - LinuxSampler Control Protocol API
5     Copyright (C) 2004-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 by the sampler backend.
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   LSCP event to subscribe.
608   *   *
609   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
610   */   */
611  lscp_status_t lscp_client_subscribe ( lscp_client_t *pClient, lscp_event_t events )  lscp_status_t lscp_client_subscribe ( lscp_client_t *pClient, lscp_event_t events )
612  {  {
613          lscp_status_t ret = LSCP_FAILED;          lscp_status_t ret = LSCP_OK;
614            lscp_event_t currentEvent;
615    
616          if (pClient == NULL)          if (pClient == NULL)
617                  return LSCP_FAILED;                  return LSCP_FAILED;
# Line 637  lscp_status_t lscp_client_subscribe ( ls Line 654  lscp_status_t lscp_client_subscribe ( ls
654                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_INFO);                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_INFO);
655          if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))          if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))
656                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MISCELLANEOUS);                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MISCELLANEOUS);
657            // Caution: for the upper 16 bits, we don't use bit flags anymore ...
658            currentEvent = events & 0xffff0000;
659            if (ret == LSCP_OK && currentEvent) {
660                    switch (currentEvent) {
661                            case LSCP_EVENT_CHANNEL_MIDI:
662                            case LSCP_EVENT_DEVICE_MIDI:
663                                    ret = _lscp_client_evt_request(pClient, 1, currentEvent);
664                                    break;
665                            default: // unknown "upper" event type
666                                    ret = LSCP_FAILED;
667                                    break;
668                    }
669            }
670    
671          // Unlock this section down.          // Unlock this section down.
672          lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
# Line 646  lscp_status_t lscp_client_subscribe ( ls Line 676  lscp_status_t lscp_client_subscribe ( ls
676    
677    
678  /**  /**
679   *  Deregister frontend from receiving UDP event messages anymore:   *  Deregister frontend from receiving UDP event messages anymore.
680     *  @e Caution: since liblscp v0.5.5.4 you have to call
681     *  lscp_client_unsubscribe() for @e each event you want to unsubscribe.
682     *  That is the old bitflag approach was abondoned at this point. You can
683     *  however still register all older events with one lscp_client_subscribe()
684     *  call at once. Thus, the old behavior of this functions was not broken.
685     *  Those older events are namely:
686     *  @code
687   *  UNSUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT   *  UNSUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT
688   *      | BUFFER_FILL | CHANNEL_INFO | TOTAL_VOICE_COUNT   *      | BUFFER_FILL | CHANNEL_INFO | TOTAL_VOICE_COUNT
689   *      | 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 691  lscp_status_t lscp_client_subscribe ( ls
691   *      | MIDI_INSTRUMENT_MAP_COUNT | MIDI_INSTRUMENT_MAP_INFO   *      | MIDI_INSTRUMENT_MAP_COUNT | MIDI_INSTRUMENT_MAP_INFO
692   *      | MIDI_INSTRUMENT_COUNT | MIDI_INSTRUMENT_INFO   *      | MIDI_INSTRUMENT_COUNT | MIDI_INSTRUMENT_INFO
693   *      | MISCELLANEOUS   *      | MISCELLANEOUS
694     *  @endcode
695     *  The old events occupy the lower 16 bits (as bit flags), and all younger
696     *  events enumerate the whole upper 16 bits range. The new, enumerated
697     *  events are namely:
698     *  @code
699     *  UNSUBSCRIBE CHANNEL_MIDI
700     *  @endcode
701   *   *
702   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
703   *  @param events   Bit-wise OR'ed event flags to unsubscribe.   *  @param events   LSCP event to unsubscribe.
704   *   *
705   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
706   */   */
707  lscp_status_t lscp_client_unsubscribe ( lscp_client_t *pClient, lscp_event_t events )  lscp_status_t lscp_client_unsubscribe ( lscp_client_t *pClient, lscp_event_t events )
708  {  {
709          lscp_status_t ret = LSCP_OK;          lscp_status_t ret = LSCP_OK;
710            lscp_event_t currentEvent;
711    
712          if (pClient == NULL)          if (pClient == NULL)
713                  return LSCP_FAILED;                  return LSCP_FAILED;
# Line 701  lscp_status_t lscp_client_unsubscribe ( Line 746  lscp_status_t lscp_client_unsubscribe (
746                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_INFO);                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_INFO);
747          if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))          if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))
748                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MISCELLANEOUS);                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MISCELLANEOUS);
749            // Caution: for the upper 16 bits, we don't use bit flags anymore ...
750            currentEvent = events & 0xffff0000;
751            if (ret == LSCP_OK && currentEvent) {
752                    switch (currentEvent) {
753                            case LSCP_EVENT_CHANNEL_MIDI:
754                            case LSCP_EVENT_DEVICE_MIDI:
755                                    ret = _lscp_client_evt_request(pClient, 0, currentEvent);
756                                    break;
757                            default: // unknown "upper" event type
758                                    ret = LSCP_FAILED;
759                                    break;
760                    }
761            }
762    
763          // If necessary, close the alternate connection...          // If necessary, close the alternate connection...
764          if (pClient->events == LSCP_EVENT_NONE)          if (pClient->events == LSCP_EVENT_NONE)
# Line 2035  lscp_fxsend_info_t *lscp_get_fxsend_info Line 2093  lscp_fxsend_info_t *lscp_get_fxsend_info
2093                                          pFxSendInfo->audio_routing = lscp_isplit_create(pszToken, ",");                                          pFxSendInfo->audio_routing = lscp_isplit_create(pszToken, ",");
2094                                  }                                  }
2095                          }                          }
2096                            else if (strcasecmp(pszToken, "LEVEL") == 0) {
2097                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2098                                    if (pszToken)
2099                                            pFxSendInfo->level = (float) atof(lscp_ltrim(pszToken));
2100                            }
2101                          pszToken = lscp_strtok(NULL, pszSeps, &(pch));                          pszToken = lscp_strtok(NULL, pszSeps, &(pch));
2102                  }                  }
2103          }          }
# Line 2046  lscp_fxsend_info_t *lscp_get_fxsend_info Line 2109  lscp_fxsend_info_t *lscp_get_fxsend_info
2109          return pFxSendInfo;          return pFxSendInfo;
2110  }  }
2111    
2112    /**
2113     *  Alter effect send's name:
2114     *  @code
2115     *  SET FX_SEND NAME <sampler-chan> <fx-send-id> <name>
2116     *  @endcode
2117     *
2118     *  @param pClient          Pointer to client instance structure.
2119     *  @param iSamplerChannel  Sampler channel number.
2120     *  @param iFxSend          Effect send number.
2121     *  @param pszFxName        Effect send's new name.
2122     *
2123     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2124     */
2125    lscp_status_t lscp_set_fxsend_name ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, const char *pszFxName )
2126    {
2127            char szQuery[LSCP_BUFSIZ];
2128    
2129            if (!pClient || iSamplerChannel < 0 || iFxSend < 0 || !pszFxName)
2130                    return LSCP_FAILED;
2131    
2132            snprintf(szQuery, LSCP_BUFSIZ, "SET FX_SEND NAME %d %d '%s'\r\n", iSamplerChannel, iFxSend, pszFxName);
2133            return lscp_client_query(pClient, szQuery);
2134    }
2135    
2136  /**  /**
2137   *  Alter effect send's audio routing:   *  Alter effect send's audio routing:
# Line 2073  lscp_status_t lscp_set_fxsend_audio_chan Line 2159  lscp_status_t lscp_set_fxsend_audio_chan
2159    
2160    
2161  /**  /**
2162     *  Alter effect send's MIDI controller:
2163     *  SET FX_SEND MIDI_CONTROLLER <sampler-chan> <fx-send-id> <midi-ctrl>
2164     *
2165     *  @param pClient          Pointer to client instance structure.
2166     *  @param iSamplerChannel  Sampler channel number.
2167     *  @param iFxSend          Effect send number.
2168     *  @param iMidiController  MIDI controller used to alter the effect,
2169     *                          usually a number between 0 and 127.
2170     *
2171     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2172     */
2173    lscp_status_t lscp_set_fxsend_midi_controller ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, int iMidiController )
2174    {
2175            char szQuery[LSCP_BUFSIZ];
2176    
2177            if (iSamplerChannel < 0 || iFxSend < 0 || iMidiController < 0 || iMidiController > 127)
2178                    return LSCP_FAILED;
2179    
2180            sprintf(szQuery, "SET FX_SEND MIDI_CONTROLLER %d %d %d\r\n", iSamplerChannel, iFxSend, iMidiController);
2181            return lscp_client_query(pClient, szQuery);
2182    }
2183    
2184    
2185    /**
2186     *  Alter effect send's audio level:
2187     *  SET FX_SEND LEVEL <sampler-chan> <fx-send-id> <level>
2188     *
2189     *  @param pClient          Pointer to client instance structure.
2190     *  @param iSamplerChannel  Sampler channel number.
2191     *  @param iFxSend          Effect send number.
2192     *  @param fLevel           Effect send volume level.
2193     *
2194     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2195     */
2196    lscp_status_t lscp_set_fxsend_level ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, float fLevel )
2197    {
2198            char szQuery[LSCP_BUFSIZ];
2199    
2200            if (iSamplerChannel < 0 || iFxSend < 0 || fLevel < 0.0f)
2201                    return LSCP_FAILED;
2202    
2203            sprintf(szQuery, "SET FX_SEND LEVEL %d %d %f\r\n", iSamplerChannel, iFxSend, fLevel);
2204            return lscp_client_query(pClient, szQuery);
2205    }
2206    
2207    
2208    /**
2209   *  Create a new MIDI instrument map:   *  Create a new MIDI instrument map:
2210   *  ADD MIDI_INSTRUMENT_MAP [<name>]   *  ADD MIDI_INSTRUMENT_MAP [<name>]
2211   *   *
# Line 2575  lscp_status_t lscp_clear_midi_instrument Line 2708  lscp_status_t lscp_clear_midi_instrument
2708    
2709          return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
2710  }  }
2711    
2712    /**
2713     * Open an instrument editor application for the instrument
2714     * on the given sampler channel:
2715     * EDIT CHANNEL INSTRUMENT <sampler-channel>
2716     *
2717     * @param pClient         Pointer to client instance structure.
2718     * @param iSamplerChannel Sampler Channel.
2719     *
2720     * @returns LSCP_OK on success, LSCP_FAILED otherwise.
2721     */
2722    lscp_status_t lscp_edit_channel_instrument ( lscp_client_t *pClient, int iSamplerChannel )
2723    {
2724            char szQuery[LSCP_BUFSIZ];
2725    
2726            if (iSamplerChannel < 0)
2727                    return LSCP_FAILED;
2728    
2729            sprintf(szQuery, "EDIT CHANNEL INSTRUMENT %d\r\n", iSamplerChannel);
2730    
2731            return lscp_client_query(pClient, szQuery);
2732    }
2733    
2734    
2735  // end of client.c  // end of client.c

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

  ViewVC Help
Powered by ViewVC