/[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 623 by capela, Thu Jun 9 10:37:19 2005 UTC revision 948 by capela, Tue Nov 28 15:31:20 2006 UTC
# Line 2  Line 2 
2  //  //
3  /****************************************************************************  /****************************************************************************
4     liblscp - LinuxSampler Control Protocol API     liblscp - LinuxSampler Control Protocol API
5     Copyright (C) 2004-2005, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2006, 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 14  Line 14 
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15     Lesser General Public License for more details.     Lesser General Public License for more details.
16    
17     You should 14have received a copy of the GNU Lesser General Public     You should have received a copy of the GNU General Public License along
18     License along with this library; if not, write to the Free Software     with this program; if not, write to the Free Software Foundation, Inc.,
19     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20    
21  *****************************************************************************/  *****************************************************************************/
22    
# Line 69  static void _lscp_client_evt_proc ( void Line 69  static void _lscp_client_evt_proc ( void
69    
70          // Use the timeout (x10) select feature ...          // Use the timeout (x10) select feature ...
71          iTimeout = 10 * pClient->iTimeout;          iTimeout = 10 * pClient->iTimeout;
72          if (iTimeout > 1000) {          if (iTimeout >= 1000) {
73              tv.tv_sec = iTimeout / 1000;              tv.tv_sec = iTimeout / 1000;
74              iTimeout -= tv.tv_sec * 1000;              iTimeout -= tv.tv_sec * 1000;
75          }          }
# 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->midi_instruments = NULL;
331      lscp_driver_info_init(&(pClient->audio_driver_info));      lscp_driver_info_init(&(pClient->audio_driver_info));
332      lscp_driver_info_init(&(pClient->midi_driver_info));      lscp_driver_info_init(&(pClient->midi_driver_info));
333      lscp_device_info_init(&(pClient->audio_device_info));      lscp_device_info_init(&(pClient->audio_device_info));
# Line 340  lscp_client_t* lscp_client_create ( cons Line 341  lscp_client_t* lscp_client_create ( cons
341      lscp_server_info_init(&(pClient->server_info));      lscp_server_info_init(&(pClient->server_info));
342      lscp_engine_info_init(&(pClient->engine_info));      lscp_engine_info_init(&(pClient->engine_info));
343      lscp_channel_info_init(&(pClient->channel_info));      lscp_channel_info_init(&(pClient->channel_info));
344        lscp_midi_instrument_info_init(&(pClient->midi_instrument_info));
345      // Initialize error stuff.      // Initialize error stuff.
346      pClient->pszResult = NULL;      pClient->pszResult = NULL;
347      pClient->iErrno = -1;      pClient->iErrno = -1;
# Line 348  lscp_client_t* lscp_client_create ( cons Line 350  lscp_client_t* lscp_client_create ( cons
350      pClient->iStreamCount = 0;      pClient->iStreamCount = 0;
351      // Default timeout value.      // Default timeout value.
352      pClient->iTimeout = LSCP_TIMEOUT_MSECS;      pClient->iTimeout = LSCP_TIMEOUT_MSECS;
353      pClient->iTimeoutCount = 0;          pClient->iTimeoutCount = 0;
354    
355      // Initialize the transaction mutex.      // Initialize the transaction mutex.
356      lscp_mutex_init(pClient->mutex);      lscp_mutex_init(pClient->mutex);
# Line 400  lscp_status_t lscp_client_destroy ( lscp Line 402  lscp_status_t lscp_client_destroy ( lscp
402      lscp_mutex_lock(pClient->mutex);      lscp_mutex_lock(pClient->mutex);
403    
404      // Free up all cached members.      // Free up all cached members.
405        lscp_midi_instrument_info_free(&(pClient->midi_instrument_info));
406      lscp_channel_info_free(&(pClient->channel_info));      lscp_channel_info_free(&(pClient->channel_info));
407      lscp_engine_info_free(&(pClient->engine_info));      lscp_engine_info_free(&(pClient->engine_info));
408      lscp_server_info_free(&(pClient->server_info));      lscp_server_info_free(&(pClient->server_info));
# Line 420  lscp_status_t lscp_client_destroy ( lscp Line 423  lscp_status_t lscp_client_destroy ( lscp
423      lscp_isplit_destroy(pClient->midi_devices);      lscp_isplit_destroy(pClient->midi_devices);
424      lscp_szsplit_destroy(pClient->engines);      lscp_szsplit_destroy(pClient->engines);
425      lscp_isplit_destroy(pClient->channels);      lscp_isplit_destroy(pClient->channels);
426        lscp_midi_instruments_destroy(pClient->midi_instruments);
427      // Make them null.      // Make them null.
428      pClient->audio_drivers = NULL;      pClient->audio_drivers = NULL;
429      pClient->midi_drivers = NULL;      pClient->midi_drivers = NULL;
430        pClient->audio_devices = NULL;
431        pClient->midi_devices = NULL;
432      pClient->engines = NULL;      pClient->engines = NULL;
433        pClient->channels = NULL;
434        pClient->midi_instruments = NULL;
435      // Free result error stuff.      // Free result error stuff.
436      lscp_client_set_result(pClient, NULL, 0);      lscp_client_set_result(pClient, NULL, 0);
437      // Free stream usage stuff.      // Free stream usage stuff.
# Line 508  lscp_status_t lscp_client_query ( lscp_c Line 516  lscp_status_t lscp_client_query ( lscp_c
516      lscp_mutex_lock(pClient->mutex);      lscp_mutex_lock(pClient->mutex);
517    
518      // Just make the now guarded call.      // Just make the now guarded call.
519      ret = lscp_client_call(pClient, pszQuery);      ret = lscp_client_call(pClient, pszQuery, 0);
520    
521      // Unlock this section down.      // Unlock this section down.
522      lscp_mutex_unlock(pClient->mutex);      lscp_mutex_unlock(pClient->mutex);
# Line 747  int lscp_get_channels ( lscp_client_t *p Line 755  int lscp_get_channels ( lscp_client_t *p
755      // Lock this section up.      // Lock this section up.
756      lscp_mutex_lock(pClient->mutex);      lscp_mutex_lock(pClient->mutex);
757    
758      if (lscp_client_call(pClient, "GET CHANNELS\r\n") == LSCP_OK)      if (lscp_client_call(pClient, "GET CHANNELS\r\n", 0) == LSCP_OK)
759          iChannels = atoi(lscp_client_get_result(pClient));          iChannels = atoi(lscp_client_get_result(pClient));
760    
761      // Unlock this section doen.      // Unlock this section doen.
# Line 781  int *lscp_list_channels ( lscp_client_t Line 789  int *lscp_list_channels ( lscp_client_t
789          pClient->channels = NULL;          pClient->channels = NULL;
790      }      }
791    
792      if (lscp_client_call(pClient, "LIST CHANNELS\r\n") == LSCP_OK)      if (lscp_client_call(pClient, "LIST CHANNELS\r\n", 0) == LSCP_OK)
793          pClient->channels = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps);          pClient->channels = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps);
794    
795      // Unlock this section down.      // Unlock this section down.
# Line 807  int lscp_add_channel ( lscp_client_t *pC Line 815  int lscp_add_channel ( lscp_client_t *pC
815      // Lock this section up.      // Lock this section up.
816      lscp_mutex_lock(pClient->mutex);      lscp_mutex_lock(pClient->mutex);
817    
818      if (lscp_client_call(pClient, "ADD CHANNEL\r\n") == LSCP_OK)      if (lscp_client_call(pClient, "ADD CHANNEL\r\n", 0) == LSCP_OK)
819          iSamplerChannel = atoi(lscp_client_get_result(pClient));          iSamplerChannel = atoi(lscp_client_get_result(pClient));
820    
821      // Unlock this section down.      // Unlock this section down.
# Line 854  int lscp_get_available_engines ( lscp_cl Line 862  int lscp_get_available_engines ( lscp_cl
862      // Lock this section up.      // Lock this section up.
863      lscp_mutex_lock(pClient->mutex);      lscp_mutex_lock(pClient->mutex);
864    
865      if (lscp_client_call(pClient, "GET AVAILABLE_ENGINES\r\n") == LSCP_OK)      if (lscp_client_call(pClient, "GET AVAILABLE_ENGINES\r\n", 0) == LSCP_OK)
866          iAvailableEngines = atoi(lscp_client_get_result(pClient));          iAvailableEngines = atoi(lscp_client_get_result(pClient));
867    
868      // Unlock this section down.      // Unlock this section down.
# Line 885  const char **lscp_list_available_engines Line 893  const char **lscp_list_available_engines
893          pClient->engines = NULL;          pClient->engines = NULL;
894      }      }
895    
896      if (lscp_client_call(pClient, "LIST AVAILABLE_ENGINES\r\n") == LSCP_OK)      if (lscp_client_call(pClient, "LIST AVAILABLE_ENGINES\r\n", 0) == LSCP_OK)
897          pClient->engines = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps);          pClient->engines = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps);
898    
899      // Unlock this section down.      // Unlock this section down.
# Line 925  lscp_engine_info_t *lscp_get_engine_info Line 933  lscp_engine_info_t *lscp_get_engine_info
933      lscp_engine_info_reset(pEngineInfo);      lscp_engine_info_reset(pEngineInfo);
934    
935      sprintf(szQuery, "GET ENGINE INFO %s\r\n", pszEngineName);      sprintf(szQuery, "GET ENGINE INFO %s\r\n", pszEngineName);
936      if (lscp_client_call(pClient, szQuery) == LSCP_OK) {      if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) {
937          pszResult = lscp_client_get_result(pClient);          pszResult = lscp_client_get_result(pClient);
938          pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));          pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
939          while (pszToken) {          while (pszToken) {
# Line 981  lscp_channel_info_t *lscp_get_channel_in Line 989  lscp_channel_info_t *lscp_get_channel_in
989      lscp_channel_info_reset(pChannelInfo);      lscp_channel_info_reset(pChannelInfo);
990    
991      sprintf(szQuery, "GET CHANNEL INFO %d\r\n", iSamplerChannel);      sprintf(szQuery, "GET CHANNEL INFO %d\r\n", iSamplerChannel);
992      if (lscp_client_call(pClient, szQuery) == LSCP_OK) {      if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) {
993          pszResult = lscp_client_get_result(pClient);          pszResult = lscp_client_get_result(pClient);
994          pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));          pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
995          while (pszToken) {          while (pszToken) {
# Line 1053  lscp_channel_info_t *lscp_get_channel_in Line 1061  lscp_channel_info_t *lscp_get_channel_in
1061                  if (pszToken)                  if (pszToken)
1062                      pChannelInfo->volume = (float) atof(lscp_ltrim(pszToken));                      pChannelInfo->volume = (float) atof(lscp_ltrim(pszToken));
1063              }              }
1064                else if (strcasecmp(pszToken, "MUTE") == 0) {
1065                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1066                    if (pszToken)
1067                        pChannelInfo->mute = (strcasecmp(lscp_unquote(&pszToken, 0), "TRUE") == 0);
1068                }
1069                else if (strcasecmp(pszToken, "SOLO") == 0) {
1070                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1071                    if (pszToken)
1072                        pChannelInfo->solo = (strcasecmp(lscp_unquote(&pszToken, 0), "TRUE") == 0);
1073                }
1074              pszToken = lscp_strtok(NULL, pszSeps, &(pch));              pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1075          }          }
1076      }      }
# Line 1086  int lscp_get_channel_voice_count ( lscp_ Line 1104  int lscp_get_channel_voice_count ( lscp_
1104      lscp_mutex_lock(pClient->mutex);      lscp_mutex_lock(pClient->mutex);
1105    
1106      sprintf(szQuery, "GET CHANNEL VOICE_COUNT %d\r\n", iSamplerChannel);      sprintf(szQuery, "GET CHANNEL VOICE_COUNT %d\r\n", iSamplerChannel);
1107      if (lscp_client_call(pClient, szQuery) == LSCP_OK)      if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
1108          iVoiceCount = atoi(lscp_client_get_result(pClient));          iVoiceCount = atoi(lscp_client_get_result(pClient));
1109    
1110      // Unlock this section down.      // Unlock this section down.
# Line 1117  int lscp_get_channel_stream_count ( lscp Line 1135  int lscp_get_channel_stream_count ( lscp
1135      lscp_mutex_lock(pClient->mutex);      lscp_mutex_lock(pClient->mutex);
1136    
1137      sprintf(szQuery, "GET CHANNEL STREAM_COUNT %d\r\n", iSamplerChannel);      sprintf(szQuery, "GET CHANNEL STREAM_COUNT %d\r\n", iSamplerChannel);
1138      if (lscp_client_call(pClient, szQuery) == LSCP_OK)      if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
1139          iStreamCount = atoi(lscp_client_get_result(pClient));          iStreamCount = atoi(lscp_client_get_result(pClient));
1140    
1141      // Unlock this section down.      // Unlock this section down.
# Line 1155  int lscp_get_channel_stream_usage ( lscp Line 1173  int lscp_get_channel_stream_usage ( lscp
1173    
1174      iStream = 0;      iStream = 0;
1175      sprintf(szQuery, "GET CHANNEL BUFFER_FILL PERCENTAGE %d\r\n", iSamplerChannel);      sprintf(szQuery, "GET CHANNEL BUFFER_FILL PERCENTAGE %d\r\n", iSamplerChannel);
1176      if (lscp_client_call(pClient, szQuery) == LSCP_OK) {      if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK) {
1177          pszResult = lscp_client_get_result(pClient);          pszResult = lscp_client_get_result(pClient);
1178          pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));          pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
1179          while (pszToken) {          while (pszToken) {
# Line 1232  lscp_buffer_fill_t *lscp_get_channel_buf Line 1250  lscp_buffer_fill_t *lscp_get_channel_buf
1250          iStream = 0;          iStream = 0;
1251          pBufferFill = pClient->buffer_fill;          pBufferFill = pClient->buffer_fill;
1252          sprintf(szQuery, "GET CHANNEL BUFFER_FILL %s %d\r\n", pszUsageType, iSamplerChannel);          sprintf(szQuery, "GET CHANNEL BUFFER_FILL %s %d\r\n", pszUsageType, iSamplerChannel);
1253          if (lscp_client_call(pClient, szQuery) == LSCP_OK) {          if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK) {
1254              pszResult = lscp_client_get_result(pClient);              pszResult = lscp_client_get_result(pClient);
1255              pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));              pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
1256              while (pszToken && iStream < pClient->iStreamCount) {              while (pszToken && iStream < pClient->iStreamCount) {
# Line 1265  lscp_buffer_fill_t *lscp_get_channel_buf Line 1283  lscp_buffer_fill_t *lscp_get_channel_buf
1283   *  @param pClient          Pointer to client instance structure.   *  @param pClient          Pointer to client instance structure.
1284   *  @param iSamplerChannel  Sampler channel number.   *  @param iSamplerChannel  Sampler channel number.
1285   *  @param pszAudioDriver   Audio output driver type (e.g. "ALSA" or "JACK").   *  @param pszAudioDriver   Audio output driver type (e.g. "ALSA" or "JACK").
1286     *
1287     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1288   */   */
1289  lscp_status_t lscp_set_channel_audio_type ( lscp_client_t *pClient, int iSamplerChannel, const char *pszAudioDriver )  lscp_status_t lscp_set_channel_audio_type ( lscp_client_t *pClient, int iSamplerChannel, const char *pszAudioDriver )
1290  {  {
# Line 1285  lscp_status_t lscp_set_channel_audio_typ Line 1305  lscp_status_t lscp_set_channel_audio_typ
1305   *  @param pClient          Pointer to client instance structure.   *  @param pClient          Pointer to client instance structure.
1306   *  @param iSamplerChannel  Sampler channel number.   *  @param iSamplerChannel  Sampler channel number.
1307   *  @param iAudioDevice     Audio output device number identifier.   *  @param iAudioDevice     Audio output device number identifier.
1308     *
1309     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1310   */   */
1311  lscp_status_t lscp_set_channel_audio_device ( lscp_client_t *pClient, int iSamplerChannel, int iAudioDevice )  lscp_status_t lscp_set_channel_audio_device ( lscp_client_t *pClient, int iSamplerChannel, int iAudioDevice )
1312  {  {
# Line 1350  lscp_status_t lscp_set_channel_midi_type Line 1372  lscp_status_t lscp_set_channel_midi_type
1372   *  @param pClient          Pointer to client instance structure.   *  @param pClient          Pointer to client instance structure.
1373   *  @param iSamplerChannel  Sampler channel number.   *  @param iSamplerChannel  Sampler channel number.
1374   *  @param iMidiDevice      MIDI input device number identifier.   *  @param iMidiDevice      MIDI input device number identifier.
1375     *
1376     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1377   */   */
1378  lscp_status_t lscp_set_channel_midi_device ( lscp_client_t *pClient, int iSamplerChannel, int iMidiDevice )  lscp_status_t lscp_set_channel_midi_device ( lscp_client_t *pClient, int iSamplerChannel, int iMidiDevice )
1379  {  {
# Line 1436  lscp_status_t lscp_set_channel_volume ( Line 1460  lscp_status_t lscp_set_channel_volume (
1460    
1461    
1462  /**  /**
1463     *  Muting a sampler channel:
1464     *  SET CHANNEL MUTE <sampler-channel> <mute>
1465     *
1466     *  @param pClient          Pointer to client instance structure.
1467     *  @param iSamplerChannel  Sampler channel number.
1468     *  @param iMute            Sampler channel mute state as a boolean value,
1469     *                          either 1 (one) to mute the channel or 0 (zero)
1470     *                          to unmute the channel.
1471     *
1472     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1473     */
1474    lscp_status_t lscp_set_channel_mute ( lscp_client_t *pClient, int iSamplerChannel, int iMute )
1475    {
1476        char szQuery[LSCP_BUFSIZ];
1477    
1478        if (iSamplerChannel < 0 || iMute < 0 || iMute > 1)
1479            return LSCP_FAILED;
1480    
1481        sprintf(szQuery, "SET CHANNEL MUTE %d %d\r\n", iSamplerChannel, iMute);
1482        return lscp_client_query(pClient, szQuery);
1483    }
1484    
1485    
1486    /**
1487     *  Soloing a sampler channel:
1488     *  SET CHANNEL SOLO <sampler-channel> <solo>
1489     *
1490     *  @param pClient          Pointer to client instance structure.
1491     *  @param iSamplerChannel  Sampler channel number.
1492     *  @param iSolo            Sampler channel solo state as a boolean value,
1493     *                          either 1 (one) to solo the channel or 0 (zero)
1494     *                          to unsolo the channel.
1495     *
1496     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1497     */
1498    lscp_status_t lscp_set_channel_solo ( lscp_client_t *pClient, int iSamplerChannel, int iSolo )
1499    {
1500        char szQuery[LSCP_BUFSIZ];
1501    
1502        if (iSamplerChannel < 0 || iSolo < 0 || iSolo > 1)
1503            return LSCP_FAILED;
1504    
1505        sprintf(szQuery, "SET CHANNEL SOLO %d %d\r\n", iSamplerChannel, iSolo);
1506        return lscp_client_query(pClient, szQuery);
1507    }
1508    
1509    
1510    /**
1511   *  Resetting a sampler channel:   *  Resetting a sampler channel:
1512   *  RESET CHANNEL <sampler-channel>   *  RESET CHANNEL <sampler-channel>
1513   *   *
# Line 1494  lscp_server_info_t *lscp_get_server_info Line 1566  lscp_server_info_t *lscp_get_server_info
1566      pServerInfo = &(pClient->server_info);      pServerInfo = &(pClient->server_info);
1567      lscp_server_info_reset(pServerInfo);      lscp_server_info_reset(pServerInfo);
1568    
1569      if (lscp_client_call(pClient, "GET SERVER INFO\r\n") == LSCP_OK) {      if (lscp_client_call(pClient, "GET SERVER INFO\r\n", 1) == LSCP_OK) {
1570          pszResult = lscp_client_get_result(pClient);          pszResult = lscp_client_get_result(pClient);
1571          pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));          pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
1572          while (pszToken) {          while (pszToken) {
# Line 1520  lscp_server_info_t *lscp_get_server_info Line 1592  lscp_server_info_t *lscp_get_server_info
1592  }  }
1593    
1594    
1595    /**
1596     *  Current total number of active voices:
1597     *  GET TOTAL_VOICE_COUNT
1598     *
1599     *  @param pClient  Pointer to client instance structure.
1600     *
1601     *  @returns The total number of voices currently active,
1602     *  -1 in case of failure.
1603     */
1604    int lscp_get_total_voice_count ( lscp_client_t *pClient )
1605    {
1606        int iVoiceCount = -1;
1607    
1608        // Lock this section up.
1609        lscp_mutex_lock(pClient->mutex);
1610    
1611        if (lscp_client_call(pClient, "GET TOTAL_VOICE_COUNT\r\n", 0) == LSCP_OK)
1612            iVoiceCount = atoi(lscp_client_get_result(pClient));
1613    
1614        // Unlock this section down.
1615        lscp_mutex_unlock(pClient->mutex);
1616    
1617        return iVoiceCount;
1618    }
1619    
1620    
1621    /**
1622     *  Maximum amount of active voices:
1623     *  GET TOTAL_VOICE_COUNT_MAX
1624     *
1625     *  @param pClient  Pointer to client instance structure.
1626     *
1627     *  @returns The maximum amount of voices currently active,
1628     *  -1 in case of failure.
1629     */
1630    int lscp_get_total_voice_count_max ( lscp_client_t *pClient )
1631    {
1632        int iVoiceCount = -1;
1633    
1634        // Lock this section up.
1635        lscp_mutex_lock(pClient->mutex);
1636    
1637        if (lscp_client_call(pClient, "GET TOTAL_VOICE_COUNT_MAX\r\n", 0) == LSCP_OK)
1638            iVoiceCount = atoi(lscp_client_get_result(pClient));
1639    
1640        // Unlock this section down.
1641        lscp_mutex_unlock(pClient->mutex);
1642    
1643        return iVoiceCount;
1644    }
1645    
1646    
1647    /**
1648     *  Create or replace a MIDI instrumnet map entry:
1649     *  MAP MIDI_INSTRUMENT <midi-bank-msb> <midi-bank-lsb> <midi-prog>
1650     *      <engine-name> <filename> <instr-index> <volume> <load-mode> [<name>]
1651     *
1652     *  @param pClient          Pointer to client instance structure.
1653     *  @param pMidiInstr       MIDI instrument bank and program parameter key.
1654     *  @param pszEngineName    Engine name.
1655     *  @param pszFileName      Instrument file name.
1656     *  @param iInstrIndex      Instrument index number.
1657     *  @param fVolume          Reflects the master volume of the instrument as
1658     *                          a positive floating point number, where a value
1659     *                          less than 1.0 for attenuation, and greater than
1660     *                          1.0 for amplification.
1661     *  @param load_mode        Instrument load life-time strategy, either
1662     *                          @ref LSCP_LOAD_DEFAULT, or
1663     *                          @ref LSCP_LOAD_ON_DEMAND, or
1664     *                          @ref LSCP_LOAD_ON_DEMAND_HOLD, or
1665     *                          @ref LSCP_LOAD_PERSISTENT.
1666     *  @param pszName          Instrument custom name for the map entry.
1667     *
1668     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1669     */
1670    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 )
1671    {
1672        char szQuery[LSCP_BUFSIZ];
1673        
1674        if (pMidiInstr->bank_msb < 0 || pMidiInstr->bank_msb > 127)
1675            return LSCP_FAILED;
1676        if (pMidiInstr->bank_lsb < 0 || pMidiInstr->bank_lsb > 127)
1677            return LSCP_FAILED;
1678        if (pMidiInstr->program < 0 || pMidiInstr->program > 127)
1679            return LSCP_FAILED;
1680        if (pszEngineName == NULL || pszFileName == NULL)
1681            return LSCP_FAILED;
1682        
1683        if (fVolume < 0.0f)
1684            fVolume = 1.0f;
1685        
1686        sprintf(szQuery, "MAP MIDI_INSTRUMENT %d %d %d %s '%s' %d %g",
1687            pMidiInstr->bank_msb, pMidiInstr->bank_lsb, pMidiInstr->program,
1688            pszEngineName, pszFileName, iInstrIndex, fVolume);
1689        
1690        switch (load_mode) {
1691        case LSCP_LOAD_PERSISTENT:
1692            strcat(szQuery, " PERSISTENT");
1693            break;
1694        case LSCP_LOAD_ON_DEMAND_HOLD:
1695            strcat(szQuery, " ON_DEMAND_HOLD");
1696            break;
1697        case LSCP_LOAD_ON_DEMAND:
1698            strcat(szQuery, " ON_DEMAND_HOLD");
1699            break;
1700        case LSCP_LOAD_DEFAULT:
1701        default:
1702            break;
1703        }
1704        
1705        if (pszName)
1706            sprintf(szQuery + strlen(szQuery), " '%s'", pszName);
1707        
1708        strcat(szQuery, "\r\n");
1709        
1710        return lscp_client_query(pClient, szQuery);
1711    }
1712    
1713    
1714    /**
1715     *  Remove an entry from the MIDI instrument map:
1716     *  UNMAP MIDI_INSTRUMENT <midi-bank-msb> <midi-bank-lsb> <midi-prog>
1717     *
1718     *  @param pClient      Pointer to client instance structure.
1719     *  @param pMidiInstr   MIDI instrument bank and program parameter key.
1720     *
1721     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1722     */
1723    lscp_status_t lscp_unmap_midi_instrument ( lscp_client_t *pClient, lscp_midi_instrument_t *pMidiInstr )
1724    {
1725        char szQuery[LSCP_BUFSIZ];
1726    
1727        if (pMidiInstr->bank_msb < 0 || pMidiInstr->bank_msb > 127)
1728            return LSCP_FAILED;
1729        if (pMidiInstr->bank_lsb < 0 || pMidiInstr->bank_lsb > 127)
1730            return LSCP_FAILED;
1731        if (pMidiInstr->program < 0 || pMidiInstr->program > 127)
1732            return LSCP_FAILED;
1733    
1734        sprintf(szQuery, "UNMAP MIDI_INSTRUMENT %d %d %d\r\n",
1735                    pMidiInstr->bank_msb, pMidiInstr->bank_lsb, pMidiInstr->program);
1736    
1737        return lscp_client_query(pClient, szQuery);
1738    }
1739    
1740    
1741    /**
1742     *  Get the total count of MIDI instrument map entries:
1743     *  GET MIDI_INSTRUMENTS
1744     *
1745     *  @param pClient  Pointer to client instance structure.
1746     *
1747     *  @returns The current total number of MIDI instrument map entries
1748     *  on success, -1 otherwise.
1749     */
1750    int lscp_get_midi_instruments ( lscp_client_t *pClient )
1751    {
1752        int iInstruments = -1;
1753    
1754        // Lock this section up.
1755        lscp_mutex_lock(pClient->mutex);
1756    
1757        if (lscp_client_call(pClient, "GET MIDI_INSTRUMENTS\r\n", 0) == LSCP_OK)
1758            iInstruments = atoi(lscp_client_get_result(pClient));
1759    
1760        // Unlock this section down.
1761        lscp_mutex_unlock(pClient->mutex);
1762    
1763        return iInstruments;
1764    }
1765    
1766    
1767    /**
1768     *  Getting indeces of all MIDI instrument map entries:
1769     *  LIST MIDI_INSTRUMENTS
1770     *
1771     *  @param pClient  Pointer to client instance structure.
1772     *
1773     *  @returns An array of @ref lscp_midi_instrument_t, terminated with the
1774     *  {-1,-1,-1} triplet, NULL otherwise.
1775     */
1776    lscp_midi_instrument_t *lscp_list_midi_instruments ( lscp_client_t *pClient )
1777    {
1778        if (pClient == NULL)
1779            return NULL;
1780    
1781        // Lock this section up.
1782        lscp_mutex_lock(pClient->mutex);
1783    
1784        if (pClient->midi_instruments) {
1785            lscp_midi_instruments_destroy(pClient->midi_instruments);
1786            pClient->midi_instruments = NULL;
1787        }
1788    
1789        if (lscp_client_call(pClient, "LIST MIDI_INSTRUMENTS\r\n", 0) == LSCP_OK)
1790            pClient->midi_instruments = lscp_midi_instruments_create(lscp_client_get_result(pClient));
1791    
1792        // Unlock this section down.
1793        lscp_mutex_unlock(pClient->mutex);
1794    
1795        return pClient->midi_instruments;
1796    }
1797    
1798    
1799    /**
1800     *  Getting information about a MIDI instrument map entry:
1801     *  GET MIDI_INSTRUMENT INFO <midi-bank-msb> <midi-bank-lsb> <midi-prog>
1802     *
1803     *  @param pClient      Pointer to client instance structure.
1804     *  @param pMidiInstr   MIDI instrument bank and program parameter key.
1805     *
1806     *  @returns A pointer to a @ref lscp_midi_instrument_info_t structure,
1807     *  with all the information of the given MIDI instrument map entry,
1808     *  or NULL in case of failure.
1809     */
1810    lscp_midi_instrument_info_t *lscp_get_midi_instrument_info ( lscp_client_t *pClient, lscp_midi_instrument_t *pMidiInstr )
1811    {
1812        lscp_midi_instrument_info_t *pInstrInfo;
1813        char szQuery[LSCP_BUFSIZ];
1814        const char *pszResult;
1815        const char *pszSeps = ":";
1816        const char *pszCrlf = "\r\n";
1817        char *pszToken;
1818        char *pch;
1819        
1820        if (pMidiInstr->bank_msb < 0 || pMidiInstr->bank_msb > 127)
1821            return NULL;
1822        if (pMidiInstr->bank_lsb < 0 || pMidiInstr->bank_lsb > 127)
1823            return NULL;
1824        if (pMidiInstr->program < 0 || pMidiInstr->program > 127)
1825            return NULL;
1826        
1827        // Lock this section up.
1828        lscp_mutex_lock(pClient->mutex);
1829        
1830        pInstrInfo = &(pClient->midi_instrument_info);
1831        lscp_midi_instrument_info_reset(pInstrInfo);
1832        
1833        sprintf(szQuery, "GET MIDI_INSTRUMENT INFO %d %d %d\r\n",
1834            pMidiInstr->bank_msb, pMidiInstr->bank_lsb, pMidiInstr->program);
1835        if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) {
1836            pszResult = lscp_client_get_result(pClient);
1837            pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
1838            while (pszToken) {
1839                if (strcasecmp(pszToken, "NAME") == 0) {
1840                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1841                    if (pszToken)
1842                        lscp_unquote_dup(&(pInstrInfo->name), &pszToken);
1843                }
1844                else if (strcasecmp(pszToken, "ENGINE_NAME") == 0) {
1845                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1846                    if (pszToken)
1847                        lscp_unquote_dup(&(pInstrInfo->engine_name), &pszToken);
1848                }
1849                else if (strcasecmp(pszToken, "INSTRUMENT_FILE") == 0) {
1850                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1851                    if (pszToken)
1852                        lscp_unquote_dup(&(pInstrInfo->instrument_file), &pszToken);
1853                }
1854                else if (strcasecmp(pszToken, "INSTRUMENT_NR") == 0) {
1855                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1856                    if (pszToken)
1857                        pInstrInfo->instrument_nr = atoi(lscp_ltrim(pszToken));
1858                }
1859                else if (strcasecmp(pszToken, "INSTRUMENT_NAME") == 0) {
1860                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1861                    if (pszToken)
1862                        lscp_unquote_dup(&(pInstrInfo->instrument_name), &pszToken);
1863                }
1864                else if (strcasecmp(pszToken, "LOAD_MODE") == 0) {
1865                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1866                    if (pszToken) {
1867                        pszToken = lscp_ltrim(pszToken);
1868                        if (strcasecmp(pszToken, "ON_DEMAND") == 0)
1869                            pInstrInfo->load_mode = LSCP_LOAD_ON_DEMAND;
1870                        else
1871                        if (strcasecmp(pszToken, "ON_DEMAND_HOLD") == 0)
1872                            pInstrInfo->load_mode = LSCP_LOAD_ON_DEMAND_HOLD;
1873                        else
1874                        if (strcasecmp(pszToken, "PERSISTENT") == 0)
1875                            pInstrInfo->load_mode = LSCP_LOAD_PERSISTENT;
1876                        else
1877                            pInstrInfo->load_mode = LSCP_LOAD_DEFAULT;
1878                    }
1879                }
1880                else if (strcasecmp(pszToken, "VOLUME") == 0) {
1881                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1882                    if (pszToken)
1883                        pInstrInfo->volume = (float) atof(lscp_ltrim(pszToken));
1884                }
1885                pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1886            }
1887        }
1888        else pInstrInfo = NULL;
1889        
1890        // Unlock this section down.
1891        lscp_mutex_unlock(pClient->mutex);
1892        
1893        return pInstrInfo;
1894    }
1895    
1896    
1897    /**
1898     *  Clear the MIDI instrumnet map:
1899     *  CLEAR MIDI_INSTRUMENTS
1900     *
1901     *  @param pClient          Pointer to client instance structure.
1902     *  @param iSamplerChannel  Sampler channel number.
1903     *
1904     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1905     */
1906    lscp_status_t lscp_clear_midi_instruments  ( lscp_client_t *pClient )
1907    {
1908        return lscp_client_query(pClient, "CLEAR MIDI_INSTRUMENTS\r\n");
1909    }
1910    
1911    
1912  // end of client.c  // end of client.c

Legend:
Removed from v.623  
changed lines
  Added in v.948

  ViewVC Help
Powered by ViewVC