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

Revision 963, 10.2 kB (checked in by ppalmers, 16 years ago)

- add clock source control to all panels that don't have it yet
- fix saffire (LE) detection bug

  • 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_saffirele import *
39 from mixer_af2 import *
40 from mixer_bcoaudio5 import *
41 from mixer_edirolfa66 import *
42 from mixer_mackie_generic import *
43
44 SupportedDevices=[
45     [(0x000aac, 0x00000003),'Phase88Control'],
46     [(0x000aac, 0x00000004),'PhaseX24Control'],
47     [(0x000aac, 0x00000007),'PhaseX24Control'],
48     [(0x00130e, 0x00000003),'SaffireProMixer'],
49     [(0x00130e, 0x00000006),'SaffireProMixer'],
50     [(0x00130e, 0x00000000),'SaffireMixer'],
51     [(0x001486, 0x00000af2),'AudioFire2Mixer'],
52     [(0x0007f5, 0x00010049),'BCoAudio5Control'],
53     [(0x0040AB, 0x00010049),'EdirolFa66Control'],
54     [(0x00000f, 0x00010067),'MackieGenericControl'],
55     [(0x000f1b, 0x00010064),'MackieGenericControl'],
56     ]
57
58 class ControlInterface:
59     def __init__(self, servername, basepath):
60         self.basepath=basepath
61         self.servername=servername
62         self.bus=dbus.SessionBus()
63
64     def setContignuous(self, subpath, v):
65         try:
66             path = self.basepath + subpath
67             dev = self.bus.get_object(self.servername, path)
68             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Continuous')
69             dev_cont.setValue(v)
70         except:
71             print "Failed to set Continuous %s on server %s" % (path, self.servername)
72
73     def getContignuous(self, subpath):
74         try:
75             path = self.basepath + subpath
76             dev = self.bus.get_object(self.servername, path)
77             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Continuous')
78             return dev_cont.getValue()
79         except:
80             print "Failed to get Continuous %s on server %s" % (path, self.servername)
81             return 0
82
83     def setDiscrete(self, subpath, v):
84         try:
85             path = self.basepath + subpath
86             dev = self.bus.get_object(self.servername, path)
87             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Discrete')
88             dev_cont.setValue(v)
89         except:
90             print "Failed to set Discrete %s on server %s" % (path, self.servername)
91
92     def getDiscrete(self, subpath):
93         try:
94             path = self.basepath + subpath
95             dev = self.bus.get_object(self.servername, path)
96             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Discrete')
97             return dev_cont.getValue()
98         except:
99             print "Failed to get Discrete %s on server %s" % (path, self.servername)
100             return 0
101
102     def setText(self, subpath, v):
103         try:
104             path = self.basepath + subpath
105             dev = self.bus.get_object(self.servername, path)
106             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Text')
107             dev_cont.setValue(v)
108         except:
109             print "Failed to set Text %s on server %s" % (path, self.servername)
110
111     def getText(self, subpath):
112         try:
113             path = self.basepath + subpath
114             dev = self.bus.get_object(self.servername, path)
115             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Text')
116             return dev_cont.getValue()
117         except:
118             print "Failed to get Text %s on server %s" % (path, self.servername)
119             return 0
120
121     def setMatrixMixerValue(self, subpath, row, col, v):
122         try:
123             path = self.basepath + subpath
124             dev = self.bus.get_object(self.servername, path)
125             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.MatrixMixer')
126             dev_cont.setValue(row, col, v)
127         except:
128             print "Failed to set MatrixMixer %s on server %s" % (path, self.servername)
129
130     def getMatrixMixerValue(self, subpath, row, col):
131         try:
132             path = self.basepath + subpath
133             dev = self.bus.get_object(self.servername, path)
134             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.MatrixMixer')
135             return dev_cont.getValue(row, col)
136         except:
137             print "Failed to get MatrixMixer %s on server %s" % (path, self.servername)
138             return 0
139
140 class DeviceManagerInterface:
141     def __init__(self, servername, basepath):
142         self.basepath=basepath + '/DeviceManager'
143         self.servername=servername
144         self.bus=dbus.SessionBus()
145         self.dev = self.bus.get_object(self.servername, self.basepath)
146         self.iface = dbus.Interface(self.dev, dbus_interface='org.ffado.Control.Element.Container')
147            
148     def getNbDevices(self):
149         return self.iface.getNbElements()
150     def getDeviceName(self, idx):
151         return self.iface.getElementName(idx) 
152
153 class ConfigRomInterface:
154     def __init__(self, servername, devicepath):
155         self.basepath=devicepath + '/ConfigRom'
156         self.servername=servername
157         self.bus=dbus.SessionBus()
158         self.dev = self.bus.get_object(self.servername, self.basepath)
159         self.iface = dbus.Interface(self.dev, dbus_interface='org.ffado.Control.Element.ConfigRomX')
160     def getGUID(self):
161         return self.iface.getGUID()
162     def getVendorName(self):
163         return self.iface.getVendorName()
164     def getModelName(self):
165         return self.iface.getModelName()
166     def getVendorId(self):
167         return self.iface.getVendorId()
168     def getModelId(self):
169         return self.iface.getModelId()
170
171 class ClockSelectInterface:
172     def __init__(self, servername, devicepath):
173         self.basepath=devicepath + '/Generic/ClockSelect'
174         self.servername=servername
175         self.bus=dbus.SessionBus()
176         self.dev = self.bus.get_object(self.servername, self.basepath)
177         self.iface = dbus.Interface(self.dev, dbus_interface='org.ffado.Control.Element.AttributeEnum')
178     def count(self):
179         return self.iface.count()
180     def select(self, idx):
181         return self.iface.select(idx)
182     def selected(self):
183         return self.iface.selected()
184     def getEnumLabel(self, idx):
185         return self.iface.getEnumLabel(idx)
186     def attributeCount(self):
187         return self.iface.attributeCount()
188     def getAttributeValue(self, idx):
189         return self.iface.getAttributeValue(idx)
190     def getAttributeName(self, idx):
191         return self.iface.getAttributeName(idx)
192
193 if __name__ == "__main__":
194    
195     server='org.ffado.Control'
196     basepath='/org/ffado/Control'
197    
198     app = QApplication(sys.argv)
199    
200     msg = QMessageBox()
201
202     repeat = 1
203     while repeat > 0:
204         try:
205             devmgr=DeviceManagerInterface(server, basepath)
206             repeat -= 1
207         except dbus.DBusException, ex:
208             print "\n"
209             print "==========================================================="
210             print "ERROR: Could not communicate with the FFADO DBus service..."
211             print "==========================================================="
212             print "\n"
213             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 )
214             if tmp == 4:
215                 sys.exit(-1)
216             else:
217                 os.spawnlp( os.P_NOWAIT, "ffado-dbus-server" )
218                 nb_checks = 10
219                 while nb_checks > 0:
220                     nb_checks = nb_checks - 1
221                     try:
222                         devmgr=DeviceManagerInterface(server, basepath)
223                         nb_checks = 0
224                         repeat = 0
225                     except dbus.DBusException, ex:
226                         time.sleep( 1 )
227
228     nbDevices=devmgr.getNbDevices()
229    
230     forms=[];
231     for idx in range(nbDevices):
232         path=devmgr.getDeviceName(idx)
233         print "Found device %d: %s" % (idx, path)
234        
235         cfgrom = ConfigRomInterface(server, basepath+'/DeviceManager/'+path)
236         vendorId = cfgrom.getVendorId()
237         modelId = cfgrom.getModelId()
238         GUID = cfgrom.getGUID()
239         print " Found (%s, %X, %X) %s %s" % (str(GUID), vendorId, modelId, cfgrom.getVendorName(), cfgrom.getModelName())
240        
241         thisdev=(vendorId, modelId);
242        
243         for dev in SupportedDevices:
244             if dev[0] == thisdev:
245                 mixerapp = dev[1]
246                
247                 # hack for the focusrite devices
248                 # Saffire:        0x130e010001????
249                 # SaffireLE:    0x130e010004????
250                 if thisdev == (0x00130e, 0x00000000):
251                     if int(GUID, 16) < 0x130e0100040000:
252                         mixerapp = "SaffireMixer"
253                     else:
254                         mixerapp = "SaffireLEMixer"
255
256                 print mixerapp
257                 exec('forms.append('+mixerapp+'())')
258                 forms[idx].hw = ControlInterface(server, basepath+'/DeviceManager/'+path)
259                 forms[idx].clockselect = ClockSelectInterface(server, basepath+'/DeviceManager/'+path)
260                 forms[idx].initValues()
261                 forms[idx].show()
262                 app.setMainWidget(forms[idx])
263
264     if forms:
265         QObject.connect(app,SIGNAL("lastWindowClosed()"),app,SLOT("quit()"))
266
267         app.exec_loop()
268     else:
269         print "No supported device found..."
270         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.