From b3579d11282ec055a42fff56a1adcc50357d46f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Sun, 18 Oct 2020 05:57:44 +0200 Subject: Explain the ticking mechanism Took time to read. Also fix an invalid comment. --- nncmpp.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/nncmpp.c b/nncmpp.c index cf616a8..51ba3b9 100644 --- a/nncmpp.c +++ b/nncmpp.c @@ -609,7 +609,7 @@ static struct app_context struct str_map playback_info; ///< Current song info struct poller_timer elapsed_event; ///< Seconds elapsed event - int64_t elapsed_since; ///< Time of the next tick + int64_t elapsed_since; ///< Time of the last tick // TODO: initialize these to -1 int song; ///< Current song index @@ -3410,7 +3410,9 @@ mpd_update_playback_state (void) poller_timer_reset (&g.elapsed_event); if (g.state == PLAYER_PLAYING) { + // Set a timer for when the next round second of playback happens poller_timer_set (&g.elapsed_event, 1000 - msec_past_second); + // Remember when the last round second was, relative to monotonic time g.elapsed_since = clock_msec (CLOCK_BEST) - msec_past_second; } @@ -3540,12 +3542,16 @@ static void mpd_on_tick (void *user_data) { (void) user_data; + + // Compute how much time has elapsed since the last round second int64_t diff_msec = clock_msec (CLOCK_BEST) - g.elapsed_since; int elapsed_sec = diff_msec / 1000; int elapsed_msec = diff_msec % 1000; g.song_elapsed += elapsed_sec; g.elapsed_since += elapsed_sec * 1000; + + // Try to get called on the next round second of playback poller_timer_set (&g.elapsed_event, 1000 - elapsed_msec); app_invalidate (); -- cgit v1.2.3