Mailinglist Archive: yast-commit (819 mails)

< Previous Next >
[yast-commit] r54482 - in /trunk/sound: agent-audio/src/ package/ sound/src/
  • From: lslezak@xxxxxxxxxxxxxxxx
  • Date: Fri, 09 Jan 2009 08:47:06 -0000
  • Message-id: <E1LLD1G-0006H6-Gp@xxxxxxxxxxxxxxxx>
Author: lslezak
Date: Fri Jan 9 09:47:06 2009
New Revision: 54482

URL: http://svn.opensuse.org/viewcvs/yast?rev=54482&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#407060)

Added:
trunk/sound/agent-audio/src/YastChannelId.cc
trunk/sound/agent-audio/src/YastChannelId.h
Modified:
trunk/sound/agent-audio/src/AlsaAudio.cc
trunk/sound/agent-audio/src/AlsaAudio.h
trunk/sound/agent-audio/src/Makefile.am
trunk/sound/package/yast2-sound.changes
trunk/sound/sound/src/mixer.ycp

Modified: trunk/sound/agent-audio/src/AlsaAudio.cc
URL:
http://svn.opensuse.org/viewcvs/yast/trunk/sound/agent-audio/src/AlsaAudio.cc?rev=54482&r1=54481&r2=54482&view=diff
==============================================================================
--- trunk/sound/agent-audio/src/AlsaAudio.cc (original)
+++ trunk/sound/agent-audio/src/AlsaAudio.cc Fri Jan 9 09:47:06 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: trunk/sound/agent-audio/src/AlsaAudio.h
URL:
http://svn.opensuse.org/viewcvs/yast/trunk/sound/agent-audio/src/AlsaAudio.h?rev=54482&r1=54481&r2=54482&view=diff
==============================================================================
--- trunk/sound/agent-audio/src/AlsaAudio.h (original)
+++ trunk/sound/agent-audio/src/AlsaAudio.h Fri Jan 9 09:47:06 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: trunk/sound/agent-audio/src/Makefile.am
URL:
http://svn.opensuse.org/viewcvs/yast/trunk/sound/agent-audio/src/Makefile.am?rev=54482&r1=54481&r2=54482&view=diff
==============================================================================
--- trunk/sound/agent-audio/src/Makefile.am (original)
+++ trunk/sound/agent-audio/src/Makefile.am Fri Jan 9 09:47:06 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: trunk/sound/agent-audio/src/YastChannelId.cc
URL:
http://svn.opensuse.org/viewcvs/yast/trunk/sound/agent-audio/src/YastChannelId.cc?rev=54482&view=auto
==============================================================================
--- trunk/sound/agent-audio/src/YastChannelId.cc (added)
+++ trunk/sound/agent-audio/src/YastChannelId.cc Fri Jan 9 09:47:06 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@xxxxxxxxxx>
+ 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: trunk/sound/agent-audio/src/YastChannelId.h
URL:
http://svn.opensuse.org/viewcvs/yast/trunk/sound/agent-audio/src/YastChannelId.h?rev=54482&view=auto
==============================================================================
--- trunk/sound/agent-audio/src/YastChannelId.h (added)
+++ trunk/sound/agent-audio/src/YastChannelId.h Fri Jan 9 09:47:06 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@xxxxxxxxxx>
+ 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: trunk/sound/package/yast2-sound.changes
URL:
http://svn.opensuse.org/viewcvs/yast/trunk/sound/package/yast2-sound.changes?rev=54482&r1=54481&r2=54482&view=diff
==============================================================================
--- trunk/sound/package/yast2-sound.changes (original)
+++ trunk/sound/package/yast2-sound.changes Fri Jan 9 09:47:06 2009
@@ -1,4 +1,11 @@
-------------------------------------------------------------------
+Fri Jan 9 09:26:30 CET 2009 - lslezak@xxxxxxx
+
+- 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#407060)
+
+-------------------------------------------------------------------
Fri Dec 19 15:18:05 CET 2008 - lslezak@xxxxxxx

- removed the progress dialog at start up (bnc#447573)

Modified: trunk/sound/sound/src/mixer.ycp
URL:
http://svn.opensuse.org/viewcvs/yast/trunk/sound/sound/src/mixer.ycp?rev=54482&r1=54481&r2=54482&view=diff
==============================================================================
--- trunk/sound/sound/src/mixer.ycp (original)
+++ trunk/sound/sound/src/mixer.ycp Fri Jan 9 09:47:06 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);
}
}

@@ -210,6 +228,8 @@
path pth = topath(sformat(".audio.alsa.cards.%1.channels", card_id));
list channels = [];
string modname = "";
+ // card name
+ string model = Sound::modules_conf[card_id, "model"]:_("Unknown");

if (Sound::use_alsa)
{
@@ -284,8 +304,8 @@

term con = mixerWidget (channels);

- // dialog header
- Wizard::SetContentsButtons (sformat(_("Volume Settings for Card %1"),
card_id),
+ // dialog header, %1 = card id (number), %2 = name
+ Wizard::SetContentsButtons (sformat(_("Volume Settings for Card %1 - %2"),
card_id, model),
con, help, Label::BackButton(), Label::OKButton() );

any ui = nil; // value can be `next `abort... or string (channel
name)

--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages