From c80e7519800611278402fa1dfd5dc119b9ee3e2e Mon Sep 17 00:00:00 2001 From: Element Green Date: Sat, 30 Aug 2003 00:55:23 +0000 Subject: [PATCH] A bunch of patches and fixes from FluidSynth users. --- fluidsynth/ChangeLog | 18 ++++++++++++ fluidsynth/src/fluid_cmd.c | 26 ++++++++++------- fluidsynth/src/fluid_defsfont.c | 1 + fluidsynth/src/fluid_midi.c | 50 +++++++++++++++++--------------- fluidsynth/src/fluid_ramsfont.c | 1 + fluidsynth/src/fluid_sys.c | 2 +- fluidsynth/src/fluidsynth_priv.h | 2 +- 7 files changed, 64 insertions(+), 36 deletions(-) diff --git a/fluidsynth/ChangeLog b/fluidsynth/ChangeLog index d46f18ef..40ed70fe 100644 --- a/fluidsynth/ChangeLog +++ b/fluidsynth/ChangeLog @@ -1,3 +1,21 @@ +2003-08-29 Josh Green + + * src/fluid_sys.c: Patch from Eric Van Buggenhaut to make i386 asm + code not compile for all non-i386 archs rather than just DARWIN. + * src/fluidsynth_priv.h: Patch from Sergey Pavlishin to fix + FLUID_REALLOC macro. + * src/fluid_cmd.c: Ken Ellinwood's patch to add -verbose to "channels" + command, and print settings values with 3 decimal places. + * src/fluid_defsfont.c (fluid_defsfont_sfont_get_preset): Ken + Ellinwood's patch to initialize sfont field of preset. + * src/fluid_ramsfont.c (fluid_ramsfont_sfont_get_preset): Ken + Ellinwood's patch to initialize sfont field of preset. + * src/fluid_midi.c (fluid_midi_file_read_event): Fixed a crash bug with + zero length MIDI meta events that was pointed out by Sergey Pavlishin. + (delete_fluid_midi_event): Fixed a stack overflow problem pointed out + by Sergey Pavlishin that was caused by recursively deleting MIDI + event linked list, now just using a while loop. + 2003-08-25 Josh Green * src/fluidsynth.c: MIDI channels switch should be -K not -L as was diff --git a/fluidsynth/src/fluid_cmd.c b/fluidsynth/src/fluid_cmd.c index e1157bf1..5051e890 100644 --- a/fluidsynth/src/fluid_cmd.c +++ b/fluidsynth/src/fluid_cmd.c @@ -73,7 +73,7 @@ fluid_cmd_t fluid_commands[] = { { "inst", "general", (fluid_cmd_func_t) fluid_handle_inst, NULL, "inst font Print out the available instruments for the font" }, { "channels", "general", (fluid_cmd_func_t) fluid_handle_channels, NULL, - "channels Print out preset of all channels" }, + "channels [-verbose] Print out preset of all channels" }, { "interp", "general", (fluid_cmd_func_t) fluid_handle_interp, NULL, "interp num Choose interpolation method for all channels" }, { "interpc", "general", (fluid_cmd_func_t) fluid_handle_interpc, NULL, @@ -480,15 +480,19 @@ fluid_handle_channels(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t o { int i; fluid_preset_t* preset; - + int verbose = 0; + + if (ac > 0 && strcmp( av[0], "-verbose") == 0) verbose = 1; + for (i = 0; i < fluid_synth_count_midi_channels(synth); i++) { preset = fluid_synth_get_channel_preset(synth, i); - if (preset != NULL) { - fluid_ostream_printf(out, "chan %d, %s\n", - i, fluid_preset_get_name(preset)); - } else { - fluid_ostream_printf(out, "chan %d, no preset\n", i); - } + if (preset == NULL) fluid_ostream_printf(out, "chan %d, no preset\n", i); + else if (!verbose) fluid_ostream_printf(out, "chan %d, %s\n", i, fluid_preset_get_name(preset)); + else fluid_ostream_printf(out, "chan %d, sfont %d, bank %d, preset %d, %s\n", i, + fluid_sfont_get_id( preset->sfont), + fluid_preset_get_banknum(preset), + fluid_preset_get_num(preset), + fluid_preset_get_name(preset)); } return 0; } @@ -1180,7 +1184,7 @@ fluid_handle_get(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) case FLUID_NUM_TYPE: { double value; fluid_synth_getnum(synth, av[0], &value); - fluid_ostream_printf(out, "%f", value); + fluid_ostream_printf(out, "%.3f", value); break; } @@ -1237,7 +1241,7 @@ static void fluid_handle_settings_iter2(void* data, char* name, int type) case FLUID_NUM_TYPE: { double value; fluid_synth_getnum(d->synth, name, &value); - fluid_ostream_printf(d->out, "%f\n", value); + fluid_ostream_printf(d->out, "%.3f\n", value); break; } @@ -1311,7 +1315,7 @@ fluid_handle_info(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out) fluid_settings_getnum(settings, av[0], &value); fluid_ostream_printf(out, "%s:\n", av[0]); fluid_ostream_printf(out, "Type: number\n"); - fluid_ostream_printf(out, "Value: %f\n", value); + fluid_ostream_printf(out, "Value: %.3f\n", value); fluid_ostream_printf(out, "Minimum value: %.3f\n", min); fluid_ostream_printf(out, "Maximum value: %.3f\n", max); fluid_ostream_printf(out, "Default value: %.3f\n", diff --git a/fluidsynth/src/fluid_defsfont.c b/fluidsynth/src/fluid_defsfont.c index 6a254075..5aee342f 100644 --- a/fluidsynth/src/fluid_defsfont.c +++ b/fluidsynth/src/fluid_defsfont.c @@ -127,6 +127,7 @@ fluid_defsfont_sfont_get_preset(fluid_sfont_t* sfont, unsigned int bank, unsigne return NULL; } + preset->sfont = sfont; preset->data = defpreset; preset->free = fluid_defpreset_preset_delete; preset->get_name = fluid_defpreset_preset_get_name; diff --git a/fluidsynth/src/fluid_midi.c b/fluidsynth/src/fluid_midi.c index 7207ade5..f056545a 100644 --- a/fluidsynth/src/fluid_midi.c +++ b/fluidsynth/src/fluid_midi.c @@ -442,29 +442,29 @@ int fluid_midi_file_read_event(fluid_midi_file* mf, fluid_track_t* track) return FLUID_FAILED; } - if (mf->varlen) { - - if (mf->varlen < 255) { - metadata = &static_buf[0]; - } else { - FLUID_LOG(FLUID_DBG, "%s: %d: alloc metadata, len = %d", __FILE__, __LINE__, mf->varlen); - dyn_buf = FLUID_MALLOC(mf->varlen + 1); - if (dyn_buf == NULL) { - FLUID_LOG(FLUID_PANIC, "Out of memory"); - return FLUID_FAILED; - } - metadata = dyn_buf; - } - - /* read the data */ - if (fluid_midi_file_read(mf, metadata, mf->varlen) != FLUID_OK) { - if (dyn_buf) { - FLUID_FREE(dyn_buf); - } + if (mf->varlen < 255) { + metadata = &static_buf[0]; + } else { + FLUID_LOG(FLUID_DBG, "%s: %d: alloc metadata, len = %d", __FILE__, __LINE__, mf->varlen); + dyn_buf = FLUID_MALLOC(mf->varlen + 1); + if (dyn_buf == NULL) { + FLUID_LOG(FLUID_PANIC, "Out of memory"); return FLUID_FAILED; } + metadata = dyn_buf; } + /* read the data */ + if (mf->varlen) + { + if (fluid_midi_file_read(mf, metadata, mf->varlen) != FLUID_OK) { + if (dyn_buf) { + FLUID_FREE(dyn_buf); + } + return FLUID_FAILED; + } + } + /* handle meta data */ switch (type) { @@ -684,10 +684,14 @@ fluid_midi_event_t* new_fluid_midi_event() */ int delete_fluid_midi_event(fluid_midi_event_t* evt) { - if (evt->next != NULL) { - delete_fluid_midi_event(evt->next); - } - FLUID_FREE(evt); + fluid_midi_event_t *temp; + + while (evt) + { + temp = evt->next; + FLUID_FREE(evt); + evt = temp; + } return FLUID_OK; } diff --git a/fluidsynth/src/fluid_ramsfont.c b/fluidsynth/src/fluid_ramsfont.c index 8a011890..631feed6 100644 --- a/fluidsynth/src/fluid_ramsfont.c +++ b/fluidsynth/src/fluid_ramsfont.c @@ -115,6 +115,7 @@ fluid_preset_t* fluid_ramsfont_sfont_get_preset(fluid_sfont_t* sfont, unsigned i return NULL; } + preset->sfont = sfont; preset->data = rampreset; preset->free = fluid_rampreset_preset_delete; preset->get_name = fluid_rampreset_preset_get_name; diff --git a/fluidsynth/src/fluid_sys.c b/fluidsynth/src/fluid_sys.c index 30b1af72..512a760c 100644 --- a/fluidsynth/src/fluid_sys.c +++ b/fluidsynth/src/fluid_sys.c @@ -704,7 +704,7 @@ double fluid_utime(void) return (rdtsc() / fluid_cpu_frequency); } -#if defined(DARWIN) +#if !defined(__i386__) double rdtsc(void) { diff --git a/fluidsynth/src/fluidsynth_priv.h b/fluidsynth/src/fluidsynth_priv.h index 52e10f4d..0d7176dc 100644 --- a/fluidsynth/src/fluidsynth_priv.h +++ b/fluidsynth/src/fluidsynth_priv.h @@ -247,7 +247,7 @@ typedef struct _fluid_server_socket_t fluid_server_socket_t; typedef FILE* fluid_file; #define FLUID_MALLOC(_n) malloc(_n) -#define FLUID_REALLOC(_n) realloc(_p,_n) +#define FLUID_REALLOC(_p,_n) realloc(_p,_n) #define FLUID_NEW(_t) (_t*)malloc(sizeof(_t)) #define FLUID_ARRAY(_t,_n) (_t*)malloc((_n)*sizeof(_t)) #define FLUID_FREE(_p) free(_p)