/[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 1020 by capela, Thu Jan 11 15:25:04 2007 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-2007, 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                            pszToken = lscp_strtok(NULL, pszSeps, &(pch));
2039                    }
2040            }
2041            else pFxSendInfo = NULL;
2042    
2043            // Unlock this section up.
2044            lscp_mutex_unlock(pClient->mutex);
2045    
2046            return pFxSendInfo;
2047    }
2048    
2049    
2050    /**
2051     *  Alter effect send's audio routing:
2052     *  SET FX_SEND AUDIO_OUTPUT_CHANNEL <sampler-chan> <fx-send-id>
2053     *    <audio-src> <audio-dst>
2054     *
2055     *  @param pClient          Pointer to client instance structure.
2056     *  @param iSamplerChannel  Sampler channel number.
2057     *  @param iFxSend          Effect send number.
2058     *  @param iAudioSrc        Audio output device channel to be routed from.
2059     *  @param iAudioDst        Audio output device channel to be routed into.
2060     *
2061     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2062     */
2063    lscp_status_t lscp_set_fxsend_audio_channel ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, int iAudioSrc, int iAudioDst )
2064    {
2065            char szQuery[LSCP_BUFSIZ];
2066    
2067            if (iSamplerChannel < 0 || iFxSend < 0 || iAudioSrc < 0 || iAudioDst < 0)
2068                    return LSCP_FAILED;
2069    
2070            sprintf(szQuery, "SET FX_SEND AUDIO_OUTPUT_CHANNEL %d %d %d %d\r\n", iSamplerChannel, iFxSend, iAudioSrc, iAudioDst);
2071            return lscp_client_query(pClient, szQuery);
2072    }
2073    
2074    
2075    /**
2076     *  Create a new MIDI instrument map:
2077     *  ADD MIDI_INSTRUMENT_MAP [<name>]
2078     *
2079     *  @param pClient      Pointer to client instance structure.
2080     *  @param pszMapName   MIDI instrument map name (optional)
2081     *
2082     *  @returns The new MIDI instrument map number identifier,
2083     *  or -1 in case of failure.
2084     */
2085    int lscp_add_midi_instrument_map ( lscp_client_t *pClient, const char *pszMapName )
2086    {
2087            int iMidiMap = -1;
2088            char szQuery[LSCP_BUFSIZ];
2089    
2090            if (pClient == NULL)
2091                    return -1;
2092    
2093            // Lock this section up.
2094            lscp_mutex_lock(pClient->mutex);
2095    
2096            strcpy(szQuery, "ADD MIDI_INSTRUMENT_MAP");
2097            
2098            if (pszMapName)
2099                    sprintf(szQuery + strlen(szQuery), " '%s'", pszMapName);
2100    
2101            strcat(szQuery, "\r\n");
2102    
2103            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
2104                    iMidiMap = atoi(lscp_client_get_result(pClient));
2105    
2106            // Unlock this section down.
2107            lscp_mutex_unlock(pClient->mutex);
2108    
2109            return iMidiMap;
2110    }
2111    
2112    
2113    /**
2114     *  Delete one particular or all MIDI instrument maps:
2115     *  REMOVE MIDI_INSTRUMENT_MAP <midi-map>
2116     *
2117     *  @param pClient  Pointer to client instance structure.
2118     *  @param iMidiMap MIDI instrument map number.
2119     *
2120     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2121     */
2122    lscp_status_t lscp_remove_midi_instrument_map ( lscp_client_t *pClient, int iMidiMap )
2123    {
2124            char szQuery[LSCP_BUFSIZ];
2125    
2126            if (iMidiMap < 0)
2127                    return LSCP_FAILED;
2128    
2129            sprintf(szQuery, "REMOVE MIDI_INSTRUMENT_MAP %d\r\n", iMidiMap);
2130    
2131            return lscp_client_query(pClient, szQuery);
2132    }
2133    
2134    
2135    /**
2136     *  Get amount of existing MIDI instrument maps:
2137     *  GET MIDI_INSTRUMENT_MAPS
2138     *
2139     *  @param pClient  Pointer to client instance structure.
2140     *
2141     *  @returns The current total number of MIDI instrument maps
2142     *  on success, -1 otherwise.
2143     */
2144    int lscp_get_midi_instrument_maps ( lscp_client_t *pClient )
2145    {
2146            int iMidiMaps = -1;
2147    
2148            if (pClient == NULL)
2149                    return -1;
2150    
2151            // Lock this section up.
2152            lscp_mutex_lock(pClient->mutex);
2153    
2154            if (lscp_client_call(pClient, "GET MIDI_INSTRUMENT_MAPS\r\n", 0) == LSCP_OK)
2155                    iMidiMaps = atoi(lscp_client_get_result(pClient));
2156    
2157            // Unlock this section doen.
2158            lscp_mutex_unlock(pClient->mutex);
2159    
2160            return iMidiMaps;
2161    }
2162    
2163    
2164    /**
2165     *  Getting all created MIDI instrument maps:
2166     *  LIST MIDI_INSTRUMENT_MAPS
2167     *
2168     *  @param pClient  Pointer to client instance structure.
2169     *
2170     *  @returns An array of the MIDI instrument map identifiers as positive
2171     *  integers, terminated with -1 on success, NULL otherwise.
2172     */
2173    int *lscp_list_midi_instrument_maps ( lscp_client_t *pClient )
2174    {
2175            const char *pszSeps = ",";
2176    
2177            if (pClient == NULL)
2178                    return NULL;
2179    
2180            // Lock this section up.
2181            lscp_mutex_lock(pClient->mutex);
2182    
2183            if (pClient->midi_maps) {
2184                    lscp_isplit_destroy(pClient->midi_maps);
2185                    pClient->midi_maps = NULL;
2186            }
2187    
2188            if (lscp_client_call(pClient, "LIST MIDI_INSTRUMENT_MAPS\r\n", 0) == LSCP_OK)
2189                    pClient->midi_maps = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps);
2190    
2191            // Unlock this section down.
2192            lscp_mutex_unlock(pClient->mutex);
2193    
2194            return pClient->midi_maps;
2195    }
2196    
2197    
2198    /**
2199     *  Getting a MIDI instrument map name:
2200     *  GET MIDI_INSTRUMENT_MAP INFO <midi-map>
2201     *
2202     *  @param pClient  Pointer to client instance structure.
2203     *  @param iMidiMap MIDI instrument map number.
2204     *
2205     *  @returns The MIDI instrument map name on success, NULL on failure.
2206     */
2207    const char *lscp_get_midi_instrument_map_name ( lscp_client_t *pClient, int iMidiMap )
2208    {
2209            char szQuery[LSCP_BUFSIZ];
2210            const char *pszResult;
2211            const char *pszSeps = ":";
2212            const char *pszCrlf = "\r\n";
2213            char *pszToken;
2214            char *pch;
2215    
2216            if (pClient == NULL)
2217                    return NULL;
2218            if (iMidiMap < 0)
2219                    return NULL;
2220    
2221            // Lock this section up.
2222            lscp_mutex_lock(pClient->mutex);
2223            
2224            if (pClient->midi_map_name) {
2225                    free(pClient->midi_map_name);
2226                    pClient->midi_map_name = NULL;
2227            }
2228    
2229            sprintf(szQuery, "GET MIDI_INSTRUMENT_MAP INFO %d\r\n", iMidiMap);
2230            if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) {
2231                    pszResult = lscp_client_get_result(pClient);
2232                    pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
2233                    while (pszToken) {
2234                            if (strcasecmp(pszToken, "NAME") == 0) {
2235                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
2236                                    if (pszToken)
2237                                            lscp_unquote_dup(&(pClient->midi_map_name), &pszToken);
2238                            }
2239                            pszToken = lscp_strtok(NULL, pszSeps, &(pch));
2240                    }
2241            }
2242    
2243            // Unlock this section down.
2244            lscp_mutex_unlock(pClient->mutex);
2245    
2246            return pClient->midi_map_name;
2247    }
2248    
2249    
2250    /**
2251     *  Renaming a MIDI instrument map:
2252     *  SET MIDI_INSTRUMENT_MAP NAME <midi-map> <map-name>
2253     *
2254     *  @param pClient      Pointer to client instance structure.
2255     *  @param iMidiMap     MIDI instrument map number.
2256     *  @param pszMapName   MIDI instrument map name.
2257     *
2258     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2259     */
2260    lscp_status_t lscp_set_midi_instrument_map_name ( lscp_client_t *pClient, int iMidiMap, const char *pszMapName )
2261    {
2262            char szQuery[LSCP_BUFSIZ];
2263    
2264            if (iMidiMap < 0)
2265                    return LSCP_FAILED;
2266            if (pszMapName == NULL)
2267                    return LSCP_FAILED;
2268    
2269            sprintf(szQuery, "SET MIDI_INSTRUMENT_MAP NAME %d '%s'\r\n",
2270                    iMidiMap, pszMapName);
2271    
2272            return lscp_client_query(pClient, szQuery);
2273    }
2274    
2275    
2276    /**
2277   *  Create or replace a MIDI instrumnet map entry:   *  Create or replace a MIDI instrumnet map entry:
2278   *  MAP MIDI_INSTRUMENT <midi-bank-msb> <midi-bank-lsb> <midi-prog>   *  MAP MIDI_INSTRUMENT <midi-map> <midi-bank> <midi-prog>
2279   *      <engine-name> <filename> <instr-index> <volume> <load-mode> [<name>]   *      <engine-name> <filename> <instr-index> <volume> [<load-mode> [<name>]}
2280   *   *
2281   *  @param pClient          Pointer to client instance structure.   *  @param pClient          Pointer to client instance structure.
2282   *  @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 2292  int lscp_get_total_voice_count_max ( lsc
2292   *                          @ref LSCP_LOAD_ON_DEMAND, or   *                          @ref LSCP_LOAD_ON_DEMAND, or
2293   *                          @ref LSCP_LOAD_ON_DEMAND_HOLD, or   *                          @ref LSCP_LOAD_ON_DEMAND_HOLD, or
2294   *                          @ref LSCP_LOAD_PERSISTENT.   *                          @ref LSCP_LOAD_PERSISTENT.
2295   *  @param pszName          Instrument custom name for the map entry.   *  @param pszName         Instrument custom name for the map entry (optional).
2296   *   *
2297   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2298   */   */
2299  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 )
2300  {  {
2301          char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
2302            
2303          if (pMidiInstr->bank_msb < 0 || pMidiInstr->bank_msb > 127)          if (pMidiInstr->map < 0)
2304                  return LSCP_FAILED;                  return LSCP_FAILED;
2305          if (pMidiInstr->bank_lsb < 0 || pMidiInstr->bank_lsb > 127)          if (pMidiInstr->bank < 0 || pMidiInstr->bank > 16383)
2306                  return LSCP_FAILED;                  return LSCP_FAILED;
2307          if (pMidiInstr->program < 0 || pMidiInstr->program > 127)          if (pMidiInstr->prog < 0 || pMidiInstr->prog > 127)
2308                  return LSCP_FAILED;                  return LSCP_FAILED;
2309          if (pszEngineName == NULL || pszFileName == NULL)          if (pszEngineName == NULL || pszFileName == NULL)
2310                  return LSCP_FAILED;                  return LSCP_FAILED;
2311            
2312          if (fVolume < 0.0f)          if (fVolume < 0.0f)
2313                  fVolume = 1.0f;                  fVolume = 1.0f;
2314            
2315          sprintf(szQuery, "MAP MIDI_INSTRUMENT %d %d %d %s '%s' %d %g",          sprintf(szQuery, "MAP MIDI_INSTRUMENT %d %d %d %s '%s' %d %g",
2316                  pMidiInstr->bank_msb, pMidiInstr->bank_lsb, pMidiInstr->program,                  pMidiInstr->map, pMidiInstr->bank, pMidiInstr->prog,
2317                  pszEngineName, pszFileName, iInstrIndex, fVolume);                  pszEngineName, pszFileName, iInstrIndex, fVolume);
2318            
2319          switch (load_mode) {          switch (load_mode) {
2320          case LSCP_LOAD_PERSISTENT:          case LSCP_LOAD_PERSISTENT:
2321                  strcat(szQuery, " PERSISTENT");                  strcat(szQuery, " PERSISTENT");
# Line 1695  lscp_status_t lscp_map_midi_instrument ( Line 2324  lscp_status_t lscp_map_midi_instrument (
2324                  strcat(szQuery, " ON_DEMAND_HOLD");                  strcat(szQuery, " ON_DEMAND_HOLD");
2325                  break;                  break;
2326          case LSCP_LOAD_ON_DEMAND:          case LSCP_LOAD_ON_DEMAND:
2327                  strcat(szQuery, " ON_DEMAND_HOLD");                  strcat(szQuery, " ON_DEMAND");
2328                  break;                  break;
2329          case LSCP_LOAD_DEFAULT:          case LSCP_LOAD_DEFAULT:
2330          default:          default:
2331                  break;                  break;
2332          }          }
2333            
2334          if (pszName)          if (pszName)
2335                  sprintf(szQuery + strlen(szQuery), " '%s'", pszName);                  sprintf(szQuery + strlen(szQuery), " '%s'", pszName);
2336            
2337          strcat(szQuery, "\r\n");          strcat(szQuery, "\r\n");
2338            
2339          return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
2340  }  }
2341    
2342    
2343  /**  /**
2344   *  Remove an entry from the MIDI instrument map:   *  Remove an entry from the MIDI instrument map:
2345   *  UNMAP MIDI_INSTRUMENT <midi-bank-msb> <midi-bank-lsb> <midi-prog>   *  UNMAP MIDI_INSTRUMENT <midi-map> <midi-bank> <midi-prog>
2346   *   *
2347   *  @param pClient      Pointer to client instance structure.   *  @param pClient      Pointer to client instance structure.
2348   *  @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 2353  lscp_status_t lscp_unmap_midi_instrument
2353  {  {
2354          char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
2355    
2356          if (pMidiInstr->bank_msb < 0 || pMidiInstr->bank_msb > 127)          if (pMidiInstr->map < 0)
2357                  return LSCP_FAILED;                  return LSCP_FAILED;
2358          if (pMidiInstr->bank_lsb < 0 || pMidiInstr->bank_lsb > 127)          if (pMidiInstr->bank < 0 || pMidiInstr->bank > 16383)
2359                  return LSCP_FAILED;                  return LSCP_FAILED;
2360          if (pMidiInstr->program < 0 || pMidiInstr->program > 127)          if (pMidiInstr->prog < 0 || pMidiInstr->prog > 127)
2361                  return LSCP_FAILED;                  return LSCP_FAILED;
2362    
2363          sprintf(szQuery, "UNMAP MIDI_INSTRUMENT %d %d %d\r\n",          sprintf(szQuery, "UNMAP MIDI_INSTRUMENT %d %d %d\r\n",
2364                  pMidiInstr->bank_msb, pMidiInstr->bank_lsb, pMidiInstr->program);                  pMidiInstr->map, pMidiInstr->bank, pMidiInstr->prog);
2365    
2366          return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
2367  }  }
# Line 1740  lscp_status_t lscp_unmap_midi_instrument Line 2369  lscp_status_t lscp_unmap_midi_instrument
2369    
2370  /**  /**
2371   *  Get the total count of MIDI instrument map entries:   *  Get the total count of MIDI instrument map entries:
2372   *  GET MIDI_INSTRUMENTS   *  GET MIDI_INSTRUMENTS ALL|<midi-map>
2373   *   *
2374   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
2375     *  @param iMidiMap MIDI instrument map number, or @ref LSCP_MIDI_MAP_ALL .
2376   *   *
2377   *  @returns The current total number of MIDI instrument map entries   *  @returns The current total number of MIDI instrument map entries
2378   *  on success, -1 otherwise.   *  on success, -1 otherwise.
2379   */   */
2380  int lscp_get_midi_instruments ( lscp_client_t *pClient )  int lscp_get_midi_instruments ( lscp_client_t *pClient, int iMidiMap )
2381  {  {
2382          int iInstruments = -1;          int iInstruments = -1;
2383            char szQuery[LSCP_BUFSIZ];
2384    
2385            if (pClient == NULL)
2386                    return -1;
2387    
2388          // Lock this section up.          // Lock this section up.
2389          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
2390    
2391          if (lscp_client_call(pClient, "GET MIDI_INSTRUMENTS\r\n", 0) == LSCP_OK)          strcpy(szQuery, "GET MIDI_INSTRUMENTS ");
2392    
2393            if (iMidiMap < 0)
2394                    strcat(szQuery, "ALL");
2395            else
2396                    sprintf(szQuery + strlen(szQuery), "%d", iMidiMap);
2397    
2398            strcat(szQuery, "\r\n");
2399    
2400            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
2401                  iInstruments = atoi(lscp_client_get_result(pClient));                  iInstruments = atoi(lscp_client_get_result(pClient));
2402    
2403          // Unlock this section down.          // Unlock this section down.
# Line 1766  int lscp_get_midi_instruments ( lscp_cli Line 2409  int lscp_get_midi_instruments ( lscp_cli
2409    
2410  /**  /**
2411   *  Getting indeces of all MIDI instrument map entries:   *  Getting indeces of all MIDI instrument map entries:
2412   *  LIST MIDI_INSTRUMENTS   *  LIST MIDI_INSTRUMENTS ALL|<midi-map>
2413   *   *
2414   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
2415     *  @param iMidiMap MIDI instrument map number, or @ref LSCP_MIDI_MAP_ALL .
2416   *   *
2417   *  @returns An array of @ref lscp_midi_instrument_t, terminated with the   *  @returns An array of @ref lscp_midi_instrument_t, terminated with the
2418   *  {-1,-1,-1} triplet, NULL otherwise.   *  {-1,-1,-1} triplet, NULL otherwise.
2419   */   */
2420  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 )
2421  {  {
2422            char szQuery[LSCP_BUFSIZ];
2423    
2424          if (pClient == NULL)          if (pClient == NULL)
2425                  return NULL;                  return NULL;
2426    
# Line 1786  lscp_midi_instrument_t *lscp_list_midi_i Line 2432  lscp_midi_instrument_t *lscp_list_midi_i
2432                  pClient->midi_instruments = NULL;                  pClient->midi_instruments = NULL;
2433          }          }
2434    
2435          if (lscp_client_call(pClient, "LIST MIDI_INSTRUMENTS\r\n", 0) == LSCP_OK)          strcpy(szQuery, "LIST MIDI_INSTRUMENTS ");
2436    
2437            if (iMidiMap < 0)
2438                    strcat(szQuery, "ALL");
2439            else
2440                    sprintf(szQuery + strlen(szQuery), "%d", iMidiMap);
2441    
2442            strcat(szQuery, "\r\n");
2443    
2444            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
2445                  pClient->midi_instruments = lscp_midi_instruments_create(lscp_client_get_result(pClient));                  pClient->midi_instruments = lscp_midi_instruments_create(lscp_client_get_result(pClient));
2446    
2447          // Unlock this section down.          // Unlock this section down.
# Line 1798  lscp_midi_instrument_t *lscp_list_midi_i Line 2453  lscp_midi_instrument_t *lscp_list_midi_i
2453    
2454  /**  /**
2455   *  Getting information about a MIDI instrument map entry:   *  Getting information about a MIDI instrument map entry:
2456   *  GET MIDI_INSTRUMENT INFO <midi-bank-msb> <midi-bank-lsb> <midi-prog>   *  GET MIDI_INSTRUMENT INFO <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 1816  lscp_midi_instrument_info_t *lscp_get_mi Line 2471  lscp_midi_instrument_info_t *lscp_get_mi
2471          const char *pszCrlf = "\r\n";          const char *pszCrlf = "\r\n";
2472          char *pszToken;          char *pszToken;
2473          char *pch;          char *pch;
2474            
2475          if (pMidiInstr->bank_msb < 0 || pMidiInstr->bank_msb > 127)          if (pClient == NULL)
2476                  return NULL;                  return NULL;
2477          if (pMidiInstr->bank_lsb < 0 || pMidiInstr->bank_lsb > 127)          if (pMidiInstr->map < 0)
2478                  return NULL;                  return NULL;
2479          if (pMidiInstr->program < 0 || pMidiInstr->program > 127)          if (pMidiInstr->bank < 0 || pMidiInstr->bank > 16383)
2480                  return NULL;                  return NULL;
2481                    if (pMidiInstr->prog < 0 || pMidiInstr->prog > 127)
2482                    return NULL;
2483    
2484          // Lock this section up.          // Lock this section up.
2485          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
2486                    
2487          pInstrInfo = &(pClient->midi_instrument_info);          pInstrInfo = &(pClient->midi_instrument_info);
2488          lscp_midi_instrument_info_reset(pInstrInfo);          lscp_midi_instrument_info_reset(pInstrInfo);
2489            
2490          sprintf(szQuery, "GET MIDI_INSTRUMENT INFO %d %d %d\r\n",          sprintf(szQuery, "GET MIDI_INSTRUMENT INFO %d %d %d\r\n",
2491                  pMidiInstr->bank_msb, pMidiInstr->bank_lsb, pMidiInstr->program);                  pMidiInstr->map, pMidiInstr->bank, pMidiInstr->prog);
2492          if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) {          if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) {
2493                  pszResult = lscp_client_get_result(pClient);                  pszResult = lscp_client_get_result(pClient);
2494                  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 2543  lscp_midi_instrument_info_t *lscp_get_mi
2543                  }                  }
2544          }          }
2545          else pInstrInfo = NULL;          else pInstrInfo = NULL;
2546            
2547          // Unlock this section down.          // Unlock this section down.
2548          lscp_mutex_unlock(pClient->mutex);          lscp_mutex_unlock(pClient->mutex);
2549            
2550          return pInstrInfo;          return pInstrInfo;
2551  }  }
2552    
2553    
2554  /**  /**
2555   *  Clear the MIDI instrumnet map:   *  Clear the MIDI instrumnet map:
2556   *  CLEAR MIDI_INSTRUMENTS   *  CLEAR MIDI_INSTRUMENTS ALL|<midi-map>
2557   *   *
2558   *  @param pClient         Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
2559   *  @param iSamplerChannel  Sampler channel number.   *  @param iMidiMap MIDI instrument map number, or @ref LSCP_MIDI_MAP_ALL .
2560   *   *
2561   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2562   */   */
2563  lscp_status_t lscp_clear_midi_instruments  ( lscp_client_t *pClient )  lscp_status_t lscp_clear_midi_instruments  ( lscp_client_t *pClient, int iMidiMap )
2564  {  {
2565          return lscp_client_query(pClient, "CLEAR MIDI_INSTRUMENTS\r\n");          char szQuery[LSCP_BUFSIZ];
2566    
2567            strcpy(szQuery, "CLEAR MIDI_INSTRUMENTS ");
2568    
2569            if (iMidiMap < 0)
2570                    strcat(szQuery, "ALL");
2571            else
2572                    sprintf(szQuery + strlen(szQuery), "%d", iMidiMap);
2573    
2574            strcat(szQuery, "\r\n");
2575    
2576            return lscp_client_query(pClient, szQuery);
2577  }  }
2578    
2579    

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

  ViewVC Help
Powered by ViewVC