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

Revision 742, 6.6 kB (checked in by ppalmers, 13 years ago)

- Remove some obsolete support files and dirs

- Clean up the license statements in the source files. Everything is

GPL version 3 now.

- Add license and copyright notices to scons scripts

- Clean up some other text files

Line 
1 #!/usr/bin/python
2 #
3 # Copyright (C) 2005-2007 by Pieter Palmers
4 #
5 # This file is part of FFADO
6 # FFADO = Free Firewire (pro-)audio drivers for linux
7 #
8 # FFADO is based upon FreeBoB.
9 #
10 # This program is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
22 #
23
24 from qt import *
25 from mixer_phase88 import *
26 from mixer_phase24 import *
27 from mixer_saffirepro import *
28 from mixer_saffire import *
29 from mixer_af2 import *
30 import sys
31 import dbus
32
33 SupportedDevices=[
34     [(0x000aac, 0x00000003),'Phase88Control'],
35     [(0x000aac, 0x00000004),'PhaseX24Control'],
36     [(0x000aac, 0x00000007),'PhaseX24Control'],
37     [(0x00130e, 0x00000003),'SaffireProMixer'],
38     [(0x00130e, 0x00000006),'SaffireProMixer'],
39     [(0x00130e, 0x00000000),'SaffireMixer'],
40     [(0x001486, 0x00000af2),'AudioFire2Mixer'],
41     ]
42
43 class ControlInterface:
44     def __init__(self, servername, basepath):
45         self.basepath=basepath
46         self.servername=servername
47         self.bus=dbus.SessionBus()
48
49     def setContignuous(self, subpath, v):
50         try:
51             path = self.basepath + subpath
52             dev = self.bus.get_object(self.servername, path)
53             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Continuous')
54             dev_cont.setValue(v)
55         except:
56             print "Failed to set Continuous %s on server %s" % (path, self.servername)
57
58     def getContignuous(self, subpath):
59         try:
60             path = self.basepath + subpath
61             dev = self.bus.get_object(self.servername, path)
62             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Continuous')
63             return dev_cont.getValue()
64         except:
65             print "Failed to get Continuous %s on server %s" % (path, self.servername)
66             return 0
67
68     def setDiscrete(self, subpath, v):
69         try:
70             path = self.basepath + subpath
71             dev = self.bus.get_object(self.servername, path)
72             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Discrete')
73             dev_cont.setValue(v)
74         except:
75             print "Failed to set Discrete %s on server %s" % (path, self.servername)
76
77     def getDiscrete(self, subpath):
78         try:
79             path = self.basepath + subpath
80             dev = self.bus.get_object(self.servername, path)
81             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Discrete')
82             return dev_cont.getValue()
83         except:
84             print "Failed to get Discrete %s on server %s" % (path, self.servername)
85             return 0
86
87     def setMatrixMixerValue(self, subpath, row, col, v):
88         try:
89             path = self.basepath + subpath
90             dev = self.bus.get_object(self.servername, path)
91             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.MatrixMixer')
92             dev_cont.setValue(row, col, v)
93         except:
94             print "Failed to set MatrixMixer %s on server %s" % (path, self.servername)
95
96     def getMatrixMixerValue(self, subpath, row, col):
97         try:
98             path = self.basepath + subpath
99             dev = self.bus.get_object(self.servername, path)
100             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.MatrixMixer')
101             return dev_cont.getValue(row, col)
102         except:
103             print "Failed to get MatrixMixer %s on server %s" % (path, self.servername)
104             return 0
105
106 class DeviceManagerInterface:
107     def __init__(self, servername, basepath):
108         self.basepath=basepath + '/DeviceManager'
109         self.servername=servername
110         self.bus=dbus.SessionBus()
111         self.dev = self.bus.get_object(self.servername, self.basepath)
112         self.iface = dbus.Interface(self.dev, dbus_interface='org.ffado.Control.Element.Container')
113            
114     def getNbDevices(self):
115         return self.iface.getNbElements()
116     def getDeviceName(self, idx):
117         return self.iface.getElementName(idx) 
118
119 class ConfigRomInterface:
120     def __init__(self, servername, devicepath):
121         self.basepath=devicepath + '/ConfigRom'
122         self.servername=servername
123         self.bus=dbus.SessionBus()
124         self.dev = self.bus.get_object(self.servername, self.basepath)
125         self.iface = dbus.Interface(self.dev, dbus_interface='org.ffado.Control.Element.ConfigRomX')
126     def getGUID(self):
127         return self.iface.getGUID()
128     def getVendorName(self):
129         return self.iface.getVendorName()
130     def getModelName(self):
131         return self.iface.getModelName()
132     def getVendorId(self):
133         return self.iface.getVendorId()
134     def getModelId(self):
135         return self.iface.getModelId()
136    
137
138 if __name__ == "__main__":
139    
140     server='org.ffado.Control'
141     basepath='/org/ffado/Control'
142    
143     app = QApplication(sys.argv)
144    
145     try:
146         devmgr=DeviceManagerInterface(server, basepath)
147     except dbus.DBusException, ex:
148         print "\n"
149         print "==========================================================="
150         print "ERROR: Could not communicate with the FFADO DBus service..."
151         print "==========================================================="
152         print "\n"
153         sys.exit(-1)
154    
155     nbDevices=devmgr.getNbDevices()
156    
157     forms=[];
158     for idx in range(nbDevices):
159         path=devmgr.getDeviceName(idx)
160         print "Found device %d: %s" % (idx, path)
161        
162         cfgrom=ConfigRomInterface(server, basepath+'/DeviceManager/'+path)
163         vendorId=cfgrom.getVendorId()
164         modelId=cfgrom.getModelId()
165        
166         print "Found (%X, %X) %s %s" % (vendorId, modelId, cfgrom.getVendorName() , cfgrom.getModelName())
167        
168         thisdev=(vendorId, modelId);
169        
170         for dev in SupportedDevices:
171             if dev[0]==thisdev:
172                 print dev[1]
173                 exec('forms.append('+dev[1]+'())')
174                 forms[idx].hw=ControlInterface(server, basepath+'/DeviceManager/'+path)
175                 forms[idx].initValues()
176                 forms[idx].show()
177                 app.setMainWidget(forms[idx])
178
179     if forms:
180         QObject.connect(app,SIGNAL("lastWindowClosed()"),app,SLOT("quit()"))
181
182         app.exec_loop()
183     else:
184         print "No supported device found..."
Note: See TracBrowser for help on using the browser.