liblscp 0.5.6

common.h

Go to the documentation of this file.
00001 // common.h
00002 //
00003 /****************************************************************************
00004    liblscp - LinuxSampler Control Protocol API
00005    Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved.
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Lesser General Public
00009    License as published by the Free Software Foundation; either
00010    version 2.1 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00015    Lesser General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License along
00018    with this program; if not, write to the Free Software Foundation, Inc.,
00019    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00020 
00021 *****************************************************************************/
00022 
00023 #ifndef __LSCP_COMMON_H
00024 #define __LSCP_COMMON_H
00025 
00026 #include "lscp/client.h"
00027 #include "lscp/device.h"
00028 
00029 
00030 // Case unsensitive comparison substitutes.
00031 #if defined(WIN32)
00032 #define strcasecmp      stricmp
00033 #define strncasecmp     strnicmp
00034 #endif
00035 
00036 //-------------------------------------------------------------------------
00037 // Client opaque descriptor struct.
00038 
00039 struct _lscp_client_t
00040 {
00041     // Client socket stuff.
00042     lscp_client_proc_t  pfnCallback;
00043     void *              pvData;
00044     lscp_socket_agent_t cmd;
00045     lscp_socket_agent_t evt;
00046     // Subscribed events.
00047     lscp_event_t        events;
00048     // Client struct persistent caches.
00049     char **             audio_drivers;
00050     char **             midi_drivers;
00051     int  *              audio_devices;
00052     int  *              midi_devices;
00053     char **             engines;
00054     int  *              channels;
00055     int  *              fxsends;
00056     lscp_midi_instrument_t *midi_instruments;
00057     int  *              midi_maps;
00058     char *              midi_map_name;
00059     // Client struct volatile caches.
00060     lscp_driver_info_t  audio_driver_info;
00061     lscp_driver_info_t  midi_driver_info;
00062     lscp_device_info_t  audio_device_info;
00063     lscp_device_info_t  midi_device_info;
00064     lscp_param_info_t   audio_param_info;
00065     lscp_param_info_t   midi_param_info;
00066     lscp_device_port_info_t audio_channel_info;
00067     lscp_device_port_info_t midi_port_info;
00068     lscp_param_info_t   audio_channel_param_info;
00069     lscp_param_info_t   midi_port_param_info;
00070     lscp_server_info_t  server_info;
00071     lscp_engine_info_t  engine_info;
00072     lscp_channel_info_t channel_info;
00073     lscp_fxsend_info_t  fxsend_info;
00074     lscp_midi_instrument_info_t midi_instrument_info;
00075     // Result and error status.
00076     char *              pszResult;
00077     int                 iErrno;
00078     // Stream buffers status.
00079     lscp_buffer_fill_t *buffer_fill;
00080     int                 iStreamCount;
00081     // Transaction call timeout (msecs).
00082     int                 iTimeout;
00083     lscp_mutex_t        mutex;
00084     lscp_cond_t         cond;
00085     // Flag last transaction timedout.
00086     int                 iTimeoutCount;
00087 };
00088 
00089 
00090 //-------------------------------------------------------------------------
00091 // Local client request executive.
00092 
00093 lscp_status_t   lscp_client_recv            (lscp_client_t *pClient, char *pchBuffer, int *pcchBuffer, int iTimeout);
00094 lscp_status_t   lscp_client_call            (lscp_client_t *pClient, const char *pszQuery, int iResult);
00095 void            lscp_client_set_result      (lscp_client_t *pClient, char *pszResult, int iErrno);
00096 
00097 //-------------------------------------------------------------------------
00098 // General utility function prototypes.
00099 
00100 char *          lscp_strtok            (char *pchBuffer, const char *pszSeps, char **ppch);
00101 char *          lscp_ltrim             (char *psz);
00102 char *          lscp_unquote           (char **ppsz, int dup);
00103 void            lscp_unquote_dup       (char **ppszDst, char **ppszSrc);
00104 
00105 char **         lscp_szsplit_create    (const char *pszCsv, const char *pszSeps);
00106 void            lscp_szsplit_destroy   (char **ppszSplit);
00107 #ifdef LSCP_SZSPLIT_COUNT
00108 int             lscp_szsplit_count     (char **ppszSplit);
00109 int             lscp_szsplit_size      (char **ppszSplit);
00110 #endif
00111 
00112 int *           lscp_isplit_create     (const char *pszCsv, const char *pszSeps);
00113 void            lscp_isplit_destroy    (int *piSplit);
00114 #ifdef LSCP_ISPLIT_COUNT
00115 int             lscp_isplit_count      (int *piSplit);
00116 int             lscp_isplit_size       (int *piSplit);
00117 #endif
00118 
00119 lscp_param_t *  lscp_psplit_create     (const char *pszCsv, const char *pszSep1, const char *pszSep2);
00120 void            lscp_psplit_destroy    (lscp_param_t *ppSplit);
00121 #ifdef LSCP_PSPLIT_COUNT
00122 int             lscp_psplit_count      (lscp_param_t *ppSplit);
00123 int             lscp_psplit_size       (lscp_param_t *ppSplit);
00124 #endif
00125 
00126 void            lscp_plist_alloc       (lscp_param_t **ppList);
00127 void            lscp_plist_free        (lscp_param_t **ppList);
00128 void            lscp_plist_append      (lscp_param_t **ppList, const char *pszKey, const char *pszValue);
00129 #ifdef LSCP_PLIST_COUNT
00130 int             lscp_plist_count       (lscp_param_t **ppList);
00131 int             lscp_plist_size        (lscp_param_t **ppList);
00132 #endif
00133 
00134 lscp_midi_instrument_t *lscp_midi_instruments_create (const char *pszCsv);
00135 void            lscp_midi_instruments_destroy (lscp_midi_instrument_t *pInstrs);
00136 #ifdef LSCP_MIDI_INSTRUMENTS_COUNT
00137 int             lscp_midi_instruments_count   (lscp_midi_instrument_t *pInstrs);
00138 int             lscp_midi_instruments_size    (lscp_midi_instrument_t *pInstrs);
00139 #endif
00140 
00141 
00142 //-------------------------------------------------------------------------
00143 // Server struct helper functions.
00144 
00145 void            lscp_server_info_init       (lscp_server_info_t *pServerInfo);
00146 void            lscp_server_info_free       (lscp_server_info_t *pServerInfo);
00147 void            lscp_server_info_reset      (lscp_server_info_t *pServerInfo);
00148 
00149 //-------------------------------------------------------------------------
00150 // Engine struct helper functions.
00151 
00152 void            lscp_engine_info_init       (lscp_engine_info_t *pEngineInfo);
00153 void            lscp_engine_info_free       (lscp_engine_info_t *pEngineInfo);
00154 void            lscp_engine_info_reset      (lscp_engine_info_t *pEngineInfo);
00155 
00156 //-------------------------------------------------------------------------
00157 // Channel struct helper functions.
00158 
00159 void            lscp_channel_info_init      (lscp_channel_info_t *pChannelInfo);
00160 void            lscp_channel_info_free      (lscp_channel_info_t *pChannelInfo);
00161 void            lscp_channel_info_reset     (lscp_channel_info_t *pChannelInfo);
00162 
00163 //-------------------------------------------------------------------------
00164 // Driver struct helper functions.
00165 
00166 void            lscp_driver_info_init       (lscp_driver_info_t *pDriverInfo);
00167 void            lscp_driver_info_free       (lscp_driver_info_t *pDriverInfo);
00168 void            lscp_driver_info_reset      (lscp_driver_info_t *pDriverInfo);
00169 
00170 //-------------------------------------------------------------------------
00171 // Device struct helper functions.
00172 
00173 void            lscp_device_info_init       (lscp_device_info_t *pDeviceInfo);
00174 void            lscp_device_info_free       (lscp_device_info_t *pDeviceInfo);
00175 void            lscp_device_info_reset      (lscp_device_info_t *pDeviceInfo);
00176 
00177 //-------------------------------------------------------------------------
00178 // Device channel/port struct helper functions.
00179 
00180 void            lscp_device_port_info_init  (lscp_device_port_info_t *pDevicePortInfo);
00181 void            lscp_device_port_info_free  (lscp_device_port_info_t *pDevicePortInfo);
00182 void            lscp_device_port_info_reset (lscp_device_port_info_t *pDevicePortInfo);
00183 
00184 //-------------------------------------------------------------------------
00185 // Parameter struct helper functions.
00186 
00187 void            lscp_param_info_init        (lscp_param_info_t *pParamInfo);
00188 void            lscp_param_info_free        (lscp_param_info_t *pParamInfo);
00189 void            lscp_param_info_reset       (lscp_param_info_t *pParamInfo);
00190 
00191 //-------------------------------------------------------------------------
00192 // Concatenate a parameter list (key='value'...) into a string.
00193 
00194 int             lscp_param_concat           (char *pszBuffer, int cchMaxBuffer, lscp_param_t *pParams);
00195 
00196 //-------------------------------------------------------------------------
00197 // Effect struct helper functions.
00198 
00199 void            lscp_fxsend_info_init       (lscp_fxsend_info_t *pFxSendInfo);
00200 void            lscp_fxsend_info_free       (lscp_fxsend_info_t *pFxSendInfo);
00201 void            lscp_fxsend_info_reset      (lscp_fxsend_info_t *pFxSendInfo);
00202 
00203 //-------------------------------------------------------------------------
00204 // MIDI instrument info struct helper functions.
00205 
00206 void            lscp_midi_instrument_info_init  (lscp_midi_instrument_info_t *pInstrInfo);
00207 void            lscp_midi_instrument_info_free  (lscp_midi_instrument_info_t *pInstrInfo);
00208 void            lscp_midi_instrument_info_reset (lscp_midi_instrument_info_t *pInstrInfo);
00209 
00210 
00211 #endif // __LSCP_COMMON_H
00212 
00213 // end of common.h