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

Revision 953, 9.3 kB (checked in by ppalmers, 16 years ago)

fixes #76

  • 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
172 if __name__ == "__main__":
173    
174     server='org.ffado.Control'
175     basepath='/org/ffado/Control'
176    
177     app = QApplication(sys.argv)
178    
179     msg = QMessageBox()
180
181     repeat = 1
182     while repeat > 0:
183         try:
184             devmgr=DeviceManagerInterface(server, basepath)
185             repeat -= 1
186         except dbus.DBusException, ex:
187             print "\n"
188             print "==========================================================="
189             print "ERROR: Could not communicate with the FFADO DBus service..."
190             print "==========================================================="
191             print "\n"
192             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 )
193             if tmp == 4:
194                 sys.exit(-1)
195             else:
196                 os.spawnlp( os.P_NOWAIT, "ffado-dbus-server" )
197                 nb_checks = 10
198                 while nb_checks > 0:
199                     nb_checks = nb_checks - 1
200                     try:
201                         devmgr=DeviceManagerInterface(server, basepath)
202                         nb_checks = 0
203                         repeat = 0
204                     except dbus.DBusException, ex:
205                         time.sleep( 1 )
206
207     nbDevices=devmgr.getNbDevices()
208    
209     forms=[];
210     for idx in range(nbDevices):
211         path=devmgr.getDeviceName(idx)
212         print "Found device %d: %s" % (idx, path)
213        
214         cfgrom = ConfigRomInterface(server, basepath+'/DeviceManager/'+path)
215         vendorId = cfgrom.getVendorId()
216         modelId = cfgrom.getModelId()
217         GUID = cfgrom.getGUID()
218         print " Found (%s, %X, %X) %s %s" % (str(GUID), vendorId, modelId, cfgrom.getVendorName(), cfgrom.getModelName())
219        
220         thisdev=(vendorId, modelId);
221        
222         for dev in SupportedDevices:
223             if dev[0] == thisdev:
224                 mixerapp = dev[1]
225                
226                 # hack for the focusrite devices
227                 # Saffire:        0x130e010001????
228                 # SaffireLE:    0x130e010004????
229                 if thisdev == (0x00130e, 0x00000000):
230                     if GUID < 0x130e0100040000:
231                         mixerapp = "SaffireMixer"
232                     else:
233                         mixerapp = "SaffireLEMixer"
234
235                 print mixerapp
236                 exec('forms.append('+mixerapp+'())')
237                 forms[idx].hw = ControlInterface(server, basepath+'/DeviceManager/'+path)
238                 forms[idx].initValues()
239                 forms[idx].show()
240                 app.setMainWidget(forms[idx])
241
242     if forms:
243         QObject.connect(app,SIGNAL("lastWindowClosed()"),app,SLOT("quit()"))
244
245         app.exec_loop()
246     else:
247         print "No supported device found..."
248         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.