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

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