From 2f5c6dda8368d8ff9d9890175aa8fc0045cb7909 Mon Sep 17 00:00:00 2001 From: Juan Borda Date: Wed, 28 Jan 2015 15:02:28 -0500 Subject: [PATCH 1/3] Add get tempo/bpm and get length/currentBeat to fluid_player --- fluidsynth/include/fluidsynth/midi.h | 10 +++++++- fluidsynth/src/midi/fluid_midi.c | 34 ++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/fluidsynth/include/fluidsynth/midi.h b/fluidsynth/include/fluidsynth/midi.h index 90e50927..15a51f70 100644 --- a/fluidsynth/include/fluidsynth/midi.h +++ b/fluidsynth/include/fluidsynth/midi.h @@ -133,7 +133,15 @@ FLUIDSYNTH_API int fluid_player_set_midi_tempo(fluid_player_t* player, int tempo FLUIDSYNTH_API int fluid_player_set_bpm(fluid_player_t* player, int bpm); FLUIDSYNTH_API int fluid_player_get_status(fluid_player_t* player); FLUIDSYNTH_API int fluid_player_set_playback_callback(fluid_player_t* player, handle_midi_event_func_t handler, void* handler_data); - + +//additional fluid_player functions +FLUIDSYNTH_API int fluid_player_get_current_tick( fluid_player_t * player ); +FLUIDSYNTH_API int fluid_player_get_total_ticks( fluid_player_t * player ); +FLUIDSYNTH_API int fluid_player_get_bpm( fluid_player_t * player ); +FLUIDSYNTH_API int fluid_player_get_midi_tempo( fluid_player_t * player ); + +/// + #ifdef __cplusplus } #endif diff --git a/fluidsynth/src/midi/fluid_midi.c b/fluidsynth/src/midi/fluid_midi.c index 236b889b..dd0ffb51 100644 --- a/fluidsynth/src/midi/fluid_midi.c +++ b/fluidsynth/src/midi/fluid_midi.c @@ -1757,8 +1757,7 @@ int fluid_player_set_midi_tempo(fluid_player_t *player, int tempo) * @param bpm Tempo in beats per minute * @return Always returns #FLUID_OK */ -int -fluid_player_set_bpm(fluid_player_t *player, int bpm) +int fluid_player_set_bpm(fluid_player_t *player, int bpm) { return fluid_player_set_midi_tempo(player, (int) ((double) 60 * 1e6 / bpm)); } @@ -1786,6 +1785,37 @@ fluid_player_join(fluid_player_t *player) return FLUID_OK; } + +int fluid_player_get_current_tick( fluid_player_t * player ) +{ + return player->cur_ticks; +} + +int fluid_player_get_total_ticks( fluid_player_t * player ) +{ + int i; + int maxTicks = 0; + for (i = 0; i < player->ntracks; i++) { + if (player->track[i] != NULL) { + int ticks = fluid_track_get_duration( player->track[i] ); + if( ticks > maxTicks ) + maxTicks = ticks; + } + } + return maxTicks; + +} + +int fluid_player_get_bpm( fluid_player_t * player ) +{ + return (int)( 60e6 / player->miditempo ); +} + +int fluid_player_get_midi_tempo( fluid_player_t * player ) +{ + return player->miditempo; +} + /************************************************************************ * MIDI PARSER * From da1b95cb19ab10949d28e405eddacf0a24723725 Mon Sep 17 00:00:00 2001 From: Tom M Date: Wed, 16 Aug 2017 09:22:43 +0200 Subject: [PATCH 2/3] reorder function delcaration in midi.h --- fluidsynth/include/fluidsynth/midi.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/fluidsynth/include/fluidsynth/midi.h b/fluidsynth/include/fluidsynth/midi.h index 15a51f70..bd991a0a 100644 --- a/fluidsynth/include/fluidsynth/midi.h +++ b/fluidsynth/include/fluidsynth/midi.h @@ -131,14 +131,13 @@ FLUIDSYNTH_API int fluid_player_join(fluid_player_t* player); FLUIDSYNTH_API int fluid_player_set_loop(fluid_player_t* player, int loop); FLUIDSYNTH_API int fluid_player_set_midi_tempo(fluid_player_t* player, int tempo); FLUIDSYNTH_API int fluid_player_set_bpm(fluid_player_t* player, int bpm); -FLUIDSYNTH_API int fluid_player_get_status(fluid_player_t* player); FLUIDSYNTH_API int fluid_player_set_playback_callback(fluid_player_t* player, handle_midi_event_func_t handler, void* handler_data); - -//additional fluid_player functions -FLUIDSYNTH_API int fluid_player_get_current_tick( fluid_player_t * player ); -FLUIDSYNTH_API int fluid_player_get_total_ticks( fluid_player_t * player ); -FLUIDSYNTH_API int fluid_player_get_bpm( fluid_player_t * player ); -FLUIDSYNTH_API int fluid_player_get_midi_tempo( fluid_player_t * player ); + +FLUIDSYNTH_API int fluid_player_get_status(fluid_player_t* player); +FLUIDSYNTH_API int fluid_player_get_current_tick(fluid_player_t * player); +FLUIDSYNTH_API int fluid_player_get_total_ticks(fluid_player_t * player); +FLUIDSYNTH_API int fluid_player_get_bpm(fluid_player_t * player); +FLUIDSYNTH_API int fluid_player_get_midi_tempo(fluid_player_t * player); /// From 27c347a28d4b52c51d833ad6a812ff7dbf77f7a5 Mon Sep 17 00:00:00 2001 From: Tom M Date: Wed, 16 Aug 2017 09:37:35 +0200 Subject: [PATCH 3/3] add documentation to new fluid_player getters --- fluidsynth/src/midi/fluid_midi.c | 38 +++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/fluidsynth/src/midi/fluid_midi.c b/fluidsynth/src/midi/fluid_midi.c index dd0ffb51..11663ab5 100644 --- a/fluidsynth/src/midi/fluid_midi.c +++ b/fluidsynth/src/midi/fluid_midi.c @@ -1785,33 +1785,55 @@ fluid_player_join(fluid_player_t *player) return FLUID_OK; } - -int fluid_player_get_current_tick( fluid_player_t * player ) +/** + * Get the number of tempo ticks passed. + * @param player MIDI player instance + * @return The number of tempo ticks passed + * @since 1.1.7 + */ +int fluid_player_get_current_tick(fluid_player_t * player) { return player->cur_ticks; } -int fluid_player_get_total_ticks( fluid_player_t * player ) +/** + * Looks through all available MIDI tracks and gets the absolute tick of the very last event to play. + * @param player MIDI player instance + * @return Total tick count of the sequence + * @since 1.1.7 + */ +int fluid_player_get_total_ticks(fluid_player_t * player) { int i; int maxTicks = 0; for (i = 0; i < player->ntracks; i++) { if (player->track[i] != NULL) { - int ticks = fluid_track_get_duration( player->track[i] ); + int ticks = fluid_track_get_duration(player->track[i]); if( ticks > maxTicks ) maxTicks = ticks; } } return maxTicks; - } -int fluid_player_get_bpm( fluid_player_t * player ) +/** + * Get the tempo of a MIDI player in beats per minute. + * @param player MIDI player instance + * @return MIDI player tempo in BPM + * @since 1.1.7 + */ +int fluid_player_get_bpm(fluid_player_t * player) { - return (int)( 60e6 / player->miditempo ); + return (int)(60e6 / player->miditempo); } -int fluid_player_get_midi_tempo( fluid_player_t * player ) +/** + * Get the tempo of a MIDI player. + * @param player MIDI player instance + * @return Tempo of the MIDI player (in microseconds per quarter note, as per MIDI file spec) + * @since 1.1.7 + */ +int fluid_player_get_midi_tempo(fluid_player_t * player) { return player->miditempo; }