Add get tempo/bpm and get length/currentBeat to fluid_player

This commit is contained in:
Juan Borda 2015-01-28 15:02:28 -05:00 committed by derselbst
parent b92b9d64da
commit 2f5c6dda83
2 changed files with 41 additions and 3 deletions

View file

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

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