fade: Add missing line break for log message.
[paraslash.git] / fade.c
diff --git a/fade.c b/fade.c
index ed543d192c7e9f852265061bc1b93dfe687f282d..e05e31733623dacae4beddad69580d077ad23a0d 100644 (file)
--- a/fade.c
+++ b/fade.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1998-2013 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 1998 Andre Noll <maan@tuebingen.mpg.de>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
@@ -46,19 +46,10 @@ __printf_2_3 void (*para_log)(int, const char*, ...) = date_log;
 
 static int set_channel(struct mixer *m, struct mixer_handle *h, const char *channel)
 {
-       char *channels;
-       int ret;
 
-       ret = m->set_channel(h, channel);
-       if (ret >= 0) {
-               PARA_NOTICE_LOG("using %s mixer channel\n",
-                       channel? channel : "default");
-               return ret;
-       }
-       channels = m->get_channels(h);
-       printf("Available channels: %s\n", channels);
-       free(channels);
-       return ret;
+       PARA_NOTICE_LOG("using %s mixer channel\n", channel?
+               channel : "default");
+       return m->set_channel(h, channel);
 }
 
 /* Fade to new volume in fade_time seconds. */
@@ -130,7 +121,7 @@ fail:
        exit(EXIT_FAILURE);
 }
 
-static void change_afs_mode_and_play(char *afs_mode)
+static void change_afs_mode(char *afs_mode)
 {
        char *cmd;
 
@@ -140,7 +131,6 @@ static void change_afs_mode_and_play(char *afs_mode)
        cmd = make_message("select %s", afs_mode);
        client_cmd(cmd);
        free(cmd);
-       client_cmd("play");
 }
 
 static int set_initial_volume(struct mixer *m, struct mixer_handle *h)
@@ -213,14 +203,15 @@ static int sweet_dreams(struct mixer *m, struct mixer_handle *h)
                tm = localtime(&t1);
        }
        wake_time_epoch = mktime(tm);
-       PARA_INFO_LOG("waketime: %s", asctime(tm));
+       PARA_INFO_LOG("waketime: %u:%02u\n", tm->tm_hour, tm->tm_min);
        client_cmd("stop");
        sleep(1);
        if (fot) {
                ret = set_initial_volume(m, h);
                if (ret < 0)
                        return ret;
-               change_afs_mode_and_play(fo_mood);
+               change_afs_mode(fo_mood);
+               client_cmd("play");
                ret = set_channel(m, h, conf.mixer_channel_arg);
                if (ret < 0)
                        return ret;
@@ -232,12 +223,14 @@ static int sweet_dreams(struct mixer *m, struct mixer_handle *h)
                if (ret < 0)
                        return ret;
        }
-       if (conf.sleep_mood_given)
-               change_afs_mode_and_play(sleep_mood);
-       else
+       if (conf.sleep_mood_given) {
+               change_afs_mode(sleep_mood);
+               client_cmd("play");
+       } else
                client_cmd("stop");
        if (!fit)
                return 1;
+       change_afs_mode(fi_mood);
        for (;;) {
                time(&t1);
                if (wake_time_epoch <= t1 + fit)
@@ -248,7 +241,7 @@ static int sweet_dreams(struct mixer *m, struct mixer_handle *h)
                        (delay % 3600) / 60);
                sleep(delay);
        }
-       change_afs_mode_and_play(fi_mood);
+       client_cmd("play");
        ret = fade(m, h, fiv, fit);
        PARA_INFO_LOG("fade complete, returning\n");
        return ret;
@@ -375,6 +368,11 @@ int main(int argc, char *argv[])
        if (ret < 0)
                goto out;
        ret = set_channel(m, h, conf.mixer_channel_arg);
+       if (ret == -E_BAD_CHANNEL) {
+               char *channels = m->get_channels(h);
+               printf("Available channels: %s\n", channels);
+               free(channels);
+       }
        if (ret < 0)
                goto out;
        switch (conf.mode_arg) {