X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;ds=sidebyside;f=mixer.c;h=52af25f9c22ae5397f03c5bf61daaae0f1bb67bd;hb=5bd68d32e37386c6a75b597a0fa1a940cd6876a7;hp=d33fa831c9c3ba2cdc29c1ab3609795ab49bba16;hpb=bd374f0948c77dd91287f73f7573bf59f3fb5666;p=paraslash.git diff --git a/mixer.c b/mixer.c index d33fa831..52af25f9 100644 --- a/mixer.c +++ b/mixer.c @@ -1,8 +1,4 @@ -/* - * Copyright (C) 1998 Andre Noll - * - * Licensed under the GPL v2. For licencing details see COPYING. - */ +/* Copyright (C) 1998 Andre Noll , see file COPYING. */ /** \file mixer.c A volume fader and alarm clock for OSS. */ @@ -21,10 +17,17 @@ /** Array of error strings. */ DEFINE_PARA_ERRLIST; -enum mixer_id {MIXER_ENUM}; -static char *mixer_name[] = {MIXER_NAMES}; -DECLARE_MIXER_INITS; -static struct mixer supported_mixer[] = {MIXER_ARRAY}; +/* At least one of the two is defined if this file gets compiled. */ +static const struct mixer *mixers[] = { +#ifdef HAVE_ALSA + &alsa_mixer, +#endif +#ifdef HAVE_OSS + &oss_mixer, +#endif +}; + +#define NUM_SUPPORTED_MIXERS (ARRAY_SIZE(mixers)) #define FOR_EACH_MIXER(i) for ((i) = 0; (i) < NUM_SUPPORTED_MIXERS; (i)++) static struct lls_parse_result *lpr, *sub_lpr; @@ -36,7 +39,7 @@ static struct lls_parse_result *lpr, *sub_lpr; #define OPT_STRING_VAL(_cmd, _opt) (lls_string_val(0, OPT_RESULT(_cmd, _opt))) #define OPT_UINT32_VAL(_cmd, _opt) (lls_uint32_val(0, OPT_RESULT(_cmd, _opt))) -typedef int (*mixer_subcommand_handler_t)(struct mixer *, struct mixer_handle *); +typedef int (*mixer_subcommand_handler_t)(const struct mixer *, struct mixer_handle *); #define EXPORT_CMD(_cmd) const mixer_subcommand_handler_t \ lsg_mixer_com_ ## _cmd ## _user_data = &com_ ## _cmd; @@ -59,7 +62,8 @@ static __printf_2_3 void date_log(int ll, const char *fmt, ...) } __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) +static int set_channel(const struct mixer *m, struct mixer_handle *h, + const char *channel) { PARA_NOTICE_LOG("using %s mixer channel\n", channel? @@ -106,7 +110,7 @@ static unsigned volume_time(double vol, double old_vol, double new_vol, } /* Fade to new volume in fade_time seconds. */ -static int fade(struct mixer *m, struct mixer_handle *h, uint32_t new_vol, +static int fade(const struct mixer *m, struct mixer_handle *h, uint32_t new_vol, uint32_t fade_time) { int i, T, old_vol, ret, slept, incr; @@ -148,7 +152,7 @@ sleep: return ret; } -static int com_fade(struct mixer *m, struct mixer_handle *h) +static int com_fade(const struct mixer *m, struct mixer_handle *h) { uint32_t new_vol = OPT_UINT32_VAL(FADE, FADE_VOL); uint32_t fade_time = OPT_UINT32_VAL(FADE, FADE_TIME); @@ -188,15 +192,12 @@ static void change_afs_mode(const char *afs_mode) { char *cmd; - client_cmd("stop"); - if (!afs_mode) - return; cmd = make_message("select %s", afs_mode); client_cmd(cmd); free(cmd); } -static int set_initial_volume(struct mixer *m, struct mixer_handle *h) +static int set_initial_volume(const struct mixer *m, struct mixer_handle *h) { int i, ret; @@ -235,7 +236,7 @@ static int set_initial_volume(struct mixer *m, struct mixer_handle *h) return 1; } -static int com_sleep(struct mixer *m, struct mixer_handle *h) +static int com_sleep(const struct mixer *m, struct mixer_handle *h) { time_t t1, wake_time_epoch; unsigned int delay; @@ -286,7 +287,7 @@ static int com_sleep(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) { + if (fot && fo_mood) { ret = set_initial_volume(m, h); if (ret < 0) return ret; @@ -303,12 +304,13 @@ static int com_sleep(struct mixer *m, struct mixer_handle *h) if (ret < 0) return ret; } - if (OPT_GIVEN(SLEEP, SLEEP_MOOD)) { + if (sleep_mood) { change_afs_mode(sleep_mood); - client_cmd("play"); - } else + if (!fot || !fo_mood) /* currently stopped */ + client_cmd("play"); + } else if (fot && fo_mood) /* currently playing */ client_cmd("stop"); - if (!fit) + if (!fit || !fi_mood) /* nothing to do */ return 1; change_afs_mode(fi_mood); for (;;) { @@ -328,7 +330,7 @@ static int com_sleep(struct mixer *m, struct mixer_handle *h) } EXPORT_CMD(sleep); -static int com_snooze(struct mixer *m, struct mixer_handle *h) +static int com_snooze(const struct mixer *m, struct mixer_handle *h) { int ret, val; @@ -355,44 +357,31 @@ static int com_snooze(struct mixer *m, struct mixer_handle *h) } EXPORT_CMD(snooze); -static void init_mixers(void) -{ - int i; - - FOR_EACH_MIXER(i) { - struct mixer *m = &supported_mixer[i]; - PARA_DEBUG_LOG("initializing mixer API #%d (%s)\n", - i, mixer_name[i]); - m->init(m); - } -} - -static int com_set(struct mixer *m, struct mixer_handle *h) +static int com_set(const struct mixer *m, struct mixer_handle *h) { return m->set(h, OPT_UINT32_VAL(SET, VAL)); } EXPORT_CMD(set); -static struct mixer *get_mixer_or_die(void) +static const struct mixer *get_mixer_or_die(void) { int i; if (!OPT_GIVEN(PARA_MIXER, MIXER_API)) - i = DEFAULT_MIXER; + i = 0; /* default: use first mixer */ else FOR_EACH_MIXER(i) - if (!strcmp(mixer_name[i], + if (!strcmp(mixers[i]->name, OPT_STRING_VAL(PARA_MIXER, MIXER_API))) break; if (i < NUM_SUPPORTED_MIXERS) { - PARA_NOTICE_LOG("using %s mixer API\n", mixer_name[i]); - return supported_mixer + i; + PARA_NOTICE_LOG("using %s mixer API\n", mixers[i]->name); + return mixers[i]; } printf("available mixer APIs: "); - FOR_EACH_MIXER(i) { - int d = (i == DEFAULT_MIXER); - printf("%s%s%s ", d? "[" : "", mixer_name[i], d? "]" : ""); - } + FOR_EACH_MIXER(i) + printf("%s%s%s ", i == 0? "[" : "", mixers[i]->name, + i == 0? "]" : ""); printf("\n"); exit(EXIT_FAILURE); } @@ -410,7 +399,8 @@ static void show_subcommands(void) } -static int com_help(__a_unused struct mixer *m, __a_unused struct mixer_handle *h) +static int com_help(__a_unused const struct mixer *m, + __a_unused struct mixer_handle *h) { const struct lls_command *cmd; const struct lls_opt_result *r_l = OPT_RESULT(HELP, LONG); @@ -536,7 +526,7 @@ int main(int argc, char *argv[]) int ret; char *errctx; const char *subcmd; - struct mixer *m; + const struct mixer *m; struct mixer_handle *h; unsigned n; @@ -567,7 +557,6 @@ int main(int argc, char *argv[]) ret = parse_and_merge_config_file(cmd); if (ret < 0) goto free_lpr; - init_mixers(); m = get_mixer_or_die(); ret = m->open(OPT_STRING_VAL(PARA_MIXER, MIXER_DEVICE), &h); if (ret < 0)