root/trunk/libffado/support/mixer/ffadomixer.in

Revision 869, 7.7 kB (checked in by arnonym, 16 years ago)

think I did enough in this script to allow a copyright. Otherwise just remove me again...

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