/[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 952 by capela, Tue Nov 28 22:46:32 2006 UTC revision 1665 by schoenebeck, Mon Feb 4 13:02:30 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;
333            pClient->midi_map_name = NULL;
334          lscp_driver_info_init(&(pClient->audio_driver_info));          lscp_driver_info_init(&(pClient->audio_driver_info));
335          lscp_driver_info_init(&(pClient->midi_driver_info));          lscp_driver_info_init(&(pClient->midi_driver_info));
336          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 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 403  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 423  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);
434            if (pClient->midi_map_name)
435                    free(pClient->midi_map_name);
436          // Make them null.          // Make them null.
437          pClient->audio_drivers = NULL;          pClient->audio_drivers = NULL;
438          pClient->midi_drivers = NULL;          pClient->midi_drivers = NULL;
# Line 431  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;
446            pClient->midi_map_name = NULL;
447          // Free result error stuff.          // Free result error stuff.
448          lscp_client_set_result(pClient, NULL, 0);          lscp_client_set_result(pClient, NULL, 0);
449          // Free stream usage stuff.          // Free stream usage stuff.
# Line 512  lscp_status_t lscp_client_query ( lscp_c Line 524  lscp_status_t lscp_client_query ( lscp_c
524  {  {
525          lscp_status_t ret;          lscp_status_t ret;
526    
527            if (pClient == NULL)
528                    return LSCP_FAILED;
529    
530          // Lock this section up.          // Lock this section up.
531          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
532    
# Line 564  int lscp_client_get_errno ( lscp_client_ Line 579  int lscp_client_get_errno ( lscp_client_
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   *  SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT
583   *      | CHANNEL_INFO | MISCELLANEOUS   *      | BUFFER_FILL | CHANNEL_INFO | TOTAL_VOICE_COUNT
584     *      | AUDIO_OUTPUT_DEVICE_COUNT | AUDIO_OUTPUT_DEVICE_INFO
585     *      | MIDI_INPUT_DEVICE_COUNT | MIDI_INPUT_DEVICE_INFO
586     *      | MIDI_INSTRUMENT_MAP_COUNT | MIDI_INSTRUMENT_MAP_INFO
587     *      | MIDI_INSTRUMENT_COUNT | MIDI_INSTRUMENT_INFO
588     *      | MISCELLANEOUS
589   *   *
590   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
591   *  @param events   Bit-wise OR'ed event flags to subscribe.   *  @param events   Bit-wise OR'ed event flags to subscribe.
# Line 597  lscp_status_t lscp_client_subscribe ( ls Line 617  lscp_status_t lscp_client_subscribe ( ls
617                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_BUFFER_FILL);                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_BUFFER_FILL);
618          if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))          if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))
619                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_INFO);                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_INFO);
620            if (ret == LSCP_OK && (events & LSCP_EVENT_TOTAL_VOICE_COUNT))
621                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_TOTAL_VOICE_COUNT);
622            if (ret == LSCP_OK && (events & LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT))
623                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT);
624            if (ret == LSCP_OK && (events & LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO))
625                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO);
626            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT))
627                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT);
628            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INPUT_DEVICE_INFO))
629                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INPUT_DEVICE_INFO);
630            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_MAP_COUNT))
631                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_MAP_COUNT);
632            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_MAP_INFO))
633                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_MAP_INFO);
634            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_COUNT))
635                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_COUNT);
636            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_INFO))
637                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_INFO);
638          if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))          if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))
639                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MISCELLANEOUS);                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MISCELLANEOUS);
640    
# Line 609  lscp_status_t lscp_client_subscribe ( ls Line 647  lscp_status_t lscp_client_subscribe ( ls
647    
648  /**  /**
649   *  Deregister frontend from receiving UDP event messages anymore:   *  Deregister frontend from receiving UDP event messages anymore:
650   *  SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL   *  UNSUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT
651   *      | CHANNEL_INFO | MISCELLANEOUS   *      | BUFFER_FILL | CHANNEL_INFO | TOTAL_VOICE_COUNT
652     *      | AUDIO_OUTPUT_DEVICE_COUNT | AUDIO_OUTPUT_DEVICE_INFO
653     *      | MIDI_INPUT_DEVICE_COUNT | MIDI_INPUT_DEVICE_INFO
654     *      | MIDI_INSTRUMENT_MAP_COUNT | MIDI_INSTRUMENT_MAP_INFO
655     *      | MIDI_INSTRUMENT_COUNT | MIDI_INSTRUMENT_INFO
656     *      | MISCELLANEOUS
657   *   *
658   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
659   *  @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 681  lscp_status_t lscp_client_unsubscribe (
681                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_BUFFER_FILL);                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_BUFFER_FILL);
682          if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))          if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))
683                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_INFO);                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_INFO);
684            if (ret == LSCP_OK && (events & LSCP_EVENT_TOTAL_VOICE_COUNT))
685                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_TOTAL_VOICE_COUNT);
686            if (ret == LSCP_OK && (events & LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT))
687                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT);
688            if (ret == LSCP_OK && (events & LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO))
689                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO);
690            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT))
691                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT);
692            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INPUT_DEVICE_INFO))
693                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INPUT_DEVICE_INFO);
694            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_MAP_COUNT))
695                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_MAP_COUNT);
696            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_MAP_INFO))
697                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_MAP_INFO);
698            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_COUNT))
699                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_COUNT);
700            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_INFO))
701                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_INFO);
702          if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))          if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))
703                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MISCELLANEOUS);                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MISCELLANEOUS);
704    
# Line 752  int lscp_get_channels ( lscp_client_t *p Line 813  int lscp_get_channels ( lscp_client_t *p
813  {  {
814          int iChannels = -1;          int iChannels = -1;
815    
816            if (pClient == NULL)
817                    return -1;
818    
819          // Lock this section up.          // Lock this section up.
820          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
821    
# Line 812  int lscp_add_channel ( lscp_client_t *pC Line 876  int lscp_add_channel ( lscp_client_t *pC
876  {  {
877          int iSamplerChannel = -1;          int iSamplerChannel = -1;
878    
879            if (pClient == NULL)
880                    return -1;
881    
882          // Lock this section up.          // Lock this section up.
883          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
884    
# Line 859  int lscp_get_available_engines ( lscp_cl Line 926  int lscp_get_available_engines ( lscp_cl
926  {  {
927          int iAvailableEngines = -1;          int iAvailableEngines = -1;
928    
929            if (pClient == NULL)
930                    return -1;
931    
932          // Lock this section up.          // Lock this section up.
933          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
934    
# Line 885  const char **lscp_list_available_engines Line 955  const char **lscp_list_available_engines
955  {  {
956          const char *pszSeps = ",";          const char *pszSeps = ",";
957    
958            if (pClient == NULL)
959                    return NULL;
960    
961          // Lock this section up.          // Lock this section up.
962          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
963    
# Line 923  lscp_engine_info_t *lscp_get_engine_info Line 996  lscp_engine_info_t *lscp_get_engine_info
996          char *pszToken;          char *pszToken;
997          char *pch;          char *pch;
998    
999            if (pClient == NULL)
1000                    return NULL;
1001          if (pszEngineName == NULL)          if (pszEngineName == NULL)
1002                  return NULL;                  return NULL;
1003    
# Line 979  lscp_channel_info_t *lscp_get_channel_in Line 1054  lscp_channel_info_t *lscp_get_channel_in
1054          char *pszToken;          char *pszToken;
1055          char *pch;          char *pch;
1056    
1057            if (pClient == NULL)
1058                    return NULL;
1059          if (iSamplerChannel < 0)          if (iSamplerChannel < 0)
1060                  return NULL;                  return NULL;
1061    
# Line 1012  lscp_channel_info_t *lscp_get_channel_in Line 1089  lscp_channel_info_t *lscp_get_channel_in
1089                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1090                                  if (pszToken) {                                  if (pszToken) {
1091                                          if (pChannelInfo->audio_routing)                                          if (pChannelInfo->audio_routing)
1092                                                  lscp_szsplit_destroy(pChannelInfo->audio_routing);                                                  lscp_isplit_destroy(pChannelInfo->audio_routing);
1093                                          pChannelInfo->audio_routing = lscp_szsplit_create(pszToken, ",");                                          pChannelInfo->audio_routing = lscp_isplit_create(pszToken, ",");
1094                                  }                                  }
1095                          }                          }
1096                          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 1133  lscp_channel_info_t *lscp_get_channel_in
1133                                                  pChannelInfo->midi_channel = atoi(pszToken);                                                  pChannelInfo->midi_channel = atoi(pszToken);
1134                                  }                                  }
1135                          }                          }
1136                            else if (strcasecmp(pszToken, "MIDI_INSTRUMENT_MAP") == 0) {
1137                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1138                                    if (pszToken) {
1139                                            pszToken = lscp_ltrim(pszToken);
1140                                            if (strcasecmp(pszToken, "NONE") == 0)
1141                                                    pChannelInfo->midi_map = LSCP_MIDI_MAP_NONE;
1142                                            else
1143                                            if (strcasecmp(pszToken, "DEFAULT") == 0)
1144                                                    pChannelInfo->midi_map = LSCP_MIDI_MAP_DEFAULT;
1145                                            else
1146                                                    pChannelInfo->midi_map = atoi(pszToken);
1147                                    }
1148                            }
1149                          else if (strcasecmp(pszToken, "VOLUME") == 0) {                          else if (strcasecmp(pszToken, "VOLUME") == 0) {
1150                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1151                                  if (pszToken)                                  if (pszToken)
# Line 1097  int lscp_get_channel_voice_count ( lscp_ Line 1187  int lscp_get_channel_voice_count ( lscp_
1187          char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1188          int iVoiceCount = -1;          int iVoiceCount = -1;
1189    
1190            if (pClient == NULL)
1191                    return -1;
1192          if (iSamplerChannel < 0)          if (iSamplerChannel < 0)
1193                  return iVoiceCount;                  return -1;
1194    
1195          // Lock this section up.          // Lock this section up.
1196          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
# Line 1128  int lscp_get_channel_stream_count ( lscp Line 1220  int lscp_get_channel_stream_count ( lscp
1220          char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1221          int iStreamCount = -1;          int iStreamCount = -1;
1222    
1223            if (pClient == NULL)
1224                    return -1;
1225          if (iSamplerChannel < 0)          if (iSamplerChannel < 0)
1226                  return iStreamCount;                  return -1;
1227    
1228          // Lock this section up.          // Lock this section up.
1229          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
# Line 1165  int lscp_get_channel_stream_usage ( lscp Line 1259  int lscp_get_channel_stream_usage ( lscp
1259          int   iStream;          int   iStream;
1260          int   iPercent;          int   iPercent;
1261    
1262            if (pClient == NULL)
1263                    return -1;
1264          if (iSamplerChannel < 0)          if (iSamplerChannel < 0)
1265                  return iStreamUsage;                  return -1;
1266    
1267          // Lock this section up.          // Lock this section up.
1268          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
# Line 1227  lscp_buffer_fill_t *lscp_get_channel_buf Line 1323  lscp_buffer_fill_t *lscp_get_channel_buf
1323    
1324          // Retrieve a channel stream estimation.          // Retrieve a channel stream estimation.
1325          iStreamCount = lscp_get_channel_stream_count(pClient, iSamplerChannel);          iStreamCount = lscp_get_channel_stream_count(pClient, iSamplerChannel);
1326          if (pClient->iStreamCount < 0)          if (iStreamCount < 0)
1327                  return NULL;                  return NULL;
1328    
1329          // Lock this section up.          // Lock this section up.
# Line 1416  lscp_status_t lscp_set_channel_midi_port Line 1512  lscp_status_t lscp_set_channel_midi_port
1512   *  @param pClient          Pointer to client instance structure.   *  @param pClient          Pointer to client instance structure.
1513   *  @param iSamplerChannel  Sampler channel number.   *  @param iSamplerChannel  Sampler channel number.
1514   *  @param iMidiChannel     MIDI channel address number to listen (0-15) or   *  @param iMidiChannel     MIDI channel address number to listen (0-15) or
1515   *                          LSCP_MIDI_CHANNEL_ALL (16) to listen on all channels.   *                          @ref LSCP_MIDI_CHANNEL_ALL (16) to listen on all channels.
1516   *   *
1517   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1518   */   */
# Line 1436  lscp_status_t lscp_set_channel_midi_chan Line 1532  lscp_status_t lscp_set_channel_midi_chan
1532    
1533    
1534  /**  /**
1535     *  Setting MIDI instrument map:
1536     *  SET CHANNEL MIDI_INSTRUMENT_MAP <sampler-channel> <midi-map>
1537     *
1538     *  @param pClient          Pointer to client instance structure.
1539     *  @param iSamplerChannel  Sampler channel number.
1540     *  @param iMidiMap         MIDI instrument map number, or either
1541     *                          @ref LSCP_MIDI_MAP_NONE or
1542     *                          @ref LSCP_MIDI_MAP_DEFAULT .
1543     *
1544     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1545     */
1546    lscp_status_t lscp_set_channel_midi_map ( lscp_client_t *pClient, int iSamplerChannel, int iMidiMap )
1547    {
1548            char szQuery[LSCP_BUFSIZ];
1549    
1550            if (iSamplerChannel < 0)
1551                    return LSCP_FAILED;
1552    
1553            sprintf(szQuery, "SET CHANNEL MIDI_INSTRUMENT_MAP %d ", iSamplerChannel);
1554            if (iMidiMap == LSCP_MIDI_MAP_NONE)
1555                    strcat(szQuery , "NONE");
1556            else
1557            if (iMidiMap == LSCP_MIDI_MAP_DEFAULT)
1558                    strcat(szQuery , "DEFAULT");
1559            else
1560                    sprintf(szQuery + strlen(szQuery), "%d", iMidiMap);
1561    
1562            strcat(szQuery, "\r\n");
1563    
1564            return lscp_client_query(pClient, szQuery);
1565    }
1566    
1567    
1568    /**
1569   *  Setting channel volume:   *  Setting channel volume:
1570   *  SET CHANNEL VOLUME <sampler-channel> <volume>   *  SET CHANNEL VOLUME <sampler-channel> <volume>
1571   *   *
# Line 1451  lscp_status_t lscp_set_channel_volume ( Line 1581  lscp_status_t lscp_set_channel_volume (
1581  {  {
1582          char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1583    
1584          if (iSamplerChannel < 0 || fVolume < 0.0)          if (iSamplerChannel < 0 || fVolume < 0.0f)
1585                  return LSCP_FAILED;                  return LSCP_FAILED;
1586    
1587          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 1668  lscp_status_t lscp_reset_channel ( lscp_
1668   */   */
1669  lscp_status_t lscp_reset_sampler ( lscp_client_t *pClient )  lscp_status_t lscp_reset_sampler ( lscp_client_t *pClient )
1670  {  {
1671            // Do actual whole sampler reset...
1672          return lscp_client_query(pClient, "RESET\r\n");          return lscp_client_query(pClient, "RESET\r\n");
1673  }  }
1674    
# Line 1560  lscp_server_info_t *lscp_get_server_info Line 1691  lscp_server_info_t *lscp_get_server_info
1691          char *pszToken;          char *pszToken;
1692          char *pch;          char *pch;
1693    
1694            if (pClient == NULL)
1695                    return NULL;
1696    
1697          // Lock this section up.          // Lock this section up.
1698          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
1699    
# Line 1580  lscp_server_info_t *lscp_get_server_info Line 1714  lscp_server_info_t *lscp_get_server_info
1714                                  if (pszToken)                                  if (pszToken)
1715                                          lscp_unquote_dup(&(pServerInfo->version), &pszToken);                                          lscp_unquote_dup(&(pServerInfo->version), &pszToken);
1716                          }                          }
1717                            else if (strcasecmp(pszToken, "PROTOCOL_VERSION") == 0) {
1718                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1719                                    if (pszToken)
1720                                            lscp_unquote_dup(&(pServerInfo->protocol_version), &pszToken);
1721                            }
1722                          pszToken = lscp_strtok(NULL, pszSeps, &(pch));                          pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1723                  }                  }
1724          }          }
# Line 1605  int lscp_get_total_voice_count ( lscp_cl Line 1744  int lscp_get_total_voice_count ( lscp_cl
1744  {  {
1745          int iVoiceCount = -1;          int iVoiceCount = -1;
1746    
1747            if (pClient == NULL)
1748                    return -1;
1749    
1750          // Lock this section up.          // Lock this section up.
1751          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
1752    
# Line 1631  int lscp_get_total_voice_count_max ( lsc Line 1773  int lscp_get_total_voice_count_max ( lsc
1773  {  {
1774          int iVoiceCount = -1;          int iVoiceCount = -1;
1775    
1776            if (pClient == NULL)
1777                    return -1;
1778    
1779          // Lock this section up.          // Lock this section up.
1780          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
1781    
# Line 1645  int lscp_get_total_voice_count_max ( lsc Line 1790  int lscp_get_total_voice_count_max ( lsc
1790    
1791    
1792  /**  /**
1793     *  Get global volume attenuation:
1794     *  GET VOLUME
1795     *
1796     *  @param pClient  Pointer to client instance structure.
1797     *
1798     *  @returns The global volume as positive floating point value usually in
1799     *  the range between 0.0 and 1.0; in case of failure 0.0 is returned.
1800     */
1801    float lscp_get_volume ( lscp_client_t *pClient )
1802    {
1803            float fVolume = 0.0f;
1804    
1805            if (pClient == NULL)
1806                    return 0.0f;
1807    
1808            // Lock this section up.
1809            lscp_mutex_lock(pClient->mutex);
1810    
1811            if (lscp_client_call(pClient, "GET VOLUME\r\n", 0) == LSCP_OK)
1812                    fVolume = (float) atof(lscp_client_get_result(pClient));
1813    
1814            // Unlock this section down.
1815            lscp_mutex_unlock(pClient->mutex);
1816    
1817            return fVolume;
1818    }
1819    
1820    
1821    /**
1822     *  Setting global volume attenuation:
1823     *  SET VOLUME <volume>
1824     *
1825     *  @param pClient  Pointer to client instance structure.
1826     *  @param fVolume  Global volume parameter as positive floating point
1827     *                  value usually be in the range between 0.0 and 1.0,
1828     *                  that is for attenuating the overall volume.
1829     *
1830     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1831     */
1832    lscp_status_t lscp_set_volume ( lscp_client_t *pClient, float fVolume )
1833    {
1834            char szQuery[LSCP_BUFSIZ];
1835    
1836            if (fVolume < 0.0f)
1837                    return LSCP_FAILED;
1838    
1839            sprintf(szQuery, "SET VOLUME %g\r\n", fVolume);
1840            return lscp_client_query(pClient, szQuery);
1841    }
1842    
1843    
1844    /**
1845     *  Add an effect send to a sampler channel:
1846     *  CREATE FX_SEND <sampler-channel> <midi-ctrl> [<name>]
1847     *
1848     *  @param pClient          Pointer to client instance structure.
1849     *  @param iSamplerChannel  Sampler channel number.
1850     *  @param iMidiController  MIDI controller used to alter the effect,
1851     *                          usually a number between 0 and 127.
1852     *  @param pszName          Optional name for the effect send entity,
1853     *                          does not have to be unique.
1854     *
1855     *  @returns The new effect send number identifier, or -1 in case of failure.
1856     */
1857    int lscp_create_fxsend ( lscp_client_t *pClient, int iSamplerChannel, int iMidiController, const char *pszFxName )
1858    {
1859            int iFxSend = -1;
1860            char szQuery[LSCP_BUFSIZ];
1861    
1862            if (pClient == NULL)
1863                    return -1;
1864            if (iSamplerChannel < 0 || iMidiController < 0 || iMidiController > 127)
1865                    return -1;
1866    
1867            // Lock this section up.
1868            lscp_mutex_lock(pClient->mutex);
1869    
1870            sprintf(szQuery, "CREATE FX_SEND %d %d", iSamplerChannel, iMidiController);
1871            
1872            if (pszFxName)
1873                    sprintf(szQuery + strlen(szQuery), " '%s'", pszFxName);
1874    
1875            strcat(szQuery, "\r\n");
1876    
1877            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
1878                    iFxSend = atoi(lscp_client_get_result(pClient));
1879    
1880            // Unlock this section down.
1881            lscp_mutex_unlock(pClient->mutex);
1882    
1883            return iFxSend;
1884    }
1885    
1886    
1887    /**
1888     *  Remove an effect send from a sampler channel:
1889     *  DESTROY FX_SEND <sampler-channel> <fx-send-id>
1890     *
1891     *  @param pClient          Pointer to client instance structure.
1892     *  @param iSamplerChannel  Sampler channel number.
1893     *  @param iFxSend          Effect send number.
1894     *
1895     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1896     */
1897    lscp_status_t lscp_destroy_fxsend ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend )
1898    {
1899            char szQuery[LSCP_BUFSIZ];
1900    
1901            if (iSamplerChannel < 0 || iFxSend < 0)
1902                    return LSCP_FAILED;
1903    
1904            sprintf(szQuery, "DESTROY FX_SEND %d %d\r\n", iSamplerChannel, iFxSend);
1905    
1906            return lscp_client_query(pClient, szQuery);
1907    }
1908    
1909    
1910    /**
1911     *  Get amount of effect sends on a sampler channel:
1912     *  GET FX_SENDS <sampler-channel>
1913     *
1914     *  @param pClient          Pointer to client instance structure.
1915     *  @param iSamplerChannel  Sampler channel number.
1916     *
1917     *  @returns The current total number of effect sends of the sampler channel
1918     *  on success, -1 otherwise.
1919     */
1920    int lscp_get_fxsends ( lscp_client_t *pClient, int iSamplerChannel )
1921    {
1922            int iFxSends = -1;
1923            char szQuery[LSCP_BUFSIZ];
1924    
1925            if (pClient == NULL)
1926                    return -1;
1927            if (iSamplerChannel < 0)
1928                    return -1;
1929    
1930            // Lock this section up.
1931            lscp_mutex_lock(pClient->mutex);
1932    
1933            sprintf(szQuery, "GET FX_SENDS %d\r\n", iSamplerChannel);
1934    
1935            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
1936                    iFxSends = atoi(lscp_client_get_result(pClient));
1937    
1938            // Unlock this section doen.
1939            lscp_mutex_unlock(pClient->mutex);
1940    
1941            return iFxSends;
1942    }
1943    
1944    
1945    /**
1946     *  List all effect sends on a sampler channel:
1947     *  LIST FX_SENDS <sampler-channel>
1948     *
1949     *  @param pClient          Pointer to client instance structure.
1950     *  @param iSamplerChannel  Sampler channel number.
1951     *
1952     *  @returns An array of the effect sends identifiers as positive integers,
1953     *  terminated with -1 on success, NULL otherwise.
1954     */
1955    int *lscp_list_fxsends ( lscp_client_t *pClient, int iSamplerChannel )
1956    {
1957            const char *pszSeps = ",";
1958            char szQuery[LSCP_BUFSIZ];
1959    
1960            if (pClient == NULL)
1961                    return NULL;
1962    
1963            // Lock this section up.
1964            lscp_mutex_lock(pClient->mutex);
1965    
1966            if (pClient->fxsends) {
1967                    lscp_isplit_destroy(pClient->fxsends);
1968                    pClient->fxsends = NULL;
1969            }
1970    
1971            sprintf(szQuery, "LIST FX_SENDS %d\r\n", iSamplerChannel);
1972    
1973            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
1974                    pClient->fxsends = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps);
1975    
1976            // Unlock this section down.
1977            lscp_mutex_unlock(pClient->mutex);
1978    
1979            return pClient->fxsends;
1980    }
1981    
1982    
1983    /**
1984     *  Getting effect send information
1985     *  GET FX_SEND INFO <sampler-channel> <fx-send-id>
1986     *
1987     *  @param pClient          Pointer to client instance structure.
1988     *  @param iSamplerChannel  Sampler channel number.
1989     *  @param iFxSend          Effect send number.
1990     *
1991     *  @returns A pointer to a @ref lscp_fxsend_info_t structure, with the
1992     *  information of the given FX send, or NULL in case of failure.
1993     */
1994    lscp_fxsend_info_t *lscp_get_fxsend_info ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend )
1995    {
1996            lscp_fxsend_info_t *pFxSendInfo;
1997            char szQuery[LSCP_BUFSIZ];
1998            const char *pszResult;
1999            const char *pszSeps = ":";
2000            const char *pszCrlf = "\r\n";
2001            char *pszToken;
2002            char *pch;
2003    
2004            if (pClient == NULL)
2005                    return NULL;
2006            if (iSamplerChannel < 0 || iFxSend < 0)
2007                    return NULL;
2008    
2009            // Lock this section up.
2010            lscp_mutex_lock(pClient->mutex);
2011    
2012            pFxSendInfo = &(pClient->fxsend_info);
2013            lscp_fxsend_info_reset(pFxSendInfo);
2014    
2015            sprintf(szQuery, "GET FX_SEND INFO %d %d\r\n", iSamplerChannel, iFxSend);
2016            if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) {
2017                    pszResult = lscp_client_get_result(pClient);
2018                    pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
2019                    while (pszToken) {
2020                            if (strcasecmp(pszToken, "NAME") == 0) {
2021                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2022                                    if (pszToken)
2023                                            lscp_unquote_dup(&(pFxSendInfo->name), &pszToken);
2024                            }
2025                            else if (strcasecmp(pszToken, "MIDI_CONTROLLER") == 0) {
2026                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2027                                    if (pszToken)
2028                                            pFxSendInfo->midi_controller = atoi(lscp_ltrim(pszToken));
2029                            }
2030                            else if (strcasecmp(pszToken, "AUDIO_OUTPUT_ROUTING") == 0) {
2031                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2032                                    if (pszToken) {
2033                                            if (pFxSendInfo->audio_routing)
2034                                                    lscp_isplit_destroy(pFxSendInfo->audio_routing);
2035                                            pFxSendInfo->audio_routing = lscp_isplit_create(pszToken, ",");
2036                                    }
2037                            }
2038                            else if (strcasecmp(pszToken, "LEVEL") == 0) {
2039                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2040                                    if (pszToken)
2041                                            pFxSendInfo->level = (float) atof(lscp_ltrim(pszToken));
2042                            }
2043                            pszToken = lscp_strtok(NULL, pszSeps, &(pch));
2044                    }
2045            }
2046            else pFxSendInfo = NULL;
2047    
2048            // Unlock this section up.
2049            lscp_mutex_unlock(pClient->mutex);
2050    
2051            return pFxSendInfo;
2052    }
2053    
2054    /**
2055     *  Alter effect send's name:
2056     *  @code
2057     *  SET FX_SEND NAME <sampler-chan> <fx-send-id> <name>
2058     *  @endcode
2059     *
2060     *  @param pClient          Pointer to client instance structure.
2061     *  @param iSamplerChannel  Sampler channel number.
2062     *  @param iFxSend          Effect send number.
2063     *  @param pszFxName        Effect send's new name.
2064     *
2065     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2066     */
2067    lscp_status_t lscp_set_fxsend_name ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, const char *pszFxName )
2068    {
2069            char szQuery[LSCP_BUFSIZ];
2070    
2071            if (!pClient || iSamplerChannel < 0 || iFxSend < 0 || !pszFxName)
2072                    return LSCP_FAILED;
2073    
2074            snprintf(szQuery, LSCP_BUFSIZ, "SET FX_SEND NAME %d %d %s\r\n", iSamplerChannel, iFxSend, pszFxName);
2075            return lscp_client_query(pClient, szQuery);
2076    }
2077    
2078    /**
2079     *  Alter effect send's audio routing:
2080     *  SET FX_SEND AUDIO_OUTPUT_CHANNEL <sampler-chan> <fx-send-id>
2081     *    <audio-src> <audio-dst>
2082     *
2083     *  @param pClient          Pointer to client instance structure.
2084     *  @param iSamplerChannel  Sampler channel number.
2085     *  @param iFxSend          Effect send number.
2086     *  @param iAudioSrc        Audio output device channel to be routed from.
2087     *  @param iAudioDst        Audio output device channel to be routed into.
2088     *
2089     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2090     */
2091    lscp_status_t lscp_set_fxsend_audio_channel ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, int iAudioSrc, int iAudioDst )
2092    {
2093            char szQuery[LSCP_BUFSIZ];
2094    
2095            if (iSamplerChannel < 0 || iFxSend < 0 || iAudioSrc < 0 || iAudioDst < 0)
2096                    return LSCP_FAILED;
2097    
2098            sprintf(szQuery, "SET FX_SEND AUDIO_OUTPUT_CHANNEL %d %d %d %d\r\n", iSamplerChannel, iFxSend, iAudioSrc, iAudioDst);
2099            return lscp_client_query(pClient, szQuery);
2100    }
2101    
2102    
2103    /**
2104     *  Alter effect send's MIDI controller:
2105     *  SET FX_SEND MIDI_CONTROLLER <sampler-chan> <fx-send-id> <midi-ctrl>
2106     *
2107     *  @param pClient          Pointer to client instance structure.
2108     *  @param iSamplerChannel  Sampler channel number.
2109     *  @param iFxSend          Effect send number.
2110     *  @param iMidiController  MIDI controller used to alter the effect,
2111     *                          usually a number between 0 and 127.
2112     *
2113     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2114     */
2115    lscp_status_t lscp_set_fxsend_midi_controller ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, int iMidiController )
2116    {
2117            char szQuery[LSCP_BUFSIZ];
2118    
2119            if (iSamplerChannel < 0 || iFxSend < 0 || iMidiController < 0 || iMidiController > 127)
2120                    return LSCP_FAILED;
2121    
2122            sprintf(szQuery, "SET FX_SEND MIDI_CONTROLLER %d %d %d\r\n", iSamplerChannel, iFxSend, iMidiController);
2123            return lscp_client_query(pClient, szQuery);
2124    }
2125    
2126    
2127    /**
2128     *  Alter effect send's audio level:
2129     *  SET FX_SEND LEVEL <sampler-chan> <fx-send-id> <level>
2130     *
2131     *  @param pClient          Pointer to client instance structure.
2132     *  @param iSamplerChannel  Sampler channel number.
2133     *  @param iFxSend          Effect send number.
2134     *  @param fLevel           Effect send volume level.
2135     *
2136     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2137     */
2138    lscp_status_t lscp_set_fxsend_level ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, float fLevel )
2139    {
2140            char szQuery[LSCP_BUFSIZ];
2141    
2142            if (iSamplerChannel < 0 || iFxSend < 0 || fLevel < 0.0f)
2143                    return LSCP_FAILED;
2144    
2145            sprintf(szQuery, "SET FX_SEND LEVEL %d %d %f\r\n", iSamplerChannel, iFxSend, fLevel);
2146            return lscp_client_query(pClient, szQuery);
2147    }
2148    
2149    
2150    /**
2151     *  Create a new MIDI instrument map:
2152     *  ADD MIDI_INSTRUMENT_MAP [<name>]
2153     *
2154     *  @param pClient      Pointer to client instance structure.
2155     *  @param pszMapName   MIDI instrument map name (optional)
2156     *
2157     *  @returns The new MIDI instrument map number identifier,
2158     *  or -1 in case of failure.
2159     */
2160    int lscp_add_midi_instrument_map ( lscp_client_t *pClient, const char *pszMapName )
2161    {
2162            int iMidiMap = -1;
2163            char szQuery[LSCP_BUFSIZ];
2164    
2165            if (pClient == NULL)
2166                    return -1;
2167    
2168            // Lock this section up.
2169            lscp_mutex_lock(pClient->mutex);
2170    
2171            strcpy(szQuery, "ADD MIDI_INSTRUMENT_MAP");
2172            
2173            if (pszMapName)
2174                    sprintf(szQuery + strlen(szQuery), " '%s'", pszMapName);
2175    
2176            strcat(szQuery, "\r\n");
2177    
2178            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
2179                    iMidiMap = atoi(lscp_client_get_result(pClient));
2180    
2181            // Unlock this section down.
2182            lscp_mutex_unlock(pClient->mutex);
2183    
2184            return iMidiMap;
2185    }
2186    
2187    
2188    /**
2189     *  Delete one particular or all MIDI instrument maps:
2190     *  REMOVE MIDI_INSTRUMENT_MAP <midi-map>
2191     *
2192     *  @param pClient  Pointer to client instance structure.
2193     *  @param iMidiMap MIDI instrument map number.
2194     *
2195     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2196     */
2197    lscp_status_t lscp_remove_midi_instrument_map ( lscp_client_t *pClient, int iMidiMap )
2198    {
2199            char szQuery[LSCP_BUFSIZ];
2200    
2201            if (iMidiMap < 0)
2202                    return LSCP_FAILED;
2203    
2204            sprintf(szQuery, "REMOVE MIDI_INSTRUMENT_MAP %d\r\n", iMidiMap);
2205    
2206            return lscp_client_query(pClient, szQuery);
2207    }
2208    
2209    
2210    /**
2211     *  Get amount of existing MIDI instrument maps:
2212     *  GET MIDI_INSTRUMENT_MAPS
2213     *
2214     *  @param pClient  Pointer to client instance structure.
2215     *
2216     *  @returns The current total number of MIDI instrument maps
2217     *  on success, -1 otherwise.
2218     */
2219    int lscp_get_midi_instrument_maps ( lscp_client_t *pClient )
2220    {
2221            int iMidiMaps = -1;
2222    
2223            if (pClient == NULL)
2224                    return -1;
2225    
2226            // Lock this section up.
2227            lscp_mutex_lock(pClient->mutex);
2228    
2229            if (lscp_client_call(pClient, "GET MIDI_INSTRUMENT_MAPS\r\n", 0) == LSCP_OK)
2230                    iMidiMaps = atoi(lscp_client_get_result(pClient));
2231    
2232            // Unlock this section doen.
2233            lscp_mutex_unlock(pClient->mutex);
2234    
2235            return iMidiMaps;
2236    }
2237    
2238    
2239    /**
2240     *  Getting all created MIDI instrument maps:
2241     *  LIST MIDI_INSTRUMENT_MAPS
2242     *
2243     *  @param pClient  Pointer to client instance structure.
2244     *
2245     *  @returns An array of the MIDI instrument map identifiers as positive
2246     *  integers, terminated with -1 on success, NULL otherwise.
2247     */
2248    int *lscp_list_midi_instrument_maps ( lscp_client_t *pClient )
2249    {
2250            const char *pszSeps = ",";
2251    
2252            if (pClient == NULL)
2253                    return NULL;
2254    
2255            // Lock this section up.
2256            lscp_mutex_lock(pClient->mutex);
2257    
2258            if (pClient->midi_maps) {
2259                    lscp_isplit_destroy(pClient->midi_maps);
2260                    pClient->midi_maps = NULL;
2261            }
2262    
2263            if (lscp_client_call(pClient, "LIST MIDI_INSTRUMENT_MAPS\r\n", 0) == LSCP_OK)
2264                    pClient->midi_maps = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps);
2265    
2266            // Unlock this section down.
2267            lscp_mutex_unlock(pClient->mutex);
2268    
2269            return pClient->midi_maps;
2270    }
2271    
2272    
2273    /**
2274     *  Getting a MIDI instrument map name:
2275     *  GET MIDI_INSTRUMENT_MAP INFO <midi-map>
2276     *
2277     *  @param pClient  Pointer to client instance structure.
2278     *  @param iMidiMap MIDI instrument map number.
2279     *
2280     *  @returns The MIDI instrument map name on success, NULL on failure.
2281     */
2282    const char *lscp_get_midi_instrument_map_name ( lscp_client_t *pClient, int iMidiMap )
2283    {
2284            char szQuery[LSCP_BUFSIZ];
2285            const char *pszResult;
2286            const char *pszSeps = ":";
2287            const char *pszCrlf = "\r\n";
2288            char *pszToken;
2289            char *pch;
2290    
2291            if (pClient == NULL)
2292                    return NULL;
2293            if (iMidiMap < 0)
2294                    return NULL;
2295    
2296            // Lock this section up.
2297            lscp_mutex_lock(pClient->mutex);
2298            
2299            if (pClient->midi_map_name) {
2300                    free(pClient->midi_map_name);
2301                    pClient->midi_map_name = NULL;
2302            }
2303    
2304            sprintf(szQuery, "GET MIDI_INSTRUMENT_MAP INFO %d\r\n", iMidiMap);
2305            if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) {
2306                    pszResult = lscp_client_get_result(pClient);
2307                    pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
2308                    while (pszToken) {
2309                            if (strcasecmp(pszToken, "NAME") == 0) {
2310                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2311                                    if (pszToken)
2312                                            lscp_unquote_dup(&(pClient->midi_map_name), &pszToken);
2313                            }
2314                            pszToken = lscp_strtok(NULL, pszSeps, &(pch));
2315                    }
2316            }
2317    
2318            // Unlock this section down.
2319            lscp_mutex_unlock(pClient->mutex);
2320    
2321            return pClient->midi_map_name;
2322    }
2323    
2324    
2325    /**
2326     *  Renaming a MIDI instrument map:
2327     *  SET MIDI_INSTRUMENT_MAP NAME <midi-map> <map-name>
2328     *
2329     *  @param pClient      Pointer to client instance structure.
2330     *  @param iMidiMap     MIDI instrument map number.
2331     *  @param pszMapName   MIDI instrument map name.
2332     *
2333     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2334     */
2335    lscp_status_t lscp_set_midi_instrument_map_name ( lscp_client_t *pClient, int iMidiMap, const char *pszMapName )
2336    {
2337            char szQuery[LSCP_BUFSIZ];
2338    
2339            if (iMidiMap < 0)
2340                    return LSCP_FAILED;
2341            if (pszMapName == NULL)
2342                    return LSCP_FAILED;
2343    
2344            sprintf(szQuery, "SET MIDI_INSTRUMENT_MAP NAME %d '%s'\r\n",
2345                    iMidiMap, pszMapName);
2346    
2347            return lscp_client_query(pClient, szQuery);
2348    }
2349    
2350    
2351    /**
2352   *  Create or replace a MIDI instrumnet map entry:   *  Create or replace a MIDI instrumnet map entry:
2353   *  MAP MIDI_INSTRUMENT <midi-bank-msb> <midi-bank-lsb> <midi-prog>   *  MAP MIDI_INSTRUMENT <midi-map> <midi-bank> <midi-prog>
2354   *      <engine-name> <filename> <instr-index> <volume> <load-mode> [<name>]   *      <engine-name> <filename> <instr-index> <volume> [<load-mode> [<name>]}
2355   *   *
2356   *  @param pClient          Pointer to client instance structure.   *  @param pClient          Pointer to client instance structure.
2357   *  @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 2367  int lscp_get_total_voice_count_max ( lsc
2367   *                          @ref LSCP_LOAD_ON_DEMAND, or   *                          @ref LSCP_LOAD_ON_DEMAND, or
2368   *                          @ref LSCP_LOAD_ON_DEMAND_HOLD, or   *                          @ref LSCP_LOAD_ON_DEMAND_HOLD, or
2369   *                          @ref LSCP_LOAD_PERSISTENT.   *                          @ref LSCP_LOAD_PERSISTENT.
2370   *  @param pszName          Instrument custom name for the map entry.   *  @param pszName         Instrument custom name for the map entry (optional).
2371   *   *
2372   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2373   */   */
2374  lscp_status_t lscp_map_midi_instrument ( lscp_client_t *pClient, lscp_midi_instrument_t *pMidiInstr, const char *pszEngineName, const char *pszFileName, int iInstrIndex, float fVolume, lscp_load_mode_t load_mode, const char *pszName )  lscp_status_t lscp_map_midi_instrument ( lscp_client_t *pClient, lscp_midi_instrument_t *pMidiInstr, const char *pszEngineName, const char *pszFileName, int iInstrIndex, float fVolume, lscp_load_mode_t load_mode, const char *pszName )
2375  {  {
2376          char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
2377            
2378          if (pMidiInstr->bank_msb < 0 || pMidiInstr->bank_msb > 127)          if (pMidiInstr->map < 0)
2379                  return LSCP_FAILED;                  return LSCP_FAILED;
2380          if (pMidiInstr->bank_lsb < 0 || pMidiInstr->bank_lsb > 127)          if (pMidiInstr->bank < 0 || pMidiInstr->bank > 16383)
2381                  return LSCP_FAILED;                  return LSCP_FAILED;
2382          if (pMidiInstr->program < 0 || pMidiInstr->program > 127)          if (pMidiInstr->prog < 0 || pMidiInstr->prog > 127)
2383                  return LSCP_FAILED;                  return LSCP_FAILED;
2384          if (pszEngineName == NULL || pszFileName == NULL)          if (pszEngineName == NULL || pszFileName == NULL)
2385                  return LSCP_FAILED;                  return LSCP_FAILED;
2386            
2387          if (fVolume < 0.0f)          if (fVolume < 0.0f)
2388                  fVolume = 1.0f;                  fVolume = 1.0f;
2389            
2390          sprintf(szQuery, "MAP MIDI_INSTRUMENT %d %d %d %s '%s' %d %g",          sprintf(szQuery, "MAP MIDI_INSTRUMENT %d %d %d %s '%s' %d %g",
2391                  pMidiInstr->bank_msb, pMidiInstr->bank_lsb, pMidiInstr->program,                  pMidiInstr->map, pMidiInstr->bank, pMidiInstr->prog,
2392                  pszEngineName, pszFileName, iInstrIndex, fVolume);                  pszEngineName, pszFileName, iInstrIndex, fVolume);
2393            
2394          switch (load_mode) {          switch (load_mode) {
2395          case LSCP_LOAD_PERSISTENT:          case LSCP_LOAD_PERSISTENT:
2396                  strcat(szQuery, " PERSISTENT");                  strcat(szQuery, " PERSISTENT");
# Line 1695  lscp_status_t lscp_map_midi_instrument ( Line 2399  lscp_status_t lscp_map_midi_instrument (
2399                  strcat(szQuery, " ON_DEMAND_HOLD");                  strcat(szQuery, " ON_DEMAND_HOLD");
2400                  break;                  break;
2401          case LSCP_LOAD_ON_DEMAND:          case LSCP_LOAD_ON_DEMAND:
2402                  strcat(szQuery, " ON_DEMAND_HOLD");                  strcat(szQuery, " ON_DEMAND");
2403                  break;                  break;
2404          case LSCP_LOAD_DEFAULT:          case LSCP_LOAD_DEFAULT:
2405          default:          default:
2406                  break;                  break;
2407          }          }
2408            
2409          if (pszName)          if (pszName)
2410                  sprintf(szQuery + strlen(szQuery), " '%s'", pszName);                  sprintf(szQuery + strlen(szQuery), " '%s'", pszName);
2411            
2412          strcat(szQuery, "\r\n");          strcat(szQuery, "\r\n");
2413            
2414          return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
2415  }  }
2416    
2417    
2418  /**  /**
2419   *  Remove an entry from the MIDI instrument map:   *  Remove an entry from the MIDI instrument map:
2420   *  UNMAP MIDI_INSTRUMENT <midi-bank-msb> <midi-bank-lsb> <midi-prog>   *  UNMAP MIDI_INSTRUMENT <midi-map> <midi-bank> <midi-prog>
2421   *   *
2422   *  @param pClient      Pointer to client instance structure.   *  @param pClient      Pointer to client instance structure.
2423   *  @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 2428  lscp_status_t lscp_unmap_midi_instrument
2428  {  {
2429          char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
2430    
2431          if (pMidiInstr->bank_msb < 0 || pMidiInstr->bank_msb > 127)          if (pMidiInstr->map < 0)
2432                  return LSCP_FAILED;                  return LSCP_FAILED;
2433          if (pMidiInstr->bank_lsb < 0 || pMidiInstr->bank_lsb > 127)          if (pMidiInstr->bank < 0 || pMidiInstr->bank > 16383)
2434                  return LSCP_FAILED;                  return LSCP_FAILED;
2435          if (pMidiInstr->program < 0 || pMidiInstr->program > 127)          if (pMidiInstr->prog < 0 || pMidiInstr->prog > 127)
2436                  return LSCP_FAILED;                  return LSCP_FAILED;
2437    
2438          sprintf(szQuery, "UNMAP MIDI_INSTRUMENT %d %d %d\r\n",          sprintf(szQuery, "UNMAP MIDI_INSTRUMENT %d %d %d\r\n",
2439                  pMidiInstr->bank_msb, pMidiInstr->bank_lsb, pMidiInstr->program);                  pMidiInstr->map, pMidiInstr->bank, pMidiInstr->prog);
2440    
2441          return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
2442  }  }
# Line 1740  lscp_status_t lscp_unmap_midi_instrument Line 2444  lscp_status_t lscp_unmap_midi_instrument
2444    
2445  /**  /**
2446   *  Get the total count of MIDI instrument map entries:   *  Get the total count of MIDI instrument map entries:
2447   *  GET MIDI_INSTRUMENTS   *  GET MIDI_INSTRUMENTS ALL|<midi-map>
2448   *   *
2449   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
2450     *  @param iMidiMap MIDI instrument map number, or @ref LSCP_MIDI_MAP_ALL .
2451   *   *
2452   *  @returns The current total number of MIDI instrument map entries   *  @returns The current total number of MIDI instrument map entries
2453   *  on success, -1 otherwise.   *  on success, -1 otherwise.
2454   */   */
2455  int lscp_get_midi_instruments ( lscp_client_t *pClient )  int lscp_get_midi_instruments ( lscp_client_t *pClient, int iMidiMap )
2456  {  {
2457          int iInstruments = -1;          int iInstruments = -1;
2458            char szQuery[LSCP_BUFSIZ];
2459    
2460            if (pClient == NULL)
2461                    return -1;
2462    
2463          // Lock this section up.          // Lock this section up.
2464          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
2465    
2466          if (lscp_client_call(pClient, "GET MIDI_INSTRUMENTS\r\n", 0) == LSCP_OK)          strcpy(szQuery, "GET MIDI_INSTRUMENTS ");
2467    
2468            if (iMidiMap < 0)
2469                    strcat(szQuery, "ALL");
2470            else
2471                    sprintf(szQuery + strlen(szQuery), "%d", iMidiMap);
2472    
2473            strcat(szQuery, "\r\n");
2474    
2475            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
2476                  iInstruments = atoi(lscp_client_get_result(pClient));                  iInstruments = atoi(lscp_client_get_result(pClient));
2477    
2478          // Unlock this section down.          // Unlock this section down.
# Line 1766  int lscp_get_midi_instruments ( lscp_cli Line 2484  int lscp_get_midi_instruments ( lscp_cli
2484    
2485  /**  /**
2486   *  Getting indeces of all MIDI instrument map entries:   *  Getting indeces of all MIDI instrument map entries:
2487   *  LIST MIDI_INSTRUMENTS   *  LIST MIDI_INSTRUMENTS ALL|<midi-map>
2488   *   *
2489   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
2490     *  @param iMidiMap MIDI instrument map number, or @ref LSCP_MIDI_MAP_ALL .
2491   *   *
2492   *  @returns An array of @ref lscp_midi_instrument_t, terminated with the   *  @returns An array of @ref lscp_midi_instrument_t, terminated with the
2493   *  {-1,-1,-1} triplet, NULL otherwise.   *  {-1,-1,-1} triplet, NULL otherwise.
2494   */   */
2495  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 )
2496  {  {
2497            char szQuery[LSCP_BUFSIZ];
2498    
2499          if (pClient == NULL)          if (pClient == NULL)
2500                  return NULL;                  return NULL;
2501    
# Line 1786  lscp_midi_instrument_t *lscp_list_midi_i Line 2507  lscp_midi_instrument_t *lscp_list_midi_i
2507                  pClient->midi_instruments = NULL;                  pClient->midi_instruments = NULL;
2508          }          }
2509    
2510          if (lscp_client_call(pClient, "LIST MIDI_INSTRUMENTS\r\n", 0) == LSCP_OK)          strcpy(szQuery, "LIST MIDI_INSTRUMENTS ");
2511    
2512            if (iMidiMap < 0)
2513                    strcat(szQuery, "ALL");
2514            else
2515                    sprintf(szQuery + strlen(szQuery), "%d", iMidiMap);
2516    
2517            strcat(szQuery, "\r\n");
2518    
2519            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
2520                  pClient->midi_instruments = lscp_midi_instruments_create(lscp_client_get_result(pClient));                  pClient->midi_instruments = lscp_midi_instruments_create(lscp_client_get_result(pClient));
2521    
2522          // Unlock this section down.          // Unlock this section down.
# Line 1798  lscp_midi_instrument_t *lscp_list_midi_i Line 2528  lscp_midi_instrument_t *lscp_list_midi_i
2528    
2529  /**  /**
2530   *  Getting information about a MIDI instrument map entry:   *  Getting information about a MIDI instrument map entry:
2531   *  GET MIDI_INSTRUMENT INFO <midi-bank-msb> <midi-bank-lsb> <midi-prog>   *  GET MIDI_INSTRUMENT INFO <midi-map> <midi-bank> <midi-prog>
2532   *   *
2533   *  @param pClient      Pointer to client instance structure.   *  @param pClient      Pointer to client instance structure.
2534   *  @param pMidiInstr   MIDI instrument bank and program parameter key.   *  @param pMidiInstr   MIDI instrument bank and program parameter key.
# Line 1816  lscp_midi_instrument_info_t *lscp_get_mi Line 2546  lscp_midi_instrument_info_t *lscp_get_mi
2546          const char *pszCrlf = "\r\n";          const char *pszCrlf = "\r\n";
2547          char *pszToken;          char *pszToken;
2548          char *pch;          char *pch;
2549            
2550          if (pMidiInstr->bank_msb < 0 || pMidiInstr->bank_msb > 127)          if (pClient == NULL)
2551                  return NULL;                  return NULL;
2552          if (pMidiInstr->bank_lsb < 0 || pMidiInstr->bank_lsb > 127)          if (pMidiInstr->map < 0)
2553                  return NULL;                  return NULL;
2554          if (pMidiInstr->program < 0 || pMidiInstr->program > 127)          if (pMidiInstr->bank < 0 || pMidiInstr->bank > 16383)
2555                  return NULL;                  return NULL;
2556                    if (pMidiInstr->prog < 0 || pMidiInstr->prog > 127)
2557                    return NULL;
2558    
2559          // Lock this section up.          // Lock this section up.
2560          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
2561                    
2562          pInstrInfo = &(pClient->midi_instrument_info);          pInstrInfo = &(pClient->midi_instrument_info);
2563          lscp_midi_instrument_info_reset(pInstrInfo);          lscp_midi_instrument_info_reset(pInstrInfo);
2564            
2565          sprintf(szQuery, "GET MIDI_INSTRUMENT INFO %d %d %d\r\n",          sprintf(szQuery, "GET MIDI_INSTRUMENT INFO %d %d %d\r\n",
2566                  pMidiInstr->bank_msb, pMidiInstr->bank_lsb, pMidiInstr->program);                  pMidiInstr->map, pMidiInstr->bank, pMidiInstr->prog);
2567          if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) {          if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) {
2568                  pszResult = lscp_client_get_result(pClient);                  pszResult = lscp_client_get_result(pClient);
2569                  pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));                  pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
# Line 1886  lscp_midi_instrument_info_t *lscp_get_mi Line 2618  lscp_midi_instrument_info_t *lscp_get_mi
2618                  }                  }
2619          }          }
2620          else pInstrInfo = NULL;          else pInstrInfo = NULL;
2621            
2622          // Unlock this section down.          // Unlock this section down.
2623          lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
2624            
2625          return pInstrInfo;          return pInstrInfo;
2626  }  }
2627    
2628    
2629  /**  /**
2630   *  Clear the MIDI instrumnet map:   *  Clear the MIDI instrumnet map:
2631   *  CLEAR MIDI_INSTRUMENTS   *  CLEAR MIDI_INSTRUMENTS ALL|<midi-map>
2632   *   *
2633   *  @param pClient         Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
2634   *  @param iSamplerChannel  Sampler channel number.   *  @param iMidiMap MIDI instrument map number, or @ref LSCP_MIDI_MAP_ALL .
2635   *   *
2636   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2637   */   */
2638  lscp_status_t lscp_clear_midi_instruments  ( lscp_client_t *pClient )  lscp_status_t lscp_clear_midi_instruments  ( lscp_client_t *pClient, int iMidiMap )
2639  {  {
2640          return lscp_client_query(pClient, "CLEAR MIDI_INSTRUMENTS\r\n");          char szQuery[LSCP_BUFSIZ];
2641    
2642            strcpy(szQuery, "CLEAR MIDI_INSTRUMENTS ");
2643    
2644            if (iMidiMap < 0)
2645                    strcat(szQuery, "ALL");
2646            else
2647                    sprintf(szQuery + strlen(szQuery), "%d", iMidiMap);
2648    
2649            strcat(szQuery, "\r\n");
2650    
2651            return lscp_client_query(pClient, szQuery);
2652    }
2653    
2654    /**
2655     * Open an instrument editor application for the instrument
2656     * on the given sampler channel:
2657     * EDIT CHANNEL INSTRUMENT <sampler-channel>
2658     *
2659     * @param pClient         Pointer to client instance structure.
2660     * @param iSamplerChannel Sampler Channel.
2661     *
2662     * @returns LSCP_OK on success, LSCP_FAILED otherwise.
2663     */
2664    lscp_status_t lscp_edit_channel_instrument ( lscp_client_t *pClient, int iSamplerChannel )
2665    {
2666            char szQuery[LSCP_BUFSIZ];
2667    
2668            if (iSamplerChannel < 0)
2669                    return LSCP_FAILED;
2670    
2671            sprintf(szQuery, "EDIT CHANNEL INSTRUMENT %d\r\n", iSamplerChannel);
2672    
2673            return lscp_client_query(pClient, szQuery);
2674  }  }
2675    
2676    

Legend:
Removed from v.952  
changed lines
  Added in v.1665

  ViewVC Help
Powered by ViewVC