Merge pull request #234 from FluidSynth/carlo-bramini-master

Wrap std C functions in FLUID_* macros
This commit is contained in:
Tom M 2017-10-15 21:15:51 +02:00 committed by GitHub
commit dc992712ab
23 changed files with 77 additions and 68 deletions

View file

@ -393,7 +393,7 @@ fluid_get_userconf(char* buf, int len)
if (home == NULL) {
return NULL;
} else {
snprintf(buf, len, "%s/.fluidsynth", home);
FLUID_SNPRINTF (buf, len, "%s/.fluidsynth", home);
return buf;
}
#endif
@ -411,7 +411,7 @@ fluid_get_sysconf(char* buf, int len)
#if defined(WIN32) || defined(MACOS9)
return NULL;
#else
snprintf(buf, len, "/etc/fluidsynth.conf");
FLUID_SNPRINTF (buf, len, "/etc/fluidsynth.conf");
return buf;
#endif
}
@ -1845,17 +1845,17 @@ char*
fluid_expand_path(char* path, char* new_path, int len)
{
#if defined(WIN32) || defined(MACOS9)
snprintf(new_path, len - 1, "%s", path);
FLUID_SNPRINTF (new_path, len - 1, "%s", path);
#else
if ((path[0] == '~') && (path[1] == '/')) {
char* home = getenv("HOME");
if (home == NULL) {
snprintf(new_path, len - 1, "%s", path);
FLUID_SNPRINTF (new_path, len - 1, "%s", path);
} else {
snprintf(new_path, len - 1, "%s%s", home, &path[1]);
FLUID_SNPRINTF (new_path, len - 1, "%s%s", home, &path[1]);
}
} else {
snprintf(new_path, len - 1, "%s", path);
FLUID_SNPRINTF (new_path, len - 1, "%s", path);
}
#endif

View file

@ -309,10 +309,10 @@ fluid_LADSPA_handle_start(fluid_synth_t* synth, int ac, char** av, fluid_ostream
fluid_LADSPA_clear(FxUnit);
return(PrintErrorMessage);
}; /* if no LADSPA_PATH */
snprintf(LibFullPath,FLUID_LADSPA_MaxPathLength,"%s/%s",LADSPA_Path,LibraryFilename);
FLUID_SNPRINTF (LibFullPath,FLUID_LADSPA_MaxPathLength,"%s/%s",LADSPA_Path,LibraryFilename);
/* If no slash in filename */
} else {
snprintf(LibFullPath,FLUID_LADSPA_MaxPathLength,"%s",LibraryFilename);
FLUID_SNPRINTF (LibFullPath,FLUID_LADSPA_MaxPathLength,"%s",LibraryFilename);
};
L(fluid_ostream_printf(out,"Full Library path name: %s",LibFullPath));

View file

@ -5,15 +5,6 @@
#define DSOUND_SUPPORT 1
#define WINMIDI_SUPPORT 1
#if _MSC_VER < 1900
#define snprintf _snprintf
#endif
#define strcasecmp _stricmp
#if _MSC_VER < 1500
#define vsnprintf _vsnprintf
#endif
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2

View file

