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

Revision 2129, 15.1 kB (checked in by jwoithe, 9 years ago)

audiofire: first attempt at disabling the save-settings button when streaming is active. Evidence suggests the hardware does not cope well when this is done with streaming active. This change has not been tested since I don't have an audiofire device; if I've broken the audiofire mixer with this commit please let me know.

  • 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, QTimer
24 from PyQt4.QtGui import QWidget, QHBoxLayout, QVBoxLayout, \
25                         QGroupBox, QTabWidget, QLabel, \
26                         QPushButton, QToolButton, 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 polledUpdate(self):
287         ss = self.streamingstatus.selected()
288
289         # Only alter controls sensitive to the streaming state when the
290         # streaming state has changed.
291         if (ss != self.streaming_state):
292             ss_txt = self.streamingstatus.getEnumLabel(ss)
293             # The device doesn't cope very well if "save settings" is done
294             # while streaming is active
295             settings.btnSaveSettings.setEnabled(ss_txt=='Idle')
296
297         self.streaming_state = ss
298
299     def initValues(self):
300         log.debug("Init values")
301
302         for ctrl, info in self.MatrixVolumeControls.iteritems():
303             vol = self.hw.getMatrixMixerValue(self.MatrixVolumeControls[ctrl][0],
304                                                 self.MatrixVolumeControls[ctrl][1],
305                                                 self.MatrixVolumeControls[ctrl][2])
306
307             #vol = 0x01000000-vol
308             log.debug("%s volume is %d" % (ctrl.objectName() , vol))
309             ctrl.setValue(vol)
310
311             # connect the UI element
312             QObject.connect(ctrl,SIGNAL('valueChanged(int)'),self.updateMatrixVolume)
313
314         for ctrl, info in self.MatrixButtonControls.iteritems():
315             state = self.hw.getMatrixMixerValue(self.MatrixButtonControls[ctrl][0],
316                                                 self.MatrixButtonControls[ctrl][1],
317                                                 self.MatrixButtonControls[ctrl][2])
318
319             log.debug("%s state is %d" % (ctrl.objectName() , state))
320             if state:
321                 ctrl.setChecked(True)
322             else:
323                 ctrl.setChecked(False)
324
325             # connect the UI element
326             QObject.connect(ctrl,SIGNAL('clicked(bool)'),self.updateMatrixButton)
327
328         for ctrl, info in self.MatrixRotaryControls.iteritems():
329             vol = self.hw.getMatrixMixerValue(self.MatrixRotaryControls[ctrl][0],
330                                                 self.MatrixRotaryControls[ctrl][1],
331                                                 self.MatrixRotaryControls[ctrl][2])
332
333             log.debug("%s value is %d" % (ctrl.objectName(), vol))
334             ctrl.setValue(vol)
335
336             # connect the UI element
337             QObject.connect(ctrl,SIGNAL('valueChanged(int)'),self.updateMatrixRotary)
338
339         for ctrl, info in self.VolumeControls.iteritems():
340             vol = self.hw.getContignuous(self.VolumeControls[ctrl][0])
341
342             #vol = 0x01000000-vol
343             log.debug("%s volume is %d" % (ctrl.objectName() , vol))
344             ctrl.setValue(vol)
345
346             # connect the UI element
347             QObject.connect(ctrl,SIGNAL('valueChanged(int)'),self.updateVolume)
348
349         for ctrl, info in self.SelectorControls.iteritems():
350             state = self.hw.getDiscrete(self.SelectorControls[ctrl][0])
351             log.debug("%s state is %d" % (ctrl.objectName() , state))
352             if state:
353                 ctrl.setChecked(True)
354             else:
355                 ctrl.setChecked(False)
356
357             # connect the UI element
358             QObject.connect(ctrl,SIGNAL('clicked(bool)'),self.updateSelector)
359
360         for ctrl, info in self.TriggerControls.iteritems():
361             # connect the UI element
362             QObject.connect(ctrl,SIGNAL('clicked()'),self.updateTrigger)
363
364         for ctrl, info in self.SPDIFmodeControls.iteritems():
365             state = self.hw.getDiscrete(self.SPDIFmodeControls[ctrl][0])
366             log.debug("%s state is %d" % (ctrl.objectName() , state))
367             if state == self.SPDIFmodeControls[ctrl][1]:
368                 ctrl.setChecked(True)
369             else:
370                 ctrl.setChecked(False)
371
372             # connect the UI element
373             QObject.connect(ctrl,SIGNAL('toggled(bool)'),self.updateSPDIFmodeControl)
374
375         self.update_timer = QTimer(self)
376         QObject.connect(self.update_timer, SIGNAL('timeout()'), self.polledUpdate)
377         self.update_timer.start(1000)
378         self.streaming_state = -1
379
380 # vim: et
Note: See TracBrowser for help on using the browser.