Hi Jari,

Can you try the attached alsamixer2 plugin? You need to change the
settings in your local_conf.py to something like the following:

ALSAMIXER2_CTRLS = [
   ('Main', 'ADC', 0, 'default', 50, 0, 100),
   ('Main', 'ADC', 1, 'default', 50, 0, 100),
]

There's only the one variable now. _MAIN_CTRL and _MIXER_CTRL are gone
and not used anymore.

...juerg



On Dec 17, 2007 9:53 AM, Juerg Haefliger <[EMAIL PROTECTED]> wrote:
> Hi Jari,
>
> I just realized that your card has multiple indices (at least that's
> what I think it is) per mixer control. That's not going to work with
> the current implementation of the alsamixer2 plugin. I have to think
> about this for a bit...
>
> ...juerg
>
>
>
>
> On Dec 17, 2007 9:38 AM, Hamalainen, Jari <[EMAIL PROTECTED]> wrote:
> > Hi!
> >
> > I noticed that it did not work. The sound leves were completely different.
> > Amixer proved that it only changes the volume to the left channel.
> >
> > amixer sget ADC
> > Simple mixer control 'ADC',0
> >   Capabilities: volume volume-joined
> >   Playback channels: Mono
> >   Capture channels: Mono
> >   Limits: 0 - 163
> >   Mono: 82 [50%] [-22.50dB]
> >
> > amixer sget ADC,1
> > Simple mixer control 'ADC',1
> >   Capabilities: volume volume-joined
> >   Playback channels: Mono
> >   Capture channels: Mono
> >   Limits: 0 - 163
> >   Mono: 124 [76%] [-1.50dB]
> >
> > - Jari
> >
> >
> >
> > >>
> > >> Hi!
> > >>
> > >> It did not help. Still get the error: Failed to open mixer control 
> > >> "ADC,1"
> > >
> > >Oh I forgot to mention that you need to drop the "ADC,1" line, that'll 
> > >never work. Just apply the patch and try the following configuration:
> > >
> > >ALSAMIXER2_MAIN_CTRL = 'ADC'
> > >ALSAMIXER2_CTRLS = [
> > >   ('ADC',       'default', 50, 0, 100),
> > >]
> > >
> > >...juerg
> >
> >
> >
> > > - Jari
> > >
> > > >Hi Jari,
> > > >
> > > >Can you apply the attached patch to alsamixer2.py and let us now if it 
> > > >fixes your problem?
> > >
> > > >Thanks
> > > >...juerg
> > >
> > >
> > >
> > >
> >
> > -------------------------------------------------------------------------
> > 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
> > _______________________________________________
> > Freevo-devel mailing list
> > Freevo-devel@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/freevo-devel
> >
>
# -*- coding: iso-8859-1 -*-
# -----------------------------------------------------------------------
# alsamixer2.py - An ALSA mixer interface for freevo.
# -----------------------------------------------------------------------
#
# Notes:
# Todo:
#
# -----------------------------------------------------------------------
# Freevo - A Home Theater PC framework
# Copyright (C) 2002 Krister Lagerstrom, et al.
# Please see the file freevo/Docs/CREDITS for a complete list of authors.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY 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, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# -----------------------------------------------------------------------

import config
import plugin
import rc
from event import *

import alsaaudio

#
# Indices into the ALSAMIXER2_CTRLS tuples
#
__TYPE__        = 0
__CTRL_NAME__   = 1
__CTRL_INDEX__  = 2
__CARD_NAME__   = 3
__DEFAULT_VOL__ = 4
__MIN_VOL__     = 5
__MAX_VOL__     = 6

class SimpleMixer:
    """
    Simple mixer class
    """

    ctrl = None
    min_vol = 0
    max_vol = 100

    def __init__(self, attr=()):
        """
        Initialize the simple mixer class
        """
        # Open the mixer control
        try:
            self.ctrl = alsaaudio.Mixer(attr[__CTRL_NAME__],
                                        attr[__CTRL_INDEX__],
                                        attr[__CARD_NAME__])
        except alsaaudio.ALSAAudioError:
            print 'Failed to open mixer control "%s,%d,%s"' % \
                  (attr[__CTRL_NAME__], attr[__CTRL_INDEX__],
                   attr[__CARD_NAME__])
            return

        # Set the min and max volume levels
        if (attr[__MIN_VOL__] >= 0):
            self.min_vol = attr[__MIN_VOL__]
        if (attr[__MAX_VOL__] >= 0):
            self.max_vol = attr[__MAX_VOL__]

        # Set the default volume level
        if (attr[__DEFAULT_VOL__] >= 0):
            self.setVolume(attr[__DEFAULT_VOL__])
    
    def getVolume(self):
        """
        Get the volume of the mixer control
        """
        return self.ctrl.getvolume()[0]

    def setVolume(self, val=0):
        """
        Set the volume of the mixer control
        """
        if (val < self.min_vol):
            val = self.min_vol
        if (val > self.max_vol):
            val = self.max_vol
        self.ctrl.setvolume(val)

    def getMute(self):
        """
        Get the Muting of the mixer control
        """
        return self.ctrl.getmute()[0]

    def setMute(self, val=0):
        """
        Set the Muting of the mixer control
        """
        self.ctrl.setmute(val)

