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

Revision 804, 7.4 kB (checked in by arnonym, 16 years ago)

Try to start ffado-dbus-server if it can't be found on the DBus.

This is probably not the right solution, it would be better to register the server as a dbus-service and request that service so dbus autostarts it.
And the error handling isn't that nice either. if ffado-dbus-server can't be started, it keeps on asking until you press "No".
And probably the time to wait for the next try is to short or to long...

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 import sys
25 # Add the path of the installed ffado-mixer-modules
26 sys.path.append( "$PYTHONDIR" )
27
28 import os
29 import time
30 import dbus
31 from qt import *
32
33 from mixer_phase88 import *
34 from mixer_phase24 import *
35 from mixer_saffirepro import *
36 from mixer_saffire import *
37 from mixer_af2 import *
38 from mixer_bcoaudio5 import *
39
40 SupportedDevices=[
41     [(0x000aac, 0x00000003),'Phase88Control'],
42     [(0x000aac, 0x00000004),'PhaseX24Control'],
43     [(0x000aac, 0x00000007),'PhaseX24Control'],
44     [(0x00130e, 0x00000003),'SaffireProMixer'],
45     [(0x00130e, 0x00000006),'SaffireProMixer'],
46     [(0x00130e, 0x00000000),'SaffireMixer'],
47     [(0x001486, 0x00000af2),'AudioFire2Mixer'],
48     [(0x0007f5, 0x00010049),'BCoAudio5Control'],
49     ]
50
51 class ControlInterface:
52     def __init__(self, servername, basepath):
53         self.basepath=basepath
54         self.servername=servername
55         self.bus=dbus.SessionBus()
56
57     def setContignuous(self, subpath, v):
58         try:
59             path = self.basepath + subpath
60             dev = self.bus.get_object(self.servername, path)
61             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Continuous')
62             dev_cont.setValue(v)
63         except:
64             print "Failed to set Continuous %s on server %s" % (path, self.servername)
65
66     def getContignuous(self, subpath):
67         try:
68             path = self.basepath + subpath
69             dev = self.bus.get_object(self.servername, path)
70             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Continuous')
71             return dev_cont.getValue()
72         except:
73             print "Failed to get Continuous %s on server %s" % (path, self.servername)
74             return 0
75
76     def setDiscrete(self, subpath, v):
77         try:
78             path = self.basepath + subpath
79             dev = self.bus.get_object(self.servername, path)
80             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Discrete')
81             dev_cont.setValue(v)
82         except:
83             print "Failed to set Discrete %s on server %s" % (path, self.servername)
84
85     def getDiscrete(self, subpath):
86         try:
87             path = self.basepath + subpath
88             dev = self.bus.get_object(self.servername, path)
89             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Discrete')
90             return dev_cont.getValue()
91         except:
92             print "Failed to get Discrete %s on server %s" % (path, self.servername)
93             return 0
94
95     def setMatrixMixerValue(self, subpath, row, col, v):
96         try:
97             path = self.basepath + subpath
98             dev = self.bus.get_object(self.servername, path)
99             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.MatrixMixer')
100             dev_cont.setValue(row, col, v)
101         except:
102             print "Failed to set MatrixMixer %s on server %s" % (path, self.servername)
103
104     def getMatrixMixerValue(self, subpath, row, col):
105         try:
106             path = self.basepath + subpath
107             dev = self.bus.get_object(self.servername, path)
108             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.MatrixMixer')
109             return dev_cont.getValue(row, col)
110         except:
111             print "Failed to get MatrixMixer %s on server %s" % (path, self.servername)
112             return 0
113
114 class DeviceManagerInterface:
115     def __init__(self, servername, basepath):
116         self.basepath=basepath + '/DeviceManager'
117         self.servername=servername
118         self.bus=dbus.SessionBus()
119         self.dev = self.bus.get_object(self.servername, self.basepath)
120         self.iface = dbus.Interface(self.dev, dbus_interface='org.ffado.Control.Element.Container')
121            
122     def getNbDevices(self):
123         return self.iface.getNbElements()
124     def getDeviceName(self, idx):
125         return self.iface.getElementName(idx) 
126
127 class ConfigRomInterface:
128     def __init__(self, servername, devicepath):
129         self.basepath=devicepath + '/ConfigRom'
130         self.servername=servername
131         self.bus=dbus.SessionBus()
132         self.dev = self.bus.get_object(self.servername, self.basepath)
133         self.iface = dbus.Interface(self.dev, dbus_interface='org.ffado.Control.Element.ConfigRomX')
134     def getGUID(self):
135         return self.iface.getGUID()
136     def getVendorName(self):
137         return self.iface.getVendorName()
138     def getModelName(self):
139         return self.iface.getModelName()
140     def getVendorId(self):
141         return self.iface.getVendorId()
142     def getModelId(self):
143         return self.iface.getModelId()
144    
145
146 if __name__ == "__main__":
147    
148     server='org.ffado.Control'
149     basepath='/org/ffado/Control'
150    
151     app = QApplication(sys.argv)
152    
153     msg = QMessageBox()
154
155     repeat = 1
156     while repeat > 0:
157         try:
158             devmgr=DeviceManagerInterface(server, basepath)
159             repeat -= 1
160         except dbus.DBusException, ex:
161             print "\n"
162             print "==========================================================="
163             print "ERROR: Could not communicate with the FFADO DBus service..."
164             print "==========================================================="
165             print "\n"
166             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 )
167             if tmp == 4:
168                 sys.exit(-1)
169             else:
170                 os.spawnlp( os.P_NOWAIT, "ffado-dbus-server" )
171                 time.sleep( 2.5 )
172
173    
174     nbDevices=devmgr.getNbDevices()
175    
176     forms=[];
177     for idx in range(nbDevices):
178         path=devmgr.getDeviceName(idx)
179         print "Found device %d: %s" % (idx, path)
180        
181         cfgrom=ConfigRomInterface(server, basepath+'/DeviceManager/'+path)
182         vendorId=cfgrom.getVendorId()
183         modelId=cfgrom.getModelId()
184        
185         print "Found (%X, %X) %s %s" % (vendorId, modelId, cfgrom.getVendorName() , cfgrom.getModelName())
186        
187         thisdev=(vendorId, modelId);
188        
189         for dev in SupportedDevices:
190             if dev[0]==thisdev:
191                 print dev[1]
192                 exec('forms.append('+dev[1]+'())')
193                 forms[idx].hw=ControlInterface(server, basepath+'/DeviceManager/'+path)
194                 forms[idx].initValues()
195                 forms[idx].show()
196                 app.setMainWidget(forms[idx])
197
198     if forms:
199         QObject.connect(app,SIGNAL("lastWindowClosed()"),app,SLOT("quit()"))
200
201         app.exec_loop()
202     else:
203         print "No supported device found..."
204         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.