/[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 187 by capela, Wed Jul 7 23:41:07 2004 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, 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 have 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 49  void lscp_client_set_result ( lscp_clien Line 49  void lscp_client_set_result ( lscp_clien
49          pClient->pszResult = strdup(lscp_ltrim(pszResult));          pClient->pszResult = strdup(lscp_ltrim(pszResult));
50  }  }
51    
52  // The main client requester call executive.  
53  lscp_status_t lscp_client_call ( lscp_client_t *pClient, const char *pszQuery )  // The common client receiver executive.
54    lscp_status_t lscp_client_recv ( lscp_client_t *pClient, char *pchBuffer, int *pcchBuffer, int iTimeout )
55  {  {
56      fd_set fds;                         // File descriptor list for select().      fd_set fds;                         // File descriptor list for select().
57      int    fd, fdmax;                   // Maximum file descriptor number.      int    fd, fdmax;                   // Maximum file descriptor number.
58      struct timeval tv;                  // For specifying a timeout value.      struct timeval tv;                  // For specifying a timeout value.
59      int    iSelect;                     // Holds select return status.      int    iSelect;                     // Holds select return status.
     int    iTimeout;  
     int    cchQuery;  
     char   achResult[LSCP_BUFSIZ];  
     int    cchResult;  
     const  char *pszSeps = ":[]";  
     char  *pszResult;  
     char  *pszToken;  
     char  *pch;  
     int    iErrno;  
60    
61      lscp_status_t ret = LSCP_FAILED;      lscp_status_t ret = LSCP_FAILED;
62    
63      if (pClient == NULL)      if (pClient == NULL)
64          return ret;          return ret;
65    
     pszResult = NULL;  
     iErrno = -1;  
   
     // Check if command socket socket is still valid.  
     if (pClient->cmd.sock == INVALID_SOCKET) {  
         pszResult = "Connection closed or no longer valid";  
         lscp_client_set_result(pClient, pszResult, iErrno);  
         return ret;  
     }  
   
     // Send data, and then, wait for the result...  
     cchQuery = strlen(pszQuery);  
     if (send(pClient->cmd.sock, pszQuery, cchQuery, 0) < cchQuery) {  
         lscp_socket_perror("_lscp_client_call: send");  
         pszResult = "Failure during send operation";  
         lscp_client_set_result(pClient, pszResult, iErrno);  
         return ret;  
     }  
   
66      // Prepare for waiting on select...      // Prepare for waiting on select...
67      fd = (int) pClient->cmd.sock;      fd = (int) pClient->cmd.sock;
68      FD_ZERO(&fds);      FD_ZERO(&fds);
# Line 97  lscp_status_t lscp_client_call ( lscp_cl Line 70  lscp_status_t lscp_client_call ( lscp_cl
70      fdmax = fd;      fdmax = fd;
71    
72      // Use the timeout select feature...      // Use the timeout select feature...
73      iTimeout = pClient->iTimeout;      if (iTimeout < 1)
74      if (iTimeout > 1000) {          iTimeout = pClient->iTimeout;
75        if (iTimeout >= 1000) {
76          tv.tv_sec = iTimeout / 1000;          tv.tv_sec = iTimeout / 1000;
77          iTimeout -= tv.tv_sec * 1000;          iTimeout -= tv.tv_sec * 1000;
78      }      }
# Line 109  lscp_status_t lscp_client_call ( lscp_cl Line 83  lscp_status_t lscp_client_call ( lscp_cl
83      iSelect = select(fdmax + 1, &fds, NULL, NULL, &tv);      iSelect = select(fdmax + 1, &fds, NULL, NULL, &tv);
84      if (iSelect > 0 && FD_ISSET(fd, &fds)) {      if (iSelect > 0 && FD_ISSET(fd, &fds)) {
85          // May recv now...          // May recv now...
86          cchResult = recv(pClient->cmd.sock, achResult, sizeof(achResult), 0);          *pcchBuffer = recv(pClient->cmd.sock, pchBuffer, *pcchBuffer, 0);
87          if (cchResult > 0) {          if (*pcchBuffer > 0)
             // Assume early success.  
88              ret = LSCP_OK;              ret = LSCP_OK;
89              // Always force the result to be null terminated (and trim trailing CRLFs)!          else if (*pcchBuffer < 0)
90              while (cchResult > 0 && (achResult[cchResult - 1] == '\n' || achResult[cchResult- 1] == '\r'))              lscp_socket_perror("lscp_client_recv: recv");
91                  cchResult--;          else if (*pcchBuffer == 0) {
92              achResult[cchResult] = (char) 0;              // Damn, server probably disconnected,
93                // we better free everything down here.
94                lscp_socket_agent_free(&(pClient->evt));
95                lscp_socket_agent_free(&(pClient->cmd));
96                // Fake a result message.
97                ret = LSCP_QUIT;
98            }
99        }   // Check if select has timed out.
100        else if (iSelect == 0)
101            ret = LSCP_TIMEOUT;
102        else
103            lscp_socket_perror("lscp_client_recv: select");
104    
105        return ret;
106    }
107    
108    
109    // The main client requester call executive.
110    lscp_status_t lscp_client_call ( lscp_client_t *pClient, const char *pszQuery, int iResult )
111    {
112        int    cchQuery;
113        char   achBuffer[LSCP_BUFSIZ];
114        int    cchBuffer;
115        const  char *pszSeps = ":[]";
116        char  *pszBuffer;
117        char  *pszToken;
118        char  *pch;
119        int    iErrno;
120        char  *pszResult;
121        int    cchResult;
122        
123        lscp_status_t ret = LSCP_FAILED;
124        
125        if (pClient == NULL)
126            return ret;
127        
128        iErrno = -1;
129        cchResult = 0;
130        pszResult = NULL;
131        pszBuffer = NULL;
132        
133        // Check if command socket socket is still valid.
134        if (pClient->cmd.sock == INVALID_SOCKET) {
135            pszResult = "Connection closed or no longer valid";
136            lscp_client_set_result(pClient, pszResult, iErrno);
137            return ret;
138        }
139        
140        // Check if last transaction has timed out, in which case
141        // we'll retry wait and flush for some pending garbage...
142        if (pClient->iTimeoutCount > 0) {
143            // We'll hope to get rid of timeout trouble...
144            pClient->iTimeoutCount = 0;
145            cchBuffer = sizeof(achBuffer);
146            ret = lscp_client_recv(pClient, achBuffer, &cchBuffer, pClient->iTimeout);
147            if (ret != LSCP_OK) {
148                // Things seems to be unresolved. Fake a result message.
149                iErrno = (int) ret;
150                pszResult = "Failure during flush timeout operation";
151                lscp_client_set_result(pClient, pszResult, iErrno);
152                return ret;
153            }
154        }
155        
156        // Send data, and then, wait for the result...
157        cchQuery = strlen(pszQuery);
158        if (send(pClient->cmd.sock, pszQuery, cchQuery, 0) < cchQuery) {
159            lscp_socket_perror("lscp_client_call: send");
160            pszResult = "Failure during send operation";
161            lscp_client_set_result(pClient, pszResult, iErrno);
162            return ret;
163        }
164        
165        // Keep receiving while result is not the expected one:
166        // single-line result (iResult = 0) : one single CRLF ends the receipt;
167        // multi-line result  (iResult > 0) : one "." followed by a last CRLF;
168        
169        while (pszResult == NULL) {
170        
171            // Wait for receive event...
172            cchBuffer = sizeof(achBuffer) - 1;
173            ret = lscp_client_recv(pClient, achBuffer, &cchBuffer, pClient->iTimeout);
174        
175            switch (ret) {
176        
177              case LSCP_OK:
178                // Always force the result to be null terminated.
179                achBuffer[cchBuffer] = (char) 0;
180              // Check if the response it's an error or warning message.              // Check if the response it's an error or warning message.
181              if (strncasecmp(achResult, "WRN:", 4) == 0)              if (strncasecmp(achBuffer, "WRN:", 4) == 0)
182                  ret = LSCP_WARNING;                  ret = LSCP_WARNING;
183              else if (strncasecmp(achResult, "ERR:", 4) == 0)              else if (strncasecmp(achBuffer, "ERR:", 4) == 0)
184                  ret = LSCP_ERROR;                  ret = LSCP_ERROR;
185              // So we got a result...              // So we got a result...
186              if (ret == LSCP_OK) {              if (ret == LSCP_OK) {
187                  // Reset errno in case of success.                  // Reset errno in case of success.
188                  iErrno = 0;                  iErrno = 0;
189                  // Is it a special successful response?                  // Is it a special successful response?
190                  if (strncasecmp(achResult, "OK[", 3) == 0) {                  if (iResult < 1 && strncasecmp(achBuffer, "OK[", 3) == 0) {
191                      // Parse the OK message, get the return string under brackets...                      // Parse the OK message, get the return string under brackets...
192                      pszToken = lscp_strtok(achResult, pszSeps, &(pch));                      pszToken = lscp_strtok(achBuffer, pszSeps, &(pch));
193                      if (pszToken)                      if (pszToken)
194                          pszResult = lscp_strtok(NULL, pszSeps, &(pch));                          pszResult = lscp_strtok(NULL, pszSeps, &(pch));
195                    } else {
196                        // It can be specially long response...
197                        cchResult += sizeof(achBuffer);
198                        pszResult  = malloc(cchResult + 1);
199                        pszResult[0] = (char) 0;
200                        if (pszBuffer) {
201                            strcat(pszResult, pszBuffer);
202                            free(pszBuffer);
203                        }
204                        strcat(pszResult, achBuffer);
205                        pszBuffer = pszResult;
206                        pszResult = NULL;
207                        // Check for correct end-of-transmission...
208                        // Depending whether its single or multi-line we'll
209                        // flag end-of-transmission...
210                        cchBuffer = strlen(pszBuffer);
211                        if (cchBuffer > 2
212                            && pszBuffer[cchBuffer - 1] == '\n'
213                            && pszBuffer[cchBuffer - 2] == '\r'
214                            && (iResult < 1 || pszBuffer[cchBuffer - 3] == '.')) {
215                            // Get rid of the trailing dot and CRLF anyway...
216                            while (cchBuffer > 0 && (
217                                pszBuffer[cchBuffer - 1] == '\r' ||
218                                pszBuffer[cchBuffer - 1] == '\n' ||
219                                pszBuffer[cchBuffer - 1] == '.'))
220                                cchBuffer--;
221                            pszBuffer[cchBuffer] = (char) 0;
222                            pszResult = pszBuffer;
223                        }
224                  }                  }
                 else pszResult = achResult;  
225                  // The result string is now set to the command response, if any.                  // The result string is now set to the command response, if any.
226              } else {              } else {
227                  // Parse the error/warning message, skip first colon...                  // Parse the error/warning message, skip first colon...
228                  pszToken = lscp_strtok(achResult, pszSeps, &(pch));                  pszToken = lscp_strtok(achBuffer, pszSeps, &(pch));
229                  if (pszToken) {                  if (pszToken) {
230                      // Get the error number...                      // Get the error number...
231                      pszToken = lscp_strtok(NULL, pszSeps, &(pch));                      pszToken = lscp_strtok(NULL, pszSeps, &(pch));
# Line 149  lscp_status_t lscp_client_call ( lscp_cl Line 237  lscp_status_t lscp_client_call ( lscp_cl
237                  }                  }
238                  // The result string is set to the error/warning message text.                  // The result string is set to the error/warning message text.
239              }              }
240          }              break;
241          else if (cchResult == 0) {      
242              // Damn, server disconnected, we better free everything down here.            case LSCP_TIMEOUT:
243              lscp_socket_agent_free(&(pClient->evt));              // We have trouble...
244              lscp_socket_agent_free(&(pClient->cmd));              pClient->iTimeoutCount++;
245                // Fake a result message.
246                pszResult = "Timeout during receive operation";
247                iErrno = (int) ret;
248                break;
249        
250              case LSCP_QUIT:
251              // Fake a result message.              // Fake a result message.
             ret = LSCP_QUIT;  
252              pszResult = "Server terminated the connection";              pszResult = "Server terminated the connection";
253              iErrno = (int) ret;              iErrno = (int) ret;
254          } else {              break;
255        
256              case LSCP_FAILED:
257              default:
258              // What's down?              // What's down?
             lscp_socket_perror("_lscp_client_call: recv");  
259              pszResult = "Failure during receive operation";              pszResult = "Failure during receive operation";
260                break;
261          }          }
262      }   // Check if select has timed out.      }
263      else if (iSelect == 0) {      
         // Fake a result message.  
         ret = LSCP_TIMEOUT;  
         pszResult = "Timeout during receive operation";  
         iErrno = (int) ret;  
    }  
     else lscp_socket_perror("_lscp_client_call: select");  
   
264      // Make the result official...      // Make the result official...
265      lscp_client_set_result(pClient, pszResult, iErrno);      lscp_client_set_result(pClient, pszResult, iErrno);
266        
267        // Free long-buffer, if any...
268        if (pszBuffer)
269            free(pszBuffer);
270        
271      return ret;      return ret;
272  }  }
273    
# Line 295  char **lscp_szsplit_create ( const char Line 388  char **lscp_szsplit_create ( const char
388              --pch;              --pch;
389          *pch = (char) 0;          *pch = (char) 0;
390          // Make it official.          // Make it official.
391          ppszSplit[i++] = lscp_unquote(&pszHead, 0);          ppszSplit[i] = lscp_unquote(&pszHead, 0);
392          // Do we need to grow?          // Do we need to grow?
393          if (i >= iSize) {          if (++i >= iSize) {
394              // Yes, but only grow in chunks.              // Yes, but only grow in chunks.
395              iSize += LSCP_SPLIT_CHUNK1;              iSize += LSCP_SPLIT_CHUNK1;
396              // Allocate and copy to new split array.              // Allocate and copy to new split array.
# Line 362  int *lscp_isplit_create ( const char *ps Line 455  int *lscp_isplit_create ( const char *ps
455      pchHead = lscp_ltrim((char *) pszCsv);      pchHead = lscp_ltrim((char *) pszCsv);
456      if (*pchHead == (char) 0)      if (*pchHead == (char) 0)
457          return NULL;          return NULL;
458        
459      // Initial size is one chunk away.      // Initial size is one chunk away.
460      iSize = LSCP_SPLIT_CHUNK1;      iSize = LSCP_SPLIT_CHUNK1;
461      // Allocate and split...      // Allocate and split...
# Line 383  int *lscp_isplit_create ( const char *ps Line 476  int *lscp_isplit_create ( const char *ps
476          // Pre-advance to next item.          // Pre-advance to next item.
477          pchHead = pch + cchSeps;          pchHead = pch + cchSeps;
478          // Make it official.          // Make it official.
479          piSplit[i++] = atoi(pchHead);          piSplit[i] = atoi(pchHead);
480          // Do we need to grow?          // Do we need to grow?
481          if (i >= iSize) {          if (++i >= iSize) {
482              // Yes, but only grow in chunks.              // Yes, but only grow in chunks.
483              iSize += LSCP_SPLIT_CHUNK1;              iSize += LSCP_SPLIT_CHUNK1;
484              // Allocate and copy to new split array.              // Allocate and copy to new split array.
# Line 547  void lscp_plist_free ( lscp_param_t **pp Line 640  void lscp_plist_free ( lscp_param_t **pp
640  {  {
641      lscp_param_t *pParams;      lscp_param_t *pParams;
642      int i;      int i;
643        
644      if (ppList) {      if (ppList) {
645          if (*ppList) {          if (*ppList) {
646              pParams = *ppList;              pParams = *ppList;
# Line 569  void lscp_plist_append ( lscp_param_t ** Line 662  void lscp_plist_append ( lscp_param_t **
662      lscp_param_t *pNewParams;      lscp_param_t *pNewParams;
663      int iSize, iNewSize;      int iSize, iNewSize;
664      int i = 0;      int i = 0;
665        
666      if (ppList && *ppList) {      if (ppList && *ppList) {
667          pParams = *ppList;          pParams = *ppList;
668          while (pParams[i].key) {          while (pParams[i].key) {
# Line 588  void lscp_plist_append ( lscp_param_t ** Line 681  void lscp_plist_append ( lscp_param_t **
681              iNewSize   = iSize + LSCP_SPLIT_CHUNK1;              iNewSize   = iSize + LSCP_SPLIT_CHUNK1;
682              pNewParams = (lscp_param_t *) malloc(iNewSize * sizeof(lscp_param_t));              pNewParams = (lscp_param_t *) malloc(iNewSize * sizeof(lscp_param_t));
683              for (i = 0; i < iSize; i++) {              for (i = 0; i < iSize; i++) {
684                  pParams[i].key   = pParams[i].key;                  pNewParams[i].key   = pParams[i].key;
685                  pParams[i].value = pParams[i].value;                  pNewParams[i].value = pParams[i].value;
686              }              }
687              for ( ; i < iNewSize; i++) {              for ( ; i < iNewSize; i++) {
688                  pNewParams[i].key   = NULL;                  pNewParams[i].key   = NULL;
# Line 625  int lscp_plist_size ( lscp_param_t **ppL Line 718  int lscp_plist_size ( lscp_param_t **ppL
718  #endif // LSCP_PLIST_COUNT  #endif // LSCP_PLIST_COUNT
719    
720    
721    // Split a string into an array of MIDI instrument triplets.
722    lscp_midi_instrument_t *lscp_midi_instruments_create ( const char *pszCsv )
723    {
724        char *pchHead, *pch;
725        int iSize, i, j, k;
726        lscp_midi_instrument_t *pInstrs;
727        lscp_midi_instrument_t *pNewInstrs;
728        
729        // Get it clean first.
730        pchHead = lscp_ltrim((char *) pszCsv);
731        if (*pchHead == (char) 0)
732            return NULL;
733        
734        // Initial size is one chunk away.
735        iSize = LSCP_SPLIT_CHUNK1;
736        // Allocate and split...
737        pInstrs = (lscp_midi_instrument_t *) malloc(iSize * sizeof(lscp_midi_instrument_t));
738        if (pInstrs == NULL)
739            return NULL;
740        
741        // Go on for it...
742        i = 0;
743        k = 0;
744        
745        while ((pch = strpbrk(pchHead, "{,}")) != NULL) {
746            // Pre-advance to next item.
747            switch (*pch) {
748            case '{':
749                pchHead = pch + 1;
750                if (k == 0) {
751                    pInstrs[i].bank_msb = atoi(pchHead);
752                    k++;
753                }
754                break;
755            case ',':
756                pchHead = pch + 1;
757                if (k == 1) {
758                    pInstrs[i].bank_lsb = atoi(pchHead);
759                    k++;
760                }
761                else
762                if (k == 2) {
763                    pInstrs[i].program = atoi(pchHead);
764                    k++;
765                }
766                break;
767            case '}':
768                pchHead = pch + 1;
769                k = 0;
770                break;
771            }
772            // Do we need to grow?
773            if (k == 3 && ++i >= iSize) {
774                // Yes, but only grow in chunks.
775                iSize += LSCP_SPLIT_CHUNK1;
776                // Allocate and copy to new split array.
777                pNewInstrs = (lscp_midi_instrument_t *) malloc(iSize * sizeof(lscp_midi_instrument_t));
778                if (pNewInstrs) {
779                    for (j = 0; j < i; j++) {
780                        pNewInstrs[j].bank_msb = pInstrs[j].bank_msb;
781                        pNewInstrs[j].bank_lsb = pInstrs[j].bank_lsb;
782                        pNewInstrs[j].program  = pInstrs[j].program;
783                    }
784                    free(pInstrs);
785                    pInstrs = pNewInstrs;
786                }
787            }
788        }
789        
790        // Special terminate split array.
791        for ( ; i < iSize; i++) {
792            pInstrs[i].bank_msb = -1;
793            pInstrs[i].bank_lsb = -1;
794            pInstrs[i].program  = -1;
795        }
796        
797        return pInstrs;
798    }
799    
800    // Destroy a MIDI instrument triplet array.
801    void lscp_midi_instruments_destroy ( lscp_midi_instrument_t *pInstrs )
802    {
803        if (pInstrs)
804            free(pInstrs);
805    }
806    
807    #ifdef LSCP_MIDI_INSTRUMENTS_COUNT
808    
809    // Compute a MIDI instrument array item count.
810    int lscp_midi_instruments_count ( lscp_midi_instrument_t *pInstrs )
811    {
812        int i = 0;
813        while (pInstrs && pInstrs[i].program >= 0)
814            i++;
815        return i;
816    }
817    
818    // Compute a MIDI instrument array size.
819    int lscp_midi_instruments_size ( lscp_midi_instrument_t *pInstrs )
820    {
821        return LSCP_SPLIT_SIZE(lscp_midi_instruments_count(pInstrs));
822    }
823    
824    #endif // LSCP_MIDI_INSTRUMENTS_COUNT
825    
826    
827    //-------------------------------------------------------------------------
828    // Server info struct helper functions.
829    
830    void lscp_server_info_init ( lscp_server_info_t *pServerInfo )
831    {
832        pServerInfo->description = NULL;
833        pServerInfo->version     = NULL;
834    }
835    
836    void lscp_server_info_free ( lscp_server_info_t *pServerInfo )
837    {
838        if (pServerInfo->description)
839            free(pServerInfo->description);
840        if (pServerInfo->version)
841            free(pServerInfo->version);
842    }
843    
844    void lscp_server_info_reset ( lscp_server_info_t *pServerInfo )
845    {
846        lscp_server_info_free(pServerInfo);
847        lscp_server_info_init(pServerInfo);
848    }
849    
850    
851  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
852  // Engine info struct helper functions.  // Engine info struct helper functions.
853    
# Line 660  void lscp_channel_info_init ( lscp_chann Line 883  void lscp_channel_info_init ( lscp_chann
883      pChannelInfo->audio_routing     = NULL;      pChannelInfo->audio_routing     = NULL;
884      pChannelInfo->instrument_file   = NULL;      pChannelInfo->instrument_file   = NULL;
885      pChannelInfo->instrument_nr     = 0;      pChannelInfo->instrument_nr     = 0;
886        pChannelInfo->instrument_name   = NULL;
887      pChannelInfo->instrument_status = 0;      pChannelInfo->instrument_status = 0;
888      pChannelInfo->midi_device       = 0;      pChannelInfo->midi_device       = 0;
889      pChannelInfo->midi_port         = 0;      pChannelInfo->midi_port         = 0;
890      pChannelInfo->midi_channel      = 0;      pChannelInfo->midi_channel      = 0;
891      pChannelInfo->volume            = 0.0;      pChannelInfo->volume            = 0.0;
892        pChannelInfo->mute              = 0;
893        pChannelInfo->solo              = 0;
894  }  }
895    
896  void lscp_channel_info_free ( lscp_channel_info_t *pChannelInfo )  void lscp_channel_info_free ( lscp_channel_info_t *pChannelInfo )
# Line 675  void lscp_channel_info_free ( lscp_chann Line 901  void lscp_channel_info_free ( lscp_chann
901          lscp_szsplit_destroy(pChannelInfo->audio_routing);          lscp_szsplit_destroy(pChannelInfo->audio_routing);
902      if (pChannelInfo->instrument_file)      if (pChannelInfo->instrument_file)
903          free(pChannelInfo->instrument_file);          free(pChannelInfo->instrument_file);
904        if (pChannelInfo->instrument_name)
905            free(pChannelInfo->instrument_name);
906  }  }
907    
908  void lscp_channel_info_reset ( lscp_channel_info_t *pChannelInfo )  void lscp_channel_info_reset ( lscp_channel_info_t *pChannelInfo )
# Line 817  int lscp_param_concat ( char *pszBuffer, Line 1045  int lscp_param_concat ( char *pszBuffer,
1045      if (cchBuffer + 2 < cchMaxBuffer) {      if (cchBuffer + 2 < cchMaxBuffer) {
1046          pszBuffer[cchBuffer++] = '\r';          pszBuffer[cchBuffer++] = '\r';
1047          pszBuffer[cchBuffer++] = '\n';          pszBuffer[cchBuffer++] = '\n';
1048            pszBuffer[cchBuffer ]  = (char) 0;
1049      }      }
1050            
1051      return cchBuffer;      return cchBuffer;
1052  }  }
1053    
1054    
1055    //-------------------------------------------------------------------------
1056    // MIDI instrument info struct helper functions.
1057    
1058    void lscp_midi_instrument_info_init ( lscp_midi_instrument_info_t *pInstrInfo )
1059    {
1060        pInstrInfo->name              = NULL;
1061        pInstrInfo->engine_name       = NULL;
1062        pInstrInfo->instrument_file   = NULL;
1063        pInstrInfo->instrument_nr     = 0;
1064        pInstrInfo->instrument_name   = NULL;
1065        pInstrInfo->load_mode         = LSCP_LOAD_DEFAULT;
1066        pInstrInfo->volume            = 0.0;
1067    }
1068    
1069    void lscp_midi_instrument_info_free ( lscp_midi_instrument_info_t *pInstrInfo )
1070    {
1071        if (pInstrInfo->name)
1072            free(pInstrInfo->name);
1073        if (pInstrInfo->engine_name)
1074            free(pInstrInfo->engine_name);
1075        if (pInstrInfo->instrument_file)
1076            free(pInstrInfo->instrument_file);
1077        if (pInstrInfo->instrument_name)
1078            free(pInstrInfo->instrument_name);
1079    }
1080    
1081    void lscp_midi_instrument_info_reset ( lscp_midi_instrument_info_t *pInstrInfo )
1082    {
1083        lscp_midi_instrument_info_free(pInstrInfo);
1084        lscp_midi_instrument_info_init(pInstrInfo);
1085    }
1086    
1087    
1088  // end of common.c  // end of common.c

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

  ViewVC Help
Powered by ViewVC