/[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 977 by capela, Sun Dec 17 15:08:35 2006 UTC revision 1802 by schoenebeck, Sun Dec 7 13:50:08 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 1738  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     *  Get global voice limit setting:
1903     *  @code
1904     *  GET VOICES
1905     *  @endcode
1906     *  This value reflects the maximum amount of voices a sampler engine
1907     *  processes simultaniously before voice stealing kicks in.
1908     *
1909     *  @param pClient  Pointer to client instance structure.
1910     *
1911     *  @returns The current global maximum amount of voices limit or a
1912     *           negative value on error (e.g. if sampler doesn't support
1913     *           this command).
1914     */
1915    int lscp_get_voices(lscp_client_t *pClient)
1916    {
1917            int iVoices = -1;
1918    
1919            if (pClient == NULL)
1920                    return -1;
1921    
1922            // Lock this section up.
1923            lscp_mutex_lock(pClient->mutex);
1924    
1925            if (lscp_client_call(pClient, "GET VOICES\r\n", 0) == LSCP_OK)
1926                    iVoices = atoi(lscp_client_get_result(pClient));
1927    
1928            // Unlock this section down.
1929            lscp_mutex_unlock(pClient->mutex);
1930    
1931            return iVoices;
1932    }
1933    
1934    /**
1935     *  Setting global voice limit setting:
1936     *  @code
1937     *  SET VOICES <max-voices>
1938     *  @endcode
1939     *  This value reflects the maximum amount of voices a sampler engine
1940     *  processes simultaniously before voice stealing kicks in. Note that
1941     *  this value will be passed to all sampler engine instances, that is
1942     *  the total amount of maximum voices on the running system is thus
1943     *  @param iMaxVoices multiplied with the current amount of sampler
1944     *  engine instances.
1945     *
1946     *  @param pClient     Pointer to client instance structure.
1947     *  @param iMaxVoices  Global voice limit setting as integer value larger
1948     *                     or equal to 1.
1949     *
1950     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1951     */
1952    lscp_status_t lscp_set_voices(lscp_client_t *pClient, int iMaxVoices)
1953    {
1954            char szQuery[LSCP_BUFSIZ];
1955    
1956            if (iMaxVoices < 1)
1957                    return LSCP_FAILED;
1958    
1959            sprintf(szQuery, "SET VOICES %d\r\n", iMaxVoices);
1960            return lscp_client_query(pClient, szQuery);
1961    }
1962    
1963    /**
1964     *  Get global disk streams limit setting:
1965     *  @code
1966     *  GET STREAMS
1967     *  @endcode
1968     *  This value reflects the maximum amount of disk streams a sampler
1969     *  engine processes simultaniously.
1970     *
1971     *  @param pClient  Pointer to client instance structure.
1972     *
1973     *  @returns The current global maximum amount of disk streams limit
1974     *           or a negative value on error (e.g. if sampler doesn't
1975     *           support this command).
1976     */
1977    int lscp_get_streams(lscp_client_t *pClient)
1978    {
1979            int iStreams = -1;
1980    
1981            if (pClient == NULL)
1982                    return -1;
1983    
1984            // Lock this section up.
1985            lscp_mutex_lock(pClient->mutex);
1986    
1987            if (lscp_client_call(pClient, "GET STREAMS\r\n", 0) == LSCP_OK)
1988                    iStreams = atoi(lscp_client_get_result(pClient));
1989    
1990            // Unlock this section down.
1991            lscp_mutex_unlock(pClient->mutex);
1992    
1993            return iStreams;
1994    }
1995    
1996    /**
1997     *  Setting global disk streams limit setting:
1998     *  @code
1999     *  SET STREAMS <max-streams>
2000     *  @endcode
2001     *  This value reflects the maximum amount of dist streams a sampler
2002     *  engine instance processes simultaniously. Note that this value will
2003     *  be passed to all sampler engine instances, that is the total amount
2004     *  of maximum disk streams on the running system is thus
2005     *  @param iMaxStreams multiplied with the current amount of sampler
2006     *  engine instances.
2007     *
2008     *  @param pClient      Pointer to client instance structure.
2009     *  @param iMaxStreams  Global streams limit setting as positive integer
2010     *                      value (larger or equal to 0).
2011     *
2012     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2013     */
2014    lscp_status_t lscp_set_streams(lscp_client_t *pClient, int iMaxStreams)
2015    {
2016            char szQuery[LSCP_BUFSIZ];
2017    
2018            if (iMaxStreams < 0)
2019                    return LSCP_FAILED;
2020    
2021            sprintf(szQuery, "SET STREAMS %d\r\n", iMaxStreams);
2022            return lscp_client_query(pClient, szQuery);
2023    }
2024    
2025    /**
2026     *  Add an effect send to a sampler channel:
2027     *  CREATE FX_SEND <sampler-channel> <midi-ctrl> [<name>]
2028     *
2029     *  @param pClient          Pointer to client instance structure.
2030     *  @param iSamplerChannel  Sampler channel number.
2031     *  @param iMidiController  MIDI controller used to alter the effect,
2032     *                          usually a number between 0 and 127.
2033     *  @param pszName          Optional name for the effect send entity,
2034     *                          does not have to be unique.
2035     *
2036     *  @returns The new effect send number identifier, or -1 in case of failure.
2037     */
2038    int lscp_create_fxsend ( lscp_client_t *pClient, int iSamplerChannel, int iMidiController, const char *pszFxName )
2039    {
2040            int iFxSend = -1;
2041            char szQuery[LSCP_BUFSIZ];
2042    
2043            if (pClient == NULL)
2044                    return -1;
2045            if (iSamplerChannel < 0 || iMidiController < 0 || iMidiController > 127)
2046                    return -1;
2047    
2048            // Lock this section up.
2049            lscp_mutex_lock(pClient->mutex);
2050    
2051            sprintf(szQuery, "CREATE FX_SEND %d %d", iSamplerChannel, iMidiController);
2052    
2053            if (pszFxName)
2054                    sprintf(szQuery + strlen(szQuery), " '%s'", pszFxName);
2055    
2056            strcat(szQuery, "\r\n");
2057    
2058            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
2059                    iFxSend = atoi(lscp_client_get_result(pClient));
2060    
2061            // Unlock this section down.
2062            lscp_mutex_unlock(pClient->mutex);
2063    
2064            return iFxSend;
2065    }
2066    
2067    
2068    /**
2069     *  Remove an effect send from a sampler channel:
2070     *  DESTROY FX_SEND <sampler-channel> <fx-send-id>
2071     *
2072     *  @param pClient          Pointer to client instance structure.
2073     *  @param iSamplerChannel  Sampler channel number.
2074     *  @param iFxSend          Effect send number.
2075     *
2076     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2077     */
2078    lscp_status_t lscp_destroy_fxsend ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend )
2079    {
2080            char szQuery[LSCP_BUFSIZ];
2081    
2082            if (iSamplerChannel < 0 || iFxSend < 0)
2083                    return LSCP_FAILED;
2084    
2085            sprintf(szQuery, "DESTROY FX_SEND %d %d\r\n", iSamplerChannel, iFxSend);
2086    
2087            return lscp_client_query(pClient, szQuery);
2088    }
2089    
2090    
2091    /**
2092     *  Get amount of effect sends on a sampler channel:
2093     *  GET FX_SENDS <sampler-channel>
2094     *
2095     *  @param pClient          Pointer to client instance structure.
2096     *  @param iSamplerChannel  Sampler channel number.
2097     *
2098     *  @returns The current total number of effect sends of the sampler channel
2099     *  on success, -1 otherwise.
2100     */
2101    int lscp_get_fxsends ( lscp_client_t *pClient, int iSamplerChannel )
2102    {
2103            int iFxSends = -1;
2104            char szQuery[LSCP_BUFSIZ];
2105    
2106            if (pClient == NULL)
2107                    return -1;
2108            if (iSamplerChannel < 0)
2109                    return -1;
2110    
2111            // Lock this section up.
2112            lscp_mutex_lock(pClient->mutex);
2113    
2114            sprintf(szQuery, "GET FX_SENDS %d\r\n", iSamplerChannel);
2115    
2116            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
2117                    iFxSends = atoi(lscp_client_get_result(pClient));
2118    
2119            // Unlock this section doen.
2120            lscp_mutex_unlock(pClient->mutex);
2121    
2122            return iFxSends;
2123    }
2124    
2125    
2126    /**
2127     *  List all effect sends on a sampler channel:
2128     *  LIST FX_SENDS <sampler-channel>
2129     *
2130     *  @param pClient          Pointer to client instance structure.
2131     *  @param iSamplerChannel  Sampler channel number.
2132     *
2133     *  @returns An array of the effect sends identifiers as positive integers,
2134     *  terminated with -1 on success, NULL otherwise.
2135     */
2136    int *lscp_list_fxsends ( lscp_client_t *pClient, int iSamplerChannel )
2137    {
2138            const char *pszSeps = ",";
2139            char szQuery[LSCP_BUFSIZ];
2140    
2141            if (pClient == NULL)
2142                    return NULL;
2143    
2144            // Lock this section up.
2145            lscp_mutex_lock(pClient->mutex);
2146    
2147            if (pClient->fxsends) {
2148                    lscp_isplit_destroy(pClient->fxsends);
2149                    pClient->fxsends = NULL;
2150            }
2151    
2152            sprintf(szQuery, "LIST FX_SENDS %d\r\n", iSamplerChannel);
2153    
2154            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
2155                    pClient->fxsends = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps);
2156    
2157            // Unlock this section down.
2158            lscp_mutex_unlock(pClient->mutex);
2159    
2160            return pClient->fxsends;
2161    }
2162    
2163    
2164    /**
2165     *  Getting effect send information
2166     *  GET FX_SEND INFO <sampler-channel> <fx-send-id>
2167     *
2168     *  @param pClient          Pointer to client instance structure.
2169     *  @param iSamplerChannel  Sampler channel number.
2170     *  @param iFxSend          Effect send number.
2171     *
2172     *  @returns A pointer to a @ref lscp_fxsend_info_t structure, with the
2173     *  information of the given FX send, or NULL in case of failure.
2174     */
2175    lscp_fxsend_info_t *lscp_get_fxsend_info ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend )
2176    {
2177            lscp_fxsend_info_t *pFxSendInfo;
2178            char szQuery[LSCP_BUFSIZ];
2179            const char *pszResult;
2180            const char *pszSeps = ":";
2181            const char *pszCrlf = "\r\n";
2182            char *pszToken;
2183            char *pch;
2184    
2185            if (pClient == NULL)
2186                    return NULL;
2187            if (iSamplerChannel < 0 || iFxSend < 0)
2188                    return NULL;
2189    
2190            // Lock this section up.
2191            lscp_mutex_lock(pClient->mutex);
2192    
2193            pFxSendInfo = &(pClient->fxsend_info);
2194            lscp_fxsend_info_reset(pFxSendInfo);
2195    
2196            sprintf(szQuery, "GET FX_SEND INFO %d %d\r\n", iSamplerChannel, iFxSend);
2197            if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) {
2198                    pszResult = lscp_client_get_result(pClient);
2199                    pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
2200                    while (pszToken) {
2201                            if (strcasecmp(pszToken, "NAME") == 0) {
2202                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2203                                    if (pszToken)
2204                                            lscp_unquote_dup(&(pFxSendInfo->name), &pszToken);
2205                            }
2206                            else if (strcasecmp(pszToken, "MIDI_CONTROLLER") == 0) {
2207                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2208                                    if (pszToken)
2209                                            pFxSendInfo->midi_controller = atoi(lscp_ltrim(pszToken));
2210                            }
2211                            else if (strcasecmp(pszToken, "AUDIO_OUTPUT_ROUTING") == 0) {
2212                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2213                                    if (pszToken) {
2214                                            if (pFxSendInfo->audio_routing)
2215                                                    lscp_isplit_destroy(pFxSendInfo->audio_routing);
2216                                            pFxSendInfo->audio_routing = lscp_isplit_create(pszToken, ",");
2217                                    }
2218                            }
2219                            else if (strcasecmp(pszToken, "LEVEL") == 0) {
2220                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2221                                    if (pszToken)
2222                                            pFxSendInfo->level = (float) atof(lscp_ltrim(pszToken));
2223                            }
2224                            pszToken = lscp_strtok(NULL, pszSeps, &(pch));
2225                    }
2226            }
2227            else pFxSendInfo = NULL;
2228    
2229            // Unlock this section up.
2230            lscp_mutex_unlock(pClient->mutex);
2231    
2232            return pFxSendInfo;
2233    }
2234    
2235    /**
2236     *  Alter effect send's name:
2237     *  @code
2238     *  SET FX_SEND NAME <sampler-chan> <fx-send-id> <name>
2239     *  @endcode
2240     *
2241     *  @param pClient          Pointer to client instance structure.
2242     *  @param iSamplerChannel  Sampler channel number.
2243     *  @param iFxSend          Effect send number.
2244     *  @param pszFxName        Effect send's new name.
2245     *
2246     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2247     */
2248    lscp_status_t lscp_set_fxsend_name ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, const char *pszFxName )
2249    {
2250            char szQuery[LSCP_BUFSIZ];
2251    
2252            if (!pClient || iSamplerChannel < 0 || iFxSend < 0 || !pszFxName)
2253                    return LSCP_FAILED;
2254    
2255            snprintf(szQuery, LSCP_BUFSIZ, "SET FX_SEND NAME %d %d '%s'\r\n", iSamplerChannel, iFxSend, pszFxName);
2256            return lscp_client_query(pClient, szQuery);
2257    }
2258    
2259    /**
2260     *  Alter effect send's audio routing:
2261     *  SET FX_SEND AUDIO_OUTPUT_CHANNEL <sampler-chan> <fx-send-id>
2262     *    <audio-src> <audio-dst>
2263     *
2264     *  @param pClient          Pointer to client instance structure.
2265     *  @param iSamplerChannel  Sampler channel number.
2266     *  @param iFxSend          Effect send number.
2267     *  @param iAudioSrc        Audio output device channel to be routed from.
2268     *  @param iAudioDst        Audio output device channel to be routed into.
2269     *
2270     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2271     */
2272    lscp_status_t lscp_set_fxsend_audio_channel ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, int iAudioSrc, int iAudioDst )
2273    {
2274            char szQuery[LSCP_BUFSIZ];
2275    
2276            if (iSamplerChannel < 0 || iFxSend < 0 || iAudioSrc < 0 || iAudioDst < 0)
2277                    return LSCP_FAILED;
2278    
2279            sprintf(szQuery, "SET FX_SEND AUDIO_OUTPUT_CHANNEL %d %d %d %d\r\n", iSamplerChannel, iFxSend, iAudioSrc, iAudioDst);
2280            return lscp_client_query(pClient, szQuery);
2281    }
2282    
2283    
2284    /**
2285     *  Alter effect send's MIDI controller:
2286     *  SET FX_SEND MIDI_CONTROLLER <sampler-chan> <fx-send-id> <midi-ctrl>
2287     *
2288     *  @param pClient          Pointer to client instance structure.
2289     *  @param iSamplerChannel  Sampler channel number.
2290     *  @param iFxSend          Effect send number.
2291     *  @param iMidiController  MIDI controller used to alter the effect,
2292     *                          usually a number between 0 and 127.
2293     *
2294     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2295     */
2296    lscp_status_t lscp_set_fxsend_midi_controller ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, int iMidiController )
2297    {
2298            char szQuery[LSCP_BUFSIZ];
2299    
2300            if (iSamplerChannel < 0 || iFxSend < 0 || iMidiController < 0 || iMidiController > 127)
2301                    return LSCP_FAILED;
2302    
2303            sprintf(szQuery, "SET FX_SEND MIDI_CONTROLLER %d %d %d\r\n", iSamplerChannel, iFxSend, iMidiController);
2304            return lscp_client_query(pClient, szQuery);
2305    }
2306    
2307    
2308    /**
2309     *  Alter effect send's audio level:
2310     *  SET FX_SEND LEVEL <sampler-chan> <fx-send-id> <level>
2311     *
2312     *  @param pClient          Pointer to client instance structure.
2313     *  @param iSamplerChannel  Sampler channel number.
2314     *  @param iFxSend          Effect send number.
2315     *  @param fLevel           Effect send volume level.
2316     *
2317     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2318     */
2319    lscp_status_t lscp_set_fxsend_level ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, float fLevel )
2320    {
2321            char szQuery[LSCP_BUFSIZ];
2322    
2323            if (iSamplerChannel < 0 || iFxSend < 0 || fLevel < 0.0f)
2324                    return LSCP_FAILED;
2325    
2326            sprintf(szQuery, "SET FX_SEND LEVEL %d %d %f\r\n", iSamplerChannel, iFxSend, fLevel);
2327            return lscp_client_query(pClient, szQuery);
2328    }
2329    
2330    
2331    /**
2332   *  Create a new MIDI instrument map:   *  Create a new MIDI instrument map:
2333   *  ADD MIDI_INSTRUMENT_MAP [<name>]   *  ADD MIDI_INSTRUMENT_MAP [<name>]
2334   *   *
# Line 1759  int lscp_add_midi_instrument_map ( lscp_ Line 2350  int lscp_add_midi_instrument_map ( lscp_
2350          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
2351    
2352          strcpy(szQuery, "ADD MIDI_INSTRUMENT_MAP");          strcpy(szQuery, "ADD MIDI_INSTRUMENT_MAP");
2353            
2354          if (pszMapName)          if (pszMapName)
2355                  sprintf(szQuery + strlen(szQuery), " '%s'", pszMapName);                  sprintf(szQuery + strlen(szQuery), " '%s'", pszMapName);
2356    
# Line 1885  const char *lscp_get_midi_instrument_map Line 2476  const char *lscp_get_midi_instrument_map
2476    
2477          // Lock this section up.          // Lock this section up.
2478          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
2479            
2480          if (pClient->midi_map_name) {          if (pClient->midi_map_name) {
2481                  free(pClient->midi_map_name);                  free(pClient->midi_map_name);
2482                  pClient->midi_map_name = NULL;                  pClient->midi_map_name = NULL;
# Line 1949  lscp_status_t lscp_set_midi_instrument_m Line 2540  lscp_status_t lscp_set_midi_instrument_m
2540   *  @param pszFileName      Instrument file name.   *  @param pszFileName      Instrument file name.
2541   *  @param iInstrIndex      Instrument index number.   *  @param iInstrIndex      Instrument index number.
2542   *  @param fVolume          Reflects the master volume of the instrument as   *  @param fVolume          Reflects the master volume of the instrument as
2543   *                          a positive floating point number, where a value   *                          a positive floating point number, where a value
2544   *                          less than 1.0 for attenuation, and greater than   *                          less than 1.0 for attenuation, and greater than
2545   *                          1.0 for amplification.   *                          1.0 for amplification.
2546   *  @param load_mode        Instrument load life-time strategy, either   *  @param load_mode        Instrument load life-time strategy, either
# Line 2148  lscp_midi_instrument_info_t *lscp_get_mi Line 2739  lscp_midi_instrument_info_t *lscp_get_mi
2739    
2740          // Lock this section up.          // Lock this section up.
2741          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
2742            
2743          pInstrInfo = &(pClient->midi_instrument_info);          pInstrInfo = &(pClient->midi_instrument_info);
2744          lscp_midi_instrument_info_reset(pInstrInfo);          lscp_midi_instrument_info_reset(pInstrInfo);
2745    
# Line 2240  lscp_status_t lscp_clear_midi_instrument Line 2831  lscp_status_t lscp_clear_midi_instrument
2831    
2832          return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
2833  }  }
2834    
2835    /**
2836     * Open an instrument editor application for the instrument
2837     * on the given sampler channel:
2838     * EDIT CHANNEL INSTRUMENT <sampler-channel>
2839     *
2840     * @param pClient         Pointer to client instance structure.
2841     * @param iSamplerChannel Sampler Channel.
2842     *
2843     * @returns LSCP_OK on success, LSCP_FAILED otherwise.
2844     */
2845    lscp_status_t lscp_edit_channel_instrument ( lscp_client_t *pClient, int iSamplerChannel )
2846    {
2847            char szQuery[LSCP_BUFSIZ];
2848    
2849            if (iSamplerChannel < 0)
2850                    return LSCP_FAILED;
2851    
2852            sprintf(szQuery, "EDIT CHANNEL INSTRUMENT %d\r\n", iSamplerChannel);
2853    
2854            return lscp_client_query(pClient, szQuery);
2855    }
2856    
2857    
2858  // end of client.c  // end of client.c

Legend:
Removed from v.977  
changed lines
  Added in v.1802

  ViewVC Help
Powered by ViewVC