diff --git a/fluidsynth/include/fluidsynth/midi.h b/fluidsynth/include/fluidsynth/midi.h index 90e50927..bd991a0a 100644 --- a/fluidsynth/include/fluidsynth/midi.h +++ b/fluidsynth/include/fluidsynth/midi.h @@ -131,9 +131,16 @@ 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); +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); + +/// + #ifdef __cplusplus } #endif diff --git a/fluidsynth/src/midi/fluid_midi.c b/fluidsynth/src/midi/fluid_midi.c index 236b889b..11663ab5 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,59 @@ fluid_player_join(fluid_player_t *player) return FLUID_OK; } +/** + * 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; +} + +/** + * 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]); + if( ticks > maxTicks ) + maxTicks = ticks; + } + } + return maxTicks; +} + +/** + * 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); +} + +/** + * 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; +} + /************************************************************************ * MIDI PARSER *