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

Diff of /liblscp/trunk/src/common.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 3664 by schoenebeck, Sun Dec 22 12:53:26 2019 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 23  Line 23 
23  #include "common.h"  #include "common.h"
24    
25  #include <ctype.h>  #include <ctype.h>
26    #include <sys/time.h>
27    #include <sys/errno.h>
28    
29    
30  // Split chunk size magic:  // Split chunk size magic:
# Line 119  lscp_status_t lscp_client_call ( lscp_cl Line 121  lscp_status_t lscp_client_call ( lscp_cl
121          int    iErrno;          int    iErrno;
122          char  *pszResult;          char  *pszResult;
123          int    cchResult;          int    cchResult;
124            ssize_t sz;
125                    
126          lscp_status_t ret = LSCP_FAILED;          lscp_status_t ret = LSCP_FAILED;
127                    
# Line 155  lscp_status_t lscp_client_call ( lscp_cl Line 158  lscp_status_t lscp_client_call ( lscp_cl
158    
159          // Send data, and then, wait for the result...          // Send data, and then, wait for the result...
160          cchQuery = strlen(pszQuery);          cchQuery = strlen(pszQuery);
161          if (send(pClient->cmd.sock, pszQuery, cchQuery, 0) < cchQuery) {          sz = send(pClient->cmd.sock, pszQuery, cchQuery, 0);
162            if (sz < cchQuery) {
163                  lscp_socket_perror("lscp_client_call: send");                  lscp_socket_perror("lscp_client_call: send");
164                  pszResult = "Failure during send operation";                  pszResult = "Failure during send operation";
165                    if (sz < 0)
166                            iErrno = -errno;
167                  lscp_client_set_result(pClient, pszResult, iErrno);                  lscp_client_set_result(pClient, pszResult, iErrno);
168                  return ret;                  return ret;
169          }          }
# Line 213  lscp_status_t lscp_client_call ( lscp_cl Line 219  lscp_status_t lscp_client_call ( lscp_cl
219                                                  && pszBuffer[cchBuffer - 2] == '\r'                                                  && pszBuffer[cchBuffer - 2] == '\r'
220                                                  && (iResult < 1 || (cchBuffer >= 3                                                  && (iResult < 1 || (cchBuffer >= 3
221                                                                  && pszBuffer[cchBuffer - 3] == '.'))) {                                                                  && pszBuffer[cchBuffer - 3] == '.'))) {
222                                                  // Get rid of the trailing dot and CRLF anyway...                                                  // Get rid of the trailling dot and CRLF anyway...
223                                                  while (cchBuffer > 0 && (                                                  while (cchBuffer > 0 && (
224                                                          pszBuffer[cchBuffer - 1] == '\r' ||                                                          pszBuffer[cchBuffer - 1] == '\r' ||
225                                                          pszBuffer[cchBuffer - 1] == '\n' ||                                                          pszBuffer[cchBuffer - 1] == '\n' ||
# Line 225  lscp_status_t lscp_client_call ( lscp_cl Line 231  lscp_status_t lscp_client_call ( lscp_cl
231                                  }                                  }
232                                  // The result string is now set to the command response, if any.                                  // The result string is now set to the command response, if any.
233                          } else {                          } else {
234                                    // Get rid of the CRLF anyway...
235                                    while (cchBuffer > 0 && (
236                                            achBuffer[cchBuffer - 1] == '\r' ||
237                                            achBuffer[cchBuffer - 1] == '\n'))
238                                            achBuffer[--cchBuffer] = (char) 0;
239                                  // Parse the error/warning message, skip first colon...                                  // Parse the error/warning message, skip first colon...
240                                  pszToken = lscp_strtok(achBuffer, pszSeps, &(pch));                                  pszToken = lscp_strtok(achBuffer, pszSeps, &(pch));
241                                  if (pszToken) {                                  if (pszToken) {
# Line 749  lscp_midi_instrument_t *lscp_midi_instru Line 760  lscp_midi_instrument_t *lscp_midi_instru
760                  case '{':                  case '{':
761                          pchHead = pch + 1;                          pchHead = pch + 1;
762                          if (k == 0) {                          if (k == 0) {
763                                  pInstrs[i].bank_msb = atoi(pchHead);                                  pInstrs[i].map = atoi(pchHead);
764                                  k++;                                  k++;
765                          }                          }
766                          break;                          break;
767                  case ',':                  case ',':
768                          pchHead = pch + 1;                          pchHead = pch + 1;
769                          if (k == 1) {                          if (k == 1) {
770                                  pInstrs[i].bank_lsb = atoi(pchHead);                                  pInstrs[i].bank = atoi(pchHead);
771                                  k++;                                  k++;
772                          }                          }
773                          else                          else
774                          if (k == 2) {                          if (k == 2) {
775                                  pInstrs[i].program = atoi(pchHead);                                  pInstrs[i].prog = atoi(pchHead);
776                                  k++;                                  k++;
777                          }                          }
778                          break;                          break;
# Line 778  lscp_midi_instrument_t *lscp_midi_instru Line 789  lscp_midi_instrument_t *lscp_midi_instru
789                          pNewInstrs = (lscp_midi_instrument_t *) malloc(iSize * sizeof(lscp_midi_instrument_t));                          pNewInstrs = (lscp_midi_instrument_t *) malloc(iSize * sizeof(lscp_midi_instrument_t));
790                          if (pNewInstrs) {                          if (pNewInstrs) {
791                                  for (j = 0; j < i; j++) {                                  for (j = 0; j < i; j++) {
792                                          pNewInstrs[j].bank_msb = pInstrs[j].bank_msb;                                          pNewInstrs[j].map  = pInstrs[j].map;
793                                          pNewInstrs[j].bank_lsb = pInstrs[j].bank_lsb;                                          pNewInstrs[j].bank = pInstrs[j].bank;
794                                          pNewInstrs[j].program  = pInstrs[j].program;                                          pNewInstrs[j].prog = pInstrs[j].prog;
795                                  }                                  }
796                                  free(pInstrs);                                  free(pInstrs);
797                                  pInstrs = pNewInstrs;                                  pInstrs = pNewInstrs;
# Line 790  lscp_midi_instrument_t *lscp_midi_instru Line 801  lscp_midi_instrument_t *lscp_midi_instru
801                    
802          // Special terminate split array.          // Special terminate split array.
803          for ( ; i < iSize; i++) {          for ( ; i < iSize; i++) {
804                  pInstrs[i].bank_msb = -1;                  pInstrs[i].map  = -1;
805                  pInstrs[i].bank_lsb = -1;                  pInstrs[i].bank = -1;
806                  pInstrs[i].program  = -1;                  pInstrs[i].prog = -1;
807          }          }
808                    
809          return pInstrs;          return pInstrs;
# Line 830  int lscp_midi_instruments_size ( lscp_mi Line 841  int lscp_midi_instruments_size ( lscp_mi
841    
842  void lscp_server_info_init ( lscp_server_info_t *pServerInfo )  void lscp_server_info_init ( lscp_server_info_t *pServerInfo )
843  {  {
844          pServerInfo->description = NULL;          pServerInfo->description      = NULL;
845          pServerInfo->version     = NULL;          pServerInfo->version          = NULL;
846            pServerInfo->protocol_version = NULL;
847  }  }
848    
849  void lscp_server_info_free ( lscp_server_info_t *pServerInfo )  void lscp_server_info_free ( lscp_server_info_t *pServerInfo )
# Line 840  void lscp_server_info_free ( lscp_server Line 852  void lscp_server_info_free ( lscp_server
852                  free(pServerInfo->description);                  free(pServerInfo->description);
853          if (pServerInfo->version)          if (pServerInfo->version)
854                  free(pServerInfo->version);                  free(pServerInfo->version);
855            if (pServerInfo->protocol_version)
856                    free(pServerInfo->protocol_version);
857  }  }
858    
859  void lscp_server_info_reset ( lscp_server_info_t *pServerInfo )  void lscp_server_info_reset ( lscp_server_info_t *pServerInfo )
# Line 889  void lscp_channel_info_init ( lscp_chann Line 903  void lscp_channel_info_init ( lscp_chann
903          pChannelInfo->midi_device       = 0;          pChannelInfo->midi_device       = 0;
904          pChannelInfo->midi_port         = 0;          pChannelInfo->midi_port         = 0;
905          pChannelInfo->midi_channel      = 0;          pChannelInfo->midi_channel      = 0;
906            pChannelInfo->midi_map          = 0;
907          pChannelInfo->volume            = 0.0;          pChannelInfo->volume            = 0.0;
908          pChannelInfo->mute              = 0;          pChannelInfo->mute              = 0;
909          pChannelInfo->solo              = 0;          pChannelInfo->solo              = 0;
# Line 899  void lscp_channel_info_free ( lscp_chann Line 914  void lscp_channel_info_free ( lscp_chann
914          if (pChannelInfo->engine_name)          if (pChannelInfo->engine_name)
915                  free(pChannelInfo->engine_name);                  free(pChannelInfo->engine_name);
916          if (pChannelInfo->audio_routing)          if (pChannelInfo->audio_routing)
917                  lscp_szsplit_destroy(pChannelInfo->audio_routing);                  lscp_isplit_destroy(pChannelInfo->audio_routing);
918          if (pChannelInfo->instrument_file)          if (pChannelInfo->instrument_file)
919                  free(pChannelInfo->instrument_file);                  free(pChannelInfo->instrument_file);
920          if (pChannelInfo->instrument_name)          if (pChannelInfo->instrument_name)
# Line 1053  int lscp_param_concat ( char *pszBuffer, Line 1068  int lscp_param_concat ( char *pszBuffer,
1068  }  }
1069    
1070    
1071    //-------------------------------------------------------------------------
1072    // Effect struct helper functions.
1073    
1074    void lscp_fxsend_info_init ( lscp_fxsend_info_t *pFxSendInfo )
1075    {
1076            pFxSendInfo->name            = NULL;
1077            pFxSendInfo->midi_controller = 0;
1078            pFxSendInfo->audio_routing   = NULL;
1079            pFxSendInfo->level           = 0.0f;
1080    }
1081    
1082    void lscp_fxsend_info_free ( lscp_fxsend_info_t *pFxSendInfo )
1083    {
1084            if (pFxSendInfo->name)
1085                    free(pFxSendInfo->name);
1086            if (pFxSendInfo->audio_routing)
1087                    lscp_isplit_destroy(pFxSendInfo->audio_routing);
1088    }
1089    
1090    void lscp_fxsend_info_reset (lscp_fxsend_info_t *pFxSendInfo )
1091    {
1092            lscp_fxsend_info_free(pFxSendInfo);
1093            lscp_fxsend_info_init(pFxSendInfo);
1094    }
1095    
1096    
1097  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
1098  // MIDI instrument info struct helper functions.  // MIDI instrument info struct helper functions.
1099    

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

  ViewVC Help
Powered by ViewVC