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

Revision 1385, 13.7 kB (checked in by ppalmers, 12 years ago)

Implement a mechanism to disable the samplerate and clock source controls while the device is streaming in order to avoid changes that could mess up jack. The saffire pro controls that cause a device reset to
happen are also disabled while streaming is active.

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