Enlightenment CVS committal Author : devilhorns Project : e_modules Module : mixer
Dir : e_modules/mixer Modified Files: alsa_mixer.c e_mod_main.c Log Message: Fix up some formatting issues; Fix issues with muting channels that do not support mute. Will restore old volume now. =================================================================== RCS file: /cvs/e/e_modules/mixer/alsa_mixer.c,v retrieving revision 1.34 retrieving revision 1.35 diff -u -3 -r1.34 -r1.35 --- alsa_mixer.c 12 Dec 2007 23:24:14 -0000 1.34 +++ alsa_mixer.c 14 Dec 2007 03:25:16 -0000 1.35 @@ -11,6 +11,9 @@ static int _alsa_get_mixer_id (const char *name); static void *_alsa_card_get_channel (void *data, int channel_id); +static Ecore_Hash *vols = NULL; +static int muted = 0; + Evas_List * alsa_get_cards() { @@ -230,8 +233,16 @@ snd_mixer_t *handle; snd_mixer_elem_t *elem; snd_mixer_selem_id_t *sid; - int err, range, ret = 0; + int err, range, ret = 0, mute; long min, max, vol; + + if (muted) + { + int v; + + if (v = (unsigned int)(ecore_hash_get(vols, (int*)(card_id << 16) + channel_id))) + return v; + } card = alsa_get_card(card_id); if (!card) return 0; @@ -292,10 +303,14 @@ } snd_mixer_close(handle); + if (card->name) evas_stringshare_del(card->name); + if (card->real) evas_stringshare_del(card->real); E_FREE(card); return ret; error: + if (card->name) evas_stringshare_del(card->name); + if (card->real) evas_stringshare_del(card->real); E_FREE(card); return 0; } @@ -362,7 +377,6 @@ snd_mixer_close(handle); goto error; } - snd_mixer_selem_get_playback_volume_range(elem, &min, &max); v = (vol < 0) ? -vol: vol; if (v > 0) @@ -380,96 +394,29 @@ snd_mixer_selem_set_playback_volume(elem, 0, v); if (!snd_mixer_selem_is_playback_mono(elem)) snd_mixer_selem_set_playback_volume(elem, 1, v); - + break; } } } - + snd_mixer_close(handle); + if (card->name) evas_stringshare_del(card->name); + if (card->real) evas_stringshare_del(card->real); E_FREE(card); return 1; error: - E_FREE(card); - return 0; + if (card->name) evas_stringshare_del(card->name); + if (card->real) evas_stringshare_del(card->real); + E_FREE(card); + return 0; } int alsa_get_mute(int card_id, int channel_id) { - Mixer_Card *card; - snd_mixer_t *handle; - snd_mixer_elem_t *elem; - snd_mixer_selem_id_t *sid; - int err, id, mute = 0; - const char *name; - - card = alsa_get_card(card_id); - if (!card) return 0; - - if ((err = snd_mixer_open(&handle, 0)) < 0) - { - printf("Cannot open mixer: %s\n", snd_strerror(err)); - goto error; - } - - if ((err = snd_mixer_attach(handle, (char *)card->name)) < 0) - { - printf("Cannot Attach Mixer: %s\n", snd_strerror(err)); - snd_mixer_close(handle); - goto error; - } - - if ((err = snd_mixer_selem_register(handle, NULL, NULL)) < 0) - { - printf("Cannot Register Mixer: %s\n", snd_strerror(err)); - snd_mixer_close(handle); - goto error; - } - - if ((err = snd_mixer_load(handle)) < 0) - { - printf("Cannot Load Mixer: %s\n", snd_strerror(err)); - snd_mixer_close(handle); - goto error; - } - - for (elem = snd_mixer_first_elem(handle); elem; elem = snd_mixer_elem_next(elem)) - { - snd_mixer_selem_id_alloca(&sid); - snd_mixer_selem_get_id(elem, sid); - if (!snd_mixer_selem_is_active(elem)) continue; - - name = snd_mixer_selem_id_get_name(sid); - id = _alsa_get_mixer_id(name); - if (id == channel_id) - { - if (snd_mixer_selem_has_playback_switch(elem)) - { - snd_mixer_selem_get_playback_switch(elem, id, &mute); - break; - } - else - { - snd_mixer_close(handle); - mute = alsa_get_volume(card_id, channel_id); - E_FREE(card); - if (mute <= 0) - return 1; - else - return 0; - } - } - } - - snd_mixer_close(handle); - E_FREE(card); - return (mute == 1 ? 0: 1); - -error: - E_FREE(card); - return 0; + return muted; } int @@ -481,7 +428,6 @@ snd_mixer_selem_id_t *sid; int id, err, vol; const char *name; - static Ecore_Hash *vols = NULL; card = alsa_get_card(card_id); if (!card) return 0; @@ -536,11 +482,11 @@ ecore_hash_free_value_cb_set(vols, NULL); } - snd_mixer_close(handle); if (mute) { ecore_hash_set(vols, (int*)(card_id << 16) + channel_id, (int*)alsa_get_volume(card_id, channel_id)); alsa_set_volume(card_id, channel_id, (0.0 * 100)); + muted = 1; } else { @@ -551,19 +497,27 @@ } else alsa_set_volume(card_id, channel_id, (0.5 * 100)); + muted = 0; } + if (card->name) evas_stringshare_del(card->name); + if (card->real) evas_stringshare_del(card->real); E_FREE(card); + snd_mixer_close(handle); return 1; } break; } } - + snd_mixer_close(handle); + if (card->name) evas_stringshare_del(card->name); + if (card->real) evas_stringshare_del(card->real); E_FREE(card); return 1; error: + if (card->name) evas_stringshare_del(card->name); + if (card->real) evas_stringshare_del(card->real); E_FREE(card); return 0; } =================================================================== RCS file: /cvs/e/e_modules/mixer/e_mod_main.c,v retrieving revision 1.72 retrieving revision 1.73 diff -u -3 -r1.72 -r1.73 --- e_mod_main.c 2 Dec 2007 16:25:54 -0000 1.72 +++ e_mod_main.c 14 Dec 2007 03:25:16 -0000 1.73 @@ -428,10 +428,8 @@ sys->get_channels = alsa_card_get_channels; sys->get_channel = alsa_card_get_channel; sys->free_cards = alsa_free_cards; - sys->get_volume = alsa_get_volume; sys->set_volume = alsa_set_volume; - sys->get_mute = alsa_get_mute; sys->set_mute = alsa_set_mute; #elif defined(HAVE_OSS) @@ -440,10 +438,8 @@ sys->get_channels = oss_card_get_channels; sys->get_channel = oss_card_get_channel; sys->free_cards = oss_free_cards; - sys->get_volume = oss_get_volume; sys->set_volume = oss_set_volume; - sys->get_mute = oss_get_mute; sys->set_mute = oss_set_mute; #endif @@ -501,21 +497,18 @@ E_CONFIG_VAL(D, T, decrease_vol_key.action, STR); E_CONFIG_VAL(D, T, decrease_vol_key.params, STR); E_CONFIG_VAL(D, T, decrease_vol_key.any_mod, UCHAR); - E_CONFIG_VAL(D, T, increase_vol_key.context, INT); E_CONFIG_VAL(D, T, increase_vol_key.modifiers, INT); E_CONFIG_VAL(D, T, increase_vol_key.key, STR); E_CONFIG_VAL(D, T, increase_vol_key.action, STR); E_CONFIG_VAL(D, T, increase_vol_key.params, STR); E_CONFIG_VAL(D, T, increase_vol_key.any_mod, UCHAR); - E_CONFIG_VAL(D, T, mute_key.context, INT); E_CONFIG_VAL(D, T, mute_key.modifiers, INT); E_CONFIG_VAL(D, T, mute_key.key, STR); E_CONFIG_VAL(D, T, mute_key.action, STR); E_CONFIG_VAL(D, T, mute_key.params, STR); E_CONFIG_VAL(D, T, mute_key.any_mod, UCHAR); - E_CONFIG_LIST(D, T, items, conf_item_edd); mixer_config = e_config_domain_load("module.mixer", conf_edd); @@ -612,8 +605,8 @@ m = mixer->mix_sys->get_mute(ci->card_id, channel_id); if (m) return; - - if ((ci->card_id != 0) && (channel_id != 0)) + + if (channel_id != 0) { int ret; @@ -661,18 +654,20 @@ if (m) { edje_object_signal_emit(mixer->base, "muted", ""); - if (win) { + if (win) + { edje_object_signal_emit(e_slider_edje_object_get(win->slider), - "e,state,disabled", "e"); - } + "e,state,disabled", "e"); + } } else { edje_object_signal_emit(mixer->base, "medium", ""); - if (win) { + if (win) + { edje_object_signal_emit(e_slider_edje_object_get(win->slider), - "e,state,enabled", "e"); - } + "e,state,enabled", "e"); + } } } @@ -1048,7 +1043,7 @@ inside = E_INSIDE(xev->x, xev->y, win->window->x, win->window->y, win->window->w, win->window->h); - if ((xev->button == 1)/* && (!win->first_mouse_up)*/ && !inside) + if ((xev->button == 1) && !inside) _mixer_window_simple_pop_down(win->mixer->inst); if ((xev->button == 1) && win->first_mouse_up) @@ -1067,9 +1062,8 @@ if (!(win = data) || (win->slide_timer)) return 1; evas_event_feed_mouse_wheel(win->window->evas, - xev->direction, xev->z, - xev->time, NULL); - + xev->direction, xev->z, xev->time, NULL); + return 1; } @@ -1119,7 +1113,7 @@ Mixer_Win_Gauge *win; char buf[4096]; - if (!inst || !inst->mixer || !inst->gcc) return; + if ((!inst) || (!inst->mixer) || (!inst->gcc)) return; if (!(con = e_container_current_get(e_manager_current_get()))) return; if (!(inst->ci->show_popup)) return; @@ -1150,16 +1144,15 @@ e_popup_resize(win->window, 300, 90); } else - { - win = inst->mixer->gauge_win; - } + win = inst->mixer->gauge_win; e_popup_move(win->window, (con->w/2.0)-150, (con->h/2.0)-45); e_popup_show(win->window); if (win->timer) ecore_timer_del(win->timer); - win->timer = ecore_timer_add(inst->ci->popup_speed, _mixer_window_gauge_visible_cb, win); + win->timer = ecore_timer_add(inst->ci->popup_speed, + _mixer_window_gauge_visible_cb, win); } static void @@ -1168,8 +1161,8 @@ Edje_Message_Int *msg; int vol; - if (!ci || !(ci->show_popup) || !win) return; - if (!mixer || !mixer->mix_sys || !mixer->mix_sys->get_volume) return; + if ((!ci) || (!ci->show_popup) || (!win)) return; + if ((!mixer) || (!mixer->mix_sys) || (!mixer->mix_sys->get_volume)) return; msg = malloc(sizeof(Edje_Message_Int)); vol = (int)mixer->mix_sys->get_volume(ci->card_id, ci->channel_id); msg->val = vol; @@ -1194,8 +1187,8 @@ m = mixer->mix_sys->get_mute(ci->card_id, ci->channel_id); if (m) return; - - if ((ci->card_id != 0) && (ci->channel_id != 0)) + + if (ci->channel_id != 0) { vol = mixer->mix_sys->get_volume(ci->card_id, ci->channel_id); mixer->mix_sys->set_volume(ci->card_id, ci->channel_id, vol+VOL_STEP); @@ -1217,12 +1210,11 @@ m = mixer->mix_sys->get_mute(ci->card_id, ci->channel_id); if (m) return; - - if ((ci->card_id != 0) && (ci->channel_id != 0)) + + if (ci->channel_id != 0) { vol = mixer->mix_sys->get_volume(ci->card_id, ci->channel_id); vol = vol-VOL_STEP < 0 ? 0 : vol-VOL_STEP; mixer->mix_sys->set_volume(ci->card_id, ci->channel_id, vol); } } - ------------------------------------------------------------------------- SF.Net email is sponsored by: Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs