]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
mixer: sleep: Add --initial-mood and --initial-delay.
authorAndre Noll <maan@tuebingen.mpg.de>
Sat, 5 Mar 2022 20:04:31 +0000 (21:04 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 16 Oct 2022 16:53:17 +0000 (18:53 +0200)
The new options allow the user to run the sleep subcommand to do the
equivalent of

$ para_client stop
$ # set initial volume
$ para_client select m/initial
$ para_client play
$ sleep $initial_delay
$ para_mixer sleep

Fortunately, the implementation is very simple.

m4/lls/mixer.suite.m4
mixer.c

index f71e6b9c19a6e8b4eb47d00ec67b837a3de730cc..e366a201569e538bc374f5356bf3d1c957164955 100644 (file)
@@ -147,10 +147,10 @@ caption = List of subcommands
 [subcommand sleep]
        purpose = stream, fade out, sleep, fade in
        [description]
-               Set the initial volume and fade-out mood, then fade to the fade-out
-               volume. 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.
+               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
@@ -164,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 42651d6a9a7ae10c9703b1c3e32516cb4accba9f..013f35fe3e37c60db0404bfe0e80eeee95cfc5a0 100644 (file)
--- a/mixer.c
+++ b/mixer.c
@@ -270,6 +270,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);
@@ -328,6 +329,13 @@ static int com_sleep(const struct mixer *m)
        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);
+               client_cmd("stop");
+       }
        if (fot && fo_mood && *fo_mood) {
                change_afs_mode(fo_mood);
                client_cmd("play");