/[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 975 by capela, Sun Dec 17 00:59:40 2006 UTC revision 1697 by schoenebeck, Sat Feb 16 19:31:32 2008 UTC
# Line 2  Line 2 
2  //  //
3  /****************************************************************************  /****************************************************************************
4     liblscp - LinuxSampler Control Protocol API     liblscp - LinuxSampler Control Protocol API
5     Copyright (C) 2004-2006, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2008, rncbc aka Rui Nuno Capela. All rights reserved.
6    
7     This library is free software; you can redistribute it and/or     This library is free software; you can redistribute it and/or
8     modify it under the terms of the GNU Lesser General Public     modify it under the terms of the GNU Lesser General Public
# Line 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 327  lscp_client_t* lscp_client_create ( cons Line 330  lscp_client_t* lscp_client_create ( cons
330          pClient->midi_devices = NULL;          pClient->midi_devices = NULL;
331          pClient->engines = NULL;          pClient->engines = NULL;
332          pClient->channels = NULL;          pClient->channels = NULL;
333            pClient->fxsends = NULL;
334          pClient->midi_instruments = NULL;          pClient->midi_instruments = NULL;
335          pClient->midi_maps = NULL;          pClient->midi_maps = NULL;
336          pClient->midi_map_name = NULL;          pClient->midi_map_name = NULL;
# Line 343  lscp_client_t* lscp_client_create ( cons Line 347  lscp_client_t* lscp_client_create ( cons
347          lscp_server_info_init(&(pClient->server_info));          lscp_server_info_init(&(pClient->server_info));
348          lscp_engine_info_init(&(pClient->engine_info));          lscp_engine_info_init(&(pClient->engine_info));
349          lscp_channel_info_init(&(pClient->channel_info));          lscp_channel_info_init(&(pClient->channel_info));
350            lscp_fxsend_info_init(&(pClient->fxsend_info));
351          lscp_midi_instrument_info_init(&(pClient->midi_instrument_info));          lscp_midi_instrument_info_init(&(pClient->midi_instrument_info));
352          // Initialize error stuff.          // Initialize error stuff.
353          pClient->pszResult = NULL;          pClient->pszResult = NULL;
# Line 405  lscp_status_t lscp_client_destroy ( lscp Line 410  lscp_status_t lscp_client_destroy ( lscp
410    
411          // Free up all cached members.          // Free up all cached members.
412          lscp_midi_instrument_info_free(&(pClient->midi_instrument_info));          lscp_midi_instrument_info_free(&(pClient->midi_instrument_info));
413            lscp_fxsend_info_free(&(pClient->fxsend_info));
414          lscp_channel_info_free(&(pClient->channel_info));          lscp_channel_info_free(&(pClient->channel_info));
415          lscp_engine_info_free(&(pClient->engine_info));          lscp_engine_info_free(&(pClient->engine_info));
416          lscp_server_info_free(&(pClient->server_info));          lscp_server_info_free(&(pClient->server_info));
# Line 425  lscp_status_t lscp_client_destroy ( lscp Line 431  lscp_status_t lscp_client_destroy ( lscp
431          lscp_isplit_destroy(pClient->midi_devices);          lscp_isplit_destroy(pClient->midi_devices);
432          lscp_szsplit_destroy(pClient->engines);          lscp_szsplit_destroy(pClient->engines);
433          lscp_isplit_destroy(pClient->channels);          lscp_isplit_destroy(pClient->channels);
434            lscp_isplit_destroy(pClient->fxsends);
435          lscp_midi_instruments_destroy(pClient->midi_instruments);          lscp_midi_instruments_destroy(pClient->midi_instruments);
436          lscp_isplit_destroy(pClient->midi_maps);          lscp_isplit_destroy(pClient->midi_maps);
437          if (pClient->midi_map_name)          if (pClient->midi_map_name)
# Line 436  lscp_status_t lscp_client_destroy ( lscp Line 443  lscp_status_t lscp_client_destroy ( lscp
443          pClient->midi_devices = NULL;          pClient->midi_devices = NULL;
444          pClient->engines = NULL;          pClient->engines = NULL;
445          pClient->channels = NULL;          pClient->channels = NULL;
446            pClient->fxsends = NULL;
447          pClient->midi_instruments = NULL;          pClient->midi_instruments = NULL;
448          pClient->midi_maps = NULL;          pClient->midi_maps = NULL;
449          pClient->midi_map_name = NULL;          pClient->midi_map_name = NULL;
# Line 573  int lscp_client_get_errno ( lscp_client_ Line 581  int lscp_client_get_errno ( lscp_client_
581  // Client registration protocol functions.  // Client registration protocol functions.
582    
583  /**  /**
584   *  Register frontend for receiving event messages:   *  Register frontend for receiving event messages by the sampler backend.
585   *  SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL   *  @e Caution: since liblscp v0.5.5.4 you have to call lscp_client_subscribe()
586   *      | CHANNEL_INFO | MISCELLANEOUS   *  for @e each event you want to subscribe. That is the old bitflag approach
587     *  was abondoned at this point. You can however still register all older
588     *  events with one lscp_client_subscribe() call at once. Thus, the old
589     *  behavior of this functions was not broken. Those older events are namely:
590     *  @code
591     *  SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT
592     *      | BUFFER_FILL | CHANNEL_INFO | TOTAL_VOICE_COUNT
593     *      | AUDIO_OUTPUT_DEVICE_COUNT | AUDIO_OUTPUT_DEVICE_INFO
594     *      | MIDI_INPUT_DEVICE_COUNT | MIDI_INPUT_DEVICE_INFO
595     *      | MIDI_INSTRUMENT_MAP_COUNT | MIDI_INSTRUMENT_MAP_INFO
596     *      | MIDI_INSTRUMENT_COUNT | MIDI_INSTRUMENT_INFO
597     *      | MISCELLANEOUS
598     *  @endcode
599     *  The old events occupy the lower 16 bits (as bit flags), and all younger
600     *  events enumerate the whole upper 16 bits range. The new, enumerated
601     *  events are namely:
602     *  @code
603     *  SUBSCRIBE CHANNEL_MIDI
604     *  @endcode
605   *   *
606   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
607   *  @param events   Bit-wise OR'ed event flags to subscribe.   *  @param events   LSCP event to subscribe.
608   *   *
609   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
610   */   */
611  lscp_status_t lscp_client_subscribe ( lscp_client_t *pClient, lscp_event_t events )  lscp_status_t lscp_client_subscribe ( lscp_client_t *pClient, lscp_event_t events )
612  {  {
613          lscp_status_t ret = LSCP_FAILED;          lscp_status_t ret = LSCP_OK;
614            lscp_event_t currentEvent;
615    
616          if (pClient == NULL)          if (pClient == NULL)
617                  return LSCP_FAILED;                  return LSCP_FAILED;
# Line 607  lscp_status_t lscp_client_subscribe ( ls Line 634  lscp_status_t lscp_client_subscribe ( ls
634                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_BUFFER_FILL);                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_BUFFER_FILL);
635          if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))          if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))
636                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_INFO);                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_INFO);
637            if (ret == LSCP_OK && (events & LSCP_EVENT_TOTAL_VOICE_COUNT))
638                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_TOTAL_VOICE_COUNT);
639            if (ret == LSCP_OK && (events & LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT))
640                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT);
641            if (ret == LSCP_OK && (events & LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO))
642                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO);
643            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT))
644                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT);
645            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INPUT_DEVICE_INFO))
646                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INPUT_DEVICE_INFO);
647            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_MAP_COUNT))
648                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_MAP_COUNT);
649            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_MAP_INFO))
650                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_MAP_INFO);
651            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_COUNT))
652                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_COUNT);
653            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_INFO))
654                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_INFO);
655          if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))          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 618  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   *  SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL   *  @e Caution: since liblscp v0.5.5.4 you have to call
681   *      | CHANNEL_INFO | MISCELLANEOUS   *  lscp_client_unsubscribe() for @e each event you want to unsubscribe.
682     *  That is the old bitflag approach was abondoned at this point. You can
683     *  however still register all older events with one lscp_client_subscribe()
684     *  call at once. Thus, the old behavior of this functions was not broken.
685     *  Those older events are namely:
686     *  @code
687     *  UNSUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT
688     *      | BUFFER_FILL | CHANNEL_INFO | TOTAL_VOICE_COUNT
689     *      | AUDIO_OUTPUT_DEVICE_COUNT | AUDIO_OUTPUT_DEVICE_INFO
690     *      | MIDI_INPUT_DEVICE_COUNT | MIDI_INPUT_DEVICE_INFO
691     *      | MIDI_INSTRUMENT_MAP_COUNT | MIDI_INSTRUMENT_MAP_INFO
692     *      | MIDI_INSTRUMENT_COUNT | MIDI_INSTRUMENT_INFO
693     *      | MISCELLANEOUS
694     *  @endcode
695     *  The old events occupy the lower 16 bits (as bit flags), and all younger
696     *  events enumerate the whole upper 16 bits range. The new, enumerated
697     *  events are namely:
698     *  @code
699     *  UNSUBSCRIBE CHANNEL_MIDI
700     *  @endcode
701   *   *
702   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
703   *  @param events   Bit-wise OR'ed event flags to unsubscribe.   *  @param events   LSCP event to unsubscribe.
704   *   *
705   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
706   */   */
707  lscp_status_t lscp_client_unsubscribe ( lscp_client_t *pClient, lscp_event_t events )  lscp_status_t lscp_client_unsubscribe ( lscp_client_t *pClient, lscp_event_t events )
708  {  {
709          lscp_status_t ret = LSCP_OK;          lscp_status_t ret = LSCP_OK;
710            lscp_event_t currentEvent;
711    
712          if (pClient == NULL)          if (pClient == NULL)
713                  return LSCP_FAILED;                  return LSCP_FAILED;
# Line 648  lscp_status_t lscp_client_unsubscribe ( Line 726  lscp_status_t lscp_client_unsubscribe (
726                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_BUFFER_FILL);                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_BUFFER_FILL);
727          if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))          if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))
728                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_INFO);                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_INFO);
729            if (ret == LSCP_OK && (events & LSCP_EVENT_TOTAL_VOICE_COUNT))
730                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_TOTAL_VOICE_COUNT);
731            if (ret == LSCP_OK && (events & LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT))
732                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT);
733            if (ret == LSCP_OK && (events & LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO))
734                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO);
735            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT))
736                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT);
737            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INPUT_DEVICE_INFO))
738                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INPUT_DEVICE_INFO);
739            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_MAP_COUNT))
740                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_MAP_COUNT);
741            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_MAP_INFO))
742                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_MAP_INFO);
743            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_COUNT))
744                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_COUNT);
745            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_INFO))
746                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_INFO);
747          if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))          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 1038  lscp_channel_info_t *lscp_get_channel_in Line 1147  lscp_channel_info_t *lscp_get_channel_in
1147                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1148                                  if (pszToken) {                                  if (pszToken) {
1149                                          if (pChannelInfo->audio_routing)                                          if (pChannelInfo->audio_routing)
1150                                                  lscp_szsplit_destroy(pChannelInfo->audio_routing);                                                  lscp_isplit_destroy(pChannelInfo->audio_routing);
1151                                          pChannelInfo->audio_routing = lscp_szsplit_create(pszToken, ",");                                          pChannelInfo->audio_routing = lscp_isplit_create(pszToken, ",");
1152                                  }                                  }
1153                          }                          }
1154                          else if (strcasecmp(pszToken, "INSTRUMENT_FILE") == 0) {                          else if (strcasecmp(pszToken, "INSTRUMENT_FILE") == 0) {
# Line 1530  lscp_status_t lscp_set_channel_volume ( Line 1639  lscp_status_t lscp_set_channel_volume (
1639  {  {
1640          char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1641    
1642          if (iSamplerChannel < 0 || fVolume < 0.0)          if (iSamplerChannel < 0 || fVolume < 0.0f)
1643                  return LSCP_FAILED;                  return LSCP_FAILED;
1644    
1645          sprintf(szQuery, "SET CHANNEL VOLUME %d %g\r\n", iSamplerChannel, fVolume);          sprintf(szQuery, "SET CHANNEL VOLUME %d %g\r\n", iSamplerChannel, fVolume);
# Line 1617  lscp_status_t lscp_reset_channel ( lscp_ Line 1726  lscp_status_t lscp_reset_channel ( lscp_
1726   */   */
1727  lscp_status_t lscp_reset_sampler ( lscp_client_t *pClient )  lscp_status_t lscp_reset_sampler ( lscp_client_t *pClient )
1728  {  {
1729            // Do actual whole sampler reset...
1730          return lscp_client_query(pClient, "RESET\r\n");          return lscp_client_query(pClient, "RESET\r\n");
1731  }  }
1732    
# Line 1662  lscp_server_info_t *lscp_get_server_info Line 1772  lscp_server_info_t *lscp_get_server_info
1772                                  if (pszToken)                                  if (pszToken)
1773                                          lscp_unquote_dup(&(pServerInfo->version), &pszToken);                                          lscp_unquote_dup(&(pServerInfo->version), &pszToken);
1774                          }                          }
1775                            else if (strcasecmp(pszToken, "PROTOCOL_VERSION") == 0) {
1776                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1777                                    if (pszToken)
1778                                            lscp_unquote_dup(&(pServerInfo->protocol_version), &pszToken);
1779                            }
1780                          pszToken = lscp_strtok(NULL, pszSeps, &(pch));                          pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1781                  }                  }
1782          }          }
# Line 1733  int lscp_get_total_voice_count_max ( lsc Line 1848  int lscp_get_total_voice_count_max ( lsc
1848    
1849    
1850  /**  /**
1851     *  Get global volume attenuation:
1852     *  GET VOLUME
1853     *
1854     *  @param pClient  Pointer to client instance structure.
1855     *
1856     *  @returns The global volume as positive floating point value usually in
1857     *  the range between 0.0 and 1.0; in case of failure 0.0 is returned.
1858     */
1859    float lscp_get_volume ( lscp_client_t *pClient )
1860    {
1861            float fVolume = 0.0f;
1862    
1863            if (pClient == NULL)
1864                    return 0.0f;
1865    
1866            // Lock this section up.
1867            lscp_mutex_lock(pClient->mutex);
1868    
1869            if (lscp_client_call(pClient, "GET VOLUME\r\n", 0) == LSCP_OK)
1870                    fVolume = (float) atof(lscp_client_get_result(pClient));
1871    
1872            // Unlock this section down.
1873            lscp_mutex_unlock(pClient->mutex);
1874    
1875            return fVolume;
1876    }
1877    
1878    
1879    /**
1880     *  Setting global volume attenuation:
1881     *  SET VOLUME <volume>
1882     *
1883     *  @param pClient  Pointer to client instance structure.
1884     *  @param fVolume  Global volume parameter as positive floating point
1885     *                  value usually be in the range between 0.0 and 1.0,
1886     *                  that is for attenuating the overall volume.
1887     *
1888     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1889     */
1890    lscp_status_t lscp_set_volume ( lscp_client_t *pClient, float fVolume )
1891    {
1892            char szQuery[LSCP_BUFSIZ];
1893    
1894            if (fVolume < 0.0f)
1895                    return LSCP_FAILED;
1896    
1897            sprintf(szQuery, "SET VOLUME %g\r\n", fVolume);
1898            return lscp_client_query(pClient, szQuery);
1899    }
1900    
1901    
1902    /**
1903     *  Add an effect send to a sampler channel:
1904     *  CREATE FX_SEND <sampler-channel> <midi-ctrl> [<name>]
1905     *
1906     *  @param pClient          Pointer to client instance structure.
1907     *  @param iSamplerChannel  Sampler channel number.
1908     *  @param iMidiController  MIDI controller used to alter the effect,
1909     *                          usually a number between 0 and 127.
1910     *  @param pszName          Optional name for the effect send entity,
1911     *                          does not have to be unique.
1912     *
1913     *  @returns The new effect send number identifier, or -1 in case of failure.
1914     */
1915    int lscp_create_fxsend ( lscp_client_t *pClient, int iSamplerChannel, int iMidiController, const char *pszFxName )
1916    {
1917            int iFxSend = -1;
1918            char szQuery[LSCP_BUFSIZ];
1919    
1920            if (pClient == NULL)
1921                    return -1;
1922            if (iSamplerChannel < 0 || iMidiController < 0 || iMidiController > 127)
1923                    return -1;
1924    
1925            // Lock this section up.
1926            lscp_mutex_lock(pClient->mutex);
1927    
1928            sprintf(szQuery, "CREATE FX_SEND %d %d", iSamplerChannel, iMidiController);
1929            
1930            if (pszFxName)
1931                    sprintf(szQuery + strlen(szQuery), " '%s'", pszFxName);
1932    
1933            strcat(szQuery, "\r\n");
1934    
1935            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
1936                    iFxSend = atoi(lscp_client_get_result(pClient));
1937    
1938            // Unlock this section down.
1939            lscp_mutex_unlock(pClient->mutex);
1940    
1941            return iFxSend;
1942    }
1943    
1944    
1945    /**
1946     *  Remove an effect send from a sampler channel:
1947     *  DESTROY FX_SEND <sampler-channel> <fx-send-id>
1948     *
1949     *  @param pClient          Pointer to client instance structure.
1950     *  @param iSamplerChannel  Sampler channel number.
1951     *  @param iFxSend          Effect send number.
1952     *
1953     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1954     */
1955    lscp_status_t lscp_destroy_fxsend ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend )
1956    {
1957            char szQuery[LSCP_BUFSIZ];
1958    
1959            if (iSamplerChannel < 0 || iFxSend < 0)
1960                    return LSCP_FAILED;
1961    
1962            sprintf(szQuery, "DESTROY FX_SEND %d %d\r\n", iSamplerChannel, iFxSend);
1963    
1964            return lscp_client_query(pClient, szQuery);
1965    }
1966    
1967    
1968    /**
1969     *  Get amount of effect sends on a sampler channel:
1970     *  GET FX_SENDS <sampler-channel>
1971     *
1972     *  @param pClient          Pointer to client instance structure.
1973     *  @param iSamplerChannel  Sampler channel number.
1974     *
1975     *  @returns The current total number of effect sends of the sampler channel
1976     *  on success, -1 otherwise.
1977     */
1978    int lscp_get_fxsends ( lscp_client_t *pClient, int iSamplerChannel )
1979    {
1980            int iFxSends = -1;
1981            char szQuery[LSCP_BUFSIZ];
1982    
1983            if (pClient == NULL)
1984                    return -1;
1985            if (iSamplerChannel < 0)
1986                    return -1;
1987    
1988            // Lock this section up.
1989            lscp_mutex_lock(pClient->mutex);
1990    
1991            sprintf(szQuery, "GET FX_SENDS %d\r\n", iSamplerChannel);
1992    
1993            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
1994                    iFxSends = atoi(lscp_client_get_result(pClient));
1995    
1996            // Unlock this section doen.
1997            lscp_mutex_unlock(pClient->mutex);
1998    
1999            return iFxSends;
2000    }
2001    
2002    
2003    /**
2004     *  List all effect sends on a sampler channel:
2005     *  LIST FX_SENDS <sampler-channel>
2006     *
2007     *  @param pClient          Pointer to client instance structure.
2008     *  @param iSamplerChannel  Sampler channel number.
2009     *
2010     *  @returns An array of the effect sends identifiers as positive integers,
2011     *  terminated with -1 on success, NULL otherwise.
2012     */
2013    int *lscp_list_fxsends ( lscp_client_t *pClient, int iSamplerChannel )
2014    {
2015            const char *pszSeps = ",";
2016            char szQuery[LSCP_BUFSIZ];
2017    
2018            if (pClient == NULL)
2019                    return NULL;
2020    
2021            // Lock this section up.
2022            lscp_mutex_lock(pClient->mutex);
2023    
2024            if (pClient->fxsends) {
2025                    lscp_isplit_destroy(pClient->fxsends);
2026                    pClient->fxsends = NULL;
2027            }
2028    
2029            sprintf(szQuery, "LIST FX_SENDS %d\r\n", iSamplerChannel);
2030    
2031            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
2032                    pClient->fxsends = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps);
2033    
2034            // Unlock this section down.
2035            lscp_mutex_unlock(pClient->mutex);
2036    
2037            return pClient->fxsends;
2038    }
2039    
2040    
2041    /**
2042     *  Getting effect send information
2043     *  GET FX_SEND INFO <sampler-channel> <fx-send-id>
2044     *
2045     *  @param pClient          Pointer to client instance structure.
2046     *  @param iSamplerChannel  Sampler channel number.
2047     *  @param iFxSend          Effect send number.
2048     *
2049     *  @returns A pointer to a @ref lscp_fxsend_info_t structure, with the
2050     *  information of the given FX send, or NULL in case of failure.
2051     */
2052    lscp_fxsend_info_t *lscp_get_fxsend_info ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend )
2053    {
2054            lscp_fxsend_info_t *pFxSendInfo;
2055            char szQuery[LSCP_BUFSIZ];
2056            const char *pszResult;
2057            const char *pszSeps = ":";
2058            const char *pszCrlf = "\r\n";
2059            char *pszToken;
2060            char *pch;
2061    
2062            if (pClient == NULL)
2063                    return NULL;
2064            if (iSamplerChannel < 0 || iFxSend < 0)
2065                    return NULL;
2066    
2067            // Lock this section up.
2068            lscp_mutex_lock(pClient->mutex);
2069    
2070            pFxSendInfo = &(pClient->fxsend_info);
2071            lscp_fxsend_info_reset(pFxSendInfo);
2072    
2073            sprintf(szQuery, "GET FX_SEND INFO %d %d\r\n", iSamplerChannel, iFxSend);
2074            if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) {
2075                    pszResult = lscp_client_get_result(pClient);
2076                    pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
2077                    while (pszToken) {
2078                            if (strcasecmp(pszToken, "NAME") == 0) {
2079                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2080                                    if (pszToken)
2081                                            lscp_unquote_dup(&(pFxSendInfo->name), &pszToken);
2082                            }
2083                            else if (strcasecmp(pszToken, "MIDI_CONTROLLER") == 0) {
2084                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2085                                    if (pszToken)
2086                                            pFxSendInfo->midi_controller = atoi(lscp_ltrim(pszToken));
2087                            }
2088                            else if (strcasecmp(pszToken, "AUDIO_OUTPUT_ROUTING") == 0) {
2089                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2090                                    if (pszToken) {
2091                                            if (pFxSendInfo->audio_routing)
2092                                                    lscp_isplit_destroy(pFxSendInfo->audio_routing);
2093                                            pFxSendInfo->audio_routing = lscp_isplit_create(pszToken, ",");
2094                                    }
2095                            }
2096                            else if (strcasecmp(pszToken, "LEVEL") == 0) {
2097                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2098                                    if (pszToken)
2099                                            pFxSendInfo->level = (float) atof(lscp_ltrim(pszToken));
2100                            }
2101                            pszToken = lscp_strtok(NULL, pszSeps, &(pch));
2102                    }
2103            }
2104            else pFxSendInfo = NULL;
2105    
2106            // Unlock this section up.
2107            lscp_mutex_unlock(pClient->mutex);
2108    
2109            return pFxSendInfo;
2110    }
2111    
2112    /**
2113     *  Alter effect send's name:
2114     *  @code
2115     *  SET FX_SEND NAME <sampler-chan> <fx-send-id> <name>
2116     *  @endcode
2117     *
2118     *  @param pClient          Pointer to client instance structure.
2119     *  @param iSamplerChannel  Sampler channel number.
2120     *  @param iFxSend          Effect send number.
2121     *  @param pszFxName        Effect send's new name.
2122     *
2123     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2124     */
2125    lscp_status_t lscp_set_fxsend_name ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, const char *pszFxName )
2126    {
2127            char szQuery[LSCP_BUFSIZ];
2128    
2129            if (!pClient || iSamplerChannel < 0 || iFxSend < 0 || !pszFxName)
2130                    return LSCP_FAILED;
2131    
2132            snprintf(szQuery, LSCP_BUFSIZ, "SET FX_SEND NAME %d %d '%s'\r\n", iSamplerChannel, iFxSend, pszFxName);
2133            return lscp_client_query(pClient, szQuery);
2134    }
2135    
2136    /**
2137     *  Alter effect send's audio routing:
2138     *  SET FX_SEND AUDIO_OUTPUT_CHANNEL <sampler-chan> <fx-send-id>
2139     *    <audio-src> <audio-dst>
2140     *
2141     *  @param pClient          Pointer to client instance structure.
2142     *  @param iSamplerChannel  Sampler channel number.
2143     *  @param iFxSend          Effect send number.
2144     *  @param iAudioSrc        Audio output device channel to be routed from.
2145     *  @param iAudioDst        Audio output device channel to be routed into.
2146     *
2147     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2148     */
2149    lscp_status_t lscp_set_fxsend_audio_channel ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, int iAudioSrc, int iAudioDst )
2150    {
2151            char szQuery[LSCP_BUFSIZ];
2152    
2153            if (iSamplerChannel < 0 || iFxSend < 0 || iAudioSrc < 0 || iAudioDst < 0)
2154                    return LSCP_FAILED;
2155    
2156            sprintf(szQuery, "SET FX_SEND AUDIO_OUTPUT_CHANNEL %d %d %d %d\r\n", iSamplerChannel, iFxSend, iAudioSrc, iAudioDst);
2157            return lscp_client_query(pClient, szQuery);
2158    }
2159    
2160    
2161    /**
2162     *  Alter effect send's MIDI controller:
2163     *  SET FX_SEND MIDI_CONTROLLER <sampler-chan> <fx-send-id> <midi-ctrl>
2164     *
2165     *  @param pClient          Pointer to client instance structure.
2166     *  @param iSamplerChannel  Sampler channel number.
2167     *  @param iFxSend          Effect send number.
2168     *  @param iMidiController  MIDI controller used to alter the effect,
2169     *                          usually a number between 0 and 127.
2170     *
2171     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2172     */
2173    lscp_status_t lscp_set_fxsend_midi_controller ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, int iMidiController )
2174    {
2175            char szQuery[LSCP_BUFSIZ];
2176    
2177            if (iSamplerChannel < 0 || iFxSend < 0 || iMidiController < 0 || iMidiController > 127)
2178                    return LSCP_FAILED;
2179    
2180            sprintf(szQuery, "SET FX_SEND MIDI_CONTROLLER %d %d %d\r\n", iSamplerChannel, iFxSend, iMidiController);
2181            return lscp_client_query(pClient, szQuery);
2182    }
2183    
2184    
2185    /**
2186     *  Alter effect send's audio level:
2187     *  SET FX_SEND LEVEL <sampler-chan> <fx-send-id> <level>
2188     *
2189     *  @param pClient          Pointer to client instance structure.
2190     *  @param iSamplerChannel  Sampler channel number.
2191     *  @param iFxSend          Effect send number.
2192     *  @param fLevel           Effect send volume level.
2193     *
2194     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2195     */
2196    lscp_status_t lscp_set_fxsend_level ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, float fLevel )
2197    {
2198            char szQuery[LSCP_BUFSIZ];
2199    
2200            if (iSamplerChannel < 0 || iFxSend < 0 || fLevel < 0.0f)
2201                    return LSCP_FAILED;
2202    
2203            sprintf(szQuery, "SET FX_SEND LEVEL %d %d %f\r\n", iSamplerChannel, iFxSend, fLevel);
2204            return lscp_client_query(pClient, szQuery);
2205    }
2206    
2207    
2208    /**
2209   *  Create a new MIDI instrument map:   *  Create a new MIDI instrument map:
2210   *  ADD MIDI_INSTRUMENT_MAP [<name>]   *  ADD MIDI_INSTRUMENT_MAP [<name>]
2211   *   *
# Line 2235  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.975  
changed lines
  Added in v.1697

  ViewVC Help
Powered by ViewVC