]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Revamp para_fade.
authorAndre Noll <maan@systemlinux.org>
Sat, 25 Jul 2009 18:07:19 +0000 (20:07 +0200)
committerAndre Noll <maan@systemlinux.org>
Sat, 25 Jul 2009 18:07:19 +0000 (20:07 +0200)
- Rename options
- Improve documentation
- Make --mode an enum option
- Cleanup ggo file indentation

error.h
fade.c
ggo/fade.ggo

diff --git a/error.h b/error.h
index d9133aa1317647c4bbf70f8052a8dff213f7f665..7416be5762c9aa09b6b858c3be1eb5f8972490f0 100644 (file)
--- a/error.h
+++ b/error.h
@@ -30,7 +30,7 @@ DEFINE_ERRLIST_OBJECT_ENUM;
 #define GGO_ERRORS
 #define COLOR_ERRORS
 #define SIGNAL_ERRORS
 #define GGO_ERRORS
 #define COLOR_ERRORS
 #define SIGNAL_ERRORS
-
+#define FADE_ERRORS
 
 extern const char **para_errlist[];
 
 
 extern const char **para_errlist[];
 
@@ -74,10 +74,6 @@ extern const char **para_errlist[];
        PARA_ERROR(MAX_CLIENTS, "maximal number of clients exceeded"), \
 
 
        PARA_ERROR(MAX_CLIENTS, "maximal number of clients exceeded"), \
 
 
-#define FADE_ERRORS \
-       PARA_ERROR(FADE_SYNTAX, "fade syntax error"), \
-
-
 #define CLIENT_ERRORS \
        PARA_ERROR(TASK_STARTED, "task started"), \
 
 #define CLIENT_ERRORS \
        PARA_ERROR(TASK_STARTED, "task started"), \
 
diff --git a/fade.c b/fade.c
index eaeaf0563e51788a6140e42e472036e84a34deea..44904ac54088124f695a63bb62a7e49867442f78 100644 (file)
--- a/fade.c
+++ b/fade.c
@@ -4,7 +4,7 @@
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
 
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
 
-/** \file fade.c A volume fader and alarm clock for linux. */
+/** \file fade.c A volume fader and alarm clock for OSS. */
 
 #include <regex.h>
 #include <sys/types.h>
 
 #include <regex.h>
 #include <sys/types.h>
