This is a stripped down version of fluidsynth (library only)
from git://github.com/FluidSynth/fluidsynth.git
-rev. v2.0.3-16-g8b18205
+rev. v2.0.4-32-g5f8fa6f5
fluidsynth is licensed in terms of the LGPL-2+, see individual source
files for (C) holders.
#define FLUIDSYNTH_VERSION_MAJOR 2
#define FLUIDSYNTH_VERSION_MINOR 0
-#define FLUIDSYNTH_VERSION_MICRO 2
-#define FLUIDSYNTH_VERSION "2.0.2"
+#define FLUIDSYNTH_VERSION_MICRO 4
+#define FLUIDSYNTH_VERSION "2.0.4"
/* Define to enable ALSA driver */
/* #undef ALSA_SUPPORT */
/* #undef TRAP_ON_FPE */
/* Version number of package */
-#define VERSION "1.1.6"
+#define VERSION "2.0.4"
/* Define to do all DSP in single floating point precision */
/* #undef WITH_FLOAT */
for(i = 0; i < GEN_LAST; i++)
{
chan->gen[i] = 0.0f;
- chan->gen_abs[i] = 0;
}
if(is_all_ctrl_off)
* applied to future notes. They are copied to a voice's generators
* in fluid_voice_init(), which calls fluid_gen_init(). */
fluid_real_t gen[GEN_LAST];
-
- /* By default, the NRPN values are relative to the values of the
- * generators set in the SoundFont. For example, if the NRPN
- * specifies an attack of 100 msec then 100 msec will be added to the
- * combined attack time of the sound font and the modulators.
- *
- * However, it is useful to be able to specify the generator value
- * absolutely, completely ignoring the generators of the SoundFont
- * and the values of modulators. The gen_abs field, is a boolean
- * flag indicating whether the NRPN value is absolute or not.
- */
- char gen_abs[GEN_LAST];
};
fluid_channel_t *new_fluid_channel(fluid_synth_t *synth, int num);
#define fluid_channel_legato(_c) ((_c)->cc[LEGATO_SWITCH] >= 64)
#define fluid_channel_sustained(_c) ((_c)->cc[SUSTAIN_SWITCH] >= 64)
#define fluid_channel_sostenuto(_c) ((_c)->cc[SOSTENUTO_SWITCH] >= 64)
-#define fluid_channel_set_gen(_c, _n, _v, _a) { (_c)->gen[_n] = _v; (_c)->gen_abs[_n] = _a; }
+#define fluid_channel_set_gen(_c, _n, _v) { (_c)->gen[_n] = _v; }
#define fluid_channel_get_gen(_c, _n) ((_c)->gen[_n])
-#define fluid_channel_get_gen_abs(_c, _n) ((_c)->gen_abs[_n])
#define fluid_channel_get_min_note_length_ticks(chan) \
((chan)->synth->min_note_length_ticks)
*/
#include "fluid_conv.h"
+#include "fluid_sys.h"
#include "fluid_conv_tables.c"
/*
while(p != NULL)
{
sfzone = (SFZone *)fluid_list_get(p);
- FLUID_SNPRINTF(zone_name, sizeof(zone_name), "%s/%d", defpreset->name, count);
+ FLUID_SNPRINTF(zone_name, sizeof(zone_name), "pz:%s/%d", defpreset->name, count);
zone = new_fluid_preset_zone(zone_name);
if(zone == NULL)
/* Flag all generators as unused (default, they will be set when they are found
* in the sound font).
* This also sets the generator values to default, but that is of no concern here.*/
- fluid_gen_set_default_values(&zone->gen[0]);
+ fluid_gen_init(&zone->gen[0], NULL);
zone->mod = NULL; /* list of modulators */
return zone;
}
if(zone->inst == NULL)
{
- zone->inst = fluid_inst_import_sfont(zone, sfinst, defsfont);
+ zone->inst = fluid_inst_import_sfont(sfinst, defsfont);
}
if(zone->inst == NULL)
* fluid_inst_import_sfont
*/
fluid_inst_t *
-fluid_inst_import_sfont(fluid_preset_zone_t *preset_zone, SFInst *sfinst, fluid_defsfont_t *defsfont)
+fluid_inst_import_sfont(SFInst *sfinst, fluid_defsfont_t *defsfont)
{
fluid_list_t *p;
fluid_inst_t *inst;
{
sfzone = (SFZone *)fluid_list_get(p);
- /* integrates preset zone name in instrument zone name */
- FLUID_SNPRINTF(zone_name, sizeof(zone_name), "%s/%s/%d", preset_zone->name,
- inst->name, count);
+ /* instrument zone name */
+ FLUID_SNPRINTF(zone_name, sizeof(zone_name), "iz:%s/%d", inst->name, count);
inst_zone = new_fluid_inst_zone(zone_name);
zone->range.ignore = FALSE;
/* Flag the generators as unused.
* This also sets the generator values to default, but they will be overwritten anyway, if used.*/
- fluid_gen_set_default_values(&zone->gen[0]);
+ fluid_gen_init(&zone->gen[0], NULL);
zone->mod = NULL; /* list of modulators */
return zone;
}
};
fluid_inst_t *new_fluid_inst(void);
-fluid_inst_t *fluid_inst_import_sfont(fluid_preset_zone_t *preset_zone, SFInst *sfinst, fluid_defsfont_t *defsfont);
+fluid_inst_t *fluid_inst_import_sfont(SFInst *sfinst, fluid_defsfont_t *defsfont);
void delete_fluid_inst(fluid_inst_t *inst);
int fluid_inst_set_global_zone(fluid_inst_t *inst, fluid_inst_zone_t *zone);
int fluid_inst_add_zone(fluid_inst_t *inst, fluid_inst_zone_t *zone);
{ GEN_CUSTOM_FILTERQ, 1, 1, 0.0f, 960.0f, 0.0f }
};
-
-/**
- * Set an array of generators to their default values.
- * @param gen Array of generators (should be #GEN_LAST in size).
- * @return Always returns #FLUID_OK
- */
-int
-fluid_gen_set_default_values(fluid_gen_t *gen)
-{
- int i;
-
- for(i = 0; i < GEN_LAST; i++)
- {
- gen[i].flags = GEN_UNUSED;
- gen[i].mod = 0.0;
- gen[i].nrpn = 0.0;
- gen[i].val = fluid_gen_info[i].def;
- }
-
- return FLUID_OK;
-}
-
-
/* fluid_gen_init
*
* Set an array of generators to their initial value
*/
-int
+void
fluid_gen_init(fluid_gen_t *gen, fluid_channel_t *channel)
{
int i;
- fluid_gen_set_default_values(gen);
-
for(i = 0; i < GEN_LAST; i++)
{
- gen[i].nrpn = fluid_channel_get_gen(channel, i);
-
- /* This is an extension to the SoundFont standard. More
- * documentation is available at the fluid_synth_set_gen2()
- * function. */
- if(fluid_channel_get_gen_abs(channel, i))
- {
- gen[i].flags = GEN_ABS_NRPN;
- }
+ gen[i].flags = GEN_UNUSED;
+ gen[i].mod = 0.0;
+ gen[i].nrpn = (channel == NULL) ? 0.0 : fluid_channel_get_gen(channel, i);
+ gen[i].val = fluid_gen_info[i].def;
}
-
- return FLUID_OK;
}
fluid_real_t fluid_gen_scale(int gen, float value)
char nrpn_scale; /* The scale to convert from NRPN (cfr. fluid_gen_map_nrpn()) */
float min; /* The minimum value */
float max; /* The maximum value */
- float def; /* The default value (cfr. fluid_gen_set_default_values()) */
+ float def; /* The default value (cfr. fluid_gen_init()) */
} fluid_gen_info_t;
/*
{
GEN_UNUSED, /**< Generator value is not set */
GEN_SET, /**< Generator value is set */
- GEN_ABS_NRPN /**< Generator is an absolute value */
};
#define fluid_gen_set_mod(_gen, _val) { (_gen)->mod = (double) (_val); }
fluid_real_t fluid_gen_scale(int gen, float value);
fluid_real_t fluid_gen_scale_nrpn(int gen, int nrpn);
-int fluid_gen_init(fluid_gen_t *gen, fluid_channel_t *channel);
-int fluid_gen_set_default_values(fluid_gen_t *gen);
+void fluid_gen_init(fluid_gen_t *gen, fluid_channel_t *channel);
#endif /* _FLUID_GEN_H */
* MT safe
*/
-#include "fluidsynth_priv.h"
+#include "fluid_sys.h"
#include "fluid_hash.h"
#include "fluid_list.h"
* Note: This rewinds the file to the start before reading.
* Returns NULL if there was an error reading or allocating memory.
*/
+typedef FILE *fluid_file;
static char *fluid_file_read_full(fluid_file fp, size_t *length);
static void fluid_midi_event_set_sysex_LOCAL(fluid_midi_event_t *evt, int type, void *data, int size, int dynamic);
static void fluid_midi_event_get_sysex_LOCAL(fluid_midi_event_t *evt, void **data, int *size);
*/
int fluid_is_midifile(const char *filename)
{
- FILE *fp = FLUID_FOPEN(filename, "rb");
+ FILE *fp;
uint32_t id;
int retcode = FALSE;
do
{
- if(fp == NULL)
+ if(!fluid_file_test(filename, G_FILE_TEST_IS_REGULAR))
{
return retcode;
}
-
+
+ // file seems to exist and is a regular file or a symlink to such
+ if((fp = FLUID_FOPEN(filename, "rb")) == NULL)
+ {
+ return retcode;
+ }
+
if(FLUID_FREAD(&id, sizeof(id), 1, fp) != 1)
{
break;
*/
#include "fluid_ringbuffer.h"
-#include "fluidsynth_priv.h"
+#include "fluid_sys.h"
/**
* 02110-1301, USA
*/
-#include "fluidsynth_priv.h"
+#include "fluid_sys.h"
#include "fluid_phase.h"
#include "fluid_rvoice.h"
-#include "fluid_sys.h"
#include "fluid_rvoice_dsp_tables.c"
/* Purpose:
#include "fluid_sys.h"
#include "fluid_rev.h"
#include "fluid_chorus.h"
-#include "fluidsynth_priv.h"
#include "fluid_synth.h"
#include "fluid_samplecache.h"
#include "fluid_sys.h"
-#include "fluidsynth.h"
#include "fluid_list.h"
else
{
/* path ends prematurely */
- FLUID_LOG(FLUID_WARN, "'%s' is not a node. Name of the setting was '%s'", tokens[n], name);
+ FLUID_LOG(FLUID_ERR, "'%s' is not a node. Name of the setting was '%s'", tokens[n], name);
return FLUID_FAILED;
}
}
else
{
- FLUID_LOG(FLUID_WARN, "Type mismatch on setting '%s'", name);
+ FLUID_LOG(FLUID_ERR, "Failed to register string setting '%s' as it already exists with a different type", name);
}
}
else
{
/* type mismatch */
- FLUID_LOG(FLUID_WARN, "Type mismatch on setting '%s'", name);
+ FLUID_LOG(FLUID_ERR, "Failed to register numeric setting '%s' as it already exists with a different type", name);
}
}
else
{
/* type mismatch */
- FLUID_LOG(FLUID_WARN, "Type mismatch on setting '%s'", name);
+ FLUID_LOG(FLUID_ERR, "Failed to register int setting '%s' as it already exists with a different type", name);
}
}
if((fluid_settings_get(settings, name, &node) != FLUID_OK)
|| (node->type != FLUID_STR_TYPE))
{
+ FLUID_LOG(FLUID_ERR, "Unknown string setting '%s'", name);
goto error_recovery;
}
if((fluid_settings_get(settings, name, &node) != FLUID_OK)
|| (node->type != FLUID_NUM_TYPE))
{
+ FLUID_LOG(FLUID_ERR, "Unknown numeric setting '%s'", name);
goto error_recovery;
}
if(val < setting->min || val > setting->max)
{
- FLUID_LOG(FLUID_DBG, "requested set value for %s out of range", name);
+ FLUID_LOG(FLUID_ERR, "requested set value for '%s' out of range", name);
goto error_recovery;
}
if((fluid_settings_get(settings, name, &node) != FLUID_OK)
|| (node->type != FLUID_INT_TYPE))
{
+ FLUID_LOG(FLUID_ERR, "Unknown integer parameter '%s'", name);
goto error_recovery;
}
if(val < setting->min || val > setting->max)
{
- FLUID_LOG(FLUID_DBG, "requested set value for %s out of range", name);
+ FLUID_LOG(FLUID_ERR, "requested set value for setting '%s' out of range", name);
goto error_recovery;
}
*/
int fluid_is_soundfont(const char *filename)
{
- FILE *fp = FLUID_FOPEN(filename, "rb");
+ FILE *fp;
uint32_t fcc;
int retcode = FALSE;
do
{
- if(fp == NULL)
+ if(!fluid_file_test(filename, G_FILE_TEST_IS_REGULAR))
{
return retcode;
}
-
+
+ // file seems to exist and is a regular file or a symlink to such
+ if((fp = FLUID_FOPEN(filename, "rb")) == NULL)
+ {
+ return retcode;
+ }
+
if(FLUID_FREAD(&fcc, sizeof(fcc), 1, fp) != 1)
{
break;
void *default_fopen(const char *path)
{
- return FLUID_FOPEN(path, "rb");
+ FILE* handle;
+
+ if(!fluid_file_test(path, G_FILE_TEST_EXISTS))
+ {
+ FLUID_LOG(FLUID_ERR, "fluid_sfloader_load(): Unable to load non-existent file. ('%s')", path);
+ return NULL;
+ }
+
+ if(!fluid_file_test(path, G_FILE_TEST_IS_REGULAR))
+ {
+ FLUID_LOG(FLUID_ERR, "fluid_sfloader_load(): Refusing to load non-regular file! ('%s')", path);
+ return NULL;
+ }
+
+ if((handle = FLUID_FOPEN(path, "rb")) == NULL)
+ {
+ FLUID_LOG(FLUID_ERR, "fluid_sfloader_load(): Specified file does not exists or insufficient permissions to open it! ('%s')", path);
+ return NULL;
+ }
+
+ return handle;
}
int default_fclose(void *handle)
static int fluid_synth_set_tuning_LOCAL(fluid_synth_t *synth, int chan,
fluid_tuning_t *tuning, int apply);
static void fluid_synth_set_gen_LOCAL(fluid_synth_t *synth, int chan,
- int param, float value, int absolute);
+ int param, float value);
static void fluid_synth_stop_LOCAL(fluid_synth_t *synth, unsigned int id);
* @deprecated This function is not thread-safe and does not work with multiple synths.
* It has been deprecated. It may return "" in a future release and will eventually be removed.
*/
-/* FIXME - The error messages are not thread-safe, yet. They are still stored
- * in a global message buffer (see fluid_sys.c). */
const char *
fluid_synth_error(fluid_synth_t *synth)
{
- return fluid_error();
+ return "";
}
/**
if(nrpn_select < GEN_LAST)
{
float val = fluid_gen_scale_nrpn(nrpn_select, data);
- fluid_synth_set_gen_LOCAL(synth, channum, nrpn_select, val, FALSE);
+ fluid_synth_set_gen_LOCAL(synth, channum, nrpn_select, val);
}
chan->nrpn_select = 0; /* Reset to 0 */
case RPN_CHANNEL_FINE_TUNE: /* Fine tune is 14 bit over +/-1 semitone (+/- 100 cents, 8192 = center) */
fluid_synth_set_gen_LOCAL(synth, channum, GEN_FINETUNE,
- (data - 8192) / 8192.0 * 100.0, FALSE);
+ (data - 8192) / 8192.0 * 100.0);
break;
case RPN_CHANNEL_COARSE_TUNE: /* Coarse tune is 7 bit and in semitones (64 is center) */
fluid_synth_set_gen_LOCAL(synth, channum, GEN_COARSETUNE,
- value - 64, FALSE);
+ value - 64);
break;
case RPN_TUNING_PROGRAM_CHANGE:
*/
int fluid_synth_set_gen(fluid_synth_t *synth, int chan, int param, float value)
{
- return fluid_synth_set_gen2(synth, chan, param, value, FALSE, FALSE);
-}
-
-/**
- * Set a SoundFont generator (effect) value on a MIDI channel in real-time.
- * @param synth FluidSynth instance
- * @param chan MIDI channel number (0 to MIDI channel count - 1)
- * @param param SoundFont generator ID (#fluid_gen_type)
- * @param value Offset or absolute generator value to assign to the MIDI channel
- * @param absolute FALSE to assign a relative value, TRUE to assign an absolute value
- * @param normalized FALSE if value is specified in the native units of the generator,
- * TRUE to take the value as a 0.0-1.0 range and apply it to the valid
- * generator effect range (scaled and shifted as necessary).
- * @return #FLUID_OK on success, #FLUID_FAILED otherwise
- *
- * This function allows for setting all effect parameters in real time on a
- * MIDI channel. Setting absolute to non-zero will cause the value to override
- * any generator values set in the instruments played on the MIDI channel.
- * See SoundFont 2.01 spec, paragraph 8.1.3, page 48 for details on SoundFont
- * generator parameters and valid ranges.
- */
-int
-fluid_synth_set_gen2(fluid_synth_t *synth, int chan, int param,
- float value, int absolute, int normalized)
-{
- float v;
fluid_return_val_if_fail(param >= 0 && param < GEN_LAST, FLUID_FAILED);
FLUID_API_ENTRY_CHAN(FLUID_FAILED);
- v = normalized ? fluid_gen_scale(param, value) : value;
-
- fluid_synth_set_gen_LOCAL(synth, chan, param, v, absolute);
+ fluid_synth_set_gen_LOCAL(synth, chan, param, value);
FLUID_API_RETURN(FLUID_OK);
}
/* Synthesis thread local set gen function */
static void
-fluid_synth_set_gen_LOCAL(fluid_synth_t *synth, int chan, int param, float value,
- int absolute)
+fluid_synth_set_gen_LOCAL(fluid_synth_t *synth, int chan, int param, float value)
{
fluid_voice_t *voice;
int i;
- fluid_channel_set_gen(synth->channel[chan], param, value, absolute);
+ fluid_channel_set_gen(synth->channel[chan], param, value);
for(i = 0; i < synth->polyphony; i++)
{
if(fluid_voice_get_channel(voice) == chan)
{
- fluid_voice_set_param(voice, param, value, absolute);
+ fluid_voice_set_param(voice, param, value);
}
}
}
void fluid_synth_process_event_queue(fluid_synth_t *synth);
-int fluid_synth_set_gen2(fluid_synth_t *synth, int chan,
- int param, float value,
- int absolute, int normalized);
/*
* misc
*/
#include "fluid_rtkit.h"
#endif
+#if HAVE_PTHREAD_H && !defined(WIN32)
+// Do not include pthread on windows. It includes winsock.h, which collides with ws2tcpip.h from fluid_sys.h
+// It isn't need on Windows anyway.
+#include <pthread.h>
+#endif
+
/* WIN32 HACK - Flag used to differentiate between a file descriptor and a socket.
* Should work, so long as no SOCKET or file descriptor ends up with this bit set. - JG */
#ifdef _WIN32
static int fluid_istream_gets(fluid_istream_t in, char *buf, int len);
-
-static char fluid_errbuf[512]; /* buffer for error message */
-
static fluid_log_function_t fluid_log_function[LAST_LOG_LEVEL] =
{
fluid_default_log_function,
int
fluid_log(int level, const char *fmt, ...)
{
- fluid_log_function_t fun = NULL;
-
- va_list args;
- va_start(args, fmt);
- FLUID_VSNPRINTF(fluid_errbuf, sizeof(fluid_errbuf), fmt, args);
- va_end(args);
-
if((level >= 0) && (level < LAST_LOG_LEVEL))
{
- fun = fluid_log_function[level];
+ fluid_log_function_t fun = fluid_log_function[level];
if(fun != NULL)
{
- (*fun)(level, fluid_errbuf, fluid_log_user_data[level]);
+ char errbuf[1024];
+
+ va_list args;
+ va_start(args, fmt);
+ FLUID_VSNPRINTF(errbuf, sizeof(errbuf), fmt, args);
+ va_end(args);
+
+ (*fun)(level, errbuf, fluid_log_user_data[level]);
}
}
return token;
}
-/*
- * fluid_error
- */
-char *
-fluid_error()
-{
- return fluid_errbuf;
-}
-
/**
* Suspend the execution of the current thread for the specified amount of time.
* @param milliseconds to wait.
/* Handle write differently depending on if its a socket or file descriptor */
if(!(out & FLUID_SOCKET_FLAG))
{
- return write(out, buf, FLUID_STRLEN(buf));
+ return write(out, buf, (unsigned int)FLUID_STRLEN(buf));
}
#ifdef NETWORK_SUPPORT
/* Socket */
- retval = send(out & ~FLUID_SOCKET_FLAG, buf, FLUID_STRLEN(buf), 0);
+ retval = send(out & ~FLUID_SOCKET_FLAG, buf, (int)FLUID_STRLEN(buf), 0);
return retval != SOCKET_ERROR ? retval : -1;
#else
return -1;
/**
-
- This header contains a bunch of (mostly) system and machine
- dependent functions:
-
- - timers
- - current time in milliseconds and microseconds
- - debug logging
- - profiling
- - memory locking
- - checking for floating point exceptions
-
+ * @file fluid_sys.h
+ *
+ * This header contains a bunch of (mostly) system and machine
+ * dependent functions:
+ *
+ * - timers
+ * - current time in milliseconds and microseconds
+ * - debug logging
+ * - profiling
+ * - memory locking
+ * - checking for floating point exceptions
+ *
+ * fluidsynth's wrapper OSAL so to say; include it in .c files, be careful to include
+ * it in fluidsynth's private header files (see comment in fluid_coreaudio.c)
*/
#ifndef _FLUID_SYS_H
#include "fluidsynth_priv.h"
+#if HAVE_MATH_H
+#include <math.h>
+#endif
+
+#if HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
+#if HAVE_STDARG_H
+#include <stdarg.h>
+#endif
+
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#if HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+
+#if HAVE_SYS_MMAN_H
+#include <sys/mman.h>
+#endif
+
+#if HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
+#if HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
+#if HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+
+#if HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+
+#if HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+
+#if HAVE_NETINET_TCP_H
+#include <netinet/tcp.h>
+#endif
+
+#if HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+
+#if HAVE_LIMITS_H
+#include <limits.h>
+#endif
+
+#if HAVE_OPENMP
+#include <omp.h>
+#endif
+
+#if HAVE_IO_H
+#include <io.h> // _open(), _close(), read(), write() on windows
+#endif
+
+#if HAVE_SIGNAL_H
+#include <signal.h>
+#endif
+
+/** Integer types */
+#if HAVE_STDINT_H
+#include <stdint.h>
+
+#else
+
+/* Assume GLIB types */
+typedef gint8 int8_t;
+typedef guint8 uint8_t;
+typedef gint16 int16_t;
+typedef guint16 uint16_t;
+typedef gint32 int32_t;
+typedef guint32 uint32_t;
+typedef gint64 int64_t;
+typedef guint64 uint64_t;
+
+#endif
+
+#if defined(WIN32) && HAVE_WINDOWS_H
+//#include <winsock2.h>
+//#include <ws2tcpip.h> /* Provides also socklen_t */
+#include <windows.h>
+
+/* WIN32 special defines */
+#define STDIN_FILENO 0
+#define STDOUT_FILENO 1
+#define STDERR_FILENO 2
+
+#ifdef _MSC_VER
+#pragma warning(disable : 4244)
+#pragma warning(disable : 4101)
+#pragma warning(disable : 4305)
+#pragma warning(disable : 4996)
+#endif
+
+#endif
+
+/* Darwin special defines (taken from config_macosx.h) */
+#ifdef DARWIN
+# define MACINTOSH
+# define __Types__
+#endif
+
#ifdef LADSPA
#include <gmodule.h>
#endif
*/
#define fluid_gerror_message(err) ((err) ? err->message : "No error details")
-/* Misc */
-#if defined(__INTEL_COMPILER)
-#define FLUID_RESTRICT restrict
-#elif defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
-#define FLUID_RESTRICT __restrict__
-#elif defined(_MSC_VER) && _MSC_VER >= 1400
-#define FLUID_RESTRICT __restrict
-#else
-#warning "Dont know how this compiler handles restrict pointers, refuse to use them."
-#define FLUID_RESTRICT
-#endif
#define FLUID_INLINE inline
#define FLUID_POINTER_TO_UINT GPOINTER_TO_UINT
#define FLUID_UINT_TO_POINTER GUINT_TO_POINTER
#define FLUID_POINTER_TO_INT GPOINTER_TO_INT
#define FLUID_INT_TO_POINTER GINT_TO_POINTER
-#define FLUID_N_ELEMENTS(struct) (sizeof (struct) / sizeof (struct[0]))
-#define FLUID_MEMBER_SIZE(struct, member) ( sizeof (((struct *)0)->member) )
-
#define FLUID_IS_BIG_ENDIAN (G_BYTE_ORDER == G_BIG_ENDIAN)
#define FLUID_LE32TOH(x) GINT32_FROM_LE(x)
(uint32_t)(((uint32_t)(_d) << 24) | ((uint32_t)(_c) << 16) | ((uint32_t)(_b) << 8) | (uint32_t)(_a))
#endif
-
-#define fluid_return_if_fail(cond) \
-if(cond) \
- ; \
-else \
- return
-
-#define fluid_return_val_if_fail(cond, val) \
- fluid_return_if_fail(cond) (val)
-
-
/*
* Utility functions
*/
/* Sockets and I/O */
-fluid_istream_t fluid_get_stdin(void);
-fluid_ostream_t fluid_get_stdout(void);
int fluid_istream_readline(fluid_istream_t in, fluid_ostream_t out, char *prompt, char *buf, int len);
int fluid_ostream_printf(fluid_ostream_t out, const char *format, ...);
+#if defined(WIN32)
+typedef SOCKET fluid_socket_t;
+#else
+typedef int fluid_socket_t;
+#endif
+
/* The function should return 0 if no error occured, non-zero
otherwise. If the function return non-zero, the socket will be
closed by the server. */
fluid_ostream_t fluid_socket_get_ostream(fluid_socket_t sock);
/* File access */
+#define fluid_stat(_filename, _statbuf) g_stat((_filename), (_statbuf))
#if !GLIB_CHECK_VERSION(2, 26, 0)
/* GStatBuf has not been introduced yet, manually typedef to what they had at that time:
* https://github.com/GNOME/glib/blob/e7763678b56e3be073cc55d707a6e92fc2055ee0/glib/gstdio.h#L98-L115
*/
#if defined(WIN32) || HAVE_WINDOWS_H // somehow reliably mock G_OS_WIN32??
- #if defined (_MSC_VER) && !defined(_WIN64)
- typedef struct _stat32 fluid_stat_buf_t;
- #else
- typedef struct _stat fluid_stat_buf_t;
- #endif
+ // Any effort from our side to reliably mock GStatBuf on Windows is in vain. E.g. glib-2.16 is broken as it uses struct stat rather than struct _stat32 on Win x86.
+ // Disable it (the user has been warned by cmake).
+ #undef fluid_stat
+ #define fluid_stat(_filename, _statbuf) (-1)
+ typedef struct _fluid_stat_buf_t{int st_mtime;} fluid_stat_buf_t;
#else
- /* posix, OS/2, etc. */
- typedef struct stat fluid_stat_buf_t;
+ /* posix, OS/2, etc. */
+ typedef struct stat fluid_stat_buf_t;
#endif
#else
typedef GStatBuf fluid_stat_buf_t;
#endif
-#define fluid_stat(_filename, _statbuf) g_stat((_filename), (_statbuf))
+#define fluid_file_test g_file_test
/* Profiling */
#if WITH_PROFILING
#include "fluid_tuning.h"
-#include "fluidsynth_priv.h"
#include "fluid_sys.h"
* 02110-1301, USA
*/
-#include "fluidsynth_priv.h"
+#include "fluid_sys.h"
#include "fluid_voice.h"
#include "fluid_mod.h"
#include "fluid_chan.h"
fluid_real_t fluid_voice_gen_value(const fluid_voice_t *voice, int num)
{
- /* This is an extension to the SoundFont standard. More
- * documentation is available at the fluid_synth_set_gen2()
- * function. */
- if(voice->gen[num].flags == GEN_ABS_NRPN)
- {
- return (fluid_real_t) voice->gen[num].nrpn;
- }
- else
- {
- return (fluid_real_t)(voice->gen[num].val + voice->gen[num].mod + voice->gen[num].nrpn);
- }
+ return (fluid_real_t)(voice->gen[num].val + voice->gen[num].mod + voice->gen[num].nrpn);
}
/*
* - Add the output value to the modulation value of the generator.
*
* Note: The generators have been initialized with
- * fluid_gen_set_default_values.
+ * fluid_gen_init().
*/
for(i = 0; i < voice->mod_count; i++)
-int fluid_voice_set_param(fluid_voice_t *voice, int gen, fluid_real_t nrpn_value, int abs)
+int fluid_voice_set_param(fluid_voice_t *voice, int gen, fluid_real_t nrpn_value)
{
voice->gen[gen].nrpn = nrpn_value;
- voice->gen[gen].flags = (abs) ? GEN_ABS_NRPN : GEN_SET;
+ voice->gen[gen].flags = GEN_SET;
fluid_voice_update_param(voice, gen);
return FLUID_OK;
}
#include "fluid_lfo.h"
#include "fluid_rvoice.h"
#include "fluid_rvoice_event.h"
-#include "fluid_sys.h"
#define NO_CHANNEL 0xff
int fluid_voice_modulate_all(fluid_voice_t *voice);
/** Set the NRPN value of a generator. */
-int fluid_voice_set_param(fluid_voice_t *voice, int gen, fluid_real_t value, int abs);
+int fluid_voice_set_param(fluid_voice_t *voice, int gen, fluid_real_t value);
/** Set the gain. */
* 02110-1301, USA
*/
+/**
+ * @file fluidsynth_priv.h
+ *
+ * lightweight part of fluid_sys.h, containing forward declarations of fluidsynth's private types and private macros
+ *
+ * include this one file in fluidsynth's private header files
+ */
#ifndef _FLUIDSYNTH_PRIV_H
#define _FLUIDSYNTH_PRIV_H
#include "config.h"
-#if HAVE_STRING_H
-#include <string.h>
-#endif
-
#if HAVE_STDLIB_H
-#include <stdlib.h>
+#include <stdlib.h> // malloc, free
#endif
#if HAVE_STDIO_H
-#include <stdio.h>
-#endif
-
-#if HAVE_MATH_H
-#include <math.h>
+#include <stdio.h> // printf
#endif
-#if HAVE_ERRNO_H
-#include <errno.h>
-#endif
-
-#if HAVE_STDARG_H
-#include <stdarg.h>
-#endif
-
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#if HAVE_FCNTL_H
-#include <fcntl.h>
-#endif
-
-#if HAVE_SYS_MMAN_H
-#include <sys/mman.h>
-#endif
-
-#if HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-
-#if HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif
-
-#if HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
-
-#if HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-
-#if HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-
-#if HAVE_NETINET_TCP_H
-#include <netinet/tcp.h>
-#endif
-
-#if HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-
-#if HAVE_LIMITS_H
-#include <limits.h>
-#endif
-
-#if HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
-
-#if HAVE_OPENMP
-#include <omp.h>
-#endif
-
-#if HAVE_IO_H
-#include <io.h> // _open(), _close(), read(), write() on windows
-#endif
-
-#if HAVE_SIGNAL_H
-#include <signal.h>
-#endif
-
-/** Integer types */
-#if HAVE_STDINT_H
-#include <stdint.h>
-
-#else
-
-/* Assume GLIB types */
-typedef gint8 int8_t;
-typedef guint8 uint8_t;
-typedef gint16 int16_t;
-typedef guint16 uint16_t;
-typedef gint32 int32_t;
-typedef guint32 uint32_t;
-typedef gint64 int64_t;
-typedef guint64 uint64_t;
-
-#endif
-
-#if defined(WIN32) && HAVE_WINDOWS_H
-//#include <winsock2.h>
-//#include <ws2tcpip.h> /* Provides also socklen_t */
-#include <windows.h>
-
-/* WIN32 special defines */
-#define STDIN_FILENO 0
-#define STDOUT_FILENO 1
-#define STDERR_FILENO 2
-
-#ifdef _MSC_VER
-#pragma warning(disable : 4244)
-#pragma warning(disable : 4101)
-#pragma warning(disable : 4305)
-#pragma warning(disable : 4996)
-#endif
-
-#endif
-
-/* Darwin special defines (taken from config_macosx.h) */
-#ifdef DARWIN
-# define MACINTOSH
-# define __Types__
+#if HAVE_STRING_H
+#include <string.h>
#endif
typedef double fluid_real_t;
#endif
-
-#if defined(WIN32)
-typedef SOCKET fluid_socket_t;
-#else
-typedef int fluid_socket_t;
-#endif
-
#if defined(SUPPORTS_VLA)
# define FLUID_DECLARE_VLA(_type, _name, _len) \
_type _name[_len]
*
* SYSTEM INTERFACE
*/
-typedef FILE *fluid_file;
#define FLUID_MALLOC(_n) malloc(_n)
#define FLUID_REALLOC(_p,_n) realloc(_p,_n)
#define FLUID_LIKELY G_LIKELY
#define FLUID_UNLIKELY G_UNLIKELY
-char *fluid_error(void);
+/* Misc */
+#if defined(__INTEL_COMPILER)
+#define FLUID_RESTRICT restrict
+#elif defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
+#define FLUID_RESTRICT __restrict__
+#elif defined(_MSC_VER) && _MSC_VER >= 1400
+#define FLUID_RESTRICT __restrict
+#else
+#warning "Dont know how this compiler handles restrict pointers, refuse to use them."
+#define FLUID_RESTRICT
+#endif
+
+#define FLUID_N_ELEMENTS(struct) (sizeof (struct) / sizeof (struct[0]))
+#define FLUID_MEMBER_SIZE(struct, member) ( sizeof (((struct *)0)->member) )
+
+
+#define fluid_return_if_fail(cond) \
+if(cond) \
+ ; \
+else \
+ return
+
+#define fluid_return_val_if_fail(cond, val) \
+ fluid_return_if_fail(cond) (val)
+
#endif /* _FLUIDSYNTH_PRIV_H */
fluid_real_t fluid_ct2hz_real(fluid_real_t cents);
fluid_real_t fluid_ct2hz(fluid_real_t cents);
diff --git b/libs/fluidsynth/src/fluid_hash.c a/libs/fluidsynth/src/fluid_hash.c
-index 37b0a06a4..b6586895b 100644
+index 946a873bb..79f83a458 100644
--- b/libs/fluidsynth/src/fluid_hash.c
+++ a/libs/fluidsynth/src/fluid_hash.c
@@ -991,6 +991,7 @@ fluid_hashtable_remove_all(fluid_hashtable_t *hashtable)
/*
* fluid_hashtable_foreach_remove_or_steal:
diff --git b/libs/fluidsynth/src/fluid_midi.c a/libs/fluidsynth/src/fluid_midi.c
-index 1a394f811..8deb0b0d1 100644
+index 38c2bf6ef..73551a6d8 100644
--- b/libs/fluidsynth/src/fluid_midi.c
+++ a/libs/fluidsynth/src/fluid_midi.c
-@@ -76,7 +76,7 @@ static int fluid_midi_file_read_tracklen(fluid_midi_file *mf);
+@@ -77,7 +77,7 @@ static int fluid_midi_file_read_tracklen(fluid_midi_file *mf);
static int fluid_midi_file_eot(fluid_midi_file *mf);
static int fluid_midi_file_get_division(fluid_midi_file *midifile);
/***************************************************************
*
* MIDIFILE
-@@ -1047,6 +1047,7 @@ fluid_midi_file_get_division(fluid_midi_file *midifile)
+@@ -1054,6 +1054,7 @@ fluid_midi_file_get_division(fluid_midi_file *midifile)
{
return midifile->division;
}
/******************************************************
*
-@@ -1413,7 +1414,7 @@ static void fluid_midi_event_get_sysex_LOCAL(fluid_midi_event_t *evt, void **dat
+@@ -1420,7 +1421,7 @@ static void fluid_midi_event_get_sysex_LOCAL(fluid_midi_event_t *evt, void **dat
*
* fluid_track_t
*/
/*
* new_fluid_track
*/
-@@ -2517,3 +2518,4 @@ fluid_midi_event_length(unsigned char event)
+@@ -2524,3 +2525,4 @@ fluid_midi_event_length(unsigned char event)
return 1;
}
#ifdef DEBUG
void fluid_dump_modulator(fluid_mod_t *mod);
diff --git b/libs/fluidsynth/src/fluid_rvoice_mixer.c a/libs/fluidsynth/src/fluid_rvoice_mixer.c
-index af0ef75d1..9acc5f830 100644
+index 85c3fb914..5ea08ff6f 100644
--- b/libs/fluidsynth/src/fluid_rvoice_mixer.c
+++ a/libs/fluidsynth/src/fluid_rvoice_mixer.c
-@@ -24,7 +24,6 @@
+@@ -23,7 +23,6 @@
+ #include "fluid_sys.h"
#include "fluid_rev.h"
#include "fluid_chorus.h"
- #include "fluidsynth_priv.h"
-#include "fluid_ladspa.h"
#include "fluid_synth.h"
typedef struct _fluid_rvoice_mixer_t fluid_rvoice_mixer_t;
diff --git b/libs/fluidsynth/src/fluid_settings.c a/libs/fluidsynth/src/fluid_settings.c
-index 02be9a033..9207ab063 100644
+index 5b2b08748..181116984 100644
--- b/libs/fluidsynth/src/fluid_settings.c
+++ a/libs/fluidsynth/src/fluid_settings.c
@@ -21,9 +21,6 @@
static int
diff --git b/libs/fluidsynth/src/fluid_synth.c a/libs/fluidsynth/src/fluid_synth.c
-index 07bfc0427..b4524a2ac 100644
+index 1c7a1f272..e26772073 100644
--- b/libs/fluidsynth/src/fluid_synth.c
+++ a/libs/fluidsynth/src/fluid_synth.c
@@ -267,7 +267,7 @@ void fluid_version(int *major, int *minor, int *micro)
fluid_version_str(void)
{
return FLUIDSYNTH_VERSION;
-@@ -6442,6 +6442,7 @@ int fluid_synth_set_channel_type(fluid_synth_t *synth, int chan, int type)
+@@ -6411,6 +6411,7 @@ int fluid_synth_set_channel_type(fluid_synth_t *synth, int chan, int type)
FLUID_API_RETURN(FLUID_OK);
}
/**
* Return the LADSPA effects instance used by FluidSynth
*
-@@ -6454,6 +6455,7 @@ fluid_ladspa_fx_t *fluid_synth_get_ladspa_fx(fluid_synth_t *synth)
+@@ -6423,6 +6424,7 @@ fluid_ladspa_fx_t *fluid_synth_get_ladspa_fx(fluid_synth_t *synth)
return synth->ladspa_fx;
}
/**
* Configure a general-purpose IIR biquad filter.
diff --git b/libs/fluidsynth/src/fluid_synth.h a/libs/fluidsynth/src/fluid_synth.h
-index 156424af1..58869730c 100644
+index 46c92ccf6..9615cb1b5 100644
--- b/libs/fluidsynth/src/fluid_synth.h
+++ a/libs/fluidsynth/src/fluid_synth.h
@@ -33,8 +33,6 @@
enum fluid_iir_filter_flags custom_filter_flags; /**< filter type of the user-defined filter currently used for all voices */
};
diff --git b/libs/fluidsynth/src/fluid_sys.c a/libs/fluidsynth/src/fluid_sys.c
-index d686737f6..28911ee7f 100644
+index b85fa3fbf..bcb86bac2 100644
--- b/libs/fluidsynth/src/fluid_sys.c
+++ a/libs/fluidsynth/src/fluid_sys.c
-@@ -202,9 +202,10 @@ fluid_log(int level, const char *fmt, ...)
+@@ -205,9 +205,10 @@ fluid_log(int level, const char *fmt, ...)
* @param delim String of delimiter chars.
* @return Pointer to the next token or NULL if no more tokens.
*/
if(str == NULL || delim == NULL || !*delim)
diff --git b/libs/fluidsynth/src/fluid_sys.h a/libs/fluidsynth/src/fluid_sys.h
-index 72b323029..122938655 100644
+index 9f2d6f6c7..e3a696741 100644
--- b/libs/fluidsynth/src/fluid_sys.h
+++ a/libs/fluidsynth/src/fluid_sys.h
-@@ -99,7 +99,7 @@ else \
- /*
- * Utility functions
- */
--char *fluid_strtok(char **str, char *delim);
-+char *fluid_strtok(char **str, const char *delim);
-
-
- #if defined(__OS2__)
-diff --git b/libs/fluidsynth/src/fluidsynth_priv.h a/libs/fluidsynth/src/fluidsynth_priv.h
-index 4df590e21..384785fcc 100644
---- b/libs/fluidsynth/src/fluidsynth_priv.h
-+++ a/libs/fluidsynth/src/fluidsynth_priv.h
-@@ -26,10 +26,6 @@
-
- #include "config.h"
-
--#if defined(__POWERPC__) && !(defined(__APPLE__) && defined(__MACH__))
--#include "config_maxmsp43.h"
--#endif
--
- #if HAVE_STRING_H
- #include <string.h>
- #endif
-@@ -133,8 +129,9 @@ typedef guint64 uint64_t;
+@@ -128,8 +128,9 @@ typedef guint64 uint64_t;
#endif
#if defined(WIN32) && HAVE_WINDOWS_H
/* WIN32 special defines */
#define STDIN_FILENO 0
+@@ -187,7 +188,7 @@ typedef guint64 uint64_t;
+ /*
+ * Utility functions
+ */
+-char *fluid_strtok(char **str, char *delim);
++char *fluid_strtok(char **str, const char *delim);
+
+
+ #if defined(__OS2__)