common.h
Go to the documentation of this file.
// common.h
//
/****************************************************************************
liblscp - LinuxSampler Control Protocol API
Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*****************************************************************************/
#ifndef __LSCP_COMMON_H
#define __LSCP_COMMON_H
#include "lscp/client.h"
#include "lscp/device.h"
// Case unsensitive comparison substitutes.
#if defined(WIN32)
#define strcasecmp stricmp
#define strncasecmp strnicmp
#endif
//-------------------------------------------------------------------------
// Client opaque descriptor struct.
struct _lscp_client_t
{
// Client socket stuff.
lscp_client_proc_t pfnCallback;
void * pvData;
lscp_socket_agent_t cmd;
lscp_socket_agent_t evt;
// Subscribed events.
lscp_event_t events;
// Client struct persistent caches.
char ** audio_drivers;
char ** midi_drivers;
int * audio_devices;
int * midi_devices;
char ** engines;
int * channels;
int * fxsends;
lscp_midi_instrument_t *midi_instruments;
int * midi_maps;
char * midi_map_name;
// Client struct volatile caches.
lscp_driver_info_t audio_driver_info;
lscp_driver_info_t midi_driver_info;
lscp_device_info_t audio_device_info;
lscp_device_info_t midi_device_info;
lscp_param_info_t audio_param_info;
lscp_param_info_t midi_param_info;
lscp_device_port_info_t audio_channel_info;
lscp_device_port_info_t midi_port_info;
lscp_param_info_t audio_channel_param_info;
lscp_param_info_t midi_port_param_info;
lscp_server_info_t server_info;
lscp_engine_info_t engine_info;
lscp_channel_info_t channel_info;
lscp_fxsend_info_t fxsend_info;
lscp_midi_instrument_info_t midi_instrument_info;
// Result and error status.
char * pszResult;
int iErrno;
// Stream buffers status.
lscp_buffer_fill_t *buffer_fill;
int iStreamCount;
// Transaction call timeout (msecs).
int iTimeout;
lscp_mutex_t mutex;
lscp_cond_t cond;
// Flag last transaction timedout.
int iTimeoutCount;
};
//-------------------------------------------------------------------------
// Local client request executive.
lscp_status_t lscp_client_recv (lscp_client_t *pClient, char *pchBuffer, int *pcchBuffer, int iTimeout);
lscp_status_t lscp_client_call (lscp_client_t *pClient, const char *pszQuery, int iResult);
void lscp_client_set_result (lscp_client_t *pClient, char *pszResult, int iErrno);
//-------------------------------------------------------------------------
// General utility function prototypes.
char * lscp_strtok (char *pchBuffer, const char *pszSeps, char **ppch);
char * lscp_ltrim (char *psz);
char * lscp_unquote (char **ppsz, int dup);
void lscp_unquote_dup (char **ppszDst, char **ppszSrc);
char ** lscp_szsplit_create (const char *pszCsv, const char *pszSeps);
void lscp_szsplit_destroy (char **ppszSplit);
#ifdef LSCP_SZSPLIT_COUNT
int lscp_szsplit_count (char **ppszSplit);
int lscp_szsplit_size (char **ppszSplit);
#endif
int * lscp_isplit_create (const char *pszCsv, const char *pszSeps);
void lscp_isplit_destroy (int *piSplit);
#ifdef LSCP_ISPLIT_COUNT
int lscp_isplit_count (int *piSplit);
int lscp_isplit_size (int *piSplit);
#endif
lscp_param_t * lscp_psplit_create (const char *pszCsv, const char *pszSep1, const char *pszSep2);
void lscp_psplit_destroy (lscp_param_t *ppSplit);
#ifdef LSCP_PSPLIT_COUNT
int lscp_psplit_count (lscp_param_t *ppSplit);
int lscp_psplit_size (lscp_param_t *ppSplit);
#endif
void lscp_plist_alloc (lscp_param_t **ppList);
void lscp_plist_free (lscp_param_t **ppList);
void lscp_plist_append (lscp_param_t **ppList, const char *pszKey, const char *pszValue);
#ifdef LSCP_PLIST_COUNT
int lscp_plist_count (lscp_param_t **ppList);
int lscp_plist_size (lscp_param_t **ppList);
#endif
lscp_midi_instrument_t *lscp_midi_instruments_create (const char *pszCsv);
void lscp_midi_instruments_destroy (lscp_midi_instrument_t *pInstrs);
#ifdef LSCP_MIDI_INSTRUMENTS_COUNT
int lscp_midi_instruments_count (lscp_midi_instrument_t *pInstrs);
int lscp_midi_instruments_size (lscp_midi_instrument_t *pInstrs);
#endif
//-------------------------------------------------------------------------
// Server struct helper functions.
void lscp_server_info_init (lscp_server_info_t *pServerInfo);
void lscp_server_info_free (lscp_server_info_t *pServerInfo);
void lscp_server_info_reset (lscp_server_info_t *pServerInfo);
//-------------------------------------------------------------------------
// Engine struct helper functions.
void lscp_engine_info_init (lscp_engine_info_t *pEngineInfo);
void lscp_engine_info_free (lscp_engine_info_t *pEngineInfo);
void lscp_engine_info_reset (lscp_engine_info_t *pEngineInfo);
//-------------------------------------------------------------------------
// Channel struct helper functions.
void lscp_channel_info_init (lscp_channel_info_t *pChannelInfo);
void lscp_channel_info_free (lscp_channel_info_t *pChannelInfo);
void lscp_channel_info_reset (lscp_channel_info_t *pChannelInfo);
//-------------------------------------------------------------------------
// Driver struct helper functions.
void lscp_driver_info_init (lscp_driver_info_t *pDriverInfo);
void lscp_driver_info_free (lscp_driver_info_t *pDriverInfo);
void lscp_driver_info_reset (lscp_driver_info_t *pDriverInfo);
//-------------------------------------------------------------------------
// Device struct helper functions.
void lscp_device_info_init (lscp_device_info_t *pDeviceInfo);
void lscp_device_info_free (lscp_device_info_t *pDeviceInfo);
void lscp_device_info_reset (lscp_device_info_t *pDeviceInfo);
//-------------------------------------------------------------------------
// Device channel/port struct helper functions.
void lscp_device_port_info_init (lscp_device_port_info_t *pDevicePortInfo);
void lscp_device_port_info_free (lscp_device_port_info_t *pDevicePortInfo);
void lscp_device_port_info_reset (lscp_device_port_info_t *pDevicePortInfo);
//-------------------------------------------------------------------------
// Parameter struct helper functions.
void lscp_param_info_init (lscp_param_info_t *pParamInfo);
void lscp_param_info_free (lscp_param_info_t *pParamInfo);
void lscp_param_info_reset (lscp_param_info_t *pParamInfo);
//-------------------------------------------------------------------------
// Concatenate a parameter list (key='value'...) into a string.
int lscp_param_concat (char *pszBuffer, int cchMaxBuffer, lscp_param_t *pParams);
//-------------------------------------------------------------------------
// Effect struct helper functions.
void lscp_fxsend_info_init (lscp_fxsend_info_t *pFxSendInfo);
void lscp_fxsend_info_free (lscp_fxsend_info_t *pFxSendInfo);
void lscp_fxsend_info_reset (lscp_fxsend_info_t *pFxSendInfo);
//-------------------------------------------------------------------------
// MIDI instrument info struct helper functions.
void lscp_midi_instrument_info_init (lscp_midi_instrument_info_t *pInstrInfo);
void lscp_midi_instrument_info_free (lscp_midi_instrument_info_t *pInstrInfo);
void lscp_midi_instrument_info_reset (lscp_midi_instrument_info_t *pInstrInfo);
#endif // __LSCP_COMMON_H
// end of common.h
_lscp_engine_info_t
Definition: client.h:53
lscp_psplit_create
lscp_param_t * lscp_psplit_create(const char *pszCsv, const char *pszSep1, const char *pszSep2)
Definition: common.c:538
lscp_plist_alloc
void lscp_plist_alloc(lscp_param_t **ppList)
Definition: common.c:625
lscp_isplit_destroy
void lscp_isplit_destroy(int *piSplit)
Definition: common.c:510
_lscp_client_t::iTimeout
int iTimeout
Definition: common.h:82
_lscp_midi_instrument_t
Definition: client.h:113
_lscp_client_t::audio_devices
int * audio_devices
Definition: common.h:51
_lscp_client_t::midi_maps
int * midi_maps
Definition: common.h:57
_lscp_client_t::iTimeoutCount
int iTimeoutCount
Definition: common.h:86
lscp_fxsend_info_reset
void lscp_fxsend_info_reset(lscp_fxsend_info_t *pFxSendInfo)
Definition: common.c:1084
lscp_psplit_destroy
void lscp_psplit_destroy(lscp_param_t *ppSplit)
Definition: common.c:595
lscp_param_info_init
void lscp_param_info_init(lscp_param_info_t *pParamInfo)
Definition: common.c:1000
_lscp_client_t::iErrno
int iErrno
Definition: common.h:77
_lscp_client_t::mutex
lscp_mutex_t mutex
Definition: common.h:83
lscp_client_proc_t
lscp_status_t(* lscp_client_proc_t)(struct _lscp_client_t *pClient, lscp_event_t event, const char *pchData, int cchData, void *pvData)
Definition: client.h:165
_lscp_client_t::midi_instrument_info
lscp_midi_instrument_info_t midi_instrument_info
Definition: common.h:74
_lscp_server_info_t
Definition: client.h:43
_lscp_client_t::midi_port_param_info
lscp_param_info_t midi_port_param_info
Definition: common.h:69
lscp_client_recv
lscp_status_t lscp_client_recv(lscp_client_t *pClient, char *pchBuffer, int *pcchBuffer, int iTimeout)
Definition: common.c:54
lscp_fxsend_info_free
void lscp_fxsend_info_free(lscp_fxsend_info_t *pFxSendInfo)
Definition: common.c:1076
_lscp_client_t::midi_devices
int * midi_devices
Definition: common.h:52
lscp_server_info_free
void lscp_server_info_free(lscp_server_info_t *pServerInfo)
Definition: common.c:843
_lscp_device_info_t
Definition: device.h:85
lscp_strtok
char * lscp_strtok(char *pchBuffer, const char *pszSeps, char **ppch)
Definition: common.c:339
lscp_channel_info_free
void lscp_channel_info_free(lscp_channel_info_t *pChannelInfo)
Definition: common.c:906
_lscp_client_t::audio_param_info
lscp_param_info_t audio_param_info
Definition: common.h:64
lscp_device_port_info_free
void lscp_device_port_info_free(lscp_device_port_info_t *pDevicePortInfo)
Definition: common.c:983
_lscp_client_t::audio_channel_info
lscp_device_port_info_t audio_channel_info
Definition: common.h:66
_lscp_client_t::midi_driver_info
lscp_driver_info_t midi_driver_info
Definition: common.h:61
lscp_status_t
enum _lscp_status_t lscp_status_t
lscp_engine_info_free
void lscp_engine_info_free(lscp_engine_info_t *pEngineInfo)
Definition: common.c:869
lscp_driver_info_reset
void lscp_driver_info_reset(lscp_driver_info_t *pDriverInfo)
Definition: common.c:944
_lscp_client_t::cond
lscp_cond_t cond
Definition: common.h:84
lscp_midi_instrument_info_free
void lscp_midi_instrument_info_free(lscp_midi_instrument_info_t *pInstrInfo)
Definition: common.c:1105
_lscp_socket_agent_t
Definition: socket.h:68
lscp_channel_info_reset
void lscp_channel_info_reset(lscp_channel_info_t *pChannelInfo)
Definition: common.c:918
_lscp_client_t::iStreamCount
int iStreamCount
Definition: common.h:80
_lscp_client_t::audio_channel_param_info
lscp_param_info_t audio_channel_param_info
Definition: common.h:68
_lscp_client_t::channels
int * channels
Definition: common.h:54
_lscp_client_t::midi_port_info
lscp_device_port_info_t midi_port_info
Definition: common.h:67
_lscp_client_t::evt
lscp_socket_agent_t evt
Definition: common.h:45
lscp_unquote_dup
void lscp_unquote_dup(char **ppszDst, char **ppszSrc)
Definition: common.c:326
_lscp_client_t::audio_device_info
lscp_device_info_t audio_device_info
Definition: common.h:62
lscp_device_info_free
void lscp_device_info_free(lscp_device_info_t *pDeviceInfo)
Definition: common.c:960
_lscp_client_t::engine_info
lscp_engine_info_t engine_info
Definition: common.h:71
lscp_mutex_t
pthread_mutex_t lscp_mutex_t
Definition: thread.h:72
lscp_server_info_init
void lscp_server_info_init(lscp_server_info_t *pServerInfo)
Definition: common.c:836
lscp_param_info_reset
void lscp_param_info_reset(lscp_param_info_t *pParamInfo)
Definition: common.c:1028
lscp_plist_append
void lscp_plist_append(lscp_param_t **ppList, const char *pszKey, const char *pszValue)
Definition: common.c:665
_lscp_param_info_t
Definition: device.h:58
_lscp_midi_instrument_info_t
Definition: client.h:134
_lscp_client_t::midi_param_info
lscp_param_info_t midi_param_info
Definition: common.h:65
_lscp_client_t::buffer_fill
lscp_buffer_fill_t * buffer_fill
Definition: common.h:79
lscp_szsplit_create
char ** lscp_szsplit_create(const char *pszCsv, const char *pszSeps)
Definition: common.c:366
_lscp_client_t::audio_drivers
char ** audio_drivers
Definition: common.h:49
lscp_isplit_create
int * lscp_isplit_create(const char *pszCsv, const char *pszSeps)
Definition: common.c:454
lscp_midi_instruments_destroy
void lscp_midi_instruments_destroy(lscp_midi_instrument_t *pInstrs)
Definition: common.c:807
lscp_param_info_free
void lscp_param_info_free(lscp_param_info_t *pParamInfo)
Definition: common.c:1014
_lscp_client_t::engines
char ** engines
Definition: common.h:53
_lscp_client_t::pszResult
char * pszResult
Definition: common.h:76
_lscp_client_t::midi_instruments
lscp_midi_instrument_t * midi_instruments
Definition: common.h:56
_lscp_client_t::fxsend_info
lscp_fxsend_info_t fxsend_info
Definition: common.h:73
_lscp_client_t::midi_map_name
char * midi_map_name
Definition: common.h:58
lscp_server_info_reset
void lscp_server_info_reset(lscp_server_info_t *pServerInfo)
Definition: common.c:853
lscp_ltrim
char * lscp_ltrim(char *psz)
Definition: common.c:285
lscp_engine_info_reset
void lscp_engine_info_reset(lscp_engine_info_t *pEngineInfo)
Definition: common.c:877
lscp_event_t
enum _lscp_event_t lscp_event_t
lscp_channel_info_init
void lscp_channel_info_init(lscp_channel_info_t *pChannelInfo)
Definition: common.c:887
_lscp_client_t::midi_drivers
char ** midi_drivers
Definition: common.h:50
lscp_szsplit_destroy
void lscp_szsplit_destroy(char **ppszSplit)
Definition: common.c:422
lscp_device_port_info_reset
void lscp_device_port_info_reset(lscp_device_port_info_t *pDevicePortInfo)
Definition: common.c:990
lscp_cond_t
pthread_cond_t lscp_cond_t
Definition: thread.h:89
_lscp_client_t::pvData
void * pvData
Definition: common.h:43
_lscp_buffer_fill_t
Definition: client.h:84
_lscp_client_t::midi_device_info
lscp_device_info_t midi_device_info
Definition: common.h:63
_lscp_client_t::fxsends
int * fxsends
Definition: common.h:55
_lscp_device_port_info_t
Definition: device.h:94
_lscp_param_t
Definition: device.h:49
lscp_client_call
lscp_status_t lscp_client_call(lscp_client_t *pClient, const char *pszQuery, int iResult)
Definition: common.c:110
lscp_client_set_result
void lscp_client_set_result(lscp_client_t *pClient, char *pszResult, int iErrno)
Definition: common.c:40
lscp_plist_free
void lscp_plist_free(lscp_param_t **ppList)
Definition: common.c:645
lscp_unquote
char * lscp_unquote(char **ppsz, int dup)
Definition: common.c:293
lscp_midi_instrument_info_init
void lscp_midi_instrument_info_init(lscp_midi_instrument_info_t *pInstrInfo)
Definition: common.c:1094
lscp_midi_instrument_info_reset
void lscp_midi_instrument_info_reset(lscp_midi_instrument_info_t *pInstrInfo)
Definition: common.c:1117
_lscp_client_t
Definition: common.h:39
lscp_device_info_init
void lscp_device_info_init(lscp_device_info_t *pDeviceInfo)
Definition: common.c:954
_lscp_client_t::pfnCallback
lscp_client_proc_t pfnCallback
Definition: common.h:42
device.h
_lscp_fxsend_info_t
Definition: client.h:102
lscp_engine_info_init
void lscp_engine_info_init(lscp_engine_info_t *pEngineInfo)
Definition: common.c:863
client.h
lscp_driver_info_free
void lscp_driver_info_free(lscp_driver_info_t *pDriverInfo)
Definition: common.c:935
_lscp_client_t::channel_info
lscp_channel_info_t channel_info
Definition: common.h:72
_lscp_client_t::cmd
lscp_socket_agent_t cmd
Definition: common.h:44
_lscp_client_t::events
lscp_event_t events
Definition: common.h:47
_lscp_channel_info_t
Definition: client.h:62
_lscp_client_t::audio_driver_info
lscp_driver_info_t audio_driver_info
Definition: common.h:60
lscp_fxsend_info_init
void lscp_fxsend_info_init(lscp_fxsend_info_t *pFxSendInfo)
Definition: common.c:1068
_lscp_client_t::server_info
lscp_server_info_t server_info
Definition: common.h:70
lscp_driver_info_init
void lscp_driver_info_init(lscp_driver_info_t *pDriverInfo)
Definition: common.c:928
lscp_midi_instruments_create
lscp_midi_instrument_t * lscp_midi_instruments_create(const char *pszCsv)
Definition: common.c:728
lscp_device_port_info_init
void lscp_device_port_info_init(lscp_device_port_info_t *pDevicePortInfo)
Definition: common.c:977
_lscp_driver_info_t
Definition: device.h:75
lscp_param_concat
int lscp_param_concat(char *pszBuffer, int cchMaxBuffer, lscp_param_t *pParams)
Definition: common.c:1039
lscp_device_info_reset
void lscp_device_info_reset(lscp_device_info_t *pDeviceInfo)
Definition: common.c:967