@@ -42,7 +42,7 @@ __printf_2_3 void para_log(__a_unused int ll, const char *fmt, ...)
 }
 
 /*
 }
 
 /*
- * open mixer device
+ * Open the mixer device.
  */
 static int open_mixer(void)
 {
  */
 static int open_mixer(void)
 {
@@ -130,7 +130,7 @@ static void fixup_mixer_channel_arg(void)
 
 /*
  * Open mixer, get volume, fade to new_vol in secs seconds and
 
 /*
  * Open mixer, get volume, fade to new_vol in secs seconds and
- * close mixer
+ * close mixer.
  */
 static int fade(int new_vol, int fade_time)
 {
  */
 static int fade(int new_vol, int fade_time)
 {
@@ -216,14 +216,14 @@ static int sweet_dreams(void)
        unsigned int delay;
        struct tm *tm;
        int ret, min = conf.wake_min_arg;
        unsigned int delay;
        struct tm *tm;
        int ret, min = conf.wake_min_arg;
-       char *fa_mode = conf.fa_mode_arg;
-       char *wake_mode = conf.wake_mode_arg;
-       char *sleep_mode = conf.sleep_mode_arg;
-       int wf = conf.wake_fade_arg;
-       int sf = conf.fa_fade_arg;
-       int wv = conf.wake_vol_arg;
-       int sv = conf.fa_vol_arg;
-       int iv = conf.sleep_ivol_arg;
+       char *fo_mood = conf.fo_mood_arg;
+       char *fi_mood = conf.fi_mood_arg;
+       char *sleep_mood = conf.sleep_mood_arg;
+       int fit = conf.fi_time_arg;
+       int fot = conf.fo_time_arg;
+       int fiv = conf.fi_vol_arg;
+       int fov = conf.fo_vol_arg;
+       int iv = conf.ivol_arg;
 
        /* calculate wake time */
        time(&t1);
 
        /* calculate wake time */
        time(&t1);
@@ -246,38 +246,38 @@ static int sweet_dreams(void)
        PARA_INFO_LOG("waketime: %s", asctime(tm));
        client_cmd("stop");
        sleep(1);
        PARA_INFO_LOG("waketime: %s", asctime(tm));
        client_cmd("stop");
        sleep(1);
-       if (sf) {
+       if (fot) {
                PARA_INFO_LOG("initial volume: %d\n", iv);
                ret = open_and_set_mixer_channel(iv);
                if (ret < 0)
                        return ret;
                PARA_INFO_LOG("initial volume: %d\n", iv);
                ret = open_and_set_mixer_channel(iv);
                if (ret < 0)
                        return ret;
-               change_afs_mode_and_play(fa_mode);
-               ret = fade(sv, sf);
+               change_afs_mode_and_play(fo_mood);
+               ret = fade(fov, fot);
                if (ret < 0)
                        return ret;
        } else {
                if (ret < 0)
                        return ret;
        } else {
-               ret = open_and_set_mixer_channel(sf);
+               ret = open_and_set_mixer_channel(fov);
                if (ret < 0)
                        return ret;
        }
                if (ret < 0)
                        return ret;
        }
-       if (conf.sleep_mode_given)
-               change_afs_mode_and_play(sleep_mode);
+       if (conf.sleep_mood_given)
+               change_afs_mode_and_play(sleep_mood);
        else
                client_cmd("stop");
        else
                client_cmd("stop");
-       if (!wf)
+       if (!fit)
                return 1;
        for (;;) {
                time(&t1);
                return 1;
        for (;;) {
                time(&t1);
-               if (wake_time_epoch <= t1 + wf)
+               if (wake_time_epoch <= t1 + fit)
                        break;
                        break;
-               delay = wake_time_epoch - t1 - wf;
+               delay = wake_time_epoch - t1 - fit;
                PARA_INFO_LOG("sleeping %u seconds (%u:%02u)\n",
                        delay, delay / 3600,
                        (delay % 3600) / 60);
                sleep(delay);
        }
                PARA_INFO_LOG("sleeping %u seconds (%u:%02u)\n",
                        delay, delay / 3600,
                        (delay % 3600) / 60);
                sleep(delay);
        }
-       change_afs_mode_and_play(wake_mode);
-       ret = fade(wv, wf);
+       change_afs_mode_and_play(fi_mood);
+       ret = fade(fiv, fit);
        PARA_INFO_LOG("fade complete, returning\n");
        return ret;
 }
        PARA_INFO_LOG("fade complete, returning\n");
        return ret;
 }
@@ -287,20 +287,20 @@ static int snooze(void)
        int ret;
        unsigned sleep_time;
 
        int ret;
        unsigned sleep_time;
 
-       if (conf.snooze_time_arg <= 0)
+       if (conf.so_time_arg <= 0)
                return 1;
                return 1;
-       sleep_time = conf.snooze_time_arg;
-       if (open_and_get_mixer_channel() < conf.snooze_out_vol_arg)
-               ret = open_and_set_mixer_channel(conf.snooze_out_vol_arg);
+       sleep_time = conf.so_time_arg;
+       if (open_and_get_mixer_channel() < conf.so_vol_arg)
+               ret = open_and_set_mixer_channel(conf.so_vol_arg);
        else
        else
-               ret = fade(conf.snooze_out_vol_arg, conf.snooze_out_fade_arg);
+               ret = fade(conf.so_vol_arg, conf.so_time_arg);
        if (ret < 0)
                return ret;
        client_cmd("pause");
        PARA_NOTICE_LOG("%d seconds snooze time...\n", conf.snooze_time_arg);
        sleep(sleep_time);
        client_cmd("play");
        if (ret < 0)
                return ret;
        client_cmd("pause");
        PARA_NOTICE_LOG("%d seconds snooze time...\n", conf.snooze_time_arg);
        sleep(sleep_time);
        client_cmd("play");
-       return fade(conf.snooze_in_vol_arg, conf.snooze_in_fade_arg);
+       return fade(conf.si_vol_arg, conf.si_time_arg);
 }
 
 static int configfile_exists(void)
 }
 
 static int configfile_exists(void)
