Author: lslezak Date: Wed Apr 1 14:23:17 2009 New Revision: 56533 URL: http://svn.opensuse.org/viewcvs/yast?rev=56533&view=rev Log: - make channel names unique - add channel index to channel name if more channels have the same name, fixes UI syntax error for some sound cards (bnc#484073) Added: branches/SuSE-Code-11-Branch/sound/agent-audio/src/YastChannelId.cc branches/SuSE-Code-11-Branch/sound/agent-audio/src/YastChannelId.h Modified: branches/SuSE-Code-11-Branch/sound/agent-audio/src/AlsaAudio.cc branches/SuSE-Code-11-Branch/sound/agent-audio/src/AlsaAudio.h branches/SuSE-Code-11-Branch/sound/agent-audio/src/Makefile.am branches/SuSE-Code-11-Branch/sound/package/yast2-sound.changes branches/SuSE-Code-11-Branch/sound/sound/src/mixer.ycp Modified: branches/SuSE-Code-11-Branch/sound/agent-audio/src/AlsaAudio.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-Branch/sound/agent-audio/src/AlsaAudio.cc?rev=56533&r1=56532&r2=56533&view=diff ============================================================================== --- branches/SuSE-Code-11-Branch/sound/agent-audio/src/AlsaAudio.cc (original) +++ branches/SuSE-Code-11-Branch/sound/agent-audio/src/AlsaAudio.cc Wed Apr 1 14:23:17 2009 @@ -57,8 +57,9 @@ return YCPNull(); \ } +#include "YastChannelId.h" -YCPValue alsaGetVolume(int card_id, const string& channel) +YCPValue alsaGetVolume(int card_id, const string& channel_name) { INIT_MIXER @@ -67,11 +68,19 @@ snd_mixer_selem_channel_id_t chn; + YastChannelId ch_id(channel_name); + std::string channel(ch_id.name()); + unsigned ch_index = ch_id.index(); + + y2debug("Channel Id: '%s' => name: '%s', index: %u", channel_name.c_str(), channel.c_str(), ch_index); for (elem = snd_mixer_first_elem(handle); elem; elem = snd_mixer_elem_next(elem)) { snd_mixer_selem_get_id(elem, sid); + + // is it the required channel? if (snd_mixer_selem_id_get_name(sid) == channel + && snd_mixer_selem_get_index(elem) == ch_index && snd_mixer_selem_is_active(elem) && snd_mixer_selem_has_playback_volume(elem)) { @@ -96,11 +105,13 @@ } } + y2warning("Card %d: channel '%s' not found", card_id, channel_name.c_str()); + snd_mixer_close(handle); return YCPInteger((long long)0); } -YCPValue alsaGetMute(int card_id, const string& channel) +YCPValue alsaGetMute(int card_id, const string& channel_name) { INIT_MIXER @@ -108,10 +119,17 @@ snd_mixer_selem_channel_id_t chn; + YastChannelId ch_id(channel_name); + std::string channel(ch_id.name()); + unsigned ch_index = ch_id.index(); + + y2debug("Channel Id: '%s' => name: '%s', index: %u", channel_name.c_str(), channel.c_str(), ch_index); + for (elem = snd_mixer_first_elem(handle); elem; elem = snd_mixer_elem_next(elem)) { snd_mixer_selem_get_id(elem, sid); if (snd_mixer_selem_id_get_name(sid) == channel + && snd_mixer_selem_get_index(elem) == ch_index && snd_mixer_selem_is_active(elem) && snd_mixer_selem_has_playback_switch(elem)) { @@ -128,21 +146,29 @@ } } + y2warning("Card %d: channel '%s' not found", card_id, channel_name.c_str()); + snd_mixer_close(handle); return YCPBoolean(false); } -YCPBoolean alsaSetVolume(int card_id, const string& channel, int value) +YCPBoolean alsaSetVolume(int card_id, const string& channel_name, int value) { INIT_MIXER long from, to, val; + YastChannelId ch_id(channel_name); + std::string channel(ch_id.name()); + unsigned ch_index = ch_id.index(); + + y2debug("Channel Id: '%s' => name: '%s', index: %u", channel_name.c_str(), channel.c_str(), ch_index); for (elem = snd_mixer_first_elem(handle); elem; elem = snd_mixer_elem_next(elem)) { snd_mixer_selem_get_id(elem, sid); if (snd_mixer_selem_id_get_name(sid) == channel + && snd_mixer_selem_get_index(elem) == ch_index && snd_mixer_selem_is_active(elem) && snd_mixer_selem_has_playback_volume(elem)) { @@ -157,20 +183,27 @@ } } + y2warning("Card %d: channel '%s' not found", card_id, channel_name.c_str()); snd_mixer_close(handle); return YCPBoolean(false); } -YCPBoolean alsaSetMute(int card_id, const string& channel, bool value) +YCPBoolean alsaSetMute(int card_id, const string& channel_name, bool value) { INIT_MIXER + YastChannelId ch_id(channel_name); + std::string channel(ch_id.name()); + unsigned ch_index = ch_id.index(); + + y2debug("Channel Id: '%s' => name: '%s', index: %u", channel_name.c_str(), channel.c_str(), ch_index); for (elem = snd_mixer_first_elem(handle); elem; elem = snd_mixer_elem_next(elem)) { snd_mixer_selem_get_id(elem, sid); if (snd_mixer_selem_id_get_name(sid) == channel + && snd_mixer_selem_get_index(elem) == ch_index && snd_mixer_selem_is_active(elem) && snd_mixer_selem_has_playback_switch(elem)) { @@ -180,6 +213,8 @@ } } + y2warning("Card %d: channel '%s' not found", card_id, channel_name.c_str()); + snd_mixer_close(handle); return YCPBoolean(false); } @@ -190,9 +225,10 @@ INIT_MIXER // well, this doesn't look like a c++ code... i'm sorry for that... see definition above + y2milestone("Sound card %d: reading channels", card_id); + for (elem = snd_mixer_first_elem(handle); elem; elem = snd_mixer_elem_next(elem)) { - snd_mixer_selem_get_id(elem, sid); if (!snd_mixer_selem_is_active(elem)) { continue; @@ -203,8 +239,12 @@ continue; } - outlist->add(YCPString(snd_mixer_selem_id_get_name(sid))); + YastChannelId ch_id(snd_mixer_selem_get_name(elem), snd_mixer_selem_get_index(elem)); + + y2milestone("Found channel: name: '%s', index: %u, id: '%s'", + ch_id.name().c_str(), ch_id.index(), ch_id.asString().c_str()); + outlist->add(YCPString(ch_id.asString())); } snd_mixer_close(handle); @@ -241,7 +281,7 @@ cmd+=tmp; } cmd+=" > /dev/null 2>&1"; - y2debug("executing '%s'", cmd.c_str()); + y2milestone("executing '%s'", cmd.c_str()); if(system(cmd.c_str())!=-1) { return YCPBoolean(true); @@ -263,7 +303,7 @@ cmd+=tmp; } cmd+=" > /dev/null 2>&1"; - y2debug("executing '%s'", cmd.c_str()); + y2milestone("executing '%s'", cmd.c_str()); if(system(cmd.c_str())) { return YCPBoolean(true); Modified: branches/SuSE-Code-11-Branch/sound/agent-audio/src/AlsaAudio.h URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-Branch/sound/agent-audio/src/AlsaAudio.h?rev=56533&r1=56532&r2=56533&view=diff ============================================================================== --- branches/SuSE-Code-11-Branch/sound/agent-audio/src/AlsaAudio.h (original) +++ branches/SuSE-Code-11-Branch/sound/agent-audio/src/AlsaAudio.h Wed Apr 1 14:23:17 2009 @@ -32,29 +32,29 @@ /** * volume setting * @param card card id - * @param channel name eg. "Master" + * @param channel_name name eg. "Master" * @param value volume 0..100 */ -YCPBoolean alsaSetVolume(int card, const string& channel, int value); +YCPBoolean alsaSetVolume(int card, const string& channel_name, int value); /** * volume reading * @param card card id - * @param channel channel name + * @param channel_name channel name */ -YCPValue alsaGetVolume(int card, const string& channel); +YCPValue alsaGetVolume(int card, const string& channel_name); /** * setMute * @param card card id - * @param channel channel name + * @param channel_name channel name * @param value boolean mute/unmute */ -YCPBoolean alsaSetMute(int card, const string& channel, bool value); -YCPValue alsaGetMute(int card, const string& channel); +YCPBoolean alsaSetMute(int card, const string& channel_name, bool value); +YCPValue alsaGetMute(int card, const string& channel_name); /** * getChannels- list of available channels for card #id Modified: branches/SuSE-Code-11-Branch/sound/agent-audio/src/Makefile.am URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-Branch/sound/agent-audio/src/Makefile.am?rev=56533&r1=56532&r2=56533&view=diff ============================================================================== --- branches/SuSE-Code-11-Branch/sound/agent-audio/src/Makefile.am (original) +++ branches/SuSE-Code-11-Branch/sound/agent-audio/src/Makefile.am Wed Apr 1 14:23:17 2009 @@ -8,6 +8,7 @@ noinst_LTLIBRARIES = liby2ag_audio.la liby2ag_audio_la_SOURCES = \ + YastChannelId.cc YastChannelId.h \ OSSAudio.cc OSSAudio.h \ AudioAgent.cc AudioAgent.h \ AlsaAudio.cc AlsaAudio.h Added: branches/SuSE-Code-11-Branch/sound/agent-audio/src/YastChannelId.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-Branch/sound/agent-audio/src/YastChannelId.cc?rev=56533&view=auto ============================================================================== --- branches/SuSE-Code-11-Branch/sound/agent-audio/src/YastChannelId.cc (added) +++ branches/SuSE-Code-11-Branch/sound/agent-audio/src/YastChannelId.cc Wed Apr 1 14:23:17 2009 @@ -0,0 +1,141 @@ +/* ------------------------------------------------------------------------------ + * Copyright (c) 2009 Novell, Inc. All Rights Reserved. + * + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of version 2 of the GNU General Public License as published by the + * Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, contact Novell, Inc. + * + * To contact Novell about this file by physical or electronic mail, you may find + * current contact information at www.novell.com. + * ------------------------------------------------------------------------------ + */ + +/* + File: $Id:$ + Author: Ladislav Slezák <lslezak@novell.com> + Summary: Class for converting Alsa channel name to Yast channel ID and vice versea. +*/ + +#include "YastChannelId.h" + +// ::snprintf +#include <cstdio> +// ::atoi +#include <cstdlib> + +// parse "<channel_name>_#<index>#" string +YastChannelId::YastChannelId(const std::string &yastID) +{ + channel_name = yastID; + channel_index = 0; + + if (yastID.empty()) + { + return; + } + + std::string::const_iterator it = yastID.end(); + + std::string::const_iterator number_end_it = yastID.end(); + std::string::const_iterator number_begin_it = yastID.end(); + + --it; + + if (it == yastID.begin()) + { + return; + } + + // no channel index appended + if (*it != '#') + { + return; + } + else + { + number_end_it = it; + --it; + + if (it == yastID.begin()) + { + return; + } + + bool digitfound = false; + + for(;it != yastID.begin(); --it) + { + if (!isdigit(*it)) + { + break; + } + else + { + digitfound = true; + } + } + + if (!digitfound) + { + // channel name end with # but no valid index is there + return; + } + else + { + // no name found + if (it == yastID.begin()) + { + return; + } + + if (*it == '#') + { + number_begin_it = it; + number_begin_it++; + + --it; + + if (it == yastID.begin()) + { + return; + } + + if (*it == '_') + { + channel_name = std::string(yastID.begin(), it); + + std::string channel_index_str(number_begin_it, number_end_it); + channel_index = atoi(channel_index_str.c_str()); + } + } + } + } +} + +std::string YastChannelId::asString() +{ + if (channel_index == 0) + { + return channel_name; + } + + // add channel index if it's greater than zero + std::string ret(channel_name); + + // add index + char buffer[16]; + ::snprintf(buffer, sizeof(buffer), "_#%u#", channel_index); + + ret += buffer; + + return ret; +} + Added: branches/SuSE-Code-11-Branch/sound/agent-audio/src/YastChannelId.h URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-Branch/sound/agent-audio/src/YastChannelId.h?rev=56533&view=auto ============================================================================== --- branches/SuSE-Code-11-Branch/sound/agent-audio/src/YastChannelId.h (added) +++ branches/SuSE-Code-11-Branch/sound/agent-audio/src/YastChannelId.h Wed Apr 1 14:23:17 2009 @@ -0,0 +1,47 @@ +/* ------------------------------------------------------------------------------ + * Copyright (c) 2009 Novell, Inc. All Rights Reserved. + * + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of version 2 of the GNU General Public License as published by the + * Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, contact Novell, Inc. + * + * To contact Novell about this file by physical or electronic mail, you may find + * current contact information at www.novell.com. + * ------------------------------------------------------------------------------ + */ + +/* + File: $Id:$ + Author: Ladislav Slezák <lslezak@novell.com> + Summary: Class for converting Alsa channel name to Yast channel ID and vice versea. +*/ + +#include <string> + +class YastChannelId +{ + public: + + YastChannelId() : channel_name(), channel_index(0) {} + YastChannelId(const char* alsa_name, unsigned alsa_index) : channel_name(alsa_name), channel_index(alsa_index) {} + YastChannelId(const std::string &YastID); + + std::string name() {return channel_name;} + unsigned index() {return channel_index;} + + std::string asString(); + + private: + + std::string channel_name; + unsigned channel_index; +}; + Modified: branches/SuSE-Code-11-Branch/sound/package/yast2-sound.changes URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-Branch/sound/package/yast2-sound.changes?rev=56533&r1=56532&r2=56533&view=diff ============================================================================== --- branches/SuSE-Code-11-Branch/sound/package/yast2-sound.changes (original) +++ branches/SuSE-Code-11-Branch/sound/package/yast2-sound.changes Wed Apr 1 14:23:17 2009 @@ -1,4 +1,11 @@ ------------------------------------------------------------------- +Wed Apr 1 14:19:56 CEST 2009 - lslezak@suse.cz + +- make channel names unique - add channel index to channel name + if more channels have the same name, fixes UI syntax error + for some sound cards (bnc#484073) + +------------------------------------------------------------------- Thu Feb 26 12:49:21 CET 2009 - lslezak@suse.cz - set 100% volume for snd-hda-intel driver (bnc#477853), Modified: branches/SuSE-Code-11-Branch/sound/sound/src/mixer.ycp URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-Branch/sound/sound/src/mixer.ycp?rev=56533&r1=56532&r2=56533&view=diff ============================================================================== --- branches/SuSE-Code-11-Branch/sound/sound/src/mixer.ycp (original) +++ branches/SuSE-Code-11-Branch/sound/sound/src/mixer.ycp Wed Apr 1 14:23:17 2009 @@ -101,14 +101,32 @@ * @param spec true-slider false-intfield * @return term widget */ - define term volElement(string label, integer value, boolean spec) ``{ + define term volElement(string channel_id, integer value, boolean spec) + { + string label = channel_id; + + // remove the index from the channel ID if it's there + if (regexpmatch(channel_id, "^.*_#[0-9]+#$")) + { + label = regexpsub(channel_id, "^(.*)_#[0-9]+#$", "\\1"); + string index_str = regexpsub(channel_id, "^.*_#([0-9]+)#$", "\\1"); + integer index = tointeger(index_str); + + if (index != nil) + { + // add index + 1 to the channel label + // so there are channels "Speaker", "Speaker 2", "Speaker 3", ... + label = sformat("%1 %2", label, index + 1); + } + } + if (UI::HasSpecialWidget(`Slider)) { - return `Slider(`id(label), `opt(`notify), translateChannelName(label), 0, 100, value); + return `Slider(`id(channel_id), `opt(`notify), translateChannelName(label), 0, 100, value); } else { - return `IntField(`id(label), `opt(`notify), translateChannelName(label), 0, 100, value); + return `IntField(`id(channel_id), `opt(`notify), translateChannelName(label), 0, 100, value); } } -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org