From 56c35c76704aac5fe25dbcec0e4fcb1ee1dd655a Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Tue, 11 Oct 2022 18:30:24 +0200 Subject: [PATCH] mixer: sleep: Fade out before stopping the stream. The user is about to fall asleep, so try to make the transition a bit smoother by fading out to volume zero before stopping the stream. --- mixer.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/mixer.c b/mixer.c index 48095d03..dda7fc1d 100644 --- a/mixer.c +++ b/mixer.c @@ -273,11 +273,18 @@ static int set_initial_volume(const struct mixer *m, struct mixer_handle *h) return 1; } -static void stop(void) +static void stop(const struct mixer *m, struct mixer_handle *h) { + int ret, old_vol = 0; + + ret = m->get(h); + if (ret > 0) + old_vol = ret; + fade(m, h, 0, 3); audioc_cmd("off"); client_cmd("stop"); audioc_cmd("on"); + m->set(h, old_vol); } static int com_sleep(const struct mixer *m) @@ -334,7 +341,7 @@ static int com_sleep(const struct mixer *m) } wake_time_epoch = mktime(tm); PARA_INFO_LOG("waketime: %d:%02d\n", tm->tm_hour, tm->tm_min); - stop(); + stop(m, h); ret = set_initial_volume(m, h); if (ret < 0) goto close_mixer; @@ -350,7 +357,7 @@ static int com_sleep(const struct mixer *m) change_afs_mode(initial_mood); client_cmd("play"); sleep(delay); - stop(); + stop(m, h); } if (fot && fo_mood && *fo_mood) { change_afs_mode(fo_mood); @@ -368,7 +375,7 @@ static int com_sleep(const struct mixer *m) if (!fot || !fo_mood) /* currently stopped */ client_cmd("play"); } else if (fot && fo_mood && *fo_mood) /* currently playing */ - stop(); + stop(m, h); m->close(&h); if (!fit || !fi_mood || !*fi_mood) /* nothing to do */ return 1; @@ -387,7 +394,7 @@ static int com_sleep(const struct mixer *m) if (ret < 0) return ret; if (sleep_mood && *sleep_mood) /* currently playing */ - stop(); + stop(m, h); client_cmd("play"); ret = fade(m, h, fiv, fit); close_mixer: -- 2.39.5