]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Merge topic branch t/mixer into master
authorAndre Noll <maan@tuebingen.mpg.de>
Wed, 16 Nov 2022 17:12:04 +0000 (18:12 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Wed, 16 Nov 2022 17:15:44 +0000 (18:15 +0100)
A few patches for the sleep subcommand of para_mixer, in particular
the two new options to set the initial mood.

This code has been cooking in next for exactly one month.

* refs/heads/t/mixer:
  mixer: sleep: Fade out before stopping the stream.
  mixer: sleep: Cycle audiod on stop.
  mixer: sleep: Add --initial-mood and --initial-delay.
  mixer: sleep: Always set initial volume and channel.
  mixer: sleep: Improve description of sleep subcommand.

NEWS.md
m4/lls/mixer.suite.m4
mixer.c

diff --git a/NEWS.md b/NEWS.md
index 45e46bc627a13398a24dbe9dc220beeeb657bed4..539f75768c6b99ef6bbbff4074e8fd309692b5c4 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -5,6 +5,9 @@ NEWS
 0.7.2 (to be announced) "optical friction"
 ------------------------------------------
 
+- The sleep subcommand of para_mixer gained two options to control
+  the startup mood and the time period before fade-out starts. A bunch
+  of further improvements for this subcommand went in as well.
 - Minor cleanup of the net subsystem.
 
 Downloads:
index 3019f7693a1d986f53cfcea45d13e572a4295a5f..e366a201569e538bc374f5356bf3d1c957164955 100644 (file)
@@ -147,11 +147,10 @@ caption = List of subcommands
 [subcommand sleep]
        purpose = stream, fade out, sleep, fade in
        [description]
-               Change to the initial volume and select the initial mood/playlist.
-               Fade out to the given fade-out volume in the specified time. Switch
-               to the sleep mood/playlist and wait until wake time minus fade-in
-               time. Finally, switch to the wake mood/playlist and fade in to the
-               fade-in volume.
+               Set the initial volume and mood, start playing and sleep. Then switch
+               to the fade-out mood and fade to the fade-out volume. Next, switch to
+               the sleep mood and wait until wake time minus fade-in time. Finally,
+               switch to the wake mood and fade in to the fade-in volume.
        [/description]
        [option ivol]
                summary = set initial volume
@@ -165,6 +164,26 @@ caption = List of subcommands
                        channel part may be omitted, in which case the default channel is
                        used. This option may be given multiple times.
                [/help]
+       [option initial-mood]
+               summary = mood or playlist to start with
+               arg_info = required_arg
+               arg_type = string
+               typestr = mood_spec
+               [help]
+                       This mood or playlist is selected right after setting the initial
+                       volume and before fade-out starts. If unset, fade-out starts
+                       immediately.
+               [/help]
+       [option initial-delay]
+               summary = time before fade-out starts.
+               arg_info = required_arg
+               arg_type = uint32
+               typestr = seconds
+               default_val = 0
+               [help]
+                       If left at the default, no initial delay occurs even if an initial
+                       mood is given.
+               [/help]
        [option fo-mood]
                summary = mood or playlist for fade-out
                arg_info = required_arg
diff --git a/mixer.c b/mixer.c
index eae8929164770053c5c18843f4cf4e4e8bc5e616..dda7fc1df729722266db7136733a28ac2391e977 100644 (file)
--- a/mixer.c
+++ b/mixer.c
@@ -187,11 +187,11 @@ static int com_fade(const struct mixer *m)
 }
 EXPORT_CMD(fade);
 
-static void client_cmd(const char *cmd)
+static void run(const char *exe, const char *cmd)
 {
        int ret, status, fds[3] = {0, 0, 0};
        pid_t pid;
-       char *cmdline = make_message(BINDIR "/para_client %s", cmd);
+       char *cmdline = make_message("%s %s", exe, cmd);
 
        PARA_NOTICE_LOG("%s\n", cmdline);
        ret = para_exec_cmdline_pid(&pid, cmdline, fds);
@@ -215,6 +215,16 @@ fail:
        exit(EXIT_FAILURE);
 }
 
+static void client_cmd(const char *cmd)
+{
+       run(BINDIR "/para_client", cmd);
+}
+
+static void audioc_cmd(const char *cmd)
+{
+       run(BINDIR "/para_audioc", cmd);
+}
+
 static void change_afs_mode(const char *afs_mode)
 {
        char *cmd;
@@ -263,6 +273,20 @@ static int set_initial_volume(const struct mixer *m, struct mixer_handle *h)
        return 1;
 }
 
+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)
 {
        time_t t1, wake_time_epoch;
@@ -270,6 +294,7 @@ static int com_sleep(const struct mixer *m)
        struct tm *tm;
        int ret;
        const char *wake_time = OPT_STRING_VAL(SLEEP, WAKE_TIME);
+       const char *initial_mood = OPT_STRING_VAL(SLEEP, INITIAL_MOOD);
        const char *fo_mood = OPT_STRING_VAL(SLEEP, FO_MOOD);
        const char *fi_mood = OPT_STRING_VAL(SLEEP, FI_MOOD);
        const char *sleep_mood = OPT_STRING_VAL(SLEEP, SLEEP_MOOD);
@@ -316,17 +341,27 @@ 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);
-       client_cmd("stop");
-       sleep(1);
+       stop(m, h);
+       ret = set_initial_volume(m, h);
+       if (ret < 0)
+               goto close_mixer;
+       /*
+        * Setting the volume invalidates the current channel setting, so we
+        * have to set it again.
+        */
+       ret = set_channel(m, h, OPT_STRING_VAL(PARA_MIXER, MIXER_CHANNEL));
+       if (ret < 0)
+               goto close_mixer;
+       delay = OPT_UINT32_VAL(SLEEP, INITIAL_DELAY);
+       if (delay > 0 && initial_mood && *initial_mood) {
+               change_afs_mode(initial_mood);
+               client_cmd("play");
+               sleep(delay);
+               stop(m, h);
+       }
        if (fot && fo_mood && *fo_mood) {
-               ret = set_initial_volume(m, h);
-               if (ret < 0)
-                       goto close_mixer;
                change_afs_mode(fo_mood);
                client_cmd("play");
-               ret = set_channel(m, h, OPT_STRING_VAL(PARA_MIXER, MIXER_CHANNEL));
-               if (ret < 0)
-                       goto close_mixer;
                ret = fade(m, h, fov, fot);
                if (ret < 0)
                        goto close_mixer;
@@ -340,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 */
-               client_cmd("stop");
+               stop(m, h);
        m->close(&h);
        if (!fit || !fi_mood || !*fi_mood) /* nothing to do */
                return 1;
@@ -355,13 +390,12 @@ static int com_sleep(const struct mixer *m)
                sleep(delay);
        }
        change_afs_mode(fi_mood);
-       if (sleep_mood && *sleep_mood) /* currently playing */
-               client_cmd("next");
-       else /* currently stopped */
-               client_cmd("play");
        ret = open_mixer_and_set_channel(m, &h);
        if (ret < 0)
                return ret;
+       if (sleep_mood && *sleep_mood) /* currently playing */
+               stop(m, h);
+       client_cmd("play");
        ret = fade(m, h, fiv, fit);
 close_mixer:
        m->close(&h);