root/trunk/libffado/support/mixer/mixer_generic.py

Revision 1361, 5.9 kB (checked in by ppalmers, 14 years ago)

Merge 2.0 branch changes.

svn merge -r1349:HEAD svn+ssh://ffadosvn@ffado.org/ffado/branches/libffado-2.0

Line 
1 #
2 # Copyright (C) 2008 by Arnold Krille
3 #
4 # This file is part of FFADO
5 # FFADO = Free Firewire (pro-)audio drivers for linux
6 #
7 # FFADO is based upon FreeBoB.
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 2 of the License, or
12 # version 3 of the License.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 #
22
23 import sys
24 import dbus
25 from qt import *
26
27 class ContainerWidget( QFrame ):
28         def __init__( self, name, interface, parent ):
29                 QFrame.__init__( self, parent )
30                 self.interface = interface
31                 self.setFrameStyle( QFrame.Plain|QFrame.StyledPanel )
32                 self.setLineWidth( 1 )
33                 self.setMargin( 5 )
34                 l2 = QVBoxLayout( self )
35                 l2.setMargin( 5 )
36                 lbl = QLabel( "<qt><b>" + name + "</b></qt>", self )
37                 l2.addWidget( lbl )
38                 self.l = QHBoxLayout( None )
39                 self.l.setMargin( 0 )
40                 self.l.setSpacing( 2 )
41                 l2.addLayout( self.l )
42
43         def layout( self ):
44                 return self.l
45
46 class ContinuousWidget( QWidget ):
47         def __init__( self, name, interface, parent ):
48                 QWidget.__init__( self, parent )
49                 self.interface = interface
50                 l = QVBoxLayout( self )
51                 l.addWidget( QLabel( name, self ) )
52                 self.slider = QSlider( self )
53                 l.addWidget( self.slider )
54
55                 self.min = self.interface.getMinimum()
56                 self.max = self.interface.getMaximum()
57                 self.slider.setMinValue( 0 )
58                 self.slider.setMaxValue( 100 )
59                 self.slider.setValue( self.interfaceToSlider( self.interface.getValue() ) )
60                 self.connect( self.slider, SIGNAL( "valueChanged(int)" ), self.sliderMoved )
61
62         def sliderToInterFace( self, slider ):
63                 return ( self.max - self.min ) * (100-slider)/100.0 + self.min
64         def interfaceToSlider( self, interface ):
65                 if self.max == self.min:
66                         return 0
67                 else:
68                         return - ( interface - self.min ) / ( self.max - self.min ) * 100.0 + 100
69
70         def sliderMoved( self, i ):
71                 #print "ContinuousWidget::sliderMoved( %i )" % i
72                 self.interface.setValue( self.sliderToInterFace( i ) )
73
74 class EnumWidget( QWidget ):
75         def __init__( self, name, interface, parent ):
76                 QWidget.__init__( self, parent )
77                 self.interface = interface
78                 l = QVBoxLayout( self )
79                 l.addWidget( QLabel( name, self ) )
80                 self.select = QComboBox( False, self )
81                 l.addWidget( self.select )
82                 for i in range( interface.count() ):
83                         self.select.insertItem( interface.getEnumLabel( i ) )
84                 self.select.setCurrentItem( self.interface.selected() )
85                 self.connect( self.select, SIGNAL( "activated(int)" ), self.currentChanged )
86
87         def currentChanged( self, i ):
88                 #print "EnumWidget::currentChanged(" + str(i) + ")"
89                 self.interface.select( i )
90
91 class TextWidget( QWidget ):
92         def __init__( self, name, interface, parent ):
93                 QWidget.__init__( self, parent )
94                 self.interface = interface
95                 l = QVBoxLayout( self )
96                 l.addWidget( QLabel( name, self ) )
97                 self.text = QLineEdit( self )
98                 l.addWidget( self.text )
99                 self.text.setText( interface.getValue() )
100                 self.connect( self.text, SIGNAL( "textChanged( const QString & )" ), self.setText )
101
102         def setText( self, text ):
103                 self.interface.setValue( text.latin1() )
104
105 class HLine( QFrame ):
106         def __init__( self, parent ):
107                 QFrame.__init__( self, parent )
108                 self.setFrameShape( QFrame.HLine )
109                 self.setLineWidth( 2 )
110                 self.setMinimumHeight( 10 )
111
112 class GenericMixer( QWidget ):
113         def __init__( self, bus, session, parent=None ):
114                 QWidget.__init__( self, parent )
115                 QVBoxLayout( self )
116                 self.layout().addWidget( QLabel( "<qt>This generic interface is only intended for developers. The controls shown here may or may not work and probably don't represent the devices real structure. This just displays the object-tree as exported by ffado-dbus-server.</qt>", self ) )
117                 self.layout().addWidget( HLine( self ) )
118                 self.introspect( bus, session, "/org/ffado/Control/DeviceManager", self )
119
120         def introspect( self, bus, session, path, parentwidget ):
121                 element = bus.get_object( session, path )
122                 element._Introspect().block()
123                 interfacemap = element._introspect_method_map
124                 interfacelist = []
125                 for t in interfacemap:
126                         tmp = ".".join(t.split(".")[:-1])
127                         if tmp not in interfacelist:
128                                 interfacelist.append( tmp )
129
130                 name = "Unnamed"
131
132                 if interfacelist.count( "org.ffado.Control.Element.Element" ):
133                         name = dbus.Interface( element, "org.ffado.Control.Element.Element" ).getName()
134
135                 w = None
136
137                 if interfacelist.count( "org.ffado.Control.Element.Container" ):
138                         container = dbus.Interface( element, "org.ffado.Control.Element.Container" )
139                         w = ContainerWidget( name, container, parentwidget )
140                         parentwidget.layout().addWidget( w )
141                         for i in range( container.getNbElements() ):
142                                 #print "%s %i %s" % ( path, i, container.getElementName( i ) )
143                                 self.introspect( bus, session, path + "/" + container.getElementName( i ), w )
144
145                 if w == None and interfacelist.count( "org.ffado.Control.Element.Continuous" ):
146                         w = ContinuousWidget( name, dbus.Interface( element, "org.ffado.Control.Element.Continuous" ), parentwidget )
147                         parentwidget.layout().addWidget( w )
148
149                 if w == None and interfacelist.count( "org.ffado.Control.Element.AttributeEnum" ):
150                         w = EnumWidget( name, dbus.Interface( element, "org.ffado.Control.Element.AttributeEnum" ), parentwidget )
151                         parentwidget.layout().addWidget( w )
152
153                 if w == None and interfacelist.count( "org.ffado.Control.Element.Text" ):
154                         w = TextWidget( name, dbus.Interface( element, "org.ffado.Control.Element.Text" ), parentwidget )
155                         parentwidget.layout().addWidget( w )
156
157                 if w == None:
158                         w = QLabel( "<qt><b>%s</b> (Not yet implemented)</qt>" % name, parentwidget )
159                         parentwidget.layout().addWidget( w )
160
Note: See TracBrowser for help on using the browser.