summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2020-10-18 05:57:44 +0200
committerPřemysl Eric Janouch <p@janouch.name>2020-10-18 05:57:44 +0200
commitb3579d11282ec055a42fff56a1adcc50357d46f5 (patch)
treea4d96236412a559a877d46b3b3de2b99dffe64d9
parent525e952753cc218a2be15438689d8ed2f5d97b50 (diff)
downloadnncmpp-b3579d11282ec055a42fff56a1adcc50357d46f5.tar.gz
nncmpp-b3579d11282ec055a42fff56a1adcc50357d46f5.tar.xz
nncmpp-b3579d11282ec055a42fff56a1adcc50357d46f5.zip
Explain the ticking mechanism
Took time to read. Also fix an invalid comment.
-rw-r--r--nncmpp.c8
1 files changed, 7 insertions, 1 deletions
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 ();