From a33e3c698d40bafcb4beec4bcf0aaf60c2997ed3 Mon Sep 17 00:00:00 2001 From: derselbst Date: Sun, 3 Jun 2018 07:13:04 +0200 Subject: [PATCH] set soundfont iteration methods on fluid_sfont_t creation --- include/fluidsynth/sfont.h | 27 +++++++++++++++++++++++++-- src/sfloader/fluid_defsfont.c | 4 ++-- src/sfloader/fluid_ramsfont.c | 9 ++++----- src/sfloader/fluid_sfont.c | 23 +++++++---------------- src/sfloader/fluid_sfont.h | 23 ----------------------- 5 files changed, 38 insertions(+), 48 deletions(-) diff --git a/include/fluidsynth/sfont.h b/include/fluidsynth/sfont.h index 86150cb9..2485c0c6 100644 --- a/include/fluidsynth/sfont.h +++ b/include/fluidsynth/sfont.h @@ -172,6 +172,26 @@ typedef const char* (*fluid_sfont_get_name_t)(fluid_sfont_t* sfont); */ typedef fluid_preset_t* (*fluid_sfont_get_preset_t)(fluid_sfont_t* sfont, int bank, int prenum); +/** + * Start virtual SoundFont preset iteration method. + * @param sfont Virtual SoundFont + * + * Starts/re-starts virtual preset iteration in a SoundFont. + */ +typedef void (*fluid_sfont_iteration_start_t)(fluid_sfont_t* sfont); + +/** + * Virtual SoundFont preset iteration function. + * @param sfont Virtual SoundFont + * @param preset Caller supplied uninitialized buffer to fill in with current preset information + * @return NULL when no more presets are available, otherwise the a pointer to the current preset + * + * Should store preset information to the caller supplied \a preset structure + * and advance the internal iteration state to the next preset for subsequent + * calls. + */ +typedef fluid_preset_t* (*fluid_sfont_iteration_next_t)(fluid_sfont_t* sfont); + /** * Method to free a virtual SoundFont bank. Any custom user provided cleanup function must ultimately call * delete_fluid_sfont() to ensure proper cleanup of the #fluid_sfont_t struct. If no private data @@ -185,8 +205,11 @@ typedef int (*fluid_sfont_free_t)(fluid_sfont_t* sfont); FLUIDSYNTH_API fluid_sfont_t* new_fluid_sfont(fluid_sfont_get_name_t get_name, - fluid_sfont_get_preset_t get_preset, - fluid_sfont_free_t free); + fluid_sfont_get_preset_t get_preset, + fluid_sfont_iteration_start_t iter_start, + fluid_sfont_iteration_next_t iter_next, + fluid_sfont_free_t free); + FLUIDSYNTH_API int delete_fluid_sfont(fluid_sfont_t* sfont); FLUIDSYNTH_API int fluid_sfont_set_data(fluid_sfont_t* sfont, void* data); diff --git a/src/sfloader/fluid_defsfont.c b/src/sfloader/fluid_defsfont.c index f6ef1794..de10542b 100644 --- a/src/sfloader/fluid_defsfont.c +++ b/src/sfloader/fluid_defsfont.c @@ -87,6 +87,8 @@ fluid_sfont_t* fluid_defsfloader_load(fluid_sfloader_t* loader, const char* file sfont = new_fluid_sfont(fluid_defsfont_sfont_get_name, fluid_defsfont_sfont_get_preset, + fluid_defsfont_sfont_iteration_start, + fluid_defsfont_sfont_iteration_next, fluid_defsfont_sfont_delete); if (sfont == NULL) { @@ -94,8 +96,6 @@ fluid_sfont_t* fluid_defsfloader_load(fluid_sfloader_t* loader, const char* file return NULL; } - fluid_sfont_set_iteration_start(sfont, fluid_defsfont_sfont_iteration_start); - fluid_sfont_set_iteration_next(sfont, fluid_defsfont_sfont_iteration_next); fluid_sfont_set_data(sfont, defsfont); defsfont->sfont = sfont; diff --git a/src/sfloader/fluid_ramsfont.c b/src/sfloader/fluid_ramsfont.c index 1d41842b..ce084a4a 100644 --- a/src/sfloader/fluid_ramsfont.c +++ b/src/sfloader/fluid_ramsfont.c @@ -92,18 +92,17 @@ fluid_ramsfont_create_sfont() sfont = new_fluid_sfont(fluid_ramsfont_sfont_get_name, fluid_ramsfont_sfont_get_preset, + fluid_ramsfont_sfont_iteration_start, + fluid_ramsfont_sfont_iteration_next, fluid_ramsfont_sfont_delete); if (sfont == NULL) { delete_fluid_ramsfont(ramsfont); return NULL; } - - ramsfont->sfont = sfont; - - fluid_sfont_set_iteration_start(sfont, fluid_ramsfont_sfont_iteration_start); - fluid_sfont_set_iteration_next(sfont, fluid_ramsfont_sfont_iteration_next); + fluid_sfont_set_data(sfont, ramsfont); + ramsfont->sfont = sfont; return sfont; } diff --git a/src/sfloader/fluid_sfont.c b/src/sfloader/fluid_sfont.c index 06c9c924..f3afed59 100644 --- a/src/sfloader/fluid_sfont.c +++ b/src/sfloader/fluid_sfont.c @@ -180,11 +180,15 @@ int fluid_sfloader_set_callbacks(fluid_sfloader_t* loader, * Creates a new virtual SoundFont instance structure. * @param get_name A function implementing #fluid_sfont_get_name_t. * @param get_preset A function implementing #fluid_sfont_get_preset_t. + * @param iter_start A function implementing #fluid_sfont_iteration_start_t, or NULL if preset iteration not needed. + * @param iter_next A function implementing #fluid_sfont_iteration_next_t, or NULL if preset iteration not needed. * @param free A function implementing #fluid_sfont_free_t. * @return The soundfont instance on success or NULL otherwise. */ fluid_sfont_t* new_fluid_sfont(fluid_sfont_get_name_t get_name, fluid_sfont_get_preset_t get_preset, + fluid_sfont_iteration_start_t iter_start, + fluid_sfont_iteration_next_t iter_next, fluid_sfont_free_t free) { fluid_sfont_t* sfont; @@ -203,6 +207,8 @@ fluid_sfont_t* new_fluid_sfont(fluid_sfont_get_name_t get_name, sfont->get_name = get_name; sfont->get_preset = get_preset; + sfont->iteration_start = iter_start; + sfont->iteration_next = iter_next; sfont->free = free; return sfont; @@ -236,22 +242,6 @@ void* fluid_sfont_get_data(fluid_sfont_t* sfont) return sfont->data; } -/** - * @internal KISS! No need to expose this to public API currently. - */ -void fluid_sfont_set_iteration_start(fluid_sfont_t* sfont, fluid_sfont_iteration_start_t iter_start) -{ - sfont->iteration_start = iter_start; -} - -/** - * @internal KISS! No need to expose this to public API currently. - */ -void fluid_sfont_set_iteration_next(fluid_sfont_t* sfont, fluid_sfont_iteration_next_t iter_next) -{ - sfont->iteration_next = iter_next; -} - /** * Retrieve the unique ID of a SoundFont instance. * @@ -277,6 +267,7 @@ const char* fluid_sfont_get_name(fluid_sfont_t* sfont) /** * Retrieve the preset assigned the a SoundFont instance * for the given bank and preset number. + * @param sfont The SoundFont instance. * @param bank bank number of the preset * @param prenum program number of the preset * @return The preset instance or NULL if none found. diff --git a/src/sfloader/fluid_sfont.h b/src/sfloader/fluid_sfont.h index bc814307..bee46bd9 100644 --- a/src/sfloader/fluid_sfont.h +++ b/src/sfloader/fluid_sfont.h @@ -83,29 +83,6 @@ struct _fluid_sfloader_t { fluid_sfloader_load_t load; }; -/** - * Start virtual SoundFont preset iteration method. - * @param sfont Virtual SoundFont - * - * Starts/re-starts virtual preset iteration in a SoundFont. - */ -typedef void (*fluid_sfont_iteration_start_t)(fluid_sfont_t* sfont); - -/** - * Virtual SoundFont preset iteration function. - * @param sfont Virtual SoundFont - * @param preset Caller supplied uninitialized buffer to fill in with current preset information - * @return NULL when no more presets are available, otherwise the a pointer to the current preset - * - * Should store preset information to the caller supplied \a preset structure - * and advance the internal iteration state to the next preset for subsequent - * calls. - */ -typedef fluid_preset_t* (*fluid_sfont_iteration_next_t)(fluid_sfont_t* sfont); - -void fluid_sfont_set_iteration_start(fluid_sfont_t* sfont, fluid_sfont_iteration_start_t iter_start); -void fluid_sfont_set_iteration_next(fluid_sfont_t* sfont, fluid_sfont_iteration_next_t iter_next); - /** * Virtual SoundFont instance structure. */