From: Andre Noll Date: Sat, 25 Jul 2009 18:07:19 +0000 (+0200) Subject: Revamp para_fade. X-Git-Tag: v0.4.0~42 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=c7592846b5002f47e32ea7ffa6d66fbb8797291f;p=paraslash.git Revamp para_fade. - Rename options - Improve documentation - Make --mode an enum option - Cleanup ggo file indentation --- diff --git a/error.h b/error.h index d9133aa1..7416be57 100644 --- a/error.h +++ b/error.h @@ -30,7 +30,7 @@ DEFINE_ERRLIST_OBJECT_ENUM; #define GGO_ERRORS #define COLOR_ERRORS #define SIGNAL_ERRORS - +#define FADE_ERRORS extern const char **para_errlist[]; @@ -74,10 +74,6 @@ extern const char **para_errlist[]; 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"), \ diff --git a/fade.c b/fade.c index eaeaf056..44904ac5 100644 --- a/fade.c +++ b/fade.c @@ -4,7 +4,7 @@ * 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 #include @@ -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) { @@ -130,7 +130,7 @@ static void fixup_mixer_channel_arg(void) /* * 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) { @@ -216,14 +216,14 @@ static int sweet_dreams(void) 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); @@ -246,38 +246,38 @@ static int sweet_dreams(void) 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; - 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 { - ret = open_and_set_mixer_channel(sf); + ret = open_and_set_mixer_channel(fov); 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"); - if (!wf) + if (!fit) return 1; for (;;) { time(&t1); - if (wake_time_epoch <= t1 + wf) + if (wake_time_epoch <= t1 + fit) 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); } - 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; } @@ -287,20 +287,20 @@ static int snooze(void) int ret; unsigned sleep_time; - if (conf.snooze_time_arg <= 0) + if (conf.so_time_arg <= 0) 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 - 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"); - 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) @@ -335,26 +335,24 @@ int main(int argc, char *argv[]) .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, ¶ms); } fixup_mixer_channel_arg(); - if (!strcmp(conf.mode_arg, "sleep")) { + switch (conf.mode_arg) { + case mode_arg_sleep: 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); - goto out; - } - if (!strcmp(conf.mode_arg, "snooze")) { + break; + case mode_arg_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; diff --git a/ggo/fade.ggo b/ggo/fade.ggo index 01eb6aa9..80f8b73c 100644 --- a/ggo/fade.ggo +++ b/ggo/fade.ggo @@ -1,190 +1,200 @@ -section "general options" +section "General options" ######################### 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 -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 -option "mixer_channel" C +option "mixer-channel" C #~~~~~~~~~~~~~~~~~~~~~~~ "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" - default="volume" + default = "volume" 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" -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 -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 -option "wake_min" M +option "wake-min" M #~~~~~~~~~~~~~~~~~~ "(0-59)" - int typestr="minutes" - default="0" + int typestr = "minutes" + default = "0" 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 + 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 -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 -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 -option "snooze_time" - +option "snooze-time" - #~~~~~~~~~~~~~~~~~~~~~ - "delay" - int typestr="seconds" - default="600" +"delay" + int typestr = "seconds" + default = "600" 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 -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 -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 -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