root/branches/libffado-2.0/support/mixer-qt4/ffado_dbus_util.py

Revision 1298, 12.7 kB (checked in by ppalmers, 13 years ago)

add Qt4 port of the mixer (only for audiofire and saffire ATM). needed since PyQt?3 doesn't support DBUS signals.

Line 
1 #!/usr/bin/python
2 #
3 # Copyright (C) 2005-2008 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 dbus
26 import dbus.mainloop.qt
27 dbus.mainloop.qt.DBusQtMainLoop(set_as_default=True)
28
29 class ControlInterface:
30     def __init__(self, servername, basepath):
31         self.basepath=basepath
32         self.servername=servername
33         self.bus=dbus.SessionBus()
34
35     def setContignuous(self, subpath, v, idx=None):
36         try:
37             path = self.basepath + subpath
38             dev = self.bus.get_object(self.servername, path)
39             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Continuous')
40             if idx == None:
41                 dev_cont.setValue(v)
42             else:
43                 dev_cont.setValueIdx(idx,v)
44         except:
45             print "Failed to set Continuous %s on server %s" % (path, self.servername)
46
47     def getContignuous(self, subpath, idx=None):
48         try:
49             path = self.basepath + subpath
50             dev = self.bus.get_object(self.servername, path)
51             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Continuous')
52             if idx == None:
53                 return dev_cont.getValue()
54             else:
55                 return dev_cont.getValueIdx(idx)
56         except:
57             print "Failed to get Continuous %s on server %s" % (path, self.servername)
58             return 0
59
60     def setDiscrete(self, subpath, v):
61         try:
62             path = self.basepath + subpath
63             dev = self.bus.get_object(self.servername, path)
64             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Discrete')
65             dev_cont.setValue(v)
66         except:
67             print "Failed to set Discrete %s on server %s" % (path, self.servername)
68
69     def getDiscrete(self, subpath):
70         try:
71             path = self.basepath + subpath
72             dev = self.bus.get_object(self.servername, path)
73             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Discrete')
74             return dev_cont.getValue()
75         except:
76             print "Failed to get Discrete %s on server %s" % (path, self.servername)
77             return 0
78
79     def setText(self, subpath, v):
80         try:
81             path = self.basepath + subpath
82             dev = self.bus.get_object(self.servername, path)
83             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Text')
84             dev_cont.setValue(v)
85         except:
86             print "Failed to set Text %s on server %s" % (path, self.servername)
87
88     def getText(self, subpath):
89         try:
90             path = self.basepath + subpath
91             dev = self.bus.get_object(self.servername, path)
92             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Text')
93             return dev_cont.getValue()
94         except:
95             print "Failed to get Text %s on server %s" % (path, self.servername)
96             return 0
97
98     def setMatrixMixerValue(self, subpath, row, col, v):
99         try:
100             path = self.basepath + subpath
101             dev = self.bus.get_object(self.servername, path)
102             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.MatrixMixer')
103             dev_cont.setValue(row, col, v)
104         except:
105             print "Failed to set MatrixMixer %s on server %s" % (path, self.servername)
106
107     def getMatrixMixerValue(self, subpath, row, col):
108         try:
109             path = self.basepath + subpath
110             dev = self.bus.get_object(self.servername, path)
111             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.MatrixMixer')
112             return dev_cont.getValue(row, col)
113         except:
114             print "Failed to get MatrixMixer %s on server %s" % (path, self.servername)
115             return 0
116
117     def enumSelect(self, subpath, v):
118         try:
119             path = self.basepath + subpath
120             dev = self.bus.get_object(self.servername, path)
121             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Enum')
122             dev_cont.select(v)
123         except:
124             print "Failed to select %s on server %s" % (path, self.servername)
125
126     def enumSelected(self, subpath):
127         try:
128             path = self.basepath + subpath
129             dev = self.bus.get_object(self.servername, path)
130             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Enum')
131             return dev_cont.selected()
132         except:
133             print "Failed to get selected enum %s on server %s" % (path, self.servername)
134             return 0
135
136     def enumGetLabel(self, subpath, v):
137         try:
138             path = self.basepath + subpath
139             dev = self.bus.get_object(self.servername, path)
140             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Enum')
141             return dev_cont.getEnumLabel(v)
142         except:
143             print "Failed to get enum label %s on server %s" % (path, self.servername)
144             return 0
145
146     def enumCount(self, subpath):
147         try:
148             path = self.basepath + subpath
149             dev = self.bus.get_object(self.servername, path)
150             dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Enum')
151             return dev_cont.count()
152         except:
153             print "Failed to get enum count %s on server %s" % (path, self.servername)
154             return 0
155
156 class DeviceManagerInterface:
157     """ Implementation of the singleton """
158     def __init__(self, servername, basepath):
159         self.basepath=basepath + '/DeviceManager'
160         self.servername=servername
161         self.bus=dbus.SessionBus()
162         self.dev = self.bus.get_object(self.servername, self.basepath)
163         self.iface = dbus.Interface(self.dev, dbus_interface='org.ffado.Control.Element.Container')
164
165         self.updateSignalHandlers = []
166         self.updateSignalHandlerArgs = {}
167         self.preUpdateSignalHandlers = []
168         self.preUpdateSignalHandlerArgs = {}
169         self.postUpdateSignalHandlers = []
170         self.postUpdateSignalHandlerArgs = {}
171         self.destroyedSignalHandlers = []
172         self.destroyedSignalHandlerArgs = {}
173
174         # signal reception does not work yet since we need a mainloop for that
175         # and qt3 doesn't provide one for python/dbus
176         try:
177             print "connecting to: Updated on %s (server: %s)" % (self.basepath, self.servername)
178             self.dev.connect_to_signal("Updated", self.updateSignal, \
179                                     dbus_interface="org.ffado.Control.Element.Container")
180             self.dev.connect_to_signal("PreUpdate", self.preUpdateSignal, \
181                                     dbus_interface="org.ffado.Control.Element.Container")
182             self.dev.connect_to_signal("PostUpdate", self.postUpdateSignal, \
183                                     dbus_interface="org.ffado.Control.Element.Container")
184             self.dev.connect_to_signal("Destroyed", self.destroyedSignal, \
185                                     dbus_interface="org.ffado.Control.Element.Container")
186
187         except dbus.DBusException:
188             traceback.print_exc()
189
190     def registerPreUpdateCallback(self, callback, arg=None):
191         if not callback in self.preUpdateSignalHandlers:
192             self.preUpdateSignalHandlers.append(callback)
193         # always update the argument
194         self.preUpdateSignalHandlerArgs[callback] = arg
195
196     def registerPostUpdateCallback(self, callback, arg=None):
197         if not callback in self.postUpdateSignalHandlers:
198             self.postUpdateSignalHandlers.append(callback)
199         # always update the argument
200         self.postUpdateSignalHandlerArgs[callback] = arg
201
202     def registerUpdateCallback(self, callback, arg=None):
203         if not callback in self.updateSignalHandlers:
204             self.updateSignalHandlers.append(callback)
205         # always update the argument
206         self.updateSignalHandlerArgs[callback] = arg
207
208     def registerDestroyedCallback(self, callback, arg=None):
209         if not callback in self.destroyedSignalHandlers:
210             self.destroyedSignalHandlers.append(callback)
211         # always update the argument
212         self.destroyedSignalHandlerArgs[callback] = arg
213
214     def updateSignal(self):
215         print ("Received update signal")
216         for handler in self.updateSignalHandlers:
217             arg = self.updateSignalHandlerArgs[handler]
218             if arg:
219                 handler(arg)
220             else:
221                 handler()
222
223     def preUpdateSignal(self):
224         print ("Received pre-update signal")
225         for handler in self.preUpdateSignalHandlers:
226             arg = self.preUpdateSignalHandlerArgs[handler]
227             if arg:
228                 handler(arg)
229             else:
230                 handler()
231
232     def postUpdateSignal(self):
233         print ("Received post-update signal")
234         for handler in self.postUpdateSignalHandlers:
235             arg = self.postUpdateSignalHandlerArgs[handler]
236             if arg:
237                 handler(arg)
238             else:
239                 handler()
240
241     def destroyedSignal(self):
242         print ("Received destroyed signal")
243         for handler in self.destroyedSignalHandlers:
244             arg = self.destroyedSignalHandlerArgs[handler]
245             if arg:
246                 handler(arg)
247             else:
248                 handler()
249
250     def getNbDevices(self):
251         return self.iface.getNbElements()
252     def getDeviceName(self, idx):
253         return self.iface.getElementName(idx)
254
255 class ConfigRomInterface:
256     def __init__(self, servername, devicepath):
257         self.basepath=devicepath + '/ConfigRom'
258         self.servername=servername
259         self.bus=dbus.SessionBus()
260         self.dev = self.bus.get_object(self.servername, self.basepath)
261         self.iface = dbus.Interface(self.dev, dbus_interface='org.ffado.Control.Element.ConfigRomX')
262     def getGUID(self):
263         return self.iface.getGUID()
264     def getVendorName(self):
265         return self.iface.getVendorName()
266     def getModelName(self):
267         return self.iface.getModelName()
268     def getVendorId(self):
269         return self.iface.getVendorId()
270     def getModelId(self):
271         return self.iface.getModelId()
272     def getUnitVersion(self):
273         return self.iface.getUnitVersion()
274
275 class ClockSelectInterface:
276     def __init__(self, servername, devicepath):
277         self.basepath=devicepath + '/Generic/ClockSelect'
278         self.servername=servername
279         self.bus=dbus.SessionBus()
280         self.dev = self.bus.get_object(self.servername, self.basepath)
281         self.iface = dbus.Interface(self.dev, dbus_interface='org.ffado.Control.Element.AttributeEnum')
282     def count(self):
283         return self.iface.count()
284     def select(self, idx):
285         return self.iface.select(idx)
286     def selected(self):
287         return self.iface.selected()
288     def getEnumLabel(self, idx):
289         return self.iface.getEnumLabel(idx)
290     def attributeCount(self):
291         return self.iface.attributeCount()
292     def getAttributeValue(self, idx):
293         return self.iface.getAttributeValue(idx)
294     def getAttributeName(self, idx):
295         return self.iface.getAttributeName(idx)
296
297 class SamplerateSelectInterface:
298     def __init__(self, servername, devicepath):
299         self.basepath=devicepath + '/Generic/SamplerateSelect'
300         self.servername=servername
301         self.bus=dbus.SessionBus()
302         self.dev = self.bus.get_object(self.servername, self.basepath)
303         self.iface = dbus.Interface(self.dev, dbus_interface='org.ffado.Control.Element.Enum')
304     def count(self):
305         return self.iface.count()
306     def select(self, idx):
307         return self.iface.select(idx)
308     def selected(self):
309         return self.iface.selected()
310     def getEnumLabel(self, idx):
311         return self.iface.getEnumLabel(idx)
312
313 class TextInterface:
314     def __init__(self, servername, basepath):
315         self.basepath=basepath
316         self.servername=servername
317         self.bus=dbus.SessionBus()
318         self.dev = self.bus.get_object( self.servername, self.basepath )
319         self.iface = dbus.Interface( self.dev, dbus_interface="org.ffado.Control.Element.Text" )
320
321     def text(self):
322         return self.iface.getValue()
323
324     def setText(self,text):
325         self.iface.setValue(text)
Note: See TracBrowser for help on using the browser.