@@ -335,26 +335,24 @@ int main(int argc, char *argv[])
                        .override = 0,
                        .initialize = 0,
                        .check_required = 0,
                        .override = 0,
                        .initialize = 0,
                        .check_required = 0,
-                       .check_ambiguity = 0
+                       .check_ambiguity = 0,
+                       .print_errors = 1
                };
                fade_cmdline_parser_config_file(conf.config_file_arg,
                        &conf, &params);
        }
        fixup_mixer_channel_arg();
                };
                fade_cmdline_parser_config_file(conf.config_file_arg,
                        &conf, &params);
        }
        fixup_mixer_channel_arg();
-       if (!strcmp(conf.mode_arg, "sleep")) {
+       switch (conf.mode_arg) {
+       case mode_arg_sleep:
                ret = sweet_dreams();
                ret = sweet_dreams();
-               goto out;
-       }
-       if (!strcmp(conf.mode_arg, "fade")) {
+               break;
+       case mode_arg_fade:
                ret = fade(conf.fade_vol_arg, conf.fade_time_arg);
                ret = fade(conf.fade_vol_arg, conf.fade_time_arg);
-               goto out;
-       }
-       if (!strcmp(conf.mode_arg, "snooze")) {
+               break;
+       case mode_arg_snooze:
                ret = snooze();
                ret = snooze();
-               goto out;
+               break;
        }
        }
-       ret = -E_FADE_SYNTAX;
-out:
        if (ret < 0)
                PARA_EMERG_LOG("%s\n", para_strerror(-ret));
        return ret < 0? EXIT_FAILURE : EXIT_SUCCESS;
        if (ret < 0)
                PARA_EMERG_LOG("%s\n", para_strerror(-ret));
        return ret < 0? EXIT_FAILURE : EXIT_SUCCESS;
index 01eb6aa98efdb801bab2718917eeb3186ad203c8..80f8b73c3999ef3c22cea89bac2931b036ed9606 100644 (file)
-section "general options"
+section "General options"
 #########################
 
 option "mode" o
 #~~~~~~~~~~~~~~
 #########################
 
 option "mode" o
 #~~~~~~~~~~~~~~
-"{sleep|fade|snooze}"
-string default="sleep"
-optional
-details="
-       para_fade knows these three different modes.
+"how to fade volume"
+       enum typestr = "mode"
+       values = "sleep", "snooze", "fade"
+       default = "sleep"
+       optional
+       details="
+               para_fade knows three different fading modes:
 
 
-       sleep mode: Change to the initial volume and an initial afs
-       mode, then fade the volume down until the fade out volume is
-       reached. Switch to the afs sleep mode until the wake time is
-       reached. Then switch to the afs wake mode and and fade in to
-       the wake volume.
+               sleep mode: Change to the initial volume and select
+               the initial afs mood/playlist. Then fade out until
+               the fade-out volume is reached. Switch to the
+               sleep mood/playlist until wake time minus fade-in
+               time. Finally switch to the wake mood/playlist and
+               fade to the fade-in volume.
 
 
-       fade: Fade the volume to the given value in the given time.
+               fade: Fade the volume to the given value in the
+               given time.
 
 
-       snooze: Fade out, sleep a bit and fade in.
+               snooze: Fade out, sleep a bit and fade in.
 "
 
 "
 
-option "config_file" c
+option "config-file" c
 #~~~~~~~~~~~~~~~~~~~~~
 #~~~~~~~~~~~~~~~~~~~~~
- "(default='~/.paraslash/fade.conf')"
-       string typestr="filename"
+"(default='~/.paraslash/fade.conf')"
+       string typestr = "filename"
        optional
 
        optional
 
-option "mixer_device" m
+option "mixer-device" m
 #~~~~~~~~~~~~~~~~~~~~~~
 #~~~~~~~~~~~~~~~~~~~~~~
