Merge pull request #190 from FluidSynth/fluid_player

Add get tempo/bpm and get length/currentBeat to fluid_player
This commit is contained in:
Tom M 2017-08-16 10:06:18 +02:00 committed by GitHub
commit 1344059be4
2 changed files with 62 additions and 3 deletions

View file

@ -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

View file

@ -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
*