/[svn]/liblscp/trunk/src/client.c
ViewVC logotype

Diff of /liblscp/trunk/src/client.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 963 by capela, Sun Dec 3 18:30:04 2006 UTC revision 994 by capela, Thu Dec 21 13:33:27 2006 UTC
# Line 328  lscp_client_t* lscp_client_create ( cons Line 328  lscp_client_t* lscp_client_create ( cons
328          pClient->engines = NULL;          pClient->engines = NULL;
329          pClient->channels = NULL;          pClient->channels = NULL;
330          pClient->midi_instruments = NULL;          pClient->midi_instruments = NULL;
331            pClient->midi_maps = NULL;
332            pClient->midi_map_name = NULL;
333          lscp_driver_info_init(&(pClient->audio_driver_info));          lscp_driver_info_init(&(pClient->audio_driver_info));
334          lscp_driver_info_init(&(pClient->midi_driver_info));          lscp_driver_info_init(&(pClient->midi_driver_info));
335          lscp_device_info_init(&(pClient->audio_device_info));          lscp_device_info_init(&(pClient->audio_device_info));
# Line 424  lscp_status_t lscp_client_destroy ( lscp Line 426  lscp_status_t lscp_client_destroy ( lscp
426          lscp_szsplit_destroy(pClient->engines);          lscp_szsplit_destroy(pClient->engines);
427          lscp_isplit_destroy(pClient->channels);          lscp_isplit_destroy(pClient->channels);
428          lscp_midi_instruments_destroy(pClient->midi_instruments);          lscp_midi_instruments_destroy(pClient->midi_instruments);
429            lscp_isplit_destroy(pClient->midi_maps);
430            if (pClient->midi_map_name)
431                    free(pClient->midi_map_name);
432          // Make them null.          // Make them null.
433          pClient->audio_drivers = NULL;          pClient->audio_drivers = NULL;
434          pClient->midi_drivers = NULL;          pClient->midi_drivers = NULL;
# Line 432  lscp_status_t lscp_client_destroy ( lscp Line 437  lscp_status_t lscp_client_destroy ( lscp
437          pClient->engines = NULL;          pClient->engines = NULL;
438          pClient->channels = NULL;          pClient->channels = NULL;
439          pClient->midi_instruments = NULL;          pClient->midi_instruments = NULL;
440            pClient->midi_maps = NULL;
441            pClient->midi_map_name = NULL;
442          // Free result error stuff.          // Free result error stuff.
443          lscp_client_set_result(pClient, NULL, 0);          lscp_client_set_result(pClient, NULL, 0);
444          // Free stream usage stuff.          // Free stream usage stuff.
# Line 512  lscp_status_t lscp_client_query ( lscp_c Line 519  lscp_status_t lscp_client_query ( lscp_c
519  {  {
520          lscp_status_t ret;          lscp_status_t ret;
521    
522            if (pClient == NULL)
523                    return LSCP_FAILED;
524    
525          // Lock this section up.          // Lock this section up.
526          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
527    
# Line 564  int lscp_client_get_errno ( lscp_client_ Line 574  int lscp_client_get_errno ( lscp_client_
574    
575  /**  /**
576   *  Register frontend for receiving event messages:   *  Register frontend for receiving event messages:
577   *  SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL   *  SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT
578   *      | CHANNEL_INFO | MISCELLANEOUS   *      | BUFFER_FILL | CHANNEL_INFO | TOTAL_VOICE_COUNT
579     *      | AUDIO_OUTPUT_DEVICE_COUNT | AUDIO_OUTPUT_DEVICE_INFO
580     *      | MIDI_INPUT_DEVICE_COUNT | MIDI_INPUT_DEVICE_INFO
581     *      | MIDI_INSTRUMENT_MAP_COUNT | MIDI_INSTRUMENT_MAP_INFO
582     *      | MIDI_INSTRUMENT_COUNT | MIDI_INSTRUMENT_INFO
583     *      | MISCELLANEOUS
584   *   *
585   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
586   *  @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 612  lscp_status_t lscp_client_subscribe ( ls
612                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_BUFFER_FILL);                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_BUFFER_FILL);
613          if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))          if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))
614                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_INFO);                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_INFO);
615            if (ret == LSCP_OK && (events & LSCP_EVENT_TOTAL_VOICE_COUNT))
616                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_TOTAL_VOICE_COUNT);
617            if (ret == LSCP_OK && (events & LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT))
618                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT);
619            if (ret == LSCP_OK && (events & LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO))
620                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO);
621            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT))
622                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT);
623            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INPUT_DEVICE_INFO))
624                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INPUT_DEVICE_INFO);
625            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_MAP_COUNT))
626                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_MAP_COUNT);
627            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_MAP_INFO))
628                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_MAP_INFO);
629            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_COUNT))
630                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_COUNT);
631            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_INFO))
632                    ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_INFO);
633          if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))          if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))
634                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MISCELLANEOUS);                  ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MISCELLANEOUS);
635    
# Line 609  lscp_status_t lscp_client_subscribe ( ls Line 642  lscp_status_t lscp_client_subscribe ( ls
642    
643  /**  /**
644   *  Deregister frontend from receiving UDP event messages anymore:   *  Deregister frontend from receiving UDP event messages anymore:
645   *  SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL   *  UNSUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT
646   *      | CHANNEL_INFO | MISCELLANEOUS   *      | BUFFER_FILL | CHANNEL_INFO | TOTAL_VOICE_COUNT
647     *      | AUDIO_OUTPUT_DEVICE_COUNT | AUDIO_OUTPUT_DEVICE_INFO
648     *      | MIDI_INPUT_DEVICE_COUNT | MIDI_INPUT_DEVICE_INFO
649     *      | MIDI_INSTRUMENT_MAP_COUNT | MIDI_INSTRUMENT_MAP_INFO
650     *      | MIDI_INSTRUMENT_COUNT | MIDI_INSTRUMENT_INFO
651     *      | MISCELLANEOUS
652   *   *
653   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
654   *  @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 676  lscp_status_t lscp_client_unsubscribe (
676                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_BUFFER_FILL);                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_BUFFER_FILL);
677          if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))          if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))
678                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_INFO);                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_INFO);
679            if (ret == LSCP_OK && (events & LSCP_EVENT_TOTAL_VOICE_COUNT))
680                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_TOTAL_VOICE_COUNT);
681            if (ret == LSCP_OK && (events & LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT))
682                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT);
683            if (ret == LSCP_OK && (events & LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO))
684                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO);
685            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT))
686                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT);
687            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INPUT_DEVICE_INFO))
688                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INPUT_DEVICE_INFO);
689            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_MAP_COUNT))
690                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_MAP_COUNT);
691            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_MAP_INFO))
692                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_MAP_INFO);
693            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_COUNT))
694                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_COUNT);
695            if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_INFO))
696                    ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_INFO);
697          if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))          if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))
698                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MISCELLANEOUS);                  ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MISCELLANEOUS);
699    
# Line 752  int lscp_get_channels ( lscp_client_t *p Line 808  int lscp_get_channels ( lscp_client_t *p
808  {  {
809          int iChannels = -1;          int iChannels = -1;
810    
811            if (pClient == NULL)
812                    return -1;
813    
814          // Lock this section up.          // Lock this section up.
815          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
816    
# Line 812  int lscp_add_channel ( lscp_client_t *pC Line 871  int lscp_add_channel ( lscp_client_t *pC
871  {  {
872          int iSamplerChannel = -1;          int iSamplerChannel = -1;
873    
874            if (pClient == NULL)
875                    return -1;
876    
877          // Lock this section up.          // Lock this section up.
878          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
879    
# Line 859  int lscp_get_available_engines ( lscp_cl Line 921  int lscp_get_available_engines ( lscp_cl
921  {  {
922          int iAvailableEngines = -1;          int iAvailableEngines = -1;
923    
924            if (pClient == NULL)
925                    return -1;
926    
927          // Lock this section up.          // Lock this section up.
928          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
929    
# Line 885  const char **lscp_list_available_engines Line 950  const char **lscp_list_available_engines
950  {  {
951          const char *pszSeps = ",";          const char *pszSeps = ",";
952    
953            if (pClient == NULL)
954                    return NULL;
955    
956          // Lock this section up.          // Lock this section up.
957          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
958    
# Line 923  lscp_engine_info_t *lscp_get_engine_info Line 991  lscp_engine_info_t *lscp_get_engine_info
991          char *pszToken;          char *pszToken;
992          char *pch;          char *pch;
993    
994            if (pClient == NULL)
995                    return NULL;
996          if (pszEngineName == NULL)          if (pszEngineName == NULL)
997                  return NULL;                  return NULL;
998    
# Line 979  lscp_channel_info_t *lscp_get_channel_in Line 1049  lscp_channel_info_t *lscp_get_channel_in
1049          char *pszToken;          char *pszToken;
1050          char *pch;          char *pch;
1051    
1052            if (pClient == NULL)
1053                    return NULL;
1054          if (iSamplerChannel < 0)          if (iSamplerChannel < 0)
1055                  return NULL;                  return NULL;
1056    
# Line 1056  lscp_channel_info_t *lscp_get_channel_in Line 1128  lscp_channel_info_t *lscp_get_channel_in
1128                                                  pChannelInfo->midi_channel = atoi(pszToken);                                                  pChannelInfo->midi_channel = atoi(pszToken);
1129                                  }                                  }
1130                          }                          }
1131                            else if (strcasecmp(pszToken, "MIDI_INSTRUMENT_MAP") == 0) {
1132                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1133                                    if (pszToken) {
1134                                            pszToken = lscp_ltrim(pszToken);
1135                                            if (strcasecmp(pszToken, "NONE") == 0)
1136                                                    pChannelInfo->midi_map = LSCP_MIDI_MAP_NONE;
1137                                            else
1138                                            if (strcasecmp(pszToken, "DEFAULT") == 0)
1139                                                    pChannelInfo->midi_map = LSCP_MIDI_MAP_DEFAULT;
1140                                            else
1141                                                    pChannelInfo->midi_map = atoi(pszToken);
1142                                    }
1143                            }
1144                          else if (strcasecmp(pszToken, "VOLUME") == 0) {                          else if (strcasecmp(pszToken, "VOLUME") == 0) {
1145                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1146                                  if (pszToken)                                  if (pszToken)
# Line 1097  int lscp_get_channel_voice_count ( lscp_ Line 1182  int lscp_get_channel_voice_count ( lscp_
1182          char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1183          int iVoiceCount = -1;          int iVoiceCount = -1;
1184    
1185            if (pClient == NULL)
1186                    return -1;
1187          if (iSamplerChannel < 0)          if (iSamplerChannel < 0)
1188                  return iVoiceCount;                  return -1;
1189    
1190          // Lock this section up.          // Lock this section up.
1191          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
# Line 1128  int lscp_get_channel_stream_count ( lscp Line 1215  int lscp_get_channel_stream_count ( lscp
1215          char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
1216          int iStreamCount = -1;          int iStreamCount = -1;
1217    
1218            if (pClient == NULL)
1219                    return -1;
1220          if (iSamplerChannel < 0)          if (iSamplerChannel < 0)
1221                  return iStreamCount;                  return -1;
1222    
1223          // Lock this section up.          // Lock this section up.
1224          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
# Line 1165  int lscp_get_channel_stream_usage ( lscp Line 1254  int lscp_get_channel_stream_usage ( lscp
1254          int   iStream;          int   iStream;
1255          int   iPercent;          int   iPercent;
1256    
1257            if (pClient == NULL)
1258                    return -1;
1259          if (iSamplerChannel < 0)          if (iSamplerChannel < 0)
1260                  return iStreamUsage;                  return -1;
1261    
1262          // Lock this section up.          // Lock this section up.
1263          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
# Line 1227  lscp_buffer_fill_t *lscp_get_channel_buf Line 1318  lscp_buffer_fill_t *lscp_get_channel_buf
1318    
1319          // Retrieve a channel stream estimation.          // Retrieve a channel stream estimation.
1320          iStreamCount = lscp_get_channel_stream_count(pClient, iSamplerChannel);          iStreamCount = lscp_get_channel_stream_count(pClient, iSamplerChannel);
1321          if (pClient->iStreamCount < 0)          if (iStreamCount < 0)
1322                  return NULL;                  return NULL;
1323    
1324          // Lock this section up.          // Lock this section up.
# Line 1416  lscp_status_t lscp_set_channel_midi_port Line 1507  lscp_status_t lscp_set_channel_midi_port
1507   *  @param pClient          Pointer to client instance structure.   *  @param pClient          Pointer to client instance structure.
1508   *  @param iSamplerChannel  Sampler channel number.   *  @param iSamplerChannel  Sampler channel number.
1509   *  @param iMidiChannel     MIDI channel address number to listen (0-15) or   *  @param iMidiChannel     MIDI channel address number to listen (0-15) or
1510   *                          LSCP_MIDI_CHANNEL_ALL (16) to listen on all channels.   *                          @ref LSCP_MIDI_CHANNEL_ALL (16) to listen on all channels.
1511   *   *
1512   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1513   */   */
# Line 1436  lscp_status_t lscp_set_channel_midi_chan Line 1527  lscp_status_t lscp_set_channel_midi_chan
1527    
1528    
1529  /**  /**
1530     *  Setting MIDI instrument map:
1531     *  SET CHANNEL MIDI_INSTRUMENT_MAP <sampler-channel> <midi-map>
1532     *
1533     *  @param pClient          Pointer to client instance structure.
1534     *  @param iSamplerChannel  Sampler channel number.
1535     *  @param iMidiMap         MIDI instrument map number, or either
1536     *                          @ref LSCP_MIDI_MAP_NONE or
1537     *                          @ref LSCP_MIDI_MAP_DEFAULT .
1538     *
1539     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1540     */
1541    lscp_status_t lscp_set_channel_midi_map ( lscp_client_t *pClient, int iSamplerChannel, int iMidiMap )
1542    {
1543            char szQuery[LSCP_BUFSIZ];
1544    
1545            if (iSamplerChannel < 0)
1546                    return LSCP_FAILED;
1547    
1548            sprintf(szQuery, "SET CHANNEL MIDI_INSTRUMENT_MAP %d ", iSamplerChannel);
1549            if (iMidiMap == LSCP_MIDI_MAP_NONE)
1550                    strcat(szQuery , "NONE");
1551            else
1552            if (iMidiMap == LSCP_MIDI_MAP_DEFAULT)
1553                    strcat(szQuery , "DEFAULT");
1554            else
1555                    sprintf(szQuery + strlen(szQuery), "%d", iMidiMap);
1556    
1557            strcat(szQuery, "\r\n");
1558    
1559            return lscp_client_query(pClient, szQuery);
1560    }
1561    
1562    
1563    /**
1564   *  Setting channel volume:   *  Setting channel volume:
1565   *  SET CHANNEL VOLUME <sampler-channel> <volume>   *  SET CHANNEL VOLUME <sampler-channel> <volume>
1566   *   *
# Line 1538  lscp_status_t lscp_reset_channel ( lscp_ Line 1663  lscp_status_t lscp_reset_channel ( lscp_
1663   */   */
1664  lscp_status_t lscp_reset_sampler ( lscp_client_t *pClient )  lscp_status_t lscp_reset_sampler ( lscp_client_t *pClient )
1665  {  {
1666            // Do actual whole sampler reset...
1667          return lscp_client_query(pClient, "RESET\r\n");          return lscp_client_query(pClient, "RESET\r\n");
1668  }  }
1669    
# Line 1560  lscp_server_info_t *lscp_get_server_info Line 1686  lscp_server_info_t *lscp_get_server_info
1686          char *pszToken;          char *pszToken;
1687          char *pch;          char *pch;
1688    
1689            if (pClient == NULL)
1690                    return NULL;
1691    
1692          // Lock this section up.          // Lock this section up.
1693          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
1694    
# Line 1580  lscp_server_info_t *lscp_get_server_info Line 1709  lscp_server_info_t *lscp_get_server_info
1709                                  if (pszToken)                                  if (pszToken)
1710                                          lscp_unquote_dup(&(pServerInfo->version), &pszToken);                                          lscp_unquote_dup(&(pServerInfo->version), &pszToken);
1711                          }                          }
1712                            else if (strcasecmp(pszToken, "PROTOCOL_VERSION") == 0) {
1713                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1714                                    if (pszToken)
1715                                            lscp_unquote_dup(&(pServerInfo->protocol_version), &pszToken);
1716                            }
1717                          pszToken = lscp_strtok(NULL, pszSeps, &(pch));                          pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1718                  }                  }
1719          }          }
# Line 1605  int lscp_get_total_voice_count ( lscp_cl Line 1739  int lscp_get_total_voice_count ( lscp_cl
1739  {  {
1740          int iVoiceCount = -1;          int iVoiceCount = -1;
1741    
1742            if (pClient == NULL)
1743                    return -1;
1744    
1745          // Lock this section up.          // Lock this section up.
1746          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
1747    
# Line 1631  int lscp_get_total_voice_count_max ( lsc Line 1768  int lscp_get_total_voice_count_max ( lsc
1768  {  {
1769          int iVoiceCount = -1;          int iVoiceCount = -1;
1770    
1771            if (pClient == NULL)
1772                    return -1;
1773    
1774          // Lock this section up.          // Lock this section up.
1775          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
1776    
# Line 1645  int lscp_get_total_voice_count_max ( lsc Line 1785  int lscp_get_total_voice_count_max ( lsc
1785    
1786    
1787  /**  /**
1788     *  Create a new MIDI instrument map:
1789     *  ADD MIDI_INSTRUMENT_MAP [<name>]
1790     *
1791     *  @param pClient      Pointer to client instance structure.
1792     *  @param pszMapName   MIDI instrument map name (optional)
1793     *
1794     *  @returns The new MIDI instrument map number identifier,
1795     *  or -1 in case of failure.
1796     */
1797    int lscp_add_midi_instrument_map ( lscp_client_t *pClient, const char *pszMapName )
1798    {
1799            int iMidiMap = -1;
1800            char szQuery[LSCP_BUFSIZ];
1801    
1802            if (pClient == NULL)
1803                    return -1;
1804    
1805            // Lock this section up.
1806            lscp_mutex_lock(pClient->mutex);
1807    
1808            strcpy(szQuery, "ADD MIDI_INSTRUMENT_MAP");
1809            
1810            if (pszMapName)
1811                    sprintf(szQuery + strlen(szQuery), " '%s'", pszMapName);
1812    
1813            strcat(szQuery, "\r\n");
1814    
1815            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
1816                    iMidiMap = atoi(lscp_client_get_result(pClient));
1817    
1818            // Unlock this section down.
1819            lscp_mutex_unlock(pClient->mutex);
1820    
1821            return iMidiMap;
1822    }
1823    
1824    
1825    /**
1826     *  Delete one particular or all MIDI instrument maps:
1827     *  REMOVE MIDI_INSTRUMENT_MAP <midi-map>
1828     *
1829     *  @param pClient  Pointer to client instance structure.
1830     *  @param iMidiMap MIDI instrument map number.
1831     *
1832     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1833     */
1834    lscp_status_t lscp_remove_midi_instrument_map ( lscp_client_t *pClient, int iMidiMap )
1835    {
1836            char szQuery[LSCP_BUFSIZ];
1837    
1838            if (iMidiMap < 0)
1839                    return LSCP_FAILED;
1840    
1841            sprintf(szQuery, "REMOVE MIDI_INSTRUMENT_MAP %d\r\n", iMidiMap);
1842    
1843            return lscp_client_query(pClient, szQuery);
1844    }
1845    
1846    
1847    /**
1848     *  Get amount of existing MIDI instrument maps:
1849     *  GET MIDI_INSTRUMENT_MAPS
1850     *
1851     *  @param pClient  Pointer to client instance structure.
1852     *
1853     *  @returns The current total number of MIDI instrument maps
1854     *  on success, -1 otherwise.
1855     */
1856    int lscp_get_midi_instrument_maps ( lscp_client_t *pClient )
1857    {
1858            int iMidiMaps = -1;
1859    
1860            if (pClient == NULL)
1861                    return -1;
1862    
1863            // Lock this section up.
1864            lscp_mutex_lock(pClient->mutex);
1865    
1866            if (lscp_client_call(pClient, "GET MIDI_INSTRUMENT_MAPS\r\n", 0) == LSCP_OK)
1867                    iMidiMaps = atoi(lscp_client_get_result(pClient));
1868    
1869            // Unlock this section doen.
1870            lscp_mutex_unlock(pClient->mutex);
1871    
1872            return iMidiMaps;
1873    }
1874    
1875    
1876    /**
1877     *  Getting all created MIDI instrument maps:
1878     *  LIST MIDI_INSTRUMENT_MAPS
1879     *
1880     *  @param pClient  Pointer to client instance structure.
1881     *
1882     *  @returns An array of the MIDI instrument map identifiers as positive
1883     *  integers, terminated with -1 on success, NULL otherwise.
1884     */
1885    int *lscp_list_midi_instrument_maps ( lscp_client_t *pClient )
1886    {
1887            const char *pszSeps = ",";
1888    
1889            if (pClient == NULL)
1890                    return NULL;
1891    
1892            // Lock this section up.
1893            lscp_mutex_lock(pClient->mutex);
1894    
1895            if (pClient->midi_maps) {
1896                    lscp_isplit_destroy(pClient->midi_maps);
1897                    pClient->midi_maps = NULL;
1898            }
1899    
1900            if (lscp_client_call(pClient, "LIST MIDI_INSTRUMENT_MAPS\r\n", 0) == LSCP_OK)
1901                    pClient->midi_maps = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps);
1902    
1903            // Unlock this section down.
1904            lscp_mutex_unlock(pClient->mutex);
1905    
1906            return pClient->midi_maps;
1907    }
1908    
1909    
1910    /**
1911     *  Getting a MIDI instrument map name:
1912     *  GET MIDI_INSTRUMENT_MAP INFO <midi-map>
1913     *
1914     *  @param pClient  Pointer to client instance structure.
1915     *  @param iMidiMap MIDI instrument map number.
1916     *
1917     *  @returns The MIDI instrument map name on success, NULL on failure.
1918     */
1919    const char *lscp_get_midi_instrument_map_name ( lscp_client_t *pClient, int iMidiMap )
1920    {
1921            char szQuery[LSCP_BUFSIZ];
1922            const char *pszResult;
1923            const char *pszSeps = ":";
1924            const char *pszCrlf = "\r\n";
1925            char *pszToken;
1926            char *pch;
1927    
1928            if (pClient == NULL)
1929                    return NULL;
1930            if (iMidiMap < 0)
1931                    return NULL;
1932    
1933            // Lock this section up.
1934            lscp_mutex_lock(pClient->mutex);
1935            
1936            if (pClient->midi_map_name) {
1937                    free(pClient->midi_map_name);
1938                    pClient->midi_map_name = NULL;
1939            }
1940    
1941            sprintf(szQuery, "GET MIDI_INSTRUMENT_MAP INFO %d\r\n", iMidiMap);
1942            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK) {
1943                    pszResult = lscp_client_get_result(pClient);
1944                    pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
1945                    while (pszToken) {
1946                            if (strcasecmp(pszToken, "NAME") == 0) {
1947                                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1948                                    if (pszToken)
1949                                            lscp_unquote_dup(&(pClient->midi_map_name), &pszToken);
1950                            }
1951                            pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1952                    }
1953            }
1954    
1955            // Unlock this section down.
1956            lscp_mutex_unlock(pClient->mutex);
1957    
1958            return pClient->midi_map_name;
1959    }
1960    
1961    
1962    /**
1963     *  Renaming a MIDI instrument map:
1964     *  SET MIDI_INSTRUMENT_MAP NAME <midi-map> <map-name>
1965     *
1966     *  @param pClient      Pointer to client instance structure.
1967     *  @param iMidiMap     MIDI instrument map number.
1968     *  @param pszMapName   MIDI instrument map name.
1969     *
1970     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1971     */
1972    lscp_status_t lscp_set_midi_instrument_map_name ( lscp_client_t *pClient, int iMidiMap, const char *pszMapName )
1973    {
1974            char szQuery[LSCP_BUFSIZ];
1975    
1976            if (iMidiMap < 0)
1977                    return LSCP_FAILED;
1978            if (pszMapName == NULL)
1979                    return LSCP_FAILED;
1980    
1981            sprintf(szQuery, "SET MIDI_INSTRUMENT_MAP NAME %d '%s'\r\n",
1982                    iMidiMap, pszMapName);
1983    
1984            return lscp_client_query(pClient, szQuery);
1985    }
1986    
1987    
1988    /**
1989   *  Create or replace a MIDI instrumnet map entry:   *  Create or replace a MIDI instrumnet map entry:
1990   *  MAP MIDI_INSTRUMENT <midi-bank-msb> <midi-bank-lsb> <midi-prog>   *  MAP MIDI_INSTRUMENT <midi-map> <midi-bank> <midi-prog>
1991   *      <engine-name> <filename> <instr-index> <volume> <load-mode> [<name>]   *      <engine-name> <filename> <instr-index> <volume> [<load-mode> [<name>]}
1992   *   *
1993   *  @param pClient          Pointer to client instance structure.   *  @param pClient          Pointer to client instance structure.
1994   *  @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 2004  int lscp_get_total_voice_count_max ( lsc
2004   *                          @ref LSCP_LOAD_ON_DEMAND, or   *                          @ref LSCP_LOAD_ON_DEMAND, or
2005   *                          @ref LSCP_LOAD_ON_DEMAND_HOLD, or   *                          @ref LSCP_LOAD_ON_DEMAND_HOLD, or
2006   *                          @ref LSCP_LOAD_PERSISTENT.   *                          @ref LSCP_LOAD_PERSISTENT.
2007   *  @param pszName          Instrument custom name for the map entry.   *  @param pszName         Instrument custom name for the map entry (optional).
2008   *   *
2009   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2010   */   */
# Line 1671  lscp_status_t lscp_map_midi_instrument ( Line 2012  lscp_status_t lscp_map_midi_instrument (
2012  {  {
2013          char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
2014    
2015          if (pMidiInstr->bank_msb < 0 || pMidiInstr->bank_msb > 127)          if (pMidiInstr->map < 0)
2016                  return LSCP_FAILED;                  return LSCP_FAILED;
2017          if (pMidiInstr->bank_lsb < 0 || pMidiInstr->bank_lsb > 127)          if (pMidiInstr->bank < 0 || pMidiInstr->bank > 16383)
2018                  return LSCP_FAILED;                  return LSCP_FAILED;
2019          if (pMidiInstr->program < 0 || pMidiInstr->program > 127)          if (pMidiInstr->prog < 0 || pMidiInstr->prog > 127)
2020                  return LSCP_FAILED;                  return LSCP_FAILED;
2021          if (pszEngineName == NULL || pszFileName == NULL)          if (pszEngineName == NULL || pszFileName == NULL)
2022                  return LSCP_FAILED;                  return LSCP_FAILED;
# Line 1684  lscp_status_t lscp_map_midi_instrument ( Line 2025  lscp_status_t lscp_map_midi_instrument (
2025                  fVolume = 1.0f;                  fVolume = 1.0f;
2026    
2027          sprintf(szQuery, "MAP MIDI_INSTRUMENT %d %d %d %s '%s' %d %g",          sprintf(szQuery, "MAP MIDI_INSTRUMENT %d %d %d %s '%s' %d %g",
2028                  pMidiInstr->bank_msb, pMidiInstr->bank_lsb, pMidiInstr->program,                  pMidiInstr->map, pMidiInstr->bank, pMidiInstr->prog,
2029                  pszEngineName, pszFileName, iInstrIndex, fVolume);                  pszEngineName, pszFileName, iInstrIndex, fVolume);
2030    
2031          switch (load_mode) {          switch (load_mode) {
# Line 1713  lscp_status_t lscp_map_midi_instrument ( Line 2054  lscp_status_t lscp_map_midi_instrument (
2054    
2055  /**  /**
2056   *  Remove an entry from the MIDI instrument map:   *  Remove an entry from the MIDI instrument map:
2057   *  UNMAP MIDI_INSTRUMENT <midi-bank-msb> <midi-bank-lsb> <midi-prog>   *  UNMAP MIDI_INSTRUMENT <midi-map> <midi-bank> <midi-prog>
2058   *   *
2059   *  @param pClient      Pointer to client instance structure.   *  @param pClient      Pointer to client instance structure.
2060   *  @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 2065  lscp_status_t lscp_unmap_midi_instrument
2065  {  {
2066          char szQuery[LSCP_BUFSIZ];          char szQuery[LSCP_BUFSIZ];
2067    
2068          if (pMidiInstr->bank_msb < 0 || pMidiInstr->bank_msb > 127)          if (pMidiInstr->map < 0)
2069                  return LSCP_FAILED;                  return LSCP_FAILED;
2070          if (pMidiInstr->bank_lsb < 0 || pMidiInstr->bank_lsb > 127)          if (pMidiInstr->bank < 0 || pMidiInstr->bank > 16383)
2071                  return LSCP_FAILED;                  return LSCP_FAILED;
2072          if (pMidiInstr->program < 0 || pMidiInstr->program > 127)          if (pMidiInstr->prog < 0 || pMidiInstr->prog > 127)
2073                  return LSCP_FAILED;                  return LSCP_FAILED;
2074    
2075          sprintf(szQuery, "UNMAP MIDI_INSTRUMENT %d %d %d\r\n",          sprintf(szQuery, "UNMAP MIDI_INSTRUMENT %d %d %d\r\n",
2076                  pMidiInstr->bank_msb, pMidiInstr->bank_lsb, pMidiInstr->program);                  pMidiInstr->map, pMidiInstr->bank, pMidiInstr->prog);
2077    
2078          return lscp_client_query(pClient, szQuery);          return lscp_client_query(pClient, szQuery);
2079  }  }
# Line 1740  lscp_status_t lscp_unmap_midi_instrument Line 2081  lscp_status_t lscp_unmap_midi_instrument
2081    
2082  /**  /**
2083   *  Get the total count of MIDI instrument map entries:   *  Get the total count of MIDI instrument map entries:
2084   *  GET MIDI_INSTRUMENTS   *  GET MIDI_INSTRUMENTS ALL|<midi-map>
2085   *   *
2086   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
2087     *  @param iMidiMap MIDI instrument map number, or @ref LSCP_MIDI_MAP_ALL .
2088   *   *
2089   *  @returns The current total number of MIDI instrument map entries   *  @returns The current total number of MIDI instrument map entries
2090   *  on success, -1 otherwise.   *  on success, -1 otherwise.
2091   */   */
2092  int lscp_get_midi_instruments ( lscp_client_t *pClient )  int lscp_get_midi_instruments ( lscp_client_t *pClient, int iMidiMap )
2093  {  {
2094          int iInstruments = -1;          int iInstruments = -1;
2095            char szQuery[LSCP_BUFSIZ];
2096    
2097            if (pClient == NULL)
2098                    return -1;
2099    
2100          // Lock this section up.          // Lock this section up.
2101          lscp_mutex_lock(pClient->mutex);          lscp_mutex_lock(pClient->mutex);
2102    
2103          if (lscp_client_call(pClient, "GET MIDI_INSTRUMENTS\r\n", 0) == LSCP_OK)          strcpy(szQuery, "GET MIDI_INSTRUMENTS ");
2104    
2105            if (iMidiMap < 0)
2106                    strcat(szQuery, "ALL");
2107            else
2108                    sprintf(szQuery + strlen(szQuery), "%d", iMidiMap);
2109    
2110            strcat(szQuery, "\r\n");
2111    
2112            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
2113                  iInstruments = atoi(lscp_client_get_result(pClient));                  iInstruments = atoi(lscp_client_get_result(pClient));
2114    
2115          // Unlock this section down.          // Unlock this section down.
# Line 1766  int lscp_get_midi_instruments ( lscp_cli Line 2121  int lscp_get_midi_instruments ( lscp_cli
2121    
2122  /**  /**
2123   *  Getting indeces of all MIDI instrument map entries:   *  Getting indeces of all MIDI instrument map entries:
2124   *  LIST MIDI_INSTRUMENTS   *  LIST MIDI_INSTRUMENTS ALL|<midi-map>
2125   *   *
2126   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
2127     *  @param iMidiMap MIDI instrument map number, or @ref LSCP_MIDI_MAP_ALL .
2128   *   *
2129   *  @returns An array of @ref lscp_midi_instrument_t, terminated with the   *  @returns An array of @ref lscp_midi_instrument_t, terminated with the
2130   *  {-1,-1,-1} triplet, NULL otherwise.   *  {-1,-1,-1} triplet, NULL otherwise.
2131   */   */
2132  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 )
2133  {  {
2134            char szQuery[LSCP_BUFSIZ];
2135    
2136          if (pClient == NULL)          if (pClient == NULL)
2137                  return NULL;                  return NULL;
2138    
# Line 1786  lscp_midi_instrument_t *lscp_list_midi_i Line 2144  lscp_midi_instrument_t *lscp_list_midi_i
2144                  pClient->midi_instruments = NULL;                  pClient->midi_instruments = NULL;
2145          }          }
2146    
2147          if (lscp_client_call(pClient, "LIST MIDI_INSTRUMENTS\r\n", 0) == LSCP_OK)          strcpy(szQuery, "LIST MIDI_INSTRUMENTS ");
2148    
2149            if (iMidiMap < 0)
2150                    strcat(szQuery, "ALL");
2151            else
2152                    sprintf(szQuery + strlen(szQuery), "%d", iMidiMap);
2153    
2154            strcat(szQuery, "\r\n");
2155    
2156            if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
2157                  pClient->midi_instruments = lscp_midi_instruments_create(lscp_client_get_result(pClient));                  pClient->midi_instruments = lscp_midi_instruments_create(lscp_client_get_result(pClient));
2158    
2159          // Unlock this section down.          // Unlock this section down.
# Line 1798  lscp_midi_instrument_t *lscp_list_midi_i Line 2165  lscp_midi_instrument_t *lscp_list_midi_i
2165    
2166  /**  /**
2167   *  Getting information about a MIDI instrument map entry:   *  Getting information about a MIDI instrument map entry:
2168   *  GET MIDI_INSTRUMENT INFO <midi-bank-msb> <midi-bank-lsb> <midi-prog>   *  GET MIDI_INSTRUMENT INFO <midi-map> <midi-bank> <midi-prog>
2169   *   *
2170   *  @param pClient      Pointer to client instance structure.   *  @param pClient      Pointer to client instance structure.
2171   *  @param pMidiInstr   MIDI instrument bank and program parameter key.   *  @param pMidiInstr   MIDI instrument bank and program parameter key.
# Line 1817  lscp_midi_instrument_info_t *lscp_get_mi Line 2184  lscp_midi_instrument_info_t *lscp_get_mi
2184          char *pszToken;          char *pszToken;
2185          char *pch;          char *pch;
2186    
2187          if (pMidiInstr->bank_msb < 0 || pMidiInstr->bank_msb > 127)          if (pClient == NULL)
2188                  return NULL;                  return NULL;
2189          if (pMidiInstr->bank_lsb < 0 || pMidiInstr->bank_lsb > 127)          if (pMidiInstr->map < 0)
2190                  return NULL;                  return NULL;
2191          if (pMidiInstr->program < 0 || pMidiInstr->program > 127)          if (pMidiInstr->bank < 0 || pMidiInstr->bank > 16383)
2192                    return NULL;
2193            if (pMidiInstr->prog < 0 || pMidiInstr->prog > 127)
2194                  return NULL;                  return NULL;
2195    
2196          // Lock this section up.          // Lock this section up.
# Line 1831  lscp_midi_instrument_info_t *lscp_get_mi Line 2200  lscp_midi_instrument_info_t *lscp_get_mi
2200          lscp_midi_instrument_info_reset(pInstrInfo);          lscp_midi_instrument_info_reset(pInstrInfo);
2201    
2202          sprintf(szQuery, "GET MIDI_INSTRUMENT INFO %d %d %d\r\n",          sprintf(szQuery, "GET MIDI_INSTRUMENT INFO %d %d %d\r\n",
2203                  pMidiInstr->bank_msb, pMidiInstr->bank_lsb, pMidiInstr->program);                  pMidiInstr->map, pMidiInstr->bank, pMidiInstr->prog);
2204          if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) {          if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) {
2205                  pszResult = lscp_client_get_result(pClient);                  pszResult = lscp_client_get_result(pClient);
2206                  pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));                  pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
# Line 1896  lscp_midi_instrument_info_t *lscp_get_mi Line 2265  lscp_midi_instrument_info_t *lscp_get_mi
2265    
2266  /**  /**
2267   *  Clear the MIDI instrumnet map:   *  Clear the MIDI instrumnet map:
2268   *  CLEAR MIDI_INSTRUMENTS   *  CLEAR MIDI_INSTRUMENTS ALL|<midi-map>
2269   *   *
2270   *  @param pClient         Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
2271   *  @param iSamplerChannel  Sampler channel number.   *  @param iMidiMap MIDI instrument map number, or @ref LSCP_MIDI_MAP_ALL .
2272   *   *
2273   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
2274   */   */
2275  lscp_status_t lscp_clear_midi_instruments  ( lscp_client_t *pClient )  lscp_status_t lscp_clear_midi_instruments  ( lscp_client_t *pClient, int iMidiMap )
2276  {  {
2277          return lscp_client_query(pClient, "CLEAR MIDI_INSTRUMENTS\r\n");          char szQuery[LSCP_BUFSIZ];
2278    
2279            strcpy(szQuery, "CLEAR MIDI_INSTRUMENTS ");
2280    
2281            if (iMidiMap < 0)
2282                    strcat(szQuery, "ALL");
2283            else
2284                    sprintf(szQuery + strlen(szQuery), "%d", iMidiMap);
2285    
2286            strcat(szQuery, "\r\n");
2287    
2288            return lscp_client_query(pClient, szQuery);
2289  }  }
2290    
2291    

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

  ViewVC Help
Powered by ViewVC