root/trunk/libffado/support/mixer-qt4/ffado/mixer/audiofire.py

Revision 1691, 14.4 kB (checked in by arnonym, 11 years ago)

Only load the mixerwidgets that are actually needed.

To automate this, a rules are imposed:

The filename has to be the lower-case variant of the mixer name

This should speed up loading time of ffado-mixer. Please everybody test this and report any errors as I don't have all the devices to test everything fully.

  • Property svn:mergeinfo set to
Line 
1 #
2 # Copyright (C) 2005-2008 by Pieter Palmers
3 #
4 # This file is part of FFADO
5 # FFADO = Free Firewire (pro-)audio drivers for linux
6 #
7 # FFADO is based upon FreeBoB.
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 2 of the License, or
12 # (at your option) version 3 of the License.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 #
22
23 from PyQt4.QtCore import SIGNAL, SLOT, QObject, Qt
24 from PyQt4.QtGui import QWidget, QHBoxLayout, QVBoxLayout, \
25                         QGroupBox, QTabWidget, QLabel, \
26                         QPushButton, QSpacerItem, QSizePolicy
27 from ffado.config import *
28 import logging
29 log = logging.getLogger('audiofire')
30
31 class AfMonitorWidget(QWidget):
32     def __init__(self,parent = None):
33         QWidget.__init__(self,parent)
34         uicLoad("ffado/mixer/audiofire_strip", self)
35
36 class AfSettingsWidget(QWidget):
37     def __init__(self,parent = None):
38         QWidget.__init__(self,parent)
39         uicLoad("ffado/mixer/audiofire_settings", self)
40
41 class AudioFire(QWidget):
42     def __init__(self,parent = None):
43         QWidget.__init__(self,parent)
44         log.debug("Init AudioFire mixer window")
45
46     def getDisplayTitle(self):
47         modelId = self.configrom.getModelId()
48         if modelId == 0x0AF2:
49             return "AudioFire2"
50         if modelId == 0x0AF4:
51             return "AudioFire4"
52         if modelId == 0x0AF8:
53             return "AudioFire8"
54         if modelId == 0x0AF12:
55             return "AudioFire12"
56         return "Generic FireWorks"
57
58     def updateMatrixButton(self,a0):
59         sender = self.sender()
60         if a0:
61             state = 1
62         else:
63             state = 0
64         log.debug("set %s %d %d to %d" % (
65                     self.MatrixButtonControls[sender][0],
66                     self.MatrixButtonControls[sender][1],
67                     self.MatrixButtonControls[sender][2],
68                     state))
69         self.hw.setMatrixMixerValue(self.MatrixButtonControls[sender][0],
70                                     self.MatrixButtonControls[sender][1],
71                                     self.MatrixButtonControls[sender][2],
72                                     state)
73
74     def updateMatrixRotary(self,a0):
75         sender = self.sender()
76         vol = a0
77         log.debug("set %s %d %d to %d" % (
78                     self.MatrixRotaryControls[sender][0],
79                     self.MatrixRotaryControls[sender][1],
80                     self.MatrixRotaryControls[sender][2],
81                     vol))
82         self.hw.setMatrixMixerValue(self.MatrixRotaryControls[sender][0],
83                                     self.MatrixRotaryControls[sender][1],
84                                     self.MatrixRotaryControls[sender][2],
85                                     vol)
86
87     def updateMatrixVolume(self,a0):
88         sender = self.sender()
89         vol = a0
90         #vol = 0x01000000-vol
91         log.debug("set %s %d %d to %d" % (
92                     self.MatrixVolumeControls[sender][0],
93                     self.MatrixVolumeControls[sender][1],
94                     self.MatrixVolumeControls[sender][2],
95                     vol))
96         self.hw.setMatrixMixerValue(self.MatrixVolumeControls[sender][0],
97                                     self.MatrixVolumeControls[sender][1],
98                                     self.MatrixVolumeControls[sender][2],
99                                     vol)
100
101     def updateVolume(self,a0):
102         sender = self.sender()
103         vol = a0
104         #vol = 0x01000000-vol
105         log.debug("set %s to %d" % (
106                     self.VolumeControls[sender][0],
107                     vol))
108         self.hw.setContignuous(self.VolumeControls[sender][0],
109                               vol)
110
111     def updateSelector(self,a0):
112         sender = self.sender()
113         if a0:
114             state = 1
115         else:
116             state = 0
117         log.debug("set %s to %d" % (
118                     self.SelectorControls[sender][0],
119                     state))
120         self.hw.setDiscrete(self.SelectorControls[sender][0], state)
121
122     def updateTrigger(self):
123         sender = self.sender()
124         log.debug("trigger %s" % (self.TriggerControls[sender][0]))
125         self.hw.setDiscrete(self.TriggerControls[sender][0], 1)
126
127     def updateSPDIFmodeControl(self,a0):
128         sender = self.sender()
129         if a0:
130             state = 1
131         else:
132             state = 0
133         if state:
134             log.debug("set %s to %d" % (
135                         self.SPDIFmodeControls[sender][0],
136                         self.SPDIFmodeControls[sender][1]))
137             self.hw.setDiscrete(self.SPDIFmodeControls[sender][0], self.SPDIFmodeControls[sender][1])
138
139     def buildMixer(self):
140         log.debug("Building mixer")
141         self.MatrixButtonControls={}
142         self.MatrixRotaryControls={}
143         self.MatrixVolumeControls={}
144         self.VolumeControls={}
145         self.SelectorControls={}
146         self.SPDIFmodeControls={}
147         self.TriggerControls={}
148
149         nb_pys_out = self.hw.getDiscrete("/HwInfo/PhysicalAudioOutCount")
150         nb_pys_in = self.hw.getDiscrete("/HwInfo/PhysicalAudioInCount")
151
152         outputtabslayout = QHBoxLayout( self )
153         outputtabs = QTabWidget(self)
154         outputtabslayout.addWidget( outputtabs, 1 )
155
156         for outpair in range(nb_pys_out/2):
157             tab = QWidget( outputtabs )
158             tablayout = QHBoxLayout( tab )
159            
160             grpMonitor = QGroupBox(tab)
161             tablayout.addWidget(grpMonitor)
162    
163             grpPlayback = QGroupBox(tab)
164             tablayout.addWidget(grpPlayback)
165    
166             grpOutput = QGroupBox(tab)
167             tablayout.addWidget(grpOutput)
168    
169             grpMonitor.setTitle("Monitor")
170             grpPlayback.setTitle("Playback")
171             grpOutput.setTitle("Output")
172            
173             # monitor controls
174             grpMonitorLayout = QHBoxLayout()
175             grpMonitor.setLayout(grpMonitorLayout);
176             output_id = outpair * 2
177             for inpair in range(nb_pys_in/2):
178                 # create GUI elements
179                 strip = AfMonitorWidget( grpMonitor )
180                 grpMonitorLayout.addWidget( strip, 1 )
181                 input_id = inpair*2
182                 strip.lblName.setText("IN %d/%d" % (input_id+1, input_id+2))
183
184                 # add the elements to the control structure
185
186                 self.MatrixButtonControls[strip.btnMute0] = ['/Mixer/MonitorMute', input_id, output_id]
187                 self.MatrixButtonControls[strip.btnMute1] = ['/Mixer/MonitorMute', input_id + 1, output_id + 1]
188                 self.MatrixButtonControls[strip.btnSolo0] = ['/Mixer/MonitorSolo', input_id, output_id]
189                 self.MatrixButtonControls[strip.btnSolo1] = ['/Mixer/MonitorSolo', input_id + 1, output_id + 1]
190                 self.MatrixRotaryControls[strip.rotPan0]  = ['/Mixer/MonitorPan', input_id, output_id]
191                 self.MatrixRotaryControls[strip.rotPan1]  = ['/Mixer/MonitorPan', input_id + 1, output_id + 1]
192                 self.MatrixVolumeControls[strip.sldGain0]  = ['/Mixer/MonitorGain', input_id, output_id]
193                 self.MatrixVolumeControls[strip.sldGain1]  = ['/Mixer/MonitorGain', input_id + 1, output_id + 1]
194
195             # playback
196             grpPlaybackLayout = QHBoxLayout()
197             grpPlayback.setLayout(grpPlaybackLayout);
198             strip = AfMonitorWidget( grpPlayback )
199             grpPlaybackLayout.addWidget(strip, 1)
200             strip.lblName.setText("Playback %d/%d" % (output_id+1, output_id+2))
201
202             self.VolumeControls[strip.sldGain0] = ["/Mixer/PC%dGain" % (output_id)]
203             self.VolumeControls[strip.sldGain1] = ["/Mixer/PC%dGain" % (output_id+1)]
204             self.SelectorControls[strip.btnMute0] = ["/Mixer/PC%dMute" % (output_id)]
205             self.SelectorControls[strip.btnMute1] = ["/Mixer/PC%dMute" % (output_id+1)]
206             self.SelectorControls[strip.btnSolo0] = ["/Mixer/PC%dSolo" % (output_id)]
207             self.SelectorControls[strip.btnSolo1] = ["/Mixer/PC%dSolo" % (output_id+1)]
208
209             # fix up mixer strip gui
210             strip.rotPan0.hide()
211             strip.rotPan1.hide()
212
213             # output
214             grpOutputLayout = QHBoxLayout()
215             grpOutput.setLayout(grpOutputLayout);
216             strip = AfMonitorWidget( grpOutput )
217             grpOutputLayout.addWidget(strip, 1)
218             strip.lblName.setText("Output %d/%d" % (output_id+1, output_id+2))
219
220             self.VolumeControls[strip.sldGain0] = ["/Mixer/OUT%dGain" % (output_id)]
221             self.VolumeControls[strip.sldGain1] = ["/Mixer/OUT%dGain" % (output_id+1)]
222             self.SelectorControls[strip.btnMute0] = ["/Mixer/OUT%dMute" % (output_id)]
223             self.SelectorControls[strip.btnMute1] = ["/Mixer/OUT%dMute" % (output_id+1)]
224             self.SelectorControls[strip.btnSolo0] = ["/Mixer/OUT%dNominal" % (output_id)]
225             self.SelectorControls[strip.btnSolo1] = ["/Mixer/OUT%dNominal" % (output_id+1)]
226
227             # fix up mixer strip gui
228             strip.btnSolo0.setText("Pad")
229             strip.btnSolo1.setText("Pad")
230             strip.rotPan0.hide()
231             strip.rotPan1.hide()
232
233             # add the tab
234             outputtabs.addTab( tab, "OUT %d/%d" % (output_id+1, output_id+2))
235
236         # add an input config tab
237         tab = QWidget( outputtabs )
238         tablayout = QHBoxLayout( tab )
239
240         for inpair in range(nb_pys_in):
241             # create GUI elements
242             log.debug("strip")
243             grpInput = QGroupBox(tab)
244             tablayout.addWidget(grpInput)
245             grpInput.setTitle("IN %d" % (inpair+1))
246
247             grpInputLayout = QVBoxLayout()
248             grpInput.setLayout(grpInputLayout);
249
250             label = QLabel( grpInput )
251             grpInputLayout.addWidget( label )
252             label.setText("frienlyname %d" % (inpair+1))
253             label.setAlignment(Qt.AlignCenter)
254
255             btn = QPushButton( grpInput )
256             grpInputLayout.addWidget( btn )
257             btn.setText("Pad")
258             btn.setCheckable(True)
259             self.SelectorControls[btn] = ["/Mixer/IN%dNominal" % (inpair)]
260
261             spacer = QSpacerItem(1,1,QSizePolicy.Minimum,QSizePolicy.Expanding)
262             grpInputLayout.addItem(spacer)
263
264         outputtabs.addTab( tab, "INPUT")
265
266         # add an settings tab
267         tab = QWidget( outputtabs )
268         tablayout = QHBoxLayout( tab )
269         outputtabs.addTab( tab, "SETTINGS")
270         settings = AfSettingsWidget( tab )
271
272         has_sw_phantom = self.hw.getDiscrete("/HwInfo/PhantomPower")
273         if has_sw_phantom:
274             self.SelectorControls[settings.btnPhantom] = ["/PhantomPower"]
275         else:
276             settings.btnPhantom.hide()
277
278         self.TriggerControls[settings.btnSaveSettings] = ["/SaveSettings"]
279         self.TriggerControls[settings.btnIdentify] = ["/Identify"]
280
281         self.SPDIFmodeControls[settings.radioConsumer] = ["/SpdifMode", 0]
282         self.SPDIFmodeControls[settings.radioProfessional] = ["/SpdifMode", 1]
283
284     def initValues(self):
285         log.debug("Init values")
286
287         for ctrl, info in self.MatrixVolumeControls.iteritems():
288             vol = self.hw.getMatrixMixerValue(self.MatrixVolumeControls[ctrl][0],
289                                                 self.MatrixVolumeControls[ctrl][1],
290                                                 self.MatrixVolumeControls[ctrl][2])
291
292             #vol = 0x01000000-vol
293             log.debug("%s volume is %d" % (ctrl.objectName() , vol))
294             ctrl.setValue(vol)
295
296             # connect the UI element
297             QObject.connect(ctrl,SIGNAL('valueChanged(int)'),self.updateMatrixVolume)
298
299         for ctrl, info in self.MatrixButtonControls.iteritems():
300             state = self.hw.getMatrixMixerValue(self.MatrixButtonControls[ctrl][0],
301                                                 self.MatrixButtonControls[ctrl][1],
302                                                 self.MatrixButtonControls[ctrl][2])
303
304             log.debug("%s state is %d" % (ctrl.objectName() , state))
305             if state:
306                 ctrl.setChecked(True)
307             else:
308                 ctrl.setChecked(False)
309
310             # connect the UI element
311             QObject.connect(ctrl,SIGNAL('clicked(bool)'),self.updateMatrixButton)
312
313         for ctrl, info in self.MatrixRotaryControls.iteritems():
314             vol = self.hw.getMatrixMixerValue(self.MatrixRotaryControls[ctrl][0],
315                                                 self.MatrixRotaryControls[ctrl][1],
316                                                 self.MatrixRotaryControls[ctrl][2])
317
318             log.debug("%s value is %d" % (ctrl.objectName(), vol))
319             ctrl.setValue(vol)
320
321             # connect the UI element
322             QObject.connect(ctrl,SIGNAL('valueChanged(int)'),self.updateMatrixRotary)
323
324         for ctrl, info in self.VolumeControls.iteritems():
325             vol = self.hw.getContignuous(self.VolumeControls[ctrl][0])
326
327             #vol = 0x01000000-vol
328             log.debug("%s volume is %d" % (ctrl.objectName() , vol))
329             ctrl.setValue(vol)
330
331             # connect the UI element
332             QObject.connect(ctrl,SIGNAL('valueChanged(int)'),self.updateVolume)
333
334         for ctrl, info in self.SelectorControls.iteritems():
335             state = self.hw.getDiscrete(self.SelectorControls[ctrl][0])
336             log.debug("%s state is %d" % (ctrl.objectName() , state))
337             if state:
338                 ctrl.setChecked(True)
339             else:
340                 ctrl.setChecked(False)
341
342             # connect the UI element
343             QObject.connect(ctrl,SIGNAL('clicked(bool)'),self.updateSelector)
344
345         for ctrl, info in self.TriggerControls.iteritems():
346             # connect the UI element
347             QObject.connect(ctrl,SIGNAL('clicked()'),self.updateTrigger)
348
349         for ctrl, info in self.SPDIFmodeControls.iteritems():
350             state = self.hw.getDiscrete(self.SPDIFmodeControls[ctrl][0])
351             log.debug("%s state is %d" % (ctrl.objectName() , state))
352             if state == self.SPDIFmodeControls[ctrl][1]:
353                 ctrl.setChecked(True)
354             else:
355                 ctrl.setChecked(False)
356
357             # connect the UI element
358             QObject.connect(ctrl,SIGNAL('toggled(bool)'),self.updateSPDIFmodeControl)
359
360 # vim: et
Note: See TracBrowser for help on using the browser.