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

Revision 1885, 14.4 kB (checked in by arnonym, 14 years ago)

Try to save some space in the mixer of the profire610.

  • 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 == 0x0AF9:
55             return "AudioFirePre8"
56         if modelId == 0x0AF12:
57             return "AudioFire12"
58         return "Generic FireWorks"
59
60     def updateMatrixButton(self,a0):
61         sender = self.sender()
62         if a0:
63             state = 1
64         else:
65             state = 0
66         log.debug("set %s %d %d to %d" % (
67                     self.MatrixButtonControls[sender][0],
68                     self.MatrixButtonControls[sender][1],
69                     self.MatrixButtonControls[sender][2],
70                     state))
71         self.hw.setMatrixMixerValue(self.MatrixButtonControls[sender][0],
72                                     self.MatrixButtonControls[sender][1],
73                                     self.MatrixButtonControls[sender][2],
74                                     state)
75
76     def updateMatrixRotary(self,a0):
77         sender = self.sender()
78         vol = a0
79         log.debug("set %s %d %d to %d" % (
80                     self.MatrixRotaryControls[sender][0],
81                     self.MatrixRotaryControls[sender][1],
82                     self.MatrixRotaryControls[sender][2],
83                     vol))
84         self.hw.setMatrixMixerValue(self.MatrixRotaryControls[sender][0],
85                                     self.MatrixRotaryControls[sender][1],
86                                     self.MatrixRotaryControls[sender][2],
87                                     vol)
88
89     def updateMatrixVolume(self,a0):
90         sender = self.sender()
91         vol = a0
92         #vol = 0x01000000-vol
93         log.debug("set %s %d %d to %d" % (
94                     self.MatrixVolumeControls[sender][0],
95                     self.MatrixVolumeControls[sender][1],
96                     self.MatrixVolumeControls[sender][2],
97                     vol))
98         self.hw.setMatrixMixerValue(self.MatrixVolumeControls[sender][0],
99                                     self.MatrixVolumeControls[sender][1],
100                                     self.MatrixVolumeControls[sender][2],
101                                     vol)
102
103     def updateVolume(self,a0):
104         sender = self.sender()
105         vol = a0
106         #vol = 0x01000000-vol
107         log.debug("set %s to %d" % (
108                     self.VolumeControls[sender][0],
109                     vol))
110         self.hw.setContignuous(self.VolumeControls[sender][0],
111                               vol)
112
113     def updateSelector(self,a0):
114         sender = self.sender()
115         if a0:
116             state = 1
117         else:
118             state = 0
119         log.debug("set %s to %d" % (
120                     self.SelectorControls[sender][0],
121                     state))
122         self.hw.setDiscrete(self.SelectorControls[sender][0], state)
123
124     def updateTrigger(self):
125         sender = self.sender()
126         log.debug("trigger %s" % (self.TriggerControls[sender][0]))
127         self.hw.setDiscrete(self.TriggerControls[sender][0], 1)
128
129     def updateSPDIFmodeControl(self,a0):
130         sender = self.sender()
131         if a0:
132             state = 1
133         else:
134             state = 0
135         if state:
136             log.debug("set %s to %d" % (
137                         self.SPDIFmodeControls[sender][0],
138                         self.SPDIFmodeControls[sender][1]))
139             self.hw.setDiscrete(self.SPDIFmodeControls[sender][0], self.SPDIFmodeControls[sender][1])
140
141     def buildMixer(self):
142         log.debug("Building mixer")
143         self.MatrixButtonControls={}
144         self.MatrixRotaryControls={}
145         self.MatrixVolumeControls={}
146         self.VolumeControls={}
147         self.SelectorControls={}
148         self.SPDIFmodeControls={}
149         self.TriggerControls={}
150
151         nb_pys_out = self.hw.getDiscrete("/HwInfo/PhysicalAudioOutCount")
152         nb_pys_in = self.hw.getDiscrete("/HwInfo/PhysicalAudioInCount")
153
154         outputtabslayout = QHBoxLayout( self )
155         outputtabs = QTabWidget(self)
156         outputtabslayout.addWidget( outputtabs, 1 )
157
158         for outpair in range(nb_pys_out/2):
159             tab = QWidget( outputtabs )
160             tablayout = QHBoxLayout( tab )
161            
162             grpMonitor = QGroupBox(tab)
163             tablayout.addWidget(grpMonitor)
164    
165             grpPlayback = QGroupBox(tab)
166             tablayout.addWidget(grpPlayback)
167    
168             grpOutput = QGroupBox(tab)
169             tablayout.addWidget(grpOutput)
170    
171             grpMonitor.setTitle("Monitor")
172             grpPlayback.setTitle("Playback")
173             grpOutput.setTitle("Output")
174            
175             # monitor controls
176             grpMonitorLayout = QHBoxLayout()
177             grpMonitor.setLayout(grpMonitorLayout);
178             output_id = outpair * 2
179             for inpair in range(nb_pys_in/2):
180                 # create GUI elements
181                 strip = AfMonitorWidget( grpMonitor )
182                 grpMonitorLayout.addWidget( strip, 1 )
183                 input_id = inpair*2
184                 strip.lblName.setText("IN %d/%d" % (input_id+1, input_id+2))
185
186                 # add the elements to the control structure
187
188                 self.MatrixButtonControls[strip.btnMute0] = ['/Mixer/MonitorMute', input_id, output_id]
189                 self.MatrixButtonControls[strip.btnMute1] = ['/Mixer/MonitorMute', input_id + 1, output_id + 1]
190                 self.MatrixButtonControls[strip.btnSolo0] = ['/Mixer/MonitorSolo', input_id, output_id]
191                 self.MatrixButtonControls[strip.btnSolo1] = ['/Mixer/MonitorSolo', input_id + 1, output_id + 1]
192                 self.MatrixRotaryControls[strip.rotPan0]  = ['/Mixer/MonitorPan', input_id, output_id]
193                 self.MatrixRotaryControls[strip.rotPan1]  = ['/Mixer/MonitorPan', input_id + 1, output_id + 1]
194                 self.MatrixVolumeControls[strip.sldGain0]  = ['/Mixer/MonitorGain', input_id, output_id]
195                 self.MatrixVolumeControls[strip.sldGain1]  = ['/Mixer/MonitorGain', input_id + 1, output_id + 1]
196
197             # playback
198             grpPlaybackLayout = QHBoxLayout()
199             grpPlayback.setLayout(grpPlaybackLayout);
200             strip = AfMonitorWidget( grpPlayback )
201             grpPlaybackLayout.addWidget(strip, 1)
202             strip.lblName.setText("Playback %d/%d" % (output_id+1, output_id+2))
203
204             self.VolumeControls[strip.sldGain0] = ["/Mixer/PC%dGain" % (output_id)]
205             self.VolumeControls[strip.sldGain1] = ["/Mixer/PC%dGain" % (output_id+1)]
206             self.SelectorControls[strip.btnMute0] = ["/Mixer/PC%dMute" % (output_id)]
207             self.SelectorControls[strip.btnMute1] = ["/Mixer/PC%dMute" % (output_id+1)]
208             self.SelectorControls[strip.btnSolo0] = ["/Mixer/PC%dSolo" % (output_id)]
209             self.SelectorControls[strip.btnSolo1] = ["/Mixer/PC%dSolo" % (output_id+1)]
210
211             # fix up mixer strip gui
212             strip.rotPan0.hide()
213             strip.rotPan1.hide()
214
215             # output
216             grpOutputLayout = QHBoxLayout()
217             grpOutput.setLayout(grpOutputLayout);
218             strip = AfMonitorWidget( grpOutput )
219             grpOutputLayout.addWidget(strip, 1)
220             strip.lblName.setText("Output %d/%d" % (output_id+1, output_id+2))
221
222             self.VolumeControls[strip.sldGain0] = ["/Mixer/OUT%dGain" % (output_id)]
223             self.VolumeControls[strip.sldGain1] = ["/Mixer/OUT%dGain" % (output_id+1)]
224             self.SelectorControls[strip.btnMute0] = ["/Mixer/OUT%dMute" % (output_id)]
225             self.SelectorControls[strip.btnMute1] = ["/Mixer/OUT%dMute" % (output_id+1)]
226             self.SelectorControls[strip.btnSolo0] = ["/Mixer/OUT%dNominal" % (output_id)]
227             self.SelectorControls[strip.btnSolo1] = ["/Mixer/OUT%dNominal" % (output_id+1)]
228
229             # fix up mixer strip gui
230             strip.btnSolo0.setText("Pad")
231             strip.btnSolo1.setText("Pad")
232             strip.rotPan0.hide()
233             strip.rotPan1.hide()
234
235             # add the tab
236             outputtabs.addTab( tab, "OUT %d/%d" % (output_id+1, output_id+2))
237
238         # add an input config tab
239         tab = QWidget( outputtabs )
240         tablayout = QHBoxLayout( tab )
241
242         for inpair in range(nb_pys_in):
243             # create GUI elements
244             log.debug("strip")
245             grpInput = QGroupBox(tab)
246             tablayout.addWidget(grpInput)
247             grpInput.setTitle("IN %d" % (inpair+1))
248
249             grpInputLayout = QVBoxLayout()
250             grpInput.setLayout(grpInputLayout);
251
252             label = QLabel( grpInput )
253             grpInputLayout.addWidget( label )
254             label.setText("In %d" % (inpair+1))
255             label.setAlignment(Qt.AlignCenter)
256
257             btn = QToolButton( grpInput )
258             grpInputLayout.addWidget( btn )
259             btn.setText("Pad")
260             btn.setCheckable(True)
261             self.SelectorControls[btn] = ["/Mixer/IN%dNominal" % (inpair)]
262
263             spacer = QSpacerItem(1,1,QSizePolicy.Minimum,QSizePolicy.Expanding)
264             grpInputLayout.addItem(spacer)
265
266         outputtabs.addTab( tab, "INPUT")
267
268         # add an settings tab
269         tab = QWidget( outputtabs )
270         tablayout = QHBoxLayout( tab )
271         outputtabs.addTab( tab, "SETTINGS")
272         settings = AfSettingsWidget( tab )
273
274         has_sw_phantom = self.hw.getDiscrete("/HwInfo/PhantomPower")
275         if has_sw_phantom:
276             self.SelectorControls[settings.btnPhantom] = ["/PhantomPower"]
277         else:
278             settings.btnPhantom.hide()
279
280         self.TriggerControls[settings.btnSaveSettings] = ["/SaveSettings"]
281         self.TriggerControls[settings.btnIdentify] = ["/Identify"]
282
283         self.SPDIFmodeControls[settings.radioConsumer] = ["/SpdifMode", 0]
284         self.SPDIFmodeControls[settings.radioProfessional] = ["/SpdifMode", 1]
285
286     def initValues(self):
287         log.debug("Init values")
288
289         for ctrl, info in self.MatrixVolumeControls.iteritems():
290             vol = self.hw.getMatrixMixerValue(self.MatrixVolumeControls[ctrl][0],
291                                                 self.MatrixVolumeControls[ctrl][1],
292                                                 self.MatrixVolumeControls[ctrl][2])
293
294             #vol = 0x01000000-vol
295             log.debug("%s volume is %d" % (ctrl.objectName() , vol))
296             ctrl.setValue(vol)
297
298             # connect the UI element
299             QObject.connect(ctrl,SIGNAL('valueChanged(int)'),self.updateMatrixVolume)
300
301         for ctrl, info in self.MatrixButtonControls.iteritems():
302             state = self.hw.getMatrixMixerValue(self.MatrixButtonControls[ctrl][0],
303                                                 self.MatrixButtonControls[ctrl][1],
304                                                 self.MatrixButtonControls[ctrl][2])
305
306             log.debug("%s state is %d" % (ctrl.objectName() , state))
307             if state:
308                 ctrl.setChecked(True)
309             else:
310                 ctrl.setChecked(False)
311
312             # connect the UI element
313             QObject.connect(ctrl,SIGNAL('clicked(bool)'),self.updateMatrixButton)
314
315         for ctrl, info in self.MatrixRotaryControls.iteritems():
316             vol = self.hw.getMatrixMixerValue(self.MatrixRotaryControls[ctrl][0],
317                                                 self.MatrixRotaryControls[ctrl][1],
318                                                 self.MatrixRotaryControls[ctrl][2])
319
320             log.debug("%s value is %d" % (ctrl.objectName(), vol))
321             ctrl.setValue(vol)
322
323             # connect the UI element
324             QObject.connect(ctrl,SIGNAL('valueChanged(int)'),self.updateMatrixRotary)
325
326         for ctrl, info in self.VolumeControls.iteritems():
327             vol = self.hw.getContignuous(self.VolumeControls[ctrl][0])
328
329             #vol = 0x01000000-vol
330             log.debug("%s volume is %d" % (ctrl.objectName() , vol))
331             ctrl.setValue(vol)
332
333             # connect the UI element
334             QObject.connect(ctrl,SIGNAL('valueChanged(int)'),self.updateVolume)
335
336         for ctrl, info in self.SelectorControls.iteritems():
337             state = self.hw.getDiscrete(self.SelectorControls[ctrl][0])
338             log.debug("%s state is %d" % (ctrl.objectName() , state))
339             if state:
340                 ctrl.setChecked(True)
341             else:
342                 ctrl.setChecked(False)
343
344             # connect the UI element
345             QObject.connect(ctrl,SIGNAL('clicked(bool)'),self.updateSelector)
346
347         for ctrl, info in self.TriggerControls.iteritems():
348             # connect the UI element
349             QObject.connect(ctrl,SIGNAL('clicked()'),self.updateTrigger)
350
351         for ctrl, info in self.SPDIFmodeControls.iteritems():
352             state = self.hw.getDiscrete(self.SPDIFmodeControls[ctrl][0])
353             log.debug("%s state is %d" % (ctrl.objectName() , state))
354             if state == self.SPDIFmodeControls[ctrl][1]:
355                 ctrl.setChecked(True)
356             else:
357                 ctrl.setChecked(False)
358
359             # connect the UI element
360             QObject.connect(ctrl,SIGNAL('toggled(bool)'),self.updateSPDIFmodeControl)
361
362 # vim: et
Note: See TracBrowser for help on using the browser.