mixer: fade: Handle empty mood strings gracefully.
[paraslash.git] / mixer.c
diff --git a/mixer.c b/mixer.c
index ad674bf537e89c5d89bb0ebf946bfd14dad1a81a..b14bb76ebe150864ae261da3c668c0be885e2f74 100644 (file)
--- a/mixer.c
+++ b/mixer.c
@@ -1,6 +1,6 @@
 /* Copyright (C) 1998 Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */
 
-/** \file mixer.c A volume fader and alarm clock for OSS. */
+/** \file mixer.c A volume fader and alarm clock. */
 
 #include <regex.h>
 #include <lopsub.h>
@@ -288,7 +288,7 @@ static int com_sleep(const struct mixer *m, struct mixer_handle *h)
        PARA_INFO_LOG("waketime: %d:%02d\n", tm->tm_hour, tm->tm_min);
        client_cmd("stop");
        sleep(1);
-       if (fot && fo_mood) {
+       if (fot && fo_mood && *fo_mood) {
                ret = set_initial_volume(m, h);
                if (ret < 0)
                        return ret;
@@ -305,15 +305,14 @@ static int com_sleep(const struct mixer *m, struct mixer_handle *h)
                if (ret < 0)
                        return ret;
        }
-       if (sleep_mood) {
+       if (sleep_mood && *sleep_mood) {
                change_afs_mode(sleep_mood);
                if (!fot || !fo_mood) /* currently stopped */
                        client_cmd("play");
-       } else if (fot && fo_mood) /* currently playing */
+       } else if (fot && fo_mood && *fo_mood) /* currently playing */
                client_cmd("stop");
-       if (!fit || !fi_mood) /* nothing to do */
+       if (!fit || !fi_mood || !*fi_mood) /* nothing to do */
                return 1;
-       change_afs_mode(fi_mood);
        for (;;) {
                time(&t1);
                if (wake_time_epoch <= t1 + fit)
@@ -324,7 +323,11 @@ static int com_sleep(const struct mixer *m, struct mixer_handle *h)
                        (delay % 3600) / 60);
                sleep(delay);
        }
-       client_cmd("play");
+       change_afs_mode(fi_mood);
+       if (sleep_mood && *sleep_mood) /* currently playing */
+               client_cmd("next");
+       else /* currently stopped */
+               client_cmd("play");
        ret = fade(m, h, fiv, fit);
        PARA_INFO_LOG("fade complete, returning\n");
        return ret;
@@ -526,7 +529,7 @@ int main(int argc, char *argv[])
        }
        if (ret < 0)
                goto close_mixer;
-       ret = (*(mixer_subcommand_handler_t *)(lls_user_data(cmd)))(m ,h);
+       ret = (*(mixer_subcommand_handler_t *)(lls_user_data(cmd)))(mh);
 close_mixer:
        m->close(&h);
 free_sub_lpr: