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 |
from ffadomixer_config import FFADO_VERSION, FFADO_DBUS_SERVER, FFADO_DBUS_BASEPATH |
---|
25 |
|
---|
26 |
from PyQt4.QtGui import QFrame, QWidget, QTabWidget, QVBoxLayout |
---|
27 |
from PyQt4.QtCore import QTimer |
---|
28 |
|
---|
29 |
from ffado_panelmanagerstatusui import Ui_PanelManagerStatusUI |
---|
30 |
|
---|
31 |
from ffado_dbus_util import * |
---|
32 |
from ffado_registration import * |
---|
33 |
|
---|
34 |
from mixer_phase88 import * |
---|
35 |
from mixer_phase24 import * |
---|
36 |
from mixer_saffire import SaffireMixer |
---|
37 |
from mixer_saffirepro import SaffireProMixer |
---|
38 |
from mixer_audiofire import AudioFireMixer |
---|
39 |
from mixer_bcoaudio5 import * |
---|
40 |
from mixer_edirolfa66 import * |
---|
41 |
from mixer_edirolfa101 import * |
---|
42 |
from mixer_mackie_onyxmixer import * |
---|
43 |
from mixer_quatafire import * |
---|
44 |
from mixer_motu import * |
---|
45 |
from mixer_dummy import * |
---|
46 |
from mixer_global import GlobalMixer |
---|
47 |
|
---|
48 |
import logging |
---|
49 |
log = logging.getLogger('panelmanager') |
---|
50 |
|
---|
51 |
use_generic = False |
---|
52 |
try: |
---|
53 |
from mixer_generic import * |
---|
54 |
log.info("The generic mixer is found, seems to be a developer using ffadomixer...") |
---|
55 |
except ImportError: |
---|
56 |
pass |
---|
57 |
else: |
---|
58 |
use_generic = True |
---|
59 |
|
---|
60 |
SupportedDevices=[ |
---|
61 |
[(0x000aac, 0x00000003),'Phase88Control'], |
---|
62 |
[(0x000aac, 0x00000004),'Phase24Control'], |
---|
63 |
[(0x000aac, 0x00000007),'Phase24Control'], |
---|
64 |
[(0x00130e, 0x00000003),'SaffireProMixer'], |
---|
65 |
[(0x00130e, 0x00000006),'SaffireProMixer'], |
---|
66 |
[(0x00130e, 0x00000000),'SaffireMixer'], |
---|
67 |
[(0x001486, 0x00000af2),'AudioFireMixer'], |
---|
68 |
[(0x001486, 0x00000af4),'AudioFireMixer'], |
---|
69 |
[(0x001486, 0x00000af8),'AudioFireMixer'], |
---|
70 |
[(0x001486, 0x0000af12),'AudioFireMixer'], |
---|
71 |
[(0x0007f5, 0x00010049),'BCoAudio5Control'], |
---|
72 |
[(0x0040AB, 0x00010049),'EdirolFa66Control'], |
---|
73 |
[(0x0040AB, 0x00010048),'EdirolFa101Control'], |
---|
74 |
[(0x00000f, 0x00010067),'MackieOnyxMixer'], |
---|
75 |
[(0x000f1b, 0x00010064),'QuataFireMixer'], |
---|
76 |
[(0x0001f2, 0x00000000),'MotuMixer'], |
---|
77 |
] |
---|
78 |
|
---|
79 |
# pseudo-guid |
---|
80 |
GUID_GENERIC_MIXER = 0 |
---|
81 |
|
---|
82 |
|
---|
83 |
class HLine( QFrame ): |
---|
84 |
def __init__( self, parent ): |
---|
85 |
QFrame.__init__( self, parent ) |
---|
86 |
self.setFrameShape( QFrame.HLine ) |
---|
87 |
self.setLineWidth( 2 ) |
---|
88 |
self.setMinimumHeight( 10 ) |
---|
89 |
|
---|
90 |
class PanelManagerStatus(QWidget, Ui_PanelManagerStatusUI): |
---|
91 |
def __init__(self, parent): |
---|
92 |
QWidget.__init__(self,parent) |
---|
93 |
self.setupUi(self) |
---|
94 |
|
---|
95 |
class PanelManager(QWidget): |
---|
96 |
def __init__(self, parent, devmgr): |
---|
97 |
QWidget.__init__(self, parent) |
---|
98 |
self.devmgr = devmgr |
---|
99 |
self.devmgr.registerPreUpdateCallback(self.devlistPreUpdate) |
---|
100 |
self.devmgr.registerPostUpdateCallback(self.devlistPostUpdate) |
---|
101 |
self.devmgr.registerUpdateCallback(self.devlistUpdate) |
---|
102 |
self.devmgr.registerDestroyedCallback(self.devmgrDestroyed) |
---|
103 |
|
---|
104 |
# maps a device GUID to a QT panel |
---|
105 |
self.panels = {} |
---|
106 |
|
---|
107 |
# a layout for ourselves |
---|
108 |
self.layout = QVBoxLayout( self ) |
---|
109 |
|
---|
110 |
# the tabs |
---|
111 |
self.tabs = QTabWidget(self) |
---|
112 |
self.tabs.hide() |
---|
113 |
self.layout.addWidget(self.tabs) |
---|
114 |
|
---|
115 |
# a dialog that is shown during update |
---|
116 |
self.status = PanelManagerStatus(self) |
---|
117 |
self.status.lblMessage.setText("Initializing...") |
---|
118 |
self.layout.addWidget(self.status) |
---|
119 |
self.status.show() |
---|
120 |
|
---|
121 |
# live check timer |
---|
122 |
self.alivetimer = QTimer() |
---|
123 |
QObject.connect( self.alivetimer, SIGNAL('timeout()'), self.commCheck ) |
---|
124 |
self.alivetimer.start( 2000 ) |
---|
125 |
|
---|
126 |
def count(self): |
---|
127 |
return self.tabs.count() |
---|
128 |
|
---|
129 |
def pollPanels(self): |
---|
130 |
# only when not modifying the tabs |
---|
131 |
if self.tabs.isEnabled(): |
---|
132 |
for guid in self.panels.keys(): |
---|
133 |
w = self.panels[guid] |
---|
134 |
if 'polledUpdate' in dir(w): |
---|
135 |
try: |
---|
136 |
w.polledUpdate() |
---|
137 |
except: |
---|
138 |
log.error("error in polled update") |
---|
139 |
|
---|
140 |
def devlistPreUpdate(self): |
---|
141 |
log.debug("devlistPreUpdate") |
---|
142 |
self.tabs.setEnabled(False) |
---|
143 |
self.tabs.hide() |
---|
144 |
self.status.lblMessage.setText("Bus reconfiguration in progress, please wait...") |
---|
145 |
self.status.show() |
---|
146 |
|
---|
147 |
def devlistPostUpdate(self): |
---|
148 |
log.debug("devlistPostUpdate") |
---|
149 |
self.updatePanels() |
---|
150 |
|
---|
151 |
def devlistUpdate(self): |
---|
152 |
log.debug("devlistUpdate") |
---|
153 |
|
---|
154 |
def devmgrDestroyed(self): |
---|
155 |
log.debug("devmgrDestroyed") |
---|
156 |
self.alivetimer.stop() |
---|
157 |
self.tabs.setEnabled(False) |
---|
158 |
self.tabs.hide() |
---|
159 |
self.status.lblMessage.setText("DBUS server was shut down, please restart it and restart ffadomixer...") |
---|
160 |
self.status.show() |
---|
161 |
|
---|
162 |
def commCheck(self): |
---|
163 |
try: |
---|
164 |
nbDevices = self.devmgr.getNbDevices() |
---|
165 |
except: |
---|
166 |
log.debug("comms lost") |
---|
167 |
self.tabs.setEnabled(False) |
---|
168 |
self.tabs.hide() |
---|
169 |
self.status.lblMessage.setText("Failed to communicate with DBUS server. Please restart it and restart ffadomixer...") |
---|
170 |
self.status.show() |
---|
171 |
self.alivetimer.stop() |
---|
172 |
|
---|
173 |
def updatePanels(self): |
---|
174 |
nbDevices = self.devmgr.getNbDevices() |
---|
175 |
|
---|
176 |
# list of panels present |
---|
177 |
guids_with_tabs = self.panels.keys() |
---|
178 |
|
---|
179 |
# build list of guids on the bus now |
---|
180 |
guids_present = [] |
---|
181 |
guid_indexes = {} |
---|
182 |
for idx in range(nbDevices): |
---|
183 |
path = self.devmgr.getDeviceName(idx) |
---|
184 |
cfgrom = ConfigRomInterface(FFADO_DBUS_SERVER, FFADO_DBUS_BASEPATH+'/DeviceManager/'+path) |
---|
185 |
guid = cfgrom.getGUID() |
---|
186 |
guids_present.append(guid) |
---|
187 |
guid_indexes[guid] = idx |
---|
188 |
|
---|
189 |
# figure out what to remove |
---|
190 |
# the special panel (generic) |
---|
191 |
# that has (pseudo-)GUID 0 |
---|
192 |
# is also automatically removed |
---|
193 |
to_remove = [] |
---|
194 |
for guid in guids_with_tabs: |
---|
195 |
if not guid in guids_present: |
---|
196 |
to_remove.append(guid) |
---|
197 |
log.debug("going to remove %s" % str(guid)) |
---|
198 |
else: |
---|
199 |
log.debug("going to keep %s" % str(guid)) |
---|
200 |
|
---|
201 |
# figure out what to add |
---|
202 |
to_add = [] |
---|
203 |
for guid in guids_present: |
---|
204 |
if not guid in guids_with_tabs: |
---|
205 |
to_add.append(guid) |
---|
206 |
log.debug("going to add %s" % str(guid)) |
---|
207 |
|
---|
208 |
# update the widget |
---|
209 |
for guid in to_remove: |
---|
210 |
w = self.panels[guid] |
---|
211 |
del self.panels[guid] # remove from the list |
---|
212 |
idx = self.tabs.indexOf(w) |
---|
213 |
self.tabs.removeTab(idx) |
---|
214 |
del w # GC might also take care of that |
---|
215 |
|
---|
216 |
for guid in to_add: |
---|
217 |
# retrieve the device manager index |
---|
218 |
idx = guid_indexes[guid] |
---|
219 |
path = self.devmgr.getDeviceName(idx) |
---|
220 |
log.debug("Adding device %d: %s" % (idx, path)) |
---|
221 |
|
---|
222 |
cfgrom = ConfigRomInterface(FFADO_DBUS_SERVER, FFADO_DBUS_BASEPATH+'/DeviceManager/'+path) |
---|
223 |
vendorId = cfgrom.getVendorId() |
---|
224 |
modelId = cfgrom.getModelId() |
---|
225 |
unitVersion = cfgrom.getUnitVersion() |
---|
226 |
guid = cfgrom.getGUID() |
---|
227 |
vendorName = cfgrom.getVendorName() |
---|
228 |
modelName = cfgrom.getModelName() |
---|
229 |
log.debug(" Found (%s, %X, %X) %s %s" % (str(guid), vendorId, modelId, vendorName, modelName)) |
---|
230 |
|
---|
231 |
# check whether this has already been registered at ffado.org |
---|
232 |
reg = ffado_registration(FFADO_VERSION, int(guid, 16), |
---|
233 |
vendorId, modelId, |
---|
234 |
vendorName, modelName) |
---|
235 |
reg.check_for_registration() |
---|
236 |
|
---|
237 |
thisdev = (vendorId, modelId); |
---|
238 |
# The MOTU devices use unitVersion to differentiate models. For the |
---|
239 |
# moment thought we don't need to know precisely which model we're |
---|
240 |
# using. |
---|
241 |
if vendorId == 0x1f2: |
---|
242 |
thisdev = (vendorId, 0x00000000) |
---|
243 |
|
---|
244 |
dev = None |
---|
245 |
for d in SupportedDevices: |
---|
246 |
if d[0] == thisdev: |
---|
247 |
dev = d |
---|
248 |
|
---|
249 |
w = QWidget( self.tabs ) |
---|
250 |
l = QVBoxLayout( w ) |
---|
251 |
|
---|
252 |
# create a control object |
---|
253 |
hw = ControlInterface(FFADO_DBUS_SERVER, FFADO_DBUS_BASEPATH+'/DeviceManager/'+path) |
---|
254 |
clockselect = ClockSelectInterface( FFADO_DBUS_SERVER, FFADO_DBUS_BASEPATH+"/DeviceManager/"+path ) |
---|
255 |
samplerateselect = SamplerateSelectInterface( FFADO_DBUS_SERVER, FFADO_DBUS_BASEPATH+"/DeviceManager/"+path ) |
---|
256 |
nickname = TextInterface( FFADO_DBUS_SERVER, FFADO_DBUS_BASEPATH+"/DeviceManager/"+path+"/Generic/Nickname" ) |
---|
257 |
|
---|
258 |
# |
---|
259 |
# Generic elements for all mixers follow here: |
---|
260 |
# |
---|
261 |
tmp = GlobalMixer( w ) |
---|
262 |
tmp.configrom = cfgrom |
---|
263 |
tmp.clockselect = clockselect |
---|
264 |
tmp.samplerateselect = samplerateselect |
---|
265 |
tmp.nickname = nickname |
---|
266 |
tmp.hw = hw |
---|
267 |
tmp.initValues() |
---|
268 |
l.addWidget( tmp, 1 ) |
---|
269 |
|
---|
270 |
# |
---|
271 |
# Line to separate |
---|
272 |
# |
---|
273 |
l.addWidget( HLine( w ) ) |
---|
274 |
|
---|
275 |
# |
---|
276 |
# Specific (or dummy) mixer widgets get loaded in the following |
---|
277 |
# |
---|
278 |
if dev != None: |
---|
279 |
mixerapp = dev[1] |
---|
280 |
exec( "mixerwidget = "+mixerapp+"( w )" ) |
---|
281 |
else: |
---|
282 |
mixerwidget = DummyMixer( w ) |
---|
283 |
mixerapp = modelName+" (Dummy)" |
---|
284 |
|
---|
285 |
# |
---|
286 |
# The same for all mixers |
---|
287 |
# |
---|
288 |
l.addWidget( mixerwidget, 10 ) |
---|
289 |
mixerwidget.configrom = cfgrom |
---|
290 |
mixerwidget.clockselect = clockselect |
---|
291 |
mixerwidget.samplerateselect = samplerateselect |
---|
292 |
mixerwidget.nickname = nickname |
---|
293 |
mixerwidget.hw = hw |
---|
294 |
if 'buildMixer' in dir(mixerwidget): |
---|
295 |
mixerwidget.buildMixer() |
---|
296 |
if 'initValues' in dir(mixerwidget): |
---|
297 |
mixerwidget.initValues() |
---|
298 |
if 'getDisplayTitle' in dir(mixerwidget): |
---|
299 |
title = mixerwidget.getDisplayTitle() |
---|
300 |
else: |
---|
301 |
title = mixerapp |
---|
302 |
|
---|
303 |
self.tabs.addTab( w, title ) |
---|
304 |
self.panels[guid] = w |
---|
305 |
|
---|
306 |
# if there is no panel, add the no-device message |
---|
307 |
# else make sure it is not present |
---|
308 |
if self.count() == 0: |
---|
309 |
self.tabs.hide() |
---|
310 |
self.tabs.setEnabled(False) |
---|
311 |
self.status.lblMessage.setText("No supported device found.") |
---|
312 |
self.status.show() |
---|
313 |
else: |
---|
314 |
self.tabs.show() |
---|
315 |
self.tabs.setEnabled(True) |
---|
316 |
self.status.hide() |
---|
317 |
if use_generic: |
---|
318 |
# |
---|
319 |
# Show the generic (development) mixer if it is available |
---|
320 |
# |
---|
321 |
w = GenericMixer( devmgr.bus, FFADO_DBUS_SERVER, mw ) |
---|
322 |
self.tabs.addTab( w, "Generic Mixer" ) |
---|
323 |
self.panels[GUID_GENERIC_MIXER] = w |
---|