class PluginInterface(plugin.DaemonPlugin):
    """
    Another mixer for ALSA. This plugin requires the alsaaudio module from
    http://sourceforge.net/projects/pyalsaaudio/. For Debian, install the
    python-alsaaudio package and you're all set.

    The plugin uses the following configuration variable, which needs to be
    defined in local_conf.py:

    ALSAMIXER2_CTRLS = [
        ( <control type>, <control name>, <control index>, <card name>,
          <default vol>, <min vol>, <max vol> ),
        ...
    ]

    This is a list of mixer controls that the plugin will use. Each entry of
    the list represent one control and contains the following items:
    <control type>  The type of this mixer control. Use 'Main' for the main
                    volume control and 'Mute' for the mute control. The main
                    control is used by the plugin to handle volume up and down
                    events. The mute control is used by the plugin to handle
                    mute and unmute events. Multiple main or mute controls can
                    be specified.
    <control name>  The name of this mixer control. The control name needs to
                    be a string as returned by 'amixer scontrols', i.e., 'PCM',
                    'Master', or such.
    <control index> The index of this mixer control. The default index is 0.
    <card name>     The name of the card that this control lives on. Use
                    something like 'hw:0'. To use the default card, use
                    'default'.
    <default vol>   Default volume for this control. The plugin will set
                    this control to this value upon initialization if the
                    value is >= 0,
    <min vol>       Minimum volume. This is the minimum volume that can be
                    reached with 'volume down' events.
    <max vol>       Maximum volume. This is the maximum volume that can be
                    reached with 'volume up' events.

    Examples:
    | ALSAMIXER2_CTRLS = [
    |    ('Main', 'PCM', 0, 'default', 50, 0, 100),
    |    ('Mute', 'Headphone', 0, 'default', -1, -1, -1),
    | ]
    |
    | ALSAMIXER2_CTRLS = [
    |    ('Main', 'PCM', 0, 'default', 50, 0, 100),
    |    ('Main', 'PCM', 1, 'default', 50, 0, 100),
    |    ('Mute', 'Headphone', 0, 'default', -1, -1, -1),
    | ]
    |
    | ALSAMIXER2_CTRLS = [
    |    ('Main', 'Master', 0, 'default', 50, 0, 100),
    |    ('Mute', 'Master', 0, 'default', -1, -1, -1),
    | ]
    
    """

    __author__        = 'Juerg Haefliger'
    __author_email__  = 'Juerg Haefliger <juergh at gmail.com>'
    __version__       = '0.1.0'

    def __init__(self):
        """
        Initialize the alsamixer2 plug-in
        """
        plugin.DaemonPlugin.__init__(self)
        self.plugin_name = 'ALSAMIXER2'

        # The main and mute mixer controls
        self.main_ctrl = []
        self.mute_ctrl = []

        # Initialize all mixer controls and identify the main and mute
        # mixer controls
        for attr in config.ALSAMIXER2_CTRLS:
            ctrl = SimpleMixer(attr)
            if (attr[__TYPE__].lower() == 'main'):
                self.main_ctrl.append(ctrl)
            if (attr[__TYPE__].lower() == 'mute'):
                self.mute_ctrl.append(ctrl)

    def config(self):
        """
        Config is called automatically. For default settings run:
        freevo plugins -i alsamixer2
        """
        return [
            ('ALSAMIXER2_CTRLS', [('Main', 'Master', 0, 'default', 50, 0, 100),
                                  ('Mute', 'Master', 0, 'default', -1, -1, -1)],
             'Alsa mixer control list'),
        ]

    def eventhandler(self, event=None, menuw=None, arg=None):
        """
        Event handler to handle VOLUME and MUTE events
        """
        if (event == MIXER_VOLUP):
            rc.post_event(Event(OSD_MESSAGE, arg=_('Volume: %s%%') %
                                '/'.join(self.incVolume())))
            return True

        elif (event == MIXER_VOLDOWN):
            rc.post_event(Event(OSD_MESSAGE, arg=_('Volume: %s%%') %
                                '/'.join(self.decVolume())))
            return True

        elif (event == MIXER_MUTE):
            if (self.getMute()):
                rc.post_event(Event(OSD_MESSAGE, arg=_('Volume: %s%%') %
                                    '/'.join(self.getVolume())))
                self.setMute(0)
            else:
                rc.post_event(Event(OSD_MESSAGE, arg=_('Mute')))
                self.setMute(1)
            return True

        return False

    def getVolume(self):
        """
        Get the volume levels of all main controls
        """
        retval = []
        for ctrl in self.main_ctrl:
            retval.append('%d' % ctrl.getVolume())
        return retval

    def incVolume(self, step=5):
        """
        Increase the volume levels of all main controls by the step (default 5)
        """
        for ctrl in self.main_ctrl:
            ctrl.setVolume(ctrl.getVolume() + step)
        return self.getVolume()

    def decVolume(self, step=5):
        """
        Decrease the volume levels of all main controls by the step (default 5)
        """
        for ctrl in self.main_ctrl:
            ctrl.setVolume(ctrl.getVolume() - step)
        return self.getVolume()

    def getMute(self):
        """
        Get the muting of all the mute controls, returns 1 if all mute controls
        are muted and 0 otherwise
        """
        retval = 1;
        for ctrl in self.mute_ctrl:
            retval &= ctrl.getMute()
        return retval

    def setMute(self, val=0):
        """
        Set the muting of all mute controls (default 0)
        """
        for ctrl in self.mute_ctrl:
            ctrl.setMute(val)
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Freevo-devel mailing list
Freevo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freevo-devel

Reply via email to