- "mixer device file"
-       string typestr="device"
-       default="/dev/mixer"
+"mixer device file"
+       string typestr = "device"
+       default = "/dev/mixer"
        optional
 
        optional
 
-option "mixer_channel" C
+option "mixer-channel" C
 #~~~~~~~~~~~~~~~~~~~~~~~
 "select the analog mixer channel"
 #~~~~~~~~~~~~~~~~~~~~~~~
 "select the analog mixer channel"
-       enum typestr="channel"
-       values="volume", "bass", "treble", "synth", "pcm", "speaker", "line",
+       enum typestr = "channel"
+       values = "volume", "bass", "treble", "synth", "pcm", "speaker", "line",
                "mic", "cd", "imix", "altpcm", "reclev", "igain", "ogain"
                "mic", "cd", "imix", "altpcm", "reclev", "igain", "ogain"
-       default="volume"
+       default = "volume"
        optional
        optional
-       details="
-       Not all listed channels might be supported on any particular hardware.
+       details = "
+               Not all listed channels might be supported on any
+               particular hardware.
 "
 
 "
 
-section "sleep options (only relevant in sleep mode)"
-#####################################################
+section "Options for sleep mode"
+################################
 
 
-option "sleep_ivol" -
-#~~~~~~~~~~~~~~~~~~~~
+option "ivol" -
+#~~~~~~~~~~~~~~
 "set initial volume"
 "set initial volume"
-int typestr="volume"
-default="60"
-optional
-details="
-       Used as the start volume, before fading out to the fade out volume.
-"
+       int typestr = "volume"
+       default = "60"
+       optional
+       details = "
+               Used as the start volume, before fading out to the
+               fade out volume.
+       "
 
 
-option "fa_mode" -
+option "fo-mood" -
 #~~~~~~~~~~~~~~~~~
 #~~~~~~~~~~~~~~~~~
-"fall asleep afs mode."
-string typestr="afs_mode"
-default="m/fade"
-optional
-details="
-       Select this mode right after setting the volume. Example:
-       --fa_mode m/sleep
+"afs mood/playlist during fade out"
+       string typestr = "mood_spec"
+       default = "m/fade"
+       optional
+       details = "
+               Select this mood right after setting the
+               volume. Example: --fo-mood m/sleep
 "
 
 "
 
-option "fa_fade" -
+option "fo-time" -
 #~~~~~~~~~~~~~~~~~
 #~~~~~~~~~~~~~~~~~
- "fall asleep fading time"
-int typestr="seconds"
-default="1800"
-optional
-details="
-       No fading if set to 0.
-"
+"fall asleep fade out time"
+       int typestr = "seconds"
+       default = "1800"
+       optional
+       details = "
+               No fading if set to 0.
+       "
 
 
-option "fa_vol" -
+option "fo-vol" -
 #~~~~~~~~~~~~~~~~
 #~~~~~~~~~~~~~~~~
- "volume to fade to"
-       int typestr="volume"
-       default="20"
+"volume to fade out to"
+       int typestr = "volume"
+       default = "20"
        optional
 
        optional
 
-option "sleep_mode" -
-#~~~~~~~~~~~~~~~~~~~~~~
-"sleep time afs mode"
-details = "
-       Select the given afs mode after the fade out is complete. If
-       unset, the \"stop\" command is sent to para_server.
-"
-string typestr="afs_mode"
-default="m/sleep"
-optional
+option "sleep-mood" -
+#~~~~~~~~~~~~~~~~~~~~
+"sleep time afs mood/playlist"
+       string typestr = "mood_spec"
+       default = "m/sleep"
+       optional
+       details = "
+               Select the given afs mood/playlist after the fade
+               out is complete. If unset, the \"stop\" command is
+               sent to para_server.
+       "
 
 
-option "wake_hour" H
+option "wake-hour" H
 #~~~~~~~~~~~~~~~~~~~
 #~~~~~~~~~~~~~~~~~~~
- "(0-23) (default: now + 9 hours)"
-       int typestr="hour"
+"(0-23) (default: now + 9 hours)"
+       int typestr = "hour"
        optional
 
        optional
 
-option "wake_min" M
+option "wake-min" M
 #~~~~~~~~~~~~~~~~~~
 "(0-59)"
 #~~~~~~~~~~~~~~~~~~
 "(0-59)"
-       int typestr="minutes"
-       default="0"
+       int typestr = "minutes"
+       default = "0"
        optional
 
        optional
 
-option "wake_mode" -
-#~~~~~~~~~~~~~~~~~~~
-"wake time afs mode"
-string typestr="afs_mode"
-default="m/wake"
-optional
-details="
-       Change to this afs mode on waketime.
-"
+option "fi-mood" -
+#~~~~~~~~~~~~~~~~~
+"afs mood/playlist during fade in"
+       string typestr = "mood_spec"
+       default = "m/wake"
+       optional
+       details = "
+               Change to this afs mood/playlist on wake time.
+       "
 
 
-option "wake_fade" -
-#~~~~~~~~~~~~~~~~~~~
- "no fading in if set to 0"
+option "fi-time" -
+#~~~~~~~~~~~~~~~~~
+"wake up fade in time"
        int typestr="seconds"
        default="1200"
        optional
        int typestr="seconds"
        default="1200"
        optional
+       details = "
+               No fading in if set to 0.
+       "
 
 
-option "wake_vol" -
-#~~~~~~~~~~~~~~~~~~
- "vol to fade to at waketime"
-       int typestr="volume"
-       default="80"
+option "fi-vol" -
+#~~~~~~~~~~~~~~~~
+"volume to fade to at wake time"
+       int typestr = "volume"
+       default = "80"
        optional
 
        optional
 
-section "snooze options"
-########################
+section "Options for snooze mode"
+#################################
 
 
-option "snooze_out_fade" -
-#~~~~~~~~~~~~~~~~~~~~~~~~~
- "fade out time"
-       int typestr="seconds"
-       default="30"
+option "so-time" -
+#~~~~~~~~~~~~~~~~~
+"snooze-out time"
+       int typestr = "seconds"
+       default = "30"
        optional
 
        optional
 
-option "snooze_out_vol" -
-#~~~~~~~~~~~~~~~~~~~~~~~~
- "vol to fade to before snooze"
-       int typestr="volume"
-       default="20"
+option "so-vol" -
+#~~~~~~~~~~~~~~~~
+"volume to fade to before snooze"
+       int typestr = "volume"
+       default = "20"
        optional
 
        optional
 
-option "snooze_time" -
+option "snooze-time" -
 #~~~~~~~~~~~~~~~~~~~~~
 #~~~~~~~~~~~~~~~~~~~~~
- "delay"
-       int typestr="seconds"
-       default="600"
+"delay"
+       int typestr = "seconds"
+       default = "600"
        optional
 
        optional
 
-option "snooze_in_fade" -
-#~~~~~~~~~~~~~~~~~~~~~~~~
- "fade in time"
-       int typestr="seconds"
-       default="180"
+option "si-time" -
+#~~~~~~~~~~~~~~~~~
+"snooze-in time"
+       int typestr = "seconds"
+       default = "180"
        optional
 
        optional
 
-option "snooze_in_vol" -
-#~~~~~~~~~~~~~~~~~~~~~~~
- "vol to fade to after snooze"
-       int typestr="volume"
-       default="80"
+option "si-vol" -
+#~~~~~~~~~~~~~~~~
+"volume to fade to after snooze"
+       int typestr = "volume"
+       default = "80"
        optional
 
        optional
 
-section "fade options"
-######################
+section "Options for fade mode"
+###############################
 
 
-option "fade_vol" f
+option "fade-vol" f
 #~~~~~~~~~~~~~~~~~~
 #~~~~~~~~~~~~~~~~~~
- "volume to fade to"
-       int typestr="volume"
-       default="50"
+"volume to fade to"
+       int typestr = "volume"
+       default = "50"
        optional
 
        optional
 
-option "fade_time" t
+option "fade-time" t
 #~~~~~~~~~~~~~~~~~~~
 #~~~~~~~~~~~~~~~~~~~
- "time to fade in"
-       int typestr="seconds"
-       default="5"
+"fading time"
+       int typestr = "seconds"
+       default = "5"
        optional
        optional