/[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 1689 by schoenebeck, Thu Feb 14 17:05:51 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 327  lscp_client_t* lscp_client_create ( cons Line 327  lscp_client_t* lscp_client_create ( cons
327          pClient->midi_devices = NULL;          pClient->midi_devices = NULL;
328          pClient->engines = NULL;          pClient->engines = NULL;
329          pClient->channels = NULL;          pClient->channels = NULL;
330            pClient->fxsends = NULL;
331          pClient->midi_instruments = NULL;          pClient->midi_instruments = NULL;
332          pClient->midi_maps = NULL;          pClient->midi_maps = NULL;
333          pClient->midi_map_name = NULL;          pClient->midi_map_name = NULL;
# Line 343  lscp_client_t* lscp_client_create ( cons Line 344  lscp_client_t* lscp_client_create ( cons
344          lscp_server_info_init(&(pClient->server_info));          lscp_server_info_init(&(pClient->server_info));
345          lscp_engine_info_init(&(pClient->engine_info));          lscp_engine_info_init(&(pClient->engine_info));
346          lscp_channel_info_init(&(pClient->channel_info));          lscp_channel_info_init(&(pClient->channel_info));
347            lscp_fxsend_info_init(&(pClient->fxsend_info));
348          lscp_midi_instrument_info_init(&(pClient->midi_instrument_info));          lscp_midi_instrument_info_init(&(pClient->midi_instrument_info));
349          // Initialize error stuff.          // Initialize error stuff.
350          pClient->pszResult = NULL;          pClient->pszResult = NULL;
# Line 405  lscp_status_t lscp_client_destroy ( lscp Line 407  lscp_status_t lscp_client_destroy ( lscp
407    
408          // Free up all cached members.          // Free up all cached members.
409          lscp_midi_instrument_info_free(&(pClient->midi_instrument_info));          lscp_midi_instrument_info_free(&(pClient->midi_instrument_info));
410            lscp_fxsend_info_free(&(pClient->fxsend_info));
411          lscp_channel_info_free(&(pClient->channel_info));          lscp_channel_info_free(&(pClient->channel_info));
412          lscp_engine_info_free(&(pClient->engine_info));          lscp_engine_info_free(&(pClient->engine_info));
413          lscp_server_info_free(&(pClient->server_info));          lscp_server_info_free(&(pClient->server_info));
# Line 425  lscp_status_t lscp_client_destroy ( lscp Line 428  lscp_status_t lscp_client_destroy ( lscp
428          lscp_isplit_destroy(pClient->midi_devices);          lscp_isplit_destroy(pClient->midi_devices);
429          lscp_szsplit_destroy(pClient->engines);          lscp_szsplit_destroy(pClient->engines);
430          lscp_isplit_destroy(pClient->channels);          lscp_isplit_destroy(pClient->channels);
431            lscp_isplit_destroy(pClient->fxsends);
432          lscp_midi_instruments_destroy(pClient->midi_instruments);          lscp_midi_instruments_destroy(pClient->midi_instruments);
433          lscp_isplit_destroy(pClient->midi_maps);          lscp_isplit_destroy(pClient->midi_maps);
434          if (pClient->midi_map_name)          if (pClient->midi_map_name)
# Line 436  lscp_status_t lscp_client_destroy ( lscp Line 440  lscp_status_t lscp_client_destroy ( lscp
440          pClient->midi_devices = NULL;          pClient->midi_devices = NULL;
441          pClient->engines = NULL;          pClient->engines = NULL;
442          pClient->channels = NULL;          pClient->channels = NULL;
443            pClient->fxsends = NULL;
444          pClient->midi_instruments = NULL;          pClient->midi_instruments = NULL;
445          pClient->midi_maps = NULL;          pClient->midi_maps = NULL;
446          pClient->midi_map_name = NULL;          pClient->midi_map_name = NULL;
# Line 573  int lscp_client_get_errno ( lscp_client_ Line 578  int lscp_client_get_errno ( lscp_client_
578  // Client registration protocol functions.  // Client registration protocol functions.
579    
580  /**  /**
581   *  Register frontend for receiving event messages:   *  Register frontend for receiving event messages.
582   *  SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL   *  @e Caution: since liblscp v0.5.5.4 you have to call lscp_client_subscribe()
583   *      | CHANNEL_INFO | MISCELLANEOUS   *  for @e each event you want to subscribe. That is the old bitflag approach
584     *  was abondoned at this point. You can however still register all older
585     *  events with one lscp_client_subscribe() call at once. Thus, the old
586     *  behavior of this functions was not broken. Those older events are namely:
587     *  @code
588     *  SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT
589     *      | BUFFER_FILL | CHANNEL_INFO | TOTAL_VOICE_COUNT
590     *      | AUDIO_OUTPUT_DEVICE_COUNT | AUDIO_OUTPUT_DEVICE_INFO
591     *      | MIDI_INPUT_DEVICE_COUNT | MIDI_INPUT_DEVICE_INFO
592     *      | MIDI_INSTRUMENT_MAP_COUNT | MIDI_INSTRUMENT_MAP_INFO
593     *      | MIDI_INSTRUMENT_COUNT | MIDI_INSTRUMENT_INFO
594     *      | MISCELLANEOUS
595     *  @endcode
596     *  The old events occupy the lower 16 bits (as bit flags), and all younger
597     *  events enumerate the whole upper 16 bits range. The new, enumerated
598     *  events are namely:
599     *  @code
600     *  SUBSCRIBE CHANNEL_MIDI
601     *  @endcode
602   *   *
603   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
604   *  @param events   Bit-wise OR'ed event flags to subscribe.   *  @param events   Bit-wise OR'ed event flags to subscribe.
# Line 607  lscp_status_t lscp_client_subscribe ( ls Line 630  lscp_status_t lscp_client_subscribe ( ls
630                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_BUFFER_FILL);                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_BUFFER_FILL);
631          if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))          if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))
632                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_INFO);                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_INFO);
633            if (ret == LSCP_OK && (events & LSCP_EVENT_TOTAL_VOICE_COUNT))
634                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_TOTAL_VOICE_COUNT);
635            if (ret == LSCP_OK && (events & LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT))
636                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT);
637            if (ret == LSCP_OK && (events & LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO))
638                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO);
639            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT))
640                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT);
641            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INPUT_DEVICE_INFO))
642                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INPUT_DEVICE_INFO);
643            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_MAP_COUNT))
644                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_MAP_COUNT);
645            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_MAP_INFO))
646                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_MAP_INFO);
647            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_COUNT))
648                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_COUNT);
649            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_INFO))
650                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_INFO);
651          if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))          if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))
652                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MISCELLANEOUS);                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MISCELLANEOUS);
653            // Caution: for the upper 16 bits, we don't use bit flags anymore ...
654            if (ret == LSCP_OK && ((events & 0xffff0000) == LSCP_EVENT_CHANNEL_MIDI))
655                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_MIDI);
656    
657          // Unlock this section down.          // Unlock this section down.
658          lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
# Line 619  lscp_status_t lscp_client_subscribe ( ls Line 663  lscp_status_t lscp_client_subscribe ( ls
663    
664  /**  /**
665   *  Deregister frontend from receiving UDP event messages anymore:   *  Deregister frontend from receiving UDP event messages anymore:
666   *  SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL   *  @e Caution: since liblscp v0.5.5.4 you have to call
667   *      | CHANNEL_INFO | MISCELLANEOUS   *  lscp_client_unsubscribe() for @e each event you want to unsubscribe.
668     *  That is the old bitflag approach was abondoned at this point. You can
669     *  however still register all older events with one lscp_client_subscribe()
670     *  call at once. Thus, the old behavior of this functions was not broken.
671     *  Those older events are namely:
672     *  @code
673     *  UNSUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT
674     *      | BUFFER_FILL | CHANNEL_INFO | TOTAL_VOICE_COUNT
675     *      | AUDIO_OUTPUT_DEVICE_COUNT | AUDIO_OUTPUT_DEVICE_INFO
676     *      | MIDI_INPUT_DEVICE_COUNT | MIDI_INPUT_DEVICE_INFO
677     *      | MIDI_INSTRUMENT_MAP_COUNT | MIDI_INSTRUMENT_MAP_INFO
678     *      | MIDI_INSTRUMENT_COUNT | MIDI_INSTRUMENT_INFO
679     *      | MISCELLANEOUS
680     *  @endcode
681     *  The old events occupy the lower 16 bits (as bit flags), and all younger
682     *  events enumerate the whole upper 16 bits range. The new, enumerated
683     *  events are namely:
684     *  @code
685     *  UNSUBSCRIBE CHANNEL_MIDI
686     *  @endcode
687   *   *
688   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
689   *  @param events   Bit-wise OR'ed event flags to unsubscribe.   *  @param events   Bit-wise OR'ed event flags to unsubscribe.
# Line 648  lscp_status_t lscp_client_unsubscribe ( Line 711  lscp_status_t lscp_client_unsubscribe (
711                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_BUFFER_FILL);                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_BUFFER_FILL);
712          if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))          if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))
713                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_INFO);                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_INFO);
714            if (ret == LSCP_OK && (events & LSCP_EVENT_TOTAL_VOICE_COUNT))
715                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_TOTAL_VOICE_COUNT);
716            if (ret == LSCP_OK && (events & LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT))
717                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT);
718            if (ret == LSCP_OK && (events & LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO))
719                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO);
720            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT))
721                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT);
722            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INPUT_DEVICE_INFO))
723                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INPUT_DEVICE_INFO);
724            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_MAP_COUNT))
725                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_MAP_COUNT);
726            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_MAP_INFO))
727                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_MAP_INFO);
728            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_COUNT))
729                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_COUNT);
730            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_INFO))
731                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_INFO);
732          if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))          if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))
733                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MISCELLANEOUS);                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MISCELLANEOUS);
734            // Caution: for the upper 16 bits, we don't use bit flags anymore ...
735            if (ret == LSCP_OK && ((events & 0xffff0000) == LSCP_EVENT_CHANNEL_MIDI))
736                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_MIDI);
737    
738          // If necessary, close the alternate connection...          // If necessary, close the alternate connection...
739          if (pClient->events == LSCP_EVENT_NONE)          if (pClient->events == LSCP_EVENT_NONE)
# Line 1038  lscp_channel_info_t *lscp_get_channel_in Line 1122  lscp_channel_info_t *lscp_get_channel_in
1122                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1123                                  if (pszToken) {                                  if (pszToken) {
1124                                          if (pChannelInfo->audio_routing)                                          if (pChannelInfo->audio_routing)
1125                                                  lscp_szsplit_destroy(pChannelInfo->audio_routing);                                                  lscp_isplit_destroy(pChannelInfo->audio_routing);
1126                                          pChannelInfo->audio_routing = lscp_szsplit_create(pszToken, ",");                                          pChannelInfo->audio_routing = lscp_isplit_create(pszToken, ",");
1127                                  }                                  }
1128                          }                          }
1129                          else if (strcasecmp(pszToken, "INSTRUMENT_FILE") == 0) {                          else if (strcasecmp(pszToken, "INSTRUMENT_FILE") == 0) {
# Line 1530  lscp_status_t lscp_set_channel_volume ( Line 1614  lscp_status_t lscp_set_channel_volume (
1614  {  {
1615          char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1616    
1617          if (iSamplerChannel < 0 || fVolume < 0.0)          if (iSamplerChannel < 0 || fVolume < 0.0f)
1618                  return LSCP_FAILED;                  return LSCP_FAILED;
1619    
1620          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 1701  lscp_status_t lscp_reset_channel ( lscp_
1701   */   */
1702  lscp_status_t lscp_reset_sampler ( lscp_client_t *pClient )  lscp_status_t lscp_reset_sampler ( lscp_client_t *pClient )
1703  {  {
1704            // Do actual whole sampler reset...
1705          return lscp_client_query(pClient, "RESET\r\n");          return lscp_client_query(pClient, "RESET\r\n");
1706  }  }
1707    
# Line 1738  int lscp_get_total_voice_count_max ( lsc Line 1823  int lscp_get_total_voice_count_max ( lsc
1823    
1824    
1825  /**  /**
1826     *  Get global volume attenuation:
1827     *  GET VOLUME
1828     *
1829     *  @param pClient  Pointer to client instance structure.
1830     *
1831     *  @returns The global volume as positive floating point value usually in
1832     *  the range between 0.0 and 1.0; in case of failure 0.0 is returned.
1833     */
1834    float lscp_get_volume ( lscp_client_t *pClient )
1835    {
1836            float fVolume = 0.0f;
1837    
1838            if (pClient == NULL)
1839                    return 0.0f;
1840    
1841            // Lock this section up.
1842            lscp_mutex_lock(pClient->mutex);
1843    
1844            if (lscp_client_call(pClient, "GET VOLUME\r\n", 0) == LSCP_OK)
1845                    fVolume = (float) atof(lscp_client_get_result(pClient));
1846    
1847            // Unlock this section down.
1848            lscp_mutex_unlock(pClient->mutex);
1849    
1850            return fVolume;
1851    }
1852    
1853    
1854    /**
1855     *  Setting global volume attenuation:
1856     *  SET VOLUME <volume>
1857     *
1858     *  @param pClient  Pointer to client instance structure.
1859     *  @param fVolume  Global volume parameter as positive floating point
1860     *                  value usually be in the range between 0.0 and 1.0,
1861     *                  that is for attenuating the overall volume.
1862     *
1863     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1864     */
1865    lscp_status_t lscp_set_volume ( lscp_client_t *pClient, float fVolume )
1866    {
1867            char szQuery[LSCP_BUFSIZ];
1868    
1869            if (fVolume < 0.0f)
1870                    return LSCP_FAILED;
1871    
1872            sprintf(szQuery, "SET VOLUME %g\r\n", fVolume);
1873            return lscp_client_query(pClient, szQuery);
1874    }
1875    
1876    
1877    /**
1878     *  Add an effect send to a sampler channel:
1879     *  CREATE FX_SEND <sampler-channel> <midi-ctrl> [<name>]
1880     *
1881     *  @param pClient          Pointer to client instance structure.
1882     *  @param iSamplerChannel  Sampler channel number.
1883     *  @param iMidiController  MIDI controller used to alter the effect,
1884     *                          usually a number between 0 and 127.
1885     *  @param pszName          Optional name for the effect send entity,
1886     *                          does not have to be unique.
1887     *
1888     *  @returns The new effect send number identifier, or -1 in case of failure.
1889     */
1890    int lscp_create_fxsend ( lscp_client_t *pClient, int iSamplerChannel, int iMidiController, const char *pszFxName )
1891    {
1892            int iFxSend = -1;
1893            char szQuery[LSCP_BUFSIZ];
1894    
1895            if (pClient == NULL)
1896                    return -1;
1897            if (iSamplerChannel < 0 || iMidiController < 0 || iMidiController > 127)
1898                    return -1;
1899    
1900            // Lock this section up.
1901            lscp_mutex_lock(pClient->mutex);
1902    
1903            sprintf(szQuery, "CREATE FX_SEND %d %d", iSamplerChannel, iMidiController);
1904            
1905            if (pszFxName)
1906                    sprintf(szQuery + strlen(szQuery), " '%s'", pszFxName);
1907    
1908            strcat(szQuery, "\r\n");
1909    
1910            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
1911                    iFxSend = atoi(lscp_client_get_result(pClient));
1912    
1913            // Unlock this section down.
1914            lscp_mutex_unlock(pClient->mutex);
1915    
1916            return iFxSend;
1917    }
1918    
1919    
1920    /**
1921     *  Remove an effect send from a sampler channel:
1922     *  DESTROY FX_SEND <sampler-channel> <fx-send-id>
1923     *
1924     *  @param pClient          Pointer to client instance structure.
1925     *  @param iSamplerChannel  Sampler channel number.
1926     *  @param iFxSend          Effect send number.
1927     *
1928     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1929     */
1930    lscp_status_t lscp_destroy_fxsend ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend )
1931    {
1932            char szQuery[LSCP_BUFSIZ];
1933    
1934            if (iSamplerChannel < 0 || iFxSend < 0)
1935                    return LSCP_FAILED;
1936    
1937            sprintf(szQuery, "DESTROY FX_SEND %d %d\r\n", iSamplerChannel, iFxSend);
1938    
1939            return lscp_client_query(pClient, szQuery);
1940    }
1941    
1942    
1943    /**
1944     *  Get amount of effect sends on a sampler channel:
1945     *  GET FX_SENDS <sampler-channel>
1946     *
1947     *  @param pClient          Pointer to client instance structure.
1948     *  @param iSamplerChannel  Sampler channel number.
1949     *
1950     *  @returns The current total number of effect sends of the sampler channel
1951     *  on success, -1 otherwise.
1952     */
1953    int lscp_get_fxsends ( lscp_client_t *pClient, int iSamplerChannel )
1954    {
1955            int iFxSends = -1;
1956            char szQuery[LSCP_BUFSIZ];
1957    
1958            if (pClient == NULL)
1959                    return -1;
1960            if (iSamplerChannel < 0)
1961                    return -1;
1962    
1963            // Lock this section up.
1964            lscp_mutex_lock(pClient->mutex);
1965    
1966            sprintf(szQuery, "GET FX_SENDS %d\r\n", iSamplerChannel);
1967    
1968            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
1969                    iFxSends = atoi(lscp_client_get_result(pClient));
1970    
1971            // Unlock this section doen.
1972            lscp_mutex_unlock(pClient->mutex);
1973    
1974            return iFxSends;
1975    }
1976    
1977    
1978    /**
1979     *  List all effect sends on a sampler channel:
1980     *  LIST FX_SENDS <sampler-channel>
1981     *
1982     *  @param pClient          Pointer to client instance structure.
1983     *  @param iSamplerChannel  Sampler channel number.
1984     *
1985     *  @returns An array of the effect sends identifiers as positive integers,
1986     *  terminated with -1 on success, NULL otherwise.
1987     */
1988    int *lscp_list_fxsends ( lscp_client_t *pClient, int iSamplerChannel )
1989    {
1990            const char *pszSeps = ",";
1991            char szQuery[LSCP_BUFSIZ];
1992    
1993            if (pClient == NULL)
1994                    return NULL;
1995    
1996            // Lock this section up.
1997            lscp_mutex_lock(pClient->mutex);
1998    
1999            if (pClient->fxsends) {
2000                    lscp_isplit_destroy(pClient->fxsends);
2001                    pClient->fxsends = NULL;
2002            }
2003    
2004            sprintf(szQuery, "LIST FX_SENDS %d\r\n", iSamplerChannel);
2005    
2006            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
2007                    pClient->fxsends = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps);
2008    
2009            // Unlock this section down.
2010            lscp_mutex_unlock(pClient->mutex);
2011    
2012            return pClient->fxsends;
2013    }
2014    
2015    
2016    /**
2017     *  Getting effect send information
2018     *  GET FX_SEND INFO <sampler-channel> <fx-send-id>
2019     *
2020     *  @param pClient          Pointer to client instance structure.
2021     *  @param iSamplerChannel  Sampler channel number.
2022     *  @param iFxSend          Effect send number.
2023     *
2024     *  @returns A pointer to a @ref lscp_fxsend_info_t structure, with the
2025     *  information of the given FX send, or NULL in case of failure.
2026     */
2027    lscp_fxsend_info_t *lscp_get_fxsend_info ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend )
2028    {
2029            lscp_fxsend_info_t *pFxSendInfo;
2030            char szQuery[LSCP_BUFSIZ];
2031            const char *pszResult;
2032            const char *pszSeps = ":";
2033            const char *pszCrlf = "\r\n";
2034            char *pszToken;
2035            char *pch;
2036    
2037            if (pClient == NULL)
2038                    return NULL;
2039            if (iSamplerChannel < 0 || iFxSend < 0)
2040                    return NULL;
2041    
2042            // Lock this section up.
2043            lscp_mutex_lock(pClient->mutex);
2044    
2045            pFxSendInfo = &(pClient->fxsend_info);
2046            lscp_fxsend_info_reset(pFxSendInfo);
2047    
2048            sprintf(szQuery, "GET FX_SEND INFO %d %d\r\n", iSamplerChannel, iFxSend);
2049            if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) {
2050                    pszResult = lscp_client_get_result(pClient);
2051                    pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
2052                    while (pszToken) {
2053                            if (strcasecmp(pszToken, "NAME") == 0) {
2054                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2055                                    if (pszToken)
2056                                            lscp_unquote_dup(&(pFxSendInfo->name), &pszToken);
2057                            }
2058                            else if (strcasecmp(pszToken, "MIDI_CONTROLLER") == 0) {
2059                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2060                                    if (pszToken)
2061                                            pFxSendInfo->midi_controller = atoi(lscp_ltrim(pszToken));
2062                            }
2063                            else if (strcasecmp(pszToken, "AUDIO_OUTPUT_ROUTING") == 0) {
2064                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2065                                    if (pszToken) {
2066                                            if (pFxSendInfo->audio_routing)
2067                                                    lscp_isplit_destroy(pFxSendInfo->audio_routing);
2068                                            pFxSendInfo->audio_routing = lscp_isplit_create(pszToken, ",");
2069                                    }
2070                            }
2071                            else if (strcasecmp(pszToken, "LEVEL") == 0) {
2072                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2073                                    if (pszToken)
2074                                            pFxSendInfo->level = (float) atof(lscp_ltrim(pszToken));
2075                            }
2076                            pszToken = lscp_strtok(NULL, pszSeps, &(pch));
2077                    }
2078            }
2079            else pFxSendInfo = NULL;
2080    
2081            // Unlock this section up.
2082            lscp_mutex_unlock(pClient->mutex);
2083    
2084            return pFxSendInfo;
2085    }
2086    
2087    /**
2088     *  Alter effect send's name:
2089     *  @code
2090     *  SET FX_SEND NAME <sampler-chan> <fx-send-id> <name>
2091     *  @endcode
2092     *
2093     *  @param pClient          Pointer to client instance structure.
2094     *  @param iSamplerChannel  Sampler channel number.
2095     *  @param iFxSend          Effect send number.
2096     *  @param pszFxName        Effect send's new name.
2097     *
2098     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2099     */
2100    lscp_status_t lscp_set_fxsend_name ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, const char *pszFxName )
2101    {
2102            char szQuery[LSCP_BUFSIZ];
2103    
2104            if (!pClient || iSamplerChannel < 0 || iFxSend < 0 || !pszFxName)
2105                    return LSCP_FAILED;
2106    
2107            snprintf(szQuery, LSCP_BUFSIZ, "SET FX_SEND NAME %d %d '%s'\r\n", iSamplerChannel, iFxSend, pszFxName);
2108            return lscp_client_query(pClient, szQuery);
2109    }
2110    
2111    /**
2112     *  Alter effect send's audio routing:
2113     *  SET FX_SEND AUDIO_OUTPUT_CHANNEL <sampler-chan> <fx-send-id>
2114     *    <audio-src> <audio-dst>
2115     *
2116     *  @param pClient          Pointer to client instance structure.
2117     *  @param iSamplerChannel  Sampler channel number.
2118     *  @param iFxSend          Effect send number.
2119     *  @param iAudioSrc        Audio output device channel to be routed from.
2120     *  @param iAudioDst        Audio output device channel to be routed into.
2121     *
2122     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2123     */
2124    lscp_status_t lscp_set_fxsend_audio_channel ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, int iAudioSrc, int iAudioDst )
2125    {
2126            char szQuery[LSCP_BUFSIZ];
2127    
2128            if (iSamplerChannel < 0 || iFxSend < 0 || iAudioSrc < 0 || iAudioDst < 0)
2129                    return LSCP_FAILED;
2130    
2131            sprintf(szQuery, "SET FX_SEND AUDIO_OUTPUT_CHANNEL %d %d %d %d\r\n", iSamplerChannel, iFxSend, iAudioSrc, iAudioDst);
2132            return lscp_client_query(pClient, szQuery);
2133    }
2134    
2135    
2136    /**
2137     *  Alter effect send's MIDI controller:
2138     *  SET FX_SEND MIDI_CONTROLLER <sampler-chan> <fx-send-id> <midi-ctrl>
2139     *
2140     *  @param pClient          Pointer to client instance structure.
2141     *  @param iSamplerChannel  Sampler channel number.
2142     *  @param iFxSend          Effect send number.
2143     *  @param iMidiController  MIDI controller used to alter the effect,
2144     *                          usually a number between 0 and 127.
2145     *
2146     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2147     */
2148    lscp_status_t lscp_set_fxsend_midi_controller ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, int iMidiController )
2149    {
2150            char szQuery[LSCP_BUFSIZ];
2151    
2152            if (iSamplerChannel < 0 || iFxSend < 0 || iMidiController < 0 || iMidiController > 127)
2153                    return LSCP_FAILED;
2154    
2155            sprintf(szQuery, "SET FX_SEND MIDI_CONTROLLER %d %d %d\r\n", iSamplerChannel, iFxSend, iMidiController);
2156            return lscp_client_query(pClient, szQuery);
2157    }
2158    
2159    
2160    /**
2161     *  Alter effect send's audio level:
2162     *  SET FX_SEND LEVEL <sampler-chan> <fx-send-id> <level>
2163     *
2164     *  @param pClient          Pointer to client instance structure.
2165     *  @param iSamplerChannel  Sampler channel number.
2166     *  @param iFxSend          Effect send number.
2167     *  @param fLevel           Effect send volume level.
2168     *
2169     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2170     */
2171    lscp_status_t lscp_set_fxsend_level ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, float fLevel )
2172    {
2173            char szQuery[LSCP_BUFSIZ];
2174    
2175            if (iSamplerChannel < 0 || iFxSend < 0 || fLevel < 0.0f)
2176                    return LSCP_FAILED;
2177    
2178            sprintf(szQuery, "SET FX_SEND LEVEL %d %d %f\r\n", iSamplerChannel, iFxSend, fLevel);
2179            return lscp_client_query(pClient, szQuery);
2180    }
2181    
2182    
2183    /**
2184   *  Create a new MIDI instrument map:   *  Create a new MIDI instrument map:
2185   *  ADD MIDI_INSTRUMENT_MAP [<name>]   *  ADD MIDI_INSTRUMENT_MAP [<name>]
2186   *   *
# Line 2240  lscp_status_t lscp_clear_midi_instrument Line 2683  lscp_status_t lscp_clear_midi_instrument
2683    
2684          return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
2685  }  }
2686    
2687    /**
2688     * Open an instrument editor application for the instrument
2689     * on the given sampler channel:
2690     * EDIT CHANNEL INSTRUMENT <sampler-channel>
2691     *
2692     * @param pClient         Pointer to client instance structure.
2693     * @param iSamplerChannel Sampler Channel.
2694     *
2695     * @returns LSCP_OK on success, LSCP_FAILED otherwise.
2696     */
2697    lscp_status_t lscp_edit_channel_instrument ( lscp_client_t *pClient, int iSamplerChannel )
2698    {
2699            char szQuery[LSCP_BUFSIZ];
2700    
2701            if (iSamplerChannel < 0)
2702                    return LSCP_FAILED;
2703    
2704            sprintf(szQuery, "EDIT CHANNEL INSTRUMENT %d\r\n", iSamplerChannel);
2705    
2706            return lscp_client_query(pClient, szQuery);
2707    }
2708    
2709    
2710  // end of client.c  // end of client.c

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

  ViewVC Help
Powered by ViewVC