/[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 963 by capela, Sun Dec 3 18:30:04 2006 UTC revision 1692 by schoenebeck, Fri Feb 15 17:04:34 2008 UTC
# Line 2  Line 2 
2  //  //
3  /****************************************************************************  /****************************************************************************
4     liblscp - LinuxSampler Control Protocol API     liblscp - LinuxSampler Control Protocol API
5     Copyright (C) 2004-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;
336            pClient->midi_map_name = NULL;
337          lscp_driver_info_init(&(pClient->audio_driver_info));          lscp_driver_info_init(&(pClient->audio_driver_info));
338          lscp_driver_info_init(&(pClient->midi_driver_info));          lscp_driver_info_init(&(pClient->midi_driver_info));
339          lscp_device_info_init(&(pClient->audio_device_info));          lscp_device_info_init(&(pClient->audio_device_info));
# Line 341  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 403  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 423  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);
437            if (pClient->midi_map_name)
438                    free(pClient->midi_map_name);
439          // Make them null.          // Make them null.
440          pClient->audio_drivers = NULL;          pClient->audio_drivers = NULL;
441          pClient->midi_drivers = NULL;          pClient->midi_drivers = NULL;
# Line 431  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;
449            pClient->midi_map_name = NULL;
450          // Free result error stuff.          // Free result error stuff.
451          lscp_client_set_result(pClient, NULL, 0);          lscp_client_set_result(pClient, NULL, 0);
452          // Free stream usage stuff.          // Free stream usage stuff.
# Line 512  lscp_status_t lscp_client_query ( lscp_c Line 527  lscp_status_t lscp_client_query ( lscp_c
527  {  {
528          lscp_status_t ret;          lscp_status_t ret;
529    
530            if (pClient == NULL)
531                    return LSCP_FAILED;
532    
533          // Lock this section up.          // Lock this section up.
534          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
535    
# Line 563  int lscp_client_get_errno ( lscp_client_ Line 581  int lscp_client_get_errno ( lscp_client_
581  // Client registration protocol functions.  // Client registration protocol functions.
582    
583  /**  /**
584   *  Register frontend for receiving event messages:   *  Register frontend for receiving event messages.
585   *  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   Bit-wise OR'ed event flags to subscribe.
# Line 574  int lscp_client_get_errno ( lscp_client_ Line 610  int lscp_client_get_errno ( lscp_client_
610   */   */
611  lscp_status_t lscp_client_subscribe ( lscp_client_t *pClient, lscp_event_t events )  lscp_status_t lscp_client_subscribe ( lscp_client_t *pClient, lscp_event_t events )
612  {  {
613          lscp_status_t ret = LSCP_FAILED;          lscp_status_t ret = LSCP_OK;
614    
615          if (pClient == NULL)          if (pClient == NULL)
616                  return LSCP_FAILED;                  return LSCP_FAILED;
# Line 597  lscp_status_t lscp_client_subscribe ( ls Line 633  lscp_status_t lscp_client_subscribe ( ls
633                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_BUFFER_FILL);                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_BUFFER_FILL);
634          if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))          if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))
635                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_INFO);                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_INFO);
636            if (ret == LSCP_OK && (events & LSCP_EVENT_TOTAL_VOICE_COUNT))
637                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_TOTAL_VOICE_COUNT);
638            if (ret == LSCP_OK && (events & LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT))
639                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT);
640            if (ret == LSCP_OK && (events & LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO))
641                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO);
642            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT))
643                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT);
644            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INPUT_DEVICE_INFO))
645                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INPUT_DEVICE_INFO);
646            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_MAP_COUNT))
647                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_MAP_COUNT);
648            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_MAP_INFO))
649                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_MAP_INFO);
650            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_COUNT))
651                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_COUNT);
652            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_INFO))
653                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_INFO);
654          if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))          if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))
655                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MISCELLANEOUS);                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MISCELLANEOUS);
656            // Caution: for the upper 16 bits, we don't use bit flags anymore ...
657            if (ret == LSCP_OK && ((events & 0xffff0000) == LSCP_EVENT_CHANNEL_MIDI))
658                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_MIDI);
659    
660          // Unlock this section down.          // Unlock this section down.
661          lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
# Line 609  lscp_status_t lscp_client_subscribe ( ls Line 666  lscp_status_t lscp_client_subscribe ( ls
666    
667  /**  /**
668   *  Deregister frontend from receiving UDP event messages anymore:   *  Deregister frontend from receiving UDP event messages anymore:
669   *  SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL   *  @e Caution: since liblscp v0.5.5.4 you have to call
670   *      | CHANNEL_INFO | MISCELLANEOUS   *  lscp_client_unsubscribe() for @e each event you want to unsubscribe.
671     *  That is the old bitflag approach was abondoned at this point. You can
672     *  however still register all older events with one lscp_client_subscribe()
673     *  call at once. Thus, the old behavior of this functions was not broken.
674     *  Those older events are namely:
675     *  @code
676     *  UNSUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT
677     *      | BUFFER_FILL | CHANNEL_INFO | TOTAL_VOICE_COUNT
678     *      | AUDIO_OUTPUT_DEVICE_COUNT | AUDIO_OUTPUT_DEVICE_INFO
679     *      | MIDI_INPUT_DEVICE_COUNT | MIDI_INPUT_DEVICE_INFO
680     *      | MIDI_INSTRUMENT_MAP_COUNT | MIDI_INSTRUMENT_MAP_INFO
681     *      | MIDI_INSTRUMENT_COUNT | MIDI_INSTRUMENT_INFO
682     *      | MISCELLANEOUS
683     *  @endcode
684     *  The old events occupy the lower 16 bits (as bit flags), and all younger
685     *  events enumerate the whole upper 16 bits range. The new, enumerated
686     *  events are namely:
687     *  @code
688     *  UNSUBSCRIBE CHANNEL_MIDI
689     *  @endcode
690   *   *
691   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
692   *  @param events   Bit-wise OR'ed event flags to unsubscribe.   *  @param events   Bit-wise OR'ed event flags to unsubscribe.
# Line 638  lscp_status_t lscp_client_unsubscribe ( Line 714  lscp_status_t lscp_client_unsubscribe (
714                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_BUFFER_FILL);                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_BUFFER_FILL);
715          if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))          if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))
716                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_INFO);                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_INFO);
717            if (ret == LSCP_OK && (events & LSCP_EVENT_TOTAL_VOICE_COUNT))
718                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_TOTAL_VOICE_COUNT);
719            if (ret == LSCP_OK && (events & LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT))
720                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT);
721            if (ret == LSCP_OK && (events & LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO))
722                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO);
723            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT))
724                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT);
725            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INPUT_DEVICE_INFO))
726                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INPUT_DEVICE_INFO);
727            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_MAP_COUNT))
728                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_MAP_COUNT);
729            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_MAP_INFO))
730                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_MAP_INFO);
731            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_COUNT))
732                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_COUNT);
733            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_INFO))
734                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_INFO);
735          if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))          if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))
736                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MISCELLANEOUS);                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MISCELLANEOUS);
737            // Caution: for the upper 16 bits, we don't use bit flags anymore ...
738            if (ret == LSCP_OK && ((events & 0xffff0000) == LSCP_EVENT_CHANNEL_MIDI))
739                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_MIDI);
740    
741          // If necessary, close the alternate connection...          // If necessary, close the alternate connection...
742          if (pClient->events == LSCP_EVENT_NONE)          if (pClient->events == LSCP_EVENT_NONE)
# Line 752  int lscp_get_channels ( lscp_client_t *p Line 849  int lscp_get_channels ( lscp_client_t *p
849  {  {
850          int iChannels = -1;          int iChannels = -1;
851    
852            if (pClient == NULL)
853                    return -1;
854    
855          // Lock this section up.          // Lock this section up.
856          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
857    
# Line 812  int lscp_add_channel ( lscp_client_t *pC Line 912  int lscp_add_channel ( lscp_client_t *pC
912  {  {
913          int iSamplerChannel = -1;          int iSamplerChannel = -1;
914    
915            if (pClient == NULL)
916                    return -1;
917    
918          // Lock this section up.          // Lock this section up.
919          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
920    
# Line 859  int lscp_get_available_engines ( lscp_cl Line 962  int lscp_get_available_engines ( lscp_cl
962  {  {
963          int iAvailableEngines = -1;          int iAvailableEngines = -1;
964    
965            if (pClient == NULL)
966                    return -1;
967    
968          // Lock this section up.          // Lock this section up.
969          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
970    
# Line 885  const char **lscp_list_available_engines Line 991  const char **lscp_list_available_engines
991  {  {
992          const char *pszSeps = ",";          const char *pszSeps = ",";
993    
994            if (pClient == NULL)
995                    return NULL;
996    
997          // Lock this section up.          // Lock this section up.
998          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
999    
# Line 923  lscp_engine_info_t *lscp_get_engine_info Line 1032  lscp_engine_info_t *lscp_get_engine_info
1032          char *pszToken;          char *pszToken;
1033          char *pch;          char *pch;
1034    
1035            if (pClient == NULL)
1036                    return NULL;
1037          if (pszEngineName == NULL)          if (pszEngineName == NULL)
1038                  return NULL;                  return NULL;
1039    
# Line 979  lscp_channel_info_t *lscp_get_channel_in Line 1090  lscp_channel_info_t *lscp_get_channel_in
1090          char *pszToken;          char *pszToken;
1091          char *pch;          char *pch;
1092    
1093            if (pClient == NULL)
1094                    return NULL;
1095          if (iSamplerChannel < 0)          if (iSamplerChannel < 0)
1096                  return NULL;                  return NULL;
1097    
# Line 1012  lscp_channel_info_t *lscp_get_channel_in Line 1125  lscp_channel_info_t *lscp_get_channel_in
1125                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1126                                  if (pszToken) {                                  if (pszToken) {
1127                                          if (pChannelInfo->audio_routing)                                          if (pChannelInfo->audio_routing)
1128                                                  lscp_szsplit_destroy(pChannelInfo->audio_routing);                                                  lscp_isplit_destroy(pChannelInfo->audio_routing);
1129                                          pChannelInfo->audio_routing = lscp_szsplit_create(pszToken, ",");                                          pChannelInfo->audio_routing = lscp_isplit_create(pszToken, ",");
1130                                  }                                  }
1131                          }                          }
1132                          else if (strcasecmp(pszToken, "INSTRUMENT_FILE") == 0) {                          else if (strcasecmp(pszToken, "INSTRUMENT_FILE") == 0) {
# Line 1056  lscp_channel_info_t *lscp_get_channel_in Line 1169  lscp_channel_info_t *lscp_get_channel_in
1169                                                  pChannelInfo->midi_channel = atoi(pszToken);                                                  pChannelInfo->midi_channel = atoi(pszToken);
1170                                  }                                  }
1171                          }                          }
1172                            else if (strcasecmp(pszToken, "MIDI_INSTRUMENT_MAP") == 0) {
1173                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1174                                    if (pszToken) {
1175                                            pszToken = lscp_ltrim(pszToken);
1176                                            if (strcasecmp(pszToken, "NONE") == 0)
1177                                                    pChannelInfo->midi_map = LSCP_MIDI_MAP_NONE;
1178                                            else
1179                                            if (strcasecmp(pszToken, "DEFAULT") == 0)
1180                                                    pChannelInfo->midi_map = LSCP_MIDI_MAP_DEFAULT;
1181                                            else
1182                                                    pChannelInfo->midi_map = atoi(pszToken);
1183                                    }
1184                            }
1185                          else if (strcasecmp(pszToken, "VOLUME") == 0) {                          else if (strcasecmp(pszToken, "VOLUME") == 0) {
1186                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1187                                  if (pszToken)                                  if (pszToken)
# Line 1097  int lscp_get_channel_voice_count ( lscp_ Line 1223  int lscp_get_channel_voice_count ( lscp_
1223          char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1224          int iVoiceCount = -1;          int iVoiceCount = -1;
1225    
1226            if (pClient == NULL)
1227                    return -1;
1228          if (iSamplerChannel < 0)          if (iSamplerChannel < 0)
1229                  return iVoiceCount;                  return -1;
1230    
1231          // Lock this section up.          // Lock this section up.
1232          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
# Line 1128  int lscp_get_channel_stream_count ( lscp Line 1256  int lscp_get_channel_stream_count ( lscp
1256          char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1257          int iStreamCount = -1;          int iStreamCount = -1;
1258    
1259            if (pClient == NULL)
1260                    return -1;
1261          if (iSamplerChannel < 0)          if (iSamplerChannel < 0)
1262                  return iStreamCount;                  return -1;
1263    
1264          // Lock this section up.          // Lock this section up.
1265          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
# Line 1165  int lscp_get_channel_stream_usage ( lscp Line 1295  int lscp_get_channel_stream_usage ( lscp
1295          int   iStream;          int   iStream;
1296          int   iPercent;          int   iPercent;
1297    
1298            if (pClient == NULL)
1299                    return -1;
1300          if (iSamplerChannel < 0)          if (iSamplerChannel < 0)
1301                  return iStreamUsage;                  return -1;
1302    
1303          // Lock this section up.          // Lock this section up.
1304          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
# Line 1227  lscp_buffer_fill_t *lscp_get_channel_buf Line 1359  lscp_buffer_fill_t *lscp_get_channel_buf
1359    
1360          // Retrieve a channel stream estimation.          // Retrieve a channel stream estimation.
1361          iStreamCount = lscp_get_channel_stream_count(pClient, iSamplerChannel);          iStreamCount = lscp_get_channel_stream_count(pClient, iSamplerChannel);
1362          if (pClient->iStreamCount < 0)          if (iStreamCount < 0)
1363                  return NULL;                  return NULL;
1364    
1365          // Lock this section up.          // Lock this section up.
# Line 1416  lscp_status_t lscp_set_channel_midi_port Line 1548  lscp_status_t lscp_set_channel_midi_port
1548   *  @param pClient          Pointer to client instance structure.   *  @param pClient          Pointer to client instance structure.
1549   *  @param iSamplerChannel  Sampler channel number.   *  @param iSamplerChannel  Sampler channel number.
1550   *  @param iMidiChannel     MIDI channel address number to listen (0-15) or   *  @param iMidiChannel     MIDI channel address number to listen (0-15) or
1551   *                          LSCP_MIDI_CHANNEL_ALL (16) to listen on all channels.   *                          @ref LSCP_MIDI_CHANNEL_ALL (16) to listen on all channels.
1552   *   *
1553   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1554   */   */
# Line 1436  lscp_status_t lscp_set_channel_midi_chan Line 1568  lscp_status_t lscp_set_channel_midi_chan
1568    
1569    
1570  /**  /**
1571     *  Setting MIDI instrument map:
1572     *  SET CHANNEL MIDI_INSTRUMENT_MAP <sampler-channel> <midi-map>
1573     *
1574     *  @param pClient          Pointer to client instance structure.
1575     *  @param iSamplerChannel  Sampler channel number.
1576     *  @param iMidiMap         MIDI instrument map number, or either
1577     *                          @ref LSCP_MIDI_MAP_NONE or
1578     *                          @ref LSCP_MIDI_MAP_DEFAULT .
1579     *
1580     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1581     */
1582    lscp_status_t lscp_set_channel_midi_map ( lscp_client_t *pClient, int iSamplerChannel, int iMidiMap )
1583    {
1584            char szQuery[LSCP_BUFSIZ];
1585    
1586            if (iSamplerChannel < 0)
1587                    return LSCP_FAILED;
1588    
1589            sprintf(szQuery, "SET CHANNEL MIDI_INSTRUMENT_MAP %d ", iSamplerChannel);
1590            if (iMidiMap == LSCP_MIDI_MAP_NONE)
1591                    strcat(szQuery , "NONE");
1592            else
1593            if (iMidiMap == LSCP_MIDI_MAP_DEFAULT)
1594                    strcat(szQuery , "DEFAULT");
1595            else
1596                    sprintf(szQuery + strlen(szQuery), "%d", iMidiMap);
1597    
1598            strcat(szQuery, "\r\n");
1599    
1600            return lscp_client_query(pClient, szQuery);
1601    }
1602    
1603    
1604    /**
1605   *  Setting channel volume:   *  Setting channel volume:
1606   *  SET CHANNEL VOLUME <sampler-channel> <volume>   *  SET CHANNEL VOLUME <sampler-channel> <volume>
1607   *   *
# Line 1451  lscp_status_t lscp_set_channel_volume ( Line 1617  lscp_status_t lscp_set_channel_volume (
1617  {  {
1618          char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1619    
1620          if (iSamplerChannel < 0 || fVolume < 0.0)          if (iSamplerChannel < 0 || fVolume < 0.0f)
1621                  return LSCP_FAILED;                  return LSCP_FAILED;
1622    
1623          sprintf(szQuery, "SET CHANNEL VOLUME %d %g\r\n", iSamplerChannel, fVolume);          sprintf(szQuery, "SET CHANNEL VOLUME %d %g\r\n", iSamplerChannel, fVolume);
# Line 1538  lscp_status_t lscp_reset_channel ( lscp_ Line 1704  lscp_status_t lscp_reset_channel ( lscp_
1704   */   */
1705  lscp_status_t lscp_reset_sampler ( lscp_client_t *pClient )  lscp_status_t lscp_reset_sampler ( lscp_client_t *pClient )
1706  {  {
1707            // Do actual whole sampler reset...
1708          return lscp_client_query(pClient, "RESET\r\n");          return lscp_client_query(pClient, "RESET\r\n");
1709  }  }
1710    
# Line 1560  lscp_server_info_t *lscp_get_server_info Line 1727  lscp_server_info_t *lscp_get_server_info
1727          char *pszToken;          char *pszToken;
1728          char *pch;          char *pch;
1729    
1730            if (pClient == NULL)
1731                    return NULL;
1732    
1733          // Lock this section up.          // Lock this section up.
1734          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
1735    
# Line 1580  lscp_server_info_t *lscp_get_server_info Line 1750  lscp_server_info_t *lscp_get_server_info
1750                                  if (pszToken)                                  if (pszToken)
1751                                          lscp_unquote_dup(&(pServerInfo->version), &pszToken);                                          lscp_unquote_dup(&(pServerInfo->version), &pszToken);
1752                          }                          }
1753                            else if (strcasecmp(pszToken, "PROTOCOL_VERSION") == 0) {
1754                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1755                                    if (pszToken)
1756                                            lscp_unquote_dup(&(pServerInfo->protocol_version), &pszToken);
1757                            }
1758                          pszToken = lscp_strtok(NULL, pszSeps, &(pch));                          pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1759                  }                  }
1760          }          }
# Line 1605  int lscp_get_total_voice_count ( lscp_cl Line 1780  int lscp_get_total_voice_count ( lscp_cl
1780  {  {
1781          int iVoiceCount = -1;          int iVoiceCount = -1;
1782    
1783            if (pClient == NULL)
1784                    return -1;
1785    
1786          // Lock this section up.          // Lock this section up.
1787          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
1788    
# Line 1631  int lscp_get_total_voice_count_max ( lsc Line 1809  int lscp_get_total_voice_count_max ( lsc
1809  {  {
1810          int iVoiceCount = -1;          int iVoiceCount = -1;
1811    
1812            if (pClient == NULL)
1813                    return -1;
1814    
1815          // Lock this section up.          // Lock this section up.
1816          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
1817    
# Line 1645  int lscp_get_total_voice_count_max ( lsc Line 1826  int lscp_get_total_voice_count_max ( lsc
1826    
1827    
1828  /**  /**
1829     *  Get global volume attenuation:
1830     *  GET VOLUME
1831     *
1832     *  @param pClient  Pointer to client instance structure.
1833     *
1834     *  @returns The global volume as positive floating point value usually in
1835     *  the range between 0.0 and 1.0; in case of failure 0.0 is returned.
1836     */
1837    float lscp_get_volume ( lscp_client_t *pClient )
1838    {
1839            float fVolume = 0.0f;
1840    
1841            if (pClient == NULL)
1842                    return 0.0f;
1843    
1844            // Lock this section up.
1845            lscp_mutex_lock(pClient->mutex);
1846    
1847            if (lscp_client_call(pClient, "GET VOLUME\r\n", 0) == LSCP_OK)
1848                    fVolume = (float) atof(lscp_client_get_result(pClient));
1849    
1850            // Unlock this section down.
1851            lscp_mutex_unlock(pClient->mutex);
1852    
1853            return fVolume;
1854    }
1855    
1856    
1857    /**
1858     *  Setting global volume attenuation:
1859     *  SET VOLUME <volume>
1860     *
1861     *  @param pClient  Pointer to client instance structure.
1862     *  @param fVolume  Global volume parameter as positive floating point
1863     *                  value usually be in the range between 0.0 and 1.0,
1864     *                  that is for attenuating the overall volume.
1865     *
1866     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1867     */
1868    lscp_status_t lscp_set_volume ( lscp_client_t *pClient, float fVolume )
1869    {
1870            char szQuery[LSCP_BUFSIZ];
1871    
1872            if (fVolume < 0.0f)
1873                    return LSCP_FAILED;
1874    
1875            sprintf(szQuery, "SET VOLUME %g\r\n", fVolume);
1876            return lscp_client_query(pClient, szQuery);
1877    }
1878    
1879    
1880    /**
1881     *  Add an effect send to a sampler channel:
1882     *  CREATE FX_SEND <sampler-channel> <midi-ctrl> [<name>]
1883     *
1884     *  @param pClient          Pointer to client instance structure.
1885     *  @param iSamplerChannel  Sampler channel number.
1886     *  @param iMidiController  MIDI controller used to alter the effect,
1887     *                          usually a number between 0 and 127.
1888     *  @param pszName          Optional name for the effect send entity,
1889     *                          does not have to be unique.
1890     *
1891     *  @returns The new effect send number identifier, or -1 in case of failure.
1892     */
1893    int lscp_create_fxsend ( lscp_client_t *pClient, int iSamplerChannel, int iMidiController, const char *pszFxName )
1894    {
1895            int iFxSend = -1;
1896            char szQuery[LSCP_BUFSIZ];
1897    
1898            if (pClient == NULL)
1899                    return -1;
1900            if (iSamplerChannel < 0 || iMidiController < 0 || iMidiController > 127)
1901                    return -1;
1902    
1903            // Lock this section up.
1904            lscp_mutex_lock(pClient->mutex);
1905    
1906            sprintf(szQuery, "CREATE FX_SEND %d %d", iSamplerChannel, iMidiController);
1907            
1908            if (pszFxName)
1909                    sprintf(szQuery + strlen(szQuery), " '%s'", pszFxName);
1910    
1911            strcat(szQuery, "\r\n");
1912    
1913            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
1914                    iFxSend = atoi(lscp_client_get_result(pClient));
1915    
1916            // Unlock this section down.
1917            lscp_mutex_unlock(pClient->mutex);
1918    
1919            return iFxSend;
1920    }
1921    
1922    
1923    /**
1924     *  Remove an effect send from a sampler channel:
1925     *  DESTROY FX_SEND <sampler-channel> <fx-send-id>
1926     *
1927     *  @param pClient          Pointer to client instance structure.
1928     *  @param iSamplerChannel  Sampler channel number.
1929     *  @param iFxSend          Effect send number.
1930     *
1931     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1932     */
1933    lscp_status_t lscp_destroy_fxsend ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend )
1934    {
1935            char szQuery[LSCP_BUFSIZ];
1936    
1937            if (iSamplerChannel < 0 || iFxSend < 0)
1938                    return LSCP_FAILED;
1939    
1940            sprintf(szQuery, "DESTROY FX_SEND %d %d\r\n", iSamplerChannel, iFxSend);
1941    
1942            return lscp_client_query(pClient, szQuery);
1943    }
1944    
1945    
1946    /**
1947     *  Get amount of effect sends on a sampler channel:
1948     *  GET FX_SENDS <sampler-channel>
1949     *
1950     *  @param pClient          Pointer to client instance structure.
1951     *  @param iSamplerChannel  Sampler channel number.
1952     *
1953     *  @returns The current total number of effect sends of the sampler channel
1954     *  on success, -1 otherwise.
1955     */
1956    int lscp_get_fxsends ( lscp_client_t *pClient, int iSamplerChannel )
1957    {
1958            int iFxSends = -1;
1959            char szQuery[LSCP_BUFSIZ];
1960    
1961            if (pClient == NULL)
1962                    return -1;
1963            if (iSamplerChannel < 0)
1964                    return -1;
1965    
1966            // Lock this section up.
1967            lscp_mutex_lock(pClient->mutex);
1968    
1969            sprintf(szQuery, "GET FX_SENDS %d\r\n", iSamplerChannel);
1970    
1971            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
1972                    iFxSends = atoi(lscp_client_get_result(pClient));
1973    
1974            // Unlock this section doen.
1975            lscp_mutex_unlock(pClient->mutex);
1976    
1977            return iFxSends;
1978    }
1979    
1980    
1981    /**
1982     *  List all effect sends on a sampler channel:
1983     *  LIST FX_SENDS <sampler-channel>
1984     *
1985     *  @param pClient          Pointer to client instance structure.
1986     *  @param iSamplerChannel  Sampler channel number.
1987     *
1988     *  @returns An array of the effect sends identifiers as positive integers,
1989     *  terminated with -1 on success, NULL otherwise.
1990     */
1991    int *lscp_list_fxsends ( lscp_client_t *pClient, int iSamplerChannel )
1992    {
1993            const char *pszSeps = ",";
1994            char szQuery[LSCP_BUFSIZ];
1995    
1996            if (pClient == NULL)
1997                    return NULL;
1998    
1999            // Lock this section up.
2000            lscp_mutex_lock(pClient->mutex);
2001    
2002            if (pClient->fxsends) {
2003                    lscp_isplit_destroy(pClient->fxsends);
2004                    pClient->fxsends = NULL;
2005            }
2006    
2007            sprintf(szQuery, "LIST FX_SENDS %d\r\n", iSamplerChannel);
2008    
2009            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
2010                    pClient->fxsends = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps);
2011    
2012            // Unlock this section down.
2013            lscp_mutex_unlock(pClient->mutex);
2014    
2015            return pClient->fxsends;
2016    }
2017    
2018    
2019    /**
2020     *  Getting effect send information
2021     *  GET FX_SEND INFO <sampler-channel> <fx-send-id>
2022     *
2023     *  @param pClient          Pointer to client instance structure.
2024     *  @param iSamplerChannel  Sampler channel number.
2025     *  @param iFxSend          Effect send number.
2026     *
2027     *  @returns A pointer to a @ref lscp_fxsend_info_t structure, with the
2028     *  information of the given FX send, or NULL in case of failure.
2029     */
2030    lscp_fxsend_info_t *lscp_get_fxsend_info ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend )
2031    {
2032            lscp_fxsend_info_t *pFxSendInfo;
2033            char szQuery[LSCP_BUFSIZ];
2034            const char *pszResult;
2035            const char *pszSeps = ":";
2036            const char *pszCrlf = "\r\n";
2037            char *pszToken;
2038            char *pch;
2039    
2040            if (pClient == NULL)
2041                    return NULL;
2042            if (iSamplerChannel < 0 || iFxSend < 0)
2043                    return NULL;
2044    
2045            // Lock this section up.
2046            lscp_mutex_lock(pClient->mutex);
2047    
2048            pFxSendInfo = &(pClient->fxsend_info);
2049            lscp_fxsend_info_reset(pFxSendInfo);
2050    
2051            sprintf(szQuery, "GET FX_SEND INFO %d %d\r\n", iSamplerChannel, iFxSend);
2052            if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) {
2053                    pszResult = lscp_client_get_result(pClient);
2054                    pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
2055                    while (pszToken) {
2056                            if (strcasecmp(pszToken, "NAME") == 0) {
2057                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2058                                    if (pszToken)
2059                                            lscp_unquote_dup(&(pFxSendInfo->name), &pszToken);
2060                            }
2061                            else if (strcasecmp(pszToken, "MIDI_CONTROLLER") == 0) {
2062                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2063                                    if (pszToken)
2064                                            pFxSendInfo->midi_controller = atoi(lscp_ltrim(pszToken));
2065                            }
2066                            else if (strcasecmp(pszToken, "AUDIO_OUTPUT_ROUTING") == 0) {
2067                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2068                                    if (pszToken) {
2069                                            if (pFxSendInfo->audio_routing)
2070                                                    lscp_isplit_destroy(pFxSendInfo->audio_routing);
2071                                            pFxSendInfo->audio_routing = lscp_isplit_create(pszToken, ",");
2072                                    }
2073                            }
2074                            else if (strcasecmp(pszToken, "LEVEL") == 0) {
2075                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2076                                    if (pszToken)
2077                                            pFxSendInfo->level = (float) atof(lscp_ltrim(pszToken));
2078                            }
2079                            pszToken = lscp_strtok(NULL, pszSeps, &(pch));
2080                    }
2081            }
2082            else pFxSendInfo = NULL;
2083    
2084            // Unlock this section up.
2085            lscp_mutex_unlock(pClient->mutex);
2086    
2087            return pFxSendInfo;
2088    }
2089    
2090    /**
2091     *  Alter effect send's name:
2092     *  @code
2093     *  SET FX_SEND NAME <sampler-chan> <fx-send-id> <name>
2094     *  @endcode
2095     *
2096     *  @param pClient          Pointer to client instance structure.
2097     *  @param iSamplerChannel  Sampler channel number.
2098     *  @param iFxSend          Effect send number.
2099     *  @param pszFxName        Effect send's new name.
2100     *
2101     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2102     */
2103    lscp_status_t lscp_set_fxsend_name ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, const char *pszFxName )
2104    {
2105            char szQuery[LSCP_BUFSIZ];
2106    
2107            if (!pClient || iSamplerChannel < 0 || iFxSend < 0 || !pszFxName)
2108                    return LSCP_FAILED;
2109    
2110            snprintf(szQuery, LSCP_BUFSIZ, "SET FX_SEND NAME %d %d '%s'\r\n", iSamplerChannel, iFxSend, pszFxName);
2111            return lscp_client_query(pClient, szQuery);
2112    }
2113    
2114    /**
2115     *  Alter effect send's audio routing:
2116     *  SET FX_SEND AUDIO_OUTPUT_CHANNEL <sampler-chan> <fx-send-id>
2117     *    <audio-src> <audio-dst>
2118     *
2119     *  @param pClient          Pointer to client instance structure.
2120     *  @param iSamplerChannel  Sampler channel number.
2121     *  @param iFxSend          Effect send number.
2122     *  @param iAudioSrc        Audio output device channel to be routed from.
2123     *  @param iAudioDst        Audio output device channel to be routed into.
2124     *
2125     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2126     */
2127    lscp_status_t lscp_set_fxsend_audio_channel ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, int iAudioSrc, int iAudioDst )
2128    {
2129            char szQuery[LSCP_BUFSIZ];
2130    
2131            if (iSamplerChannel < 0 || iFxSend < 0 || iAudioSrc < 0 || iAudioDst < 0)
2132                    return LSCP_FAILED;
2133    
2134            sprintf(szQuery, "SET FX_SEND AUDIO_OUTPUT_CHANNEL %d %d %d %d\r\n", iSamplerChannel, iFxSend, iAudioSrc, iAudioDst);
2135            return lscp_client_query(pClient, szQuery);
2136    }
2137    
2138    
2139    /**
2140     *  Alter effect send's MIDI controller:
2141     *  SET FX_SEND MIDI_CONTROLLER <sampler-chan> <fx-send-id> <midi-ctrl>
2142     *
2143     *  @param pClient          Pointer to client instance structure.
2144     *  @param iSamplerChannel  Sampler channel number.
2145     *  @param iFxSend          Effect send number.
2146     *  @param iMidiController  MIDI controller used to alter the effect,
2147     *                          usually a number between 0 and 127.
2148     *
2149     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2150     */
2151    lscp_status_t lscp_set_fxsend_midi_controller ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, int iMidiController )
2152    {
2153            char szQuery[LSCP_BUFSIZ];
2154    
2155            if (iSamplerChannel < 0 || iFxSend < 0 || iMidiController < 0 || iMidiController > 127)
2156                    return LSCP_FAILED;
2157    
2158            sprintf(szQuery, "SET FX_SEND MIDI_CONTROLLER %d %d %d\r\n", iSamplerChannel, iFxSend, iMidiController);
2159            return lscp_client_query(pClient, szQuery);
2160    }
2161    
2162    
2163    /**
2164     *  Alter effect send's audio level:
2165     *  SET FX_SEND LEVEL <sampler-chan> <fx-send-id> <level>
2166     *
2167     *  @param pClient          Pointer to client instance structure.
2168     *  @param iSamplerChannel  Sampler channel number.
2169     *  @param iFxSend          Effect send number.
2170     *  @param fLevel           Effect send volume level.
2171     *
2172     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2173     */
2174    lscp_status_t lscp_set_fxsend_level ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, float fLevel )
2175    {
2176            char szQuery[LSCP_BUFSIZ];
2177    
2178            if (iSamplerChannel < 0 || iFxSend < 0 || fLevel < 0.0f)
2179                    return LSCP_FAILED;
2180    
2181            sprintf(szQuery, "SET FX_SEND LEVEL %d %d %f\r\n", iSamplerChannel, iFxSend, fLevel);
2182            return lscp_client_query(pClient, szQuery);
2183    }
2184    
2185    
2186    /**
2187     *  Create a new MIDI instrument map:
2188     *  ADD MIDI_INSTRUMENT_MAP [<name>]
2189     *
2190     *  @param pClient      Pointer to client instance structure.
2191     *  @param pszMapName   MIDI instrument map name (optional)
2192     *
2193     *  @returns The new MIDI instrument map number identifier,
2194     *  or -1 in case of failure.
2195     */
2196    int lscp_add_midi_instrument_map ( lscp_client_t *pClient, const char *pszMapName )
2197    {
2198            int iMidiMap = -1;
2199            char szQuery[LSCP_BUFSIZ];
2200    
2201            if (pClient == NULL)
2202                    return -1;
2203    
2204            // Lock this section up.
2205            lscp_mutex_lock(pClient->mutex);
2206    
2207            strcpy(szQuery, "ADD MIDI_INSTRUMENT_MAP");
2208            
2209            if (pszMapName)
2210                    sprintf(szQuery + strlen(szQuery), " '%s'", pszMapName);
2211    
2212            strcat(szQuery, "\r\n");
2213    
2214            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
2215                    iMidiMap = atoi(lscp_client_get_result(pClient));
2216    
2217            // Unlock this section down.
2218            lscp_mutex_unlock(pClient->mutex);
2219    
2220            return iMidiMap;
2221    }
2222    
2223    
2224    /**
2225     *  Delete one particular or all MIDI instrument maps:
2226     *  REMOVE MIDI_INSTRUMENT_MAP <midi-map>
2227     *
2228     *  @param pClient  Pointer to client instance structure.
2229     *  @param iMidiMap MIDI instrument map number.
2230     *
2231     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2232     */
2233    lscp_status_t lscp_remove_midi_instrument_map ( lscp_client_t *pClient, int iMidiMap )
2234    {
2235            char szQuery[LSCP_BUFSIZ];
2236    
2237            if (iMidiMap < 0)
2238                    return LSCP_FAILED;
2239    
2240            sprintf(szQuery, "REMOVE MIDI_INSTRUMENT_MAP %d\r\n", iMidiMap);
2241    
2242            return lscp_client_query(pClient, szQuery);
2243    }
2244    
2245    
2246    /**
2247     *  Get amount of existing MIDI instrument maps:
2248     *  GET MIDI_INSTRUMENT_MAPS
2249     *
2250     *  @param pClient  Pointer to client instance structure.
2251     *
2252     *  @returns The current total number of MIDI instrument maps
2253     *  on success, -1 otherwise.
2254     */
2255    int lscp_get_midi_instrument_maps ( lscp_client_t *pClient )
2256    {
2257            int iMidiMaps = -1;
2258    
2259            if (pClient == NULL)
2260                    return -1;
2261    
2262            // Lock this section up.
2263            lscp_mutex_lock(pClient->mutex);
2264    
2265            if (lscp_client_call(pClient, "GET MIDI_INSTRUMENT_MAPS\r\n", 0) == LSCP_OK)
2266                    iMidiMaps = atoi(lscp_client_get_result(pClient));
2267    
2268            // Unlock this section doen.
2269            lscp_mutex_unlock(pClient->mutex);
2270    
2271            return iMidiMaps;
2272    }
2273    
2274    
2275    /**
2276     *  Getting all created MIDI instrument maps:
2277     *  LIST MIDI_INSTRUMENT_MAPS
2278     *
2279     *  @param pClient  Pointer to client instance structure.
2280     *
2281     *  @returns An array of the MIDI instrument map identifiers as positive
2282     *  integers, terminated with -1 on success, NULL otherwise.
2283     */
2284    int *lscp_list_midi_instrument_maps ( lscp_client_t *pClient )
2285    {
2286            const char *pszSeps = ",";
2287    
2288            if (pClient == NULL)
2289                    return NULL;
2290    
2291            // Lock this section up.
2292            lscp_mutex_lock(pClient->mutex);
2293    
2294            if (pClient->midi_maps) {
2295                    lscp_isplit_destroy(pClient->midi_maps);
2296                    pClient->midi_maps = NULL;
2297            }
2298    
2299            if (lscp_client_call(pClient, "LIST MIDI_INSTRUMENT_MAPS\r\n", 0) == LSCP_OK)
2300                    pClient->midi_maps = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps);
2301    
2302            // Unlock this section down.
2303            lscp_mutex_unlock(pClient->mutex);
2304    
2305            return pClient->midi_maps;
2306    }
2307    
2308    
2309    /**
2310     *  Getting a MIDI instrument map name:
2311     *  GET MIDI_INSTRUMENT_MAP INFO <midi-map>
2312     *
2313     *  @param pClient  Pointer to client instance structure.
2314     *  @param iMidiMap MIDI instrument map number.
2315     *
2316     *  @returns The MIDI instrument map name on success, NULL on failure.
2317     */
2318    const char *lscp_get_midi_instrument_map_name ( lscp_client_t *pClient, int iMidiMap )
2319    {
2320            char szQuery[LSCP_BUFSIZ];
2321            const char *pszResult;
2322            const char *pszSeps = ":";
2323            const char *pszCrlf = "\r\n";
2324            char *pszToken;
2325            char *pch;
2326    
2327            if (pClient == NULL)
2328                    return NULL;
2329            if (iMidiMap < 0)
2330                    return NULL;
2331    
2332            // Lock this section up.
2333            lscp_mutex_lock(pClient->mutex);
2334            
2335            if (pClient->midi_map_name) {
2336                    free(pClient->midi_map_name);
2337                    pClient->midi_map_name = NULL;
2338            }
2339    
2340            sprintf(szQuery, "GET MIDI_INSTRUMENT_MAP INFO %d\r\n", iMidiMap);
2341            if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) {
2342                    pszResult = lscp_client_get_result(pClient);
2343                    pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
2344                    while (pszToken) {
2345                            if (strcasecmp(pszToken, "NAME") == 0) {
2346                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2347                                    if (pszToken)
2348                                            lscp_unquote_dup(&(pClient->midi_map_name), &pszToken);
2349                            }
2350                            pszToken = lscp_strtok(NULL, pszSeps, &(pch));
2351                    }
2352            }
2353    
2354            // Unlock this section down.
2355            lscp_mutex_unlock(pClient->mutex);
2356    
2357            return pClient->midi_map_name;
2358    }
2359    
2360    
2361    /**
2362     *  Renaming a MIDI instrument map:
2363     *  SET MIDI_INSTRUMENT_MAP NAME <midi-map> <map-name>
2364     *
2365     *  @param pClient      Pointer to client instance structure.
2366     *  @param iMidiMap     MIDI instrument map number.
2367     *  @param pszMapName   MIDI instrument map name.
2368     *
2369     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2370     */
2371    lscp_status_t lscp_set_midi_instrument_map_name ( lscp_client_t *pClient, int iMidiMap, const char *pszMapName )
2372    {
2373            char szQuery[LSCP_BUFSIZ];
2374    
2375            if (iMidiMap < 0)
2376                    return LSCP_FAILED;
2377            if (pszMapName == NULL)
2378                    return LSCP_FAILED;
2379    
2380            sprintf(szQuery, "SET MIDI_INSTRUMENT_MAP NAME %d '%s'\r\n",
2381                    iMidiMap, pszMapName);
2382    
2383            return lscp_client_query(pClient, szQuery);
2384    }
2385    
2386    
2387    /**
2388   *  Create or replace a MIDI instrumnet map entry:   *  Create or replace a MIDI instrumnet map entry:
2389   *  MAP MIDI_INSTRUMENT <midi-bank-msb> <midi-bank-lsb> <midi-prog>   *  MAP MIDI_INSTRUMENT <midi-map> <midi-bank> <midi-prog>
2390   *      <engine-name> <filename> <instr-index> <volume> <load-mode> [<name>]   *      <engine-name> <filename> <instr-index> <volume> [<load-mode> [<name>]}
2391   *   *
2392   *  @param pClient          Pointer to client instance structure.   *  @param pClient          Pointer to client instance structure.
2393   *  @param pMidiInstr       MIDI instrument bank and program parameter key.   *  @param pMidiInstr       MIDI instrument bank and program parameter key.
# Line 1663  int lscp_get_total_voice_count_max ( lsc Line 2403  int lscp_get_total_voice_count_max ( lsc
2403   *                          @ref LSCP_LOAD_ON_DEMAND, or   *                          @ref LSCP_LOAD_ON_DEMAND, or
2404   *                          @ref LSCP_LOAD_ON_DEMAND_HOLD, or   *                          @ref LSCP_LOAD_ON_DEMAND_HOLD, or
2405   *                          @ref LSCP_LOAD_PERSISTENT.   *                          @ref LSCP_LOAD_PERSISTENT.
2406   *  @param pszName          Instrument custom name for the map entry.   *  @param pszName         Instrument custom name for the map entry (optional).
2407   *   *
2408   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2409   */   */
# Line 1671  lscp_status_t lscp_map_midi_instrument ( Line 2411  lscp_status_t lscp_map_midi_instrument (
2411  {  {
2412          char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
2413    
2414          if (pMidiInstr->bank_msb < 0 || pMidiInstr->bank_msb > 127)          if (pMidiInstr->map < 0)
2415                  return LSCP_FAILED;                  return LSCP_FAILED;
2416          if (pMidiInstr->bank_lsb < 0 || pMidiInstr->bank_lsb > 127)          if (pMidiInstr->bank < 0 || pMidiInstr->bank > 16383)
2417                  return LSCP_FAILED;                  return LSCP_FAILED;
2418          if (pMidiInstr->program < 0 || pMidiInstr->program > 127)          if (pMidiInstr->prog < 0 || pMidiInstr->prog > 127)
2419                  return LSCP_FAILED;                  return LSCP_FAILED;
2420          if (pszEngineName == NULL || pszFileName == NULL)          if (pszEngineName == NULL || pszFileName == NULL)
2421                  return LSCP_FAILED;                  return LSCP_FAILED;
# Line 1684  lscp_status_t lscp_map_midi_instrument ( Line 2424  lscp_status_t lscp_map_midi_instrument (
2424                  fVolume = 1.0f;                  fVolume = 1.0f;
2425    
2426          sprintf(szQuery, "MAP MIDI_INSTRUMENT %d %d %d %s '%s' %d %g",          sprintf(szQuery, "MAP MIDI_INSTRUMENT %d %d %d %s '%s' %d %g",
2427                  pMidiInstr->bank_msb, pMidiInstr->bank_lsb, pMidiInstr->program,                  pMidiInstr->map, pMidiInstr->bank, pMidiInstr->prog,
2428                  pszEngineName, pszFileName, iInstrIndex, fVolume);                  pszEngineName, pszFileName, iInstrIndex, fVolume);
2429    
2430          switch (load_mode) {          switch (load_mode) {
# Line 1713  lscp_status_t lscp_map_midi_instrument ( Line 2453  lscp_status_t lscp_map_midi_instrument (
2453    
2454  /**  /**
2455   *  Remove an entry from the MIDI instrument map:   *  Remove an entry from the MIDI instrument map:
2456   *  UNMAP MIDI_INSTRUMENT <midi-bank-msb> <midi-bank-lsb> <midi-prog>   *  UNMAP MIDI_INSTRUMENT <midi-map> <midi-bank> <midi-prog>
2457   *   *
2458   *  @param pClient      Pointer to client instance structure.   *  @param pClient      Pointer to client instance structure.
2459   *  @param pMidiInstr   MIDI instrument bank and program parameter key.   *  @param pMidiInstr   MIDI instrument bank and program parameter key.
# Line 1724  lscp_status_t lscp_unmap_midi_instrument Line 2464  lscp_status_t lscp_unmap_midi_instrument
2464  {  {
2465          char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
2466    
2467          if (pMidiInstr->bank_msb < 0 || pMidiInstr->bank_msb > 127)          if (pMidiInstr->map < 0)
2468                  return LSCP_FAILED;                  return LSCP_FAILED;
2469          if (pMidiInstr->bank_lsb < 0 || pMidiInstr->bank_lsb > 127)          if (pMidiInstr->bank < 0 || pMidiInstr->bank > 16383)
2470                  return LSCP_FAILED;                  return LSCP_FAILED;
2471          if (pMidiInstr->program < 0 || pMidiInstr->program > 127)          if (pMidiInstr->prog < 0 || pMidiInstr->prog > 127)
2472                  return LSCP_FAILED;                  return LSCP_FAILED;
2473    
2474          sprintf(szQuery, "UNMAP MIDI_INSTRUMENT %d %d %d\r\n",          sprintf(szQuery, "UNMAP MIDI_INSTRUMENT %d %d %d\r\n",
2475                  pMidiInstr->bank_msb, pMidiInstr->bank_lsb, pMidiInstr->program);                  pMidiInstr->map, pMidiInstr->bank, pMidiInstr->prog);
2476    
2477          return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
2478  }  }
# Line 1740  lscp_status_t lscp_unmap_midi_instrument Line 2480  lscp_status_t lscp_unmap_midi_instrument
2480    
2481  /**  /**
2482   *  Get the total count of MIDI instrument map entries:   *  Get the total count of MIDI instrument map entries:
2483   *  GET MIDI_INSTRUMENTS   *  GET MIDI_INSTRUMENTS ALL|<midi-map>
2484   *   *
2485   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
2486     *  @param iMidiMap MIDI instrument map number, or @ref LSCP_MIDI_MAP_ALL .
2487   *   *
2488   *  @returns The current total number of MIDI instrument map entries   *  @returns The current total number of MIDI instrument map entries
2489   *  on success, -1 otherwise.   *  on success, -1 otherwise.
2490   */   */
2491  int lscp_get_midi_instruments ( lscp_client_t *pClient )  int lscp_get_midi_instruments ( lscp_client_t *pClient, int iMidiMap )
2492  {  {
2493          int iInstruments = -1;          int iInstruments = -1;
2494            char szQuery[LSCP_BUFSIZ];
2495    
2496            if (pClient == NULL)
2497                    return -1;
2498    
2499          // Lock this section up.          // Lock this section up.
2500          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
2501    
2502          if (lscp_client_call(pClient, "GET MIDI_INSTRUMENTS\r\n", 0) == LSCP_OK)          strcpy(szQuery, "GET MIDI_INSTRUMENTS ");
2503    
2504            if (iMidiMap < 0)
2505                    strcat(szQuery, "ALL");
2506            else
2507                    sprintf(szQuery + strlen(szQuery), "%d", iMidiMap);
2508    
2509            strcat(szQuery, "\r\n");
2510    
2511            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
2512                  iInstruments = atoi(lscp_client_get_result(pClient));                  iInstruments = atoi(lscp_client_get_result(pClient));
2513    
2514          // Unlock this section down.          // Unlock this section down.
# Line 1766  int lscp_get_midi_instruments ( lscp_cli Line 2520  int lscp_get_midi_instruments ( lscp_cli
2520    
2521  /**  /**
2522   *  Getting indeces of all MIDI instrument map entries:   *  Getting indeces of all MIDI instrument map entries:
2523   *  LIST MIDI_INSTRUMENTS   *  LIST MIDI_INSTRUMENTS ALL|<midi-map>
2524   *   *
2525   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
2526     *  @param iMidiMap MIDI instrument map number, or @ref LSCP_MIDI_MAP_ALL .
2527   *   *
2528   *  @returns An array of @ref lscp_midi_instrument_t, terminated with the   *  @returns An array of @ref lscp_midi_instrument_t, terminated with the
2529   *  {-1,-1,-1} triplet, NULL otherwise.   *  {-1,-1,-1} triplet, NULL otherwise.
2530   */   */
2531  lscp_midi_instrument_t *lscp_list_midi_instruments ( lscp_client_t *pClient )  lscp_midi_instrument_t *lscp_list_midi_instruments ( lscp_client_t *pClient, int iMidiMap )
2532  {  {
2533            char szQuery[LSCP_BUFSIZ];
2534    
2535          if (pClient == NULL)          if (pClient == NULL)
2536                  return NULL;                  return NULL;
2537    
# Line 1786  lscp_midi_instrument_t *lscp_list_midi_i Line 2543  lscp_midi_instrument_t *lscp_list_midi_i
2543                  pClient->midi_instruments = NULL;                  pClient->midi_instruments = NULL;
2544          }          }
2545    
2546          if (lscp_client_call(pClient, "LIST MIDI_INSTRUMENTS\r\n", 0) == LSCP_OK)          strcpy(szQuery, "LIST MIDI_INSTRUMENTS ");
2547    
2548            if (iMidiMap < 0)
2549                    strcat(szQuery, "ALL");
2550            else
2551                    sprintf(szQuery + strlen(szQuery), "%d", iMidiMap);
2552    
2553            strcat(szQuery, "\r\n");
2554    
2555            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
2556                  pClient->midi_instruments = lscp_midi_instruments_create(lscp_client_get_result(pClient));                  pClient->midi_instruments = lscp_midi_instruments_create(lscp_client_get_result(pClient));
2557    
2558          // Unlock this section down.          // Unlock this section down.
# Line 1798  lscp_midi_instrument_t *lscp_list_midi_i Line 2564  lscp_midi_instrument_t *lscp_list_midi_i
2564    
2565  /**  /**
2566   *  Getting information about a MIDI instrument map entry:   *  Getting information about a MIDI instrument map entry:
2567   *  GET MIDI_INSTRUMENT INFO <midi-bank-msb> <midi-bank-lsb> <midi-prog>   *  GET MIDI_INSTRUMENT INFO <midi-map> <midi-bank> <midi-prog>
2568   *   *
2569   *  @param pClient      Pointer to client instance structure.   *  @param pClient      Pointer to client instance structure.
2570   *  @param pMidiInstr   MIDI instrument bank and program parameter key.   *  @param pMidiInstr   MIDI instrument bank and program parameter key.
# Line 1817  lscp_midi_instrument_info_t *lscp_get_mi Line 2583  lscp_midi_instrument_info_t *lscp_get_mi
2583          char *pszToken;          char *pszToken;
2584          char *pch;          char *pch;
2585    
2586          if (pMidiInstr->bank_msb < 0 || pMidiInstr->bank_msb > 127)          if (pClient == NULL)
2587                  return NULL;                  return NULL;
2588          if (pMidiInstr->bank_lsb < 0 || pMidiInstr->bank_lsb > 127)          if (pMidiInstr->map < 0)
2589                  return NULL;                  return NULL;
2590          if (pMidiInstr->program < 0 || pMidiInstr->program > 127)          if (pMidiInstr->bank < 0 || pMidiInstr->bank > 16383)
2591                    return NULL;
2592            if (pMidiInstr->prog < 0 || pMidiInstr->prog > 127)
2593                  return NULL;                  return NULL;
2594    
2595          // Lock this section up.          // Lock this section up.
# Line 1831  lscp_midi_instrument_info_t *lscp_get_mi Line 2599  lscp_midi_instrument_info_t *lscp_get_mi
2599          lscp_midi_instrument_info_reset(pInstrInfo);          lscp_midi_instrument_info_reset(pInstrInfo);
2600    
2601          sprintf(szQuery, "GET MIDI_INSTRUMENT INFO %d %d %d\r\n",          sprintf(szQuery, "GET MIDI_INSTRUMENT INFO %d %d %d\r\n",
2602                  pMidiInstr->bank_msb, pMidiInstr->bank_lsb, pMidiInstr->program);                  pMidiInstr->map, pMidiInstr->bank, pMidiInstr->prog);
2603          if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) {          if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) {
2604                  pszResult = lscp_client_get_result(pClient);                  pszResult = lscp_client_get_result(pClient);
2605                  pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));                  pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
# Line 1896  lscp_midi_instrument_info_t *lscp_get_mi Line 2664  lscp_midi_instrument_info_t *lscp_get_mi
2664    
2665  /**  /**
2666   *  Clear the MIDI instrumnet map:   *  Clear the MIDI instrumnet map:
2667   *  CLEAR MIDI_INSTRUMENTS   *  CLEAR MIDI_INSTRUMENTS ALL|<midi-map>
2668   *   *
2669   *  @param pClient         Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
2670   *  @param iSamplerChannel  Sampler channel number.   *  @param iMidiMap MIDI instrument map number, or @ref LSCP_MIDI_MAP_ALL .
2671   *   *
2672   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2673   */   */
2674  lscp_status_t lscp_clear_midi_instruments  ( lscp_client_t *pClient )  lscp_status_t lscp_clear_midi_instruments  ( lscp_client_t *pClient, int iMidiMap )
2675  {  {
2676          return lscp_client_query(pClient, "CLEAR MIDI_INSTRUMENTS\r\n");          char szQuery[LSCP_BUFSIZ];
2677    
2678            strcpy(szQuery, "CLEAR MIDI_INSTRUMENTS ");
2679    
2680            if (iMidiMap < 0)
2681                    strcat(szQuery, "ALL");
2682            else
2683                    sprintf(szQuery + strlen(szQuery), "%d", iMidiMap);
2684    
2685            strcat(szQuery, "\r\n");
2686    
2687            return lscp_client_query(pClient, szQuery);
2688    }
2689    
2690    /**
2691     * Open an instrument editor application for the instrument
2692     * on the given sampler channel:
2693     * EDIT CHANNEL INSTRUMENT <sampler-channel>
2694     *
2695     * @param pClient         Pointer to client instance structure.
2696     * @param iSamplerChannel Sampler Channel.
2697     *
2698     * @returns LSCP_OK on success, LSCP_FAILED otherwise.
2699     */
2700    lscp_status_t lscp_edit_channel_instrument ( lscp_client_t *pClient, int iSamplerChannel )
2701    {
2702            char szQuery[LSCP_BUFSIZ];
2703    
2704            if (iSamplerChannel < 0)
2705                    return LSCP_FAILED;
2706    
2707            sprintf(szQuery, "EDIT CHANNEL INSTRUMENT %d\r\n", iSamplerChannel);
2708    
2709            return lscp_client_query(pClient, szQuery);
2710  }  }
2711    
2712    

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

  ViewVC Help
Powered by ViewVC