@ -726,12 +726,12 @@ static char* fluid_alsa_seq_full_id(char* id, char* buf, int len)
{
if (id != NULL) {
if (FLUID_STRCMP(id, "pid") == 0) {
snprintf(buf, len, "FLUID Synth (%d)", getpid());
FLUID_SNPRINTF (buf, len, "FLUID Synth (%d)", getpid());
} else {
snprintf(buf, len, "FLUID Synth (%s)", id);
FLUID_SNPRINTF (buf, len, "FLUID Synth (%s)", id);
}
} else {
snprintf(buf, len, "FLUID Synth");
FLUID_SNPRINTF (buf, len, "FLUID Synth");
}
return buf;
@ -741,12 +741,12 @@ static char* fluid_alsa_seq_full_name(char* id, int port, char* buf, int len)
{
if (id != NULL) {
if (FLUID_STRCMP(id, "pid") == 0) {
snprintf(buf, len, "Synth input port (%d:%d)", getpid(), port);
FLUID_SNPRINTF (buf, len, "Synth input port (%d:%d)", getpid(), port);
} else {
snprintf(buf, len, "Synth input port (%s:%d)", id, port);
FLUID_SNPRINTF (buf, len, "Synth input port (%s:%d)", id, port);
}
} else {
snprintf(buf, len, "Synth input port");
FLUID_SNPRINTF (buf, len, "Synth input port");
}
return buf;
}

View file

@ -221,7 +221,7 @@ new_fluid_core_audio_driver2(fluid_settings_t* settings, fluid_audio_func_t func
size = sizeof (name);
pa.mSelector = kAudioDevicePropertyDeviceName;
if (OK (AudioObjectGetPropertyData (devs[i], &pa, 0, 0, &size, name))) {
if (get_num_outputs (devs[i]) > 0 && strcasecmp(devname, name) == 0) {
if (get_num_outputs (devs[i]) > 0 && FLUID_STRCASECMP(devname, name) == 0) {
AudioDeviceID selectedID = devs[i];
status = AudioUnitSetProperty (dev->outputUnit,
kAudioOutputUnitProperty_CurrentDevice,

View file

@ -112,9 +112,9 @@ new_fluid_coremidi_driver(fluid_settings_t* settings, handle_midi_event_func_t h
memset (clientid, 0, sizeof(clientid));
if (id != NULL) {
if (FLUID_STRCMP (id, "pid") == 0) {
snprintf (clientid, sizeof(clientid), " (%d)", getpid());
FLUID_SNPRINTF (clientid, sizeof(clientid), " (%d)", getpid());
} else {
snprintf (clientid, sizeof(clientid), " (%s)", id);
FLUID_SNPRINTF (clientid, sizeof(clientid), " (%s)", id);
}
FLUID_FREE (id); /* -- free id string */
}

View file

@ -76,7 +76,7 @@ fluid_dsound_enum_callback2(LPGUID guid, LPCTSTR description, LPCTSTR module, LP
{
fluid_dsound_devsel_t* devsel = (fluid_dsound_devsel_t*) context;
FLUID_LOG(FLUID_DBG, "Testing audio device: %s", description);
if (strcasecmp(devsel->devname, description) == 0) {
if (FLUID_STRCASECMP(devsel->devname, description) == 0) {
devsel->devGUID = FLUID_NEW(GUID);
if(devsel->devGUID) {
memcpy(devsel->devGUID, guid, sizeof(GUID));

View file

@ -171,7 +171,7 @@ new_fluid_jack_client (fluid_settings_t *settings, int isaudio, void *driver)
: "midi.jack.id", &client_name);
if (client_name != NULL && client_name[0] != 0)
snprintf(name, 64, "%s", client_name);
FLUID_SNPRINTF (name, 64, "%s", client_name);
else strcpy (name, "fluidsynth");
name[63] = '\0';

View file

@ -150,12 +150,12 @@ new_fluid_winmidi_driver(fluid_settings_t* settings,
}
/* find the device */
if (strcasecmp("default", devname) != 0) {
if (FLUID_STRCASECMP("default", devname) != 0) {
for (i = 0; i < num; i++) {
res = midiInGetDevCaps(i, &in_caps, sizeof(MIDIINCAPS));
if (res == MMSYSERR_NOERROR) {
FLUID_LOG(FLUID_DBG, "Testing midi device: %s\n", in_caps.szPname);
if (strcasecmp(devname, in_caps.szPname) == 0) {
if (FLUID_STRCASECMP(devname, in_caps.szPname) == 0) {
FLUID_LOG(FLUID_DBG, "Selected midi device number: %d\n", i);
midi_num = i;
break;

View file

@ -211,7 +211,7 @@ fluid_seq_dotrace(fluid_sequencer_t* seq, char *fmt, ...)
if (remain <= 0) return;
va_start (args, fmt);
len = vsnprintf(seq->traceptr, remain, fmt, args);
len = FLUID_VSNPRINTF (seq->traceptr, remain, fmt, args);
va_end (args);
if (len > 0) {

View file

@ -111,7 +111,7 @@ fluid_adsr_env_set_data(fluid_adsr_env_t* env,
fluid_real_t min,
fluid_real_t max);
static inline void
static FLUID_INLINE void
fluid_adsr_env_reset(fluid_adsr_env_t* env)
{
env->count = 0;
@ -119,25 +119,25 @@ fluid_adsr_env_reset(fluid_adsr_env_t* env)
env->val = 0.0f;
}
static inline fluid_real_t
static FLUID_INLINE fluid_real_t
fluid_adsr_env_get_val(fluid_adsr_env_t* env)
{
return env->val;
}
static inline void
static FLUID_INLINE void
fluid_adsr_env_set_val(fluid_adsr_env_t* env, fluid_real_t val)
{
env->val = val;
}
static inline fluid_adsr_env_section_t
static FLUID_INLINE fluid_adsr_env_section_t
fluid_adsr_env_get_section(fluid_adsr_env_t* env)
{
return env->section;
}
static inline void
static FLUID_INLINE void
fluid_adsr_env_set_section(fluid_adsr_env_t* env,
fluid_adsr_env_section_t section)
{
@ -148,7 +148,7 @@ fluid_adsr_env_set_section(fluid_adsr_env_t* env,
/* Used for determining which voice to kill.
Returns max amplitude from now, and forward in time.
*/
static inline fluid_real_t
static FLUID_INLINE fluid_real_t
fluid_adsr_env_get_max_val(fluid_adsr_env_t* env)
{
if (env->section > FLUID_VOICE_ENVATTACK){

View file

@ -174,7 +174,7 @@ fluid_iir_filter_set_q_dB(fluid_iir_filter_t* iir_filter,
}
static inline void
static FLUID_INLINE void
fluid_iir_filter_calculate_coefficients(fluid_iir_filter_t* iir_filter,
int transition_samples,
fluid_real_t output_rate)

View file

@ -21,7 +21,7 @@
#ifndef _FLUID_LFO_H
#define _FLUID_LFO_H
#include "fluidsynth_priv.h"
#include "fluid_sys.h"
typedef struct _fluid_lfo_t fluid_lfo_t;
@ -31,7 +31,7 @@ struct _fluid_lfo_t {
fluid_real_t increment; /* the lfo frequency is converted to a per-buffer increment */
};
static inline void
static FLUID_INLINE void
fluid_lfo_reset(fluid_lfo_t* lfo)
{
lfo->val = 0.0f;
@ -41,13 +41,13 @@ fluid_lfo_reset(fluid_lfo_t* lfo)
void fluid_lfo_set_incr(fluid_lfo_t* lfo, fluid_real_t increment);
void fluid_lfo_set_delay(fluid_lfo_t* lfo, unsigned int delay);
static inline fluid_real_t
static FLUID_INLINE fluid_real_t
fluid_lfo_get_val(fluid_lfo_t* lfo)
{
return lfo->val;
}
static inline void
static FLUID_INLINE void
fluid_lfo_calc(fluid_lfo_t* lfo, unsigned int cur_delay)
{
if (cur_delay < lfo->delay)

View file

@ -25,7 +25,7 @@
/**
* @return -1 if voice has finished, 0 if it's currently quiet, 1 otherwise
*/
static inline int
static FLUID_INLINE int
fluid_rvoice_calc_amp(fluid_rvoice_t* voice)
{
fluid_real_t target_amp; /* target amplitude */
@ -371,7 +371,7 @@ fluid_rvoice_write (fluid_rvoice_t* voice, fluid_real_t *dsp_buf)
}
static inline fluid_real_t*
static FLUID_INLINE fluid_real_t*
get_dest_buf(fluid_rvoice_buffers_t* buffers, int index,
fluid_real_t** dest_bufs, int dest_bufcount)
{

View file

@ -940,7 +940,7 @@ fluid_rvoice_mixer_set_threads(fluid_rvoice_mixer_t* mixer, int thread_count,
if (!fluid_mixer_buffers_init(b, mixer))
return;
fluid_atomic_int_set(&b->ready, THREAD_BUF_NODATA);
g_snprintf (name, sizeof (name), "mixer%d", i);
FLUID_SNPRINTF (name, sizeof (name), "mixer%d", i);
b->thread = new_fluid_thread(name, fluid_mixer_thread_func, b, prio_level, 0);
if (!b->thread)
return;

View file

@ -80,7 +80,7 @@ static int fluid_synth_update_polyphony(fluid_synth_t* synth,
char* name, int value);
static int fluid_synth_update_polyphony_LOCAL(fluid_synth_t* synth, int new_polyphony);
static void init_dither(void);
static inline int roundi (float x);
static FLUID_INLINE int roundi (float x);
static int fluid_synth_render_blocks(fluid_synth_t* synth, int blockcount);
static fluid_voice_t* fluid_synth_free_voice_by_kill_LOCAL(fluid_synth_t* synth);
@ -2898,7 +2898,7 @@ init_dither(void)
}
/* A portable replacement for roundf(), seems it may actually be faster too! */
static inline int
static FLUID_INLINE int
roundi (float x)
{
if (x >= 0.0f)
@ -4946,7 +4946,7 @@ fluid_synth_tuning_dump(fluid_synth_t* synth, int bank, int prog,
{
if (name)
{
snprintf (name, len - 1, "%s", fluid_tuning_get_name (tuning));
FLUID_SNPRINTF (name, len - 1, "%s", fluid_tuning_get_name (tuning));
name[len - 1] = 0; /* make sure the string is null terminated */
}

View file

@ -104,7 +104,7 @@ fluid_voice_get_lower_boundary_for_attenuation(fluid_voice_t* voice);
#define UPDATE_RVOICE_ENVLFO_R1(proc, envp, rarg) UPDATE_RVOICE_GENERIC_R1(proc, &voice->rvoice->envlfo.envp, rarg)
#define UPDATE_RVOICE_ENVLFO_I1(proc, envp, iarg) UPDATE_RVOICE_GENERIC_I1(proc, &voice->rvoice->envlfo.envp, iarg)
static inline void
static FLUID_INLINE void
fluid_voice_update_volenv(fluid_voice_t* voice,
fluid_adsr_env_section_t section,
unsigned int count,
@ -120,7 +120,7 @@ fluid_voice_update_volenv(fluid_voice_t* voice,
coeff, increment, min, max);
}
static inline void
static FLUID_INLINE void
fluid_voice_update_modenv(fluid_voice_t* voice,
fluid_adsr_env_section_t section,
unsigned int count,
@ -134,7 +134,7 @@ fluid_voice_update_modenv(fluid_voice_t* voice,
coeff, increment, min, max);
}
static inline void fluid_sample_null_ptr(fluid_sample_t** sample)
static FLUID_INLINE void fluid_sample_null_ptr(fluid_sample_t** sample)
{
if (*sample != NULL) {
fluid_sample_decr_ref(*sample);

View file

@ -123,7 +123,7 @@ void fluid_dsp_float_config (void)
}
static inline int
static FLUID_INLINE int
fluid_voice_is_looping(fluid_voice_t *voice)
{
return _SAMPLEMODE (voice) == FLUID_LOOP_DURING_RELEASE

View file

@ -112,7 +112,7 @@ fluid_rvoice_handler_remove_voice(fluid_rvoice_handler_t* handler, int index)
* @return Number of samples written
*/
#if 0
static inline int
static FLUID_INLINE int
fluid_rvoice_handler_write_one(fluid_rvoice_handler_t* handler, int index,
fluid_real_t* buf, int blockcount)
{
@ -137,7 +137,7 @@ fluid_rvoice_handler_write_one(fluid_rvoice_handler_t* handler, int index,
* voice has been finished, removed and possibly replaced with another voice.
* @return Number of samples written
*/
static inline int
static FLUID_INLINE int
fluid_rvoice_handler_mix_one(fluid_rvoice_handler_t* handler, int index,
fluid_real_t** bufs, unsigned int blockcount, unsigned int bufcount)
{
@ -166,7 +166,7 @@ fluid_rvoice_handler_mix_one(fluid_rvoice_handler_t* handler, int index,
return result;
}
static inline void
static FLUID_INLINE void
fluid_resetbufs(int blockcount, int bufcount, fluid_real_t** bufs)
{
int i;
@ -177,7 +177,7 @@ fluid_resetbufs(int blockcount, int bufcount, fluid_real_t** bufs)
/**
* Single-threaded scenario, no worker threads
*/
static inline void
static FLUID_INLINE void
fluid_rvoice_handler_render_loop_simple(fluid_rvoice_handler_t* handler,
int blockcount, int bufcount, fluid_real_t** bufs)
{

View file

@ -66,7 +66,7 @@ fluid_rvoice_handler_get_finished_voices(fluid_rvoice_handler_t* handler,
return handler->finished_voices;
}
static inline void
static FLUID_INLINE void
fluid_rvoice_handler_clear_finished_voices(fluid_rvoice_handler_t* handler)
{
handler->finished_voice_count = 0;

View file

@ -136,7 +136,7 @@ spaced_primes_closest (unsigned int num)
* save insertions from having to compute the hash record again for
* the new record.
*/
static inline fluid_hashnode_t **
static FLUID_INLINE fluid_hashnode_t **
fluid_hashtable_lookup_node (fluid_hashtable_t *hashtable, const void *key,
unsigned int *hash_return)
{
@ -316,7 +316,7 @@ fluid_hashtable_resize (fluid_hashtable_t *hashtable)
* Essentially, calls fluid_hashtable_resize() if the table has strayed
* too far from its ideal size for its number of nodes.
*/
static inline void
static FLUID_INLINE void
fluid_hashtable_maybe_resize (fluid_hashtable_t *hashtable)
{
int nnodes = hashtable->nnodes;

View file

@ -96,7 +96,7 @@ int fluid_debug(int level, char * fmt, ...)
va_list args;
va_start (args, fmt);
vsnprintf(fluid_errbuf, sizeof (fluid_errbuf), fmt, args);
FLUID_VSNPRINTF (fluid_errbuf, sizeof (fluid_errbuf), fmt, args);
va_end (args);
fun = fluid_log_function[FLUID_DBG];
@ -220,7 +220,7 @@ fluid_log(int level, const char* fmt, ...)
va_list args;
va_start (args, fmt);
vsnprintf(fluid_errbuf, sizeof (fluid_errbuf), fmt, args);
FLUID_VSNPRINTF (fluid_errbuf, sizeof (fluid_errbuf), fmt, args);
va_end (args);
if ((level >= 0) && (level < LAST_LOG_LEVEL)) {
@ -834,7 +834,7 @@ fluid_istream_readline (fluid_istream_t in, fluid_ostream_t out, char* prompt,
if (line == NULL)
return -1;
snprintf(buf, len, "%s", line);
FLUID_SNPRINTF (buf, len, "%s", line);
buf[len - 1] = 0;
free(line);
@ -916,7 +916,7 @@ fluid_ostream_printf (fluid_ostream_t out, char* format, ...)
int len;
va_start (args, format);
len = vsnprintf (buf, 4095, format, args);
len = FLUID_VSNPRINTF (buf, 4095, format, args);
va_end (args);
if (len == 0)

View file

@ -122,8 +122,6 @@
#ifdef MINGW32
#include <stdint.h>
#define snprintf _snprintf
#define vsnprintf _vsnprintf
#define DSOUND_SUPPORT 1
#define WINMIDI_SUPPORT 1
@ -236,15 +234,35 @@ typedef FILE* fluid_file;
#define FLUID_STRNCPY(_dst,_src,_n) strncpy(_dst,_src,_n)
#define FLUID_STRCHR(_s,_c) strchr(_s,_c)
#define FLUID_STRRCHR(_s,_c) strrchr(_s,_c)
#ifdef strdup
#define FLUID_STRDUP(s) strdup(s)
#else
#define FLUID_STRDUP(s) FLUID_STRCPY(FLUID_MALLOC(FLUID_STRLEN(s) + 1), s)
#endif
#define FLUID_SPRINTF sprintf
#define FLUID_SNPRINTF snprintf
#define FLUID_FPRINTF fprintf
#if (defined(WIN32) && _MSC_VER < 1900) || defined(MINGW32)
#define FLUID_SNPRINTF _snprintf
#else
#define FLUID_SNPRINTF snprintf
#endif
#if (defined(WIN32) && _MSC_VER < 1500) || defined(MINGW32)
#define FLUID_VSNPRINTF _vsnprintf
#else
#define FLUID_VSNPRINTF vsnprintf
#endif
#if defined(WIN32) && !defined(MINGW32)
#define FLUID_STRCASECMP _stricmp
#else
#define FLUID_STRCASECMP strcasecmp
#endif
#define fluid_clip(_val, _min, _max) \
{ (_val) = ((_val) < (_min))? (_min) : (((_val) > (_max))? (_max) : (_val)); }