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

Revision 2126, 10.8 kB (checked in by jwoithe, 9 years ago)

dice: permit the Saffire pro24dsp to be treated the same as a pro24 so the streaming side of the latter can at least be used.

  • Property svn:mergeinfo set to
Line 
1 #
2 # Copyright (C) 2009-2010 by Arnold Krille
3 #
4 # This file is part of FFADO
5 # FFADO = Free Firewire (pro-)audio drivers for linux
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 2 of the License, or
10 # (at your option) version 3 of the License.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20
21 from PyQt4 import QtGui, QtCore, Qt
22 import dbus
23
24 from ffado.widgets.matrixmixer import MatrixMixer
25 from ffado.widgets.crossbarrouter import *
26 from ffado.mixer.generic_dice_eap import *
27
28 from ffado.config import *
29
30 class BooleanControl:
31     def __init__(self, hw, path):
32         self.iface = dbus.Interface(
33                 hw.bus.get_object(hw.servername, path),
34                 dbus_interface="org.ffado.Control.Element.Boolean")
35         self.value = self.iface.selected()
36
37     def selected(self):
38         return self.value
39
40     def select(self, n):
41         if self.iface.select(n):
42             self.value = n
43             return True
44         return False
45
46 class DiscreteControl:
47     def __init__(self, hw, path):
48         self.iface = dbus.Interface(
49                 hw.bus.get_object(hw.servername, path),
50                 dbus_interface="org.ffado.Control.Element.Discrete")
51         self.value = self.iface.getValue()
52
53     def getvalue(self):
54         return self.value
55
56     def setvalue(self, v):
57         if v != self.value:
58             self.iface.setValue(v)
59             self.value = v
60
61 class MonitoringModel(QtCore.QAbstractTableModel):
62     def __init__(self, hw, parent):
63         QtCore.QAbstractTableModel.__init__(self, parent)
64
65         self.hw = hw
66
67         self.mutestates = ("Global", "True", "False")
68
69         self.globaldims = []
70         self.globalmutes = []
71         self.perchannelmutes = []
72         self.globalvolumes = []
73         self.perchannelvolumes = []
74         for i in range(10):
75             self.globaldims.append(BooleanControl(self.hw, self.hw.basepath + ("/EAP/Monitoring/GlobalDim/AffectsCh%i" % i)))
76             self.globalmutes.append(BooleanControl(self.hw, self.hw.basepath + ("/EAP/Monitoring/GlobalMute/AffectsCh%i" % i)))
77             self.perchannelmutes.append(BooleanControl(self.hw, self.hw.basepath + ("/EAP/Monitoring/PerChannel/Mute%i" % i)))
78             self.globalvolumes.append(BooleanControl(self.hw, self.hw.basepath + ("/EAP/Monitoring/GlobalVolume/AffectsCh%i" % i)))
79             self.perchannelvolumes.append(DiscreteControl(self.hw, self.hw.basepath + ("/EAP/Monitoring/PerChannel/Volume%i" % i)))
80
81     def rowCount(self, parent):
82         return 3
83
84     def columnCount(self, parent):
85         return 10
86
87     def headerData(self, section, orientation, role=Qt.Qt.DisplayRole):
88         if role != Qt.Qt.DisplayRole:
89             #print "headerData will return nothing"
90             return None
91         #print "headerData() Will return a label"
92         if orientation == Qt.Qt.Horizontal:
93             return "Ch. %i" % section
94         if orientation == Qt.Qt.Vertical:
95             return ("Mute", "Dim", "Volume")[section]
96         return None
97
98     def data(self, index, role):
99         if not role in (Qt.Qt.DisplayRole, Qt.Qt.EditRole):
100             return None
101         row = index.row()
102         col = index.column()
103         if role == Qt.Qt.DisplayRole:
104             if row is 0:
105                 if self.perchannelmutes[col].selected():
106                     return self.mutestates[1]
107                 else:
108                     if self.globalmutes[col].selected():
109                         return self.mutestates[0]
110                 return self.mutestates[2]
111             if row is 1:
112                 if self.globaldims[col].selected():
113                     return "Enabled"
114                 else:
115                     return "Disabled"
116             if row is 2:
117                 if self.globalvolumes[col].selected():
118                     return "Global"
119                 else:
120                     return self.perchannelvolumes[col].getvalue()
121         if role == Qt.Qt.EditRole:
122             if row is 0:
123                 return QtCore.QStringList(self.mutestates)
124             if row is 1:
125                 return QtCore.QStringList(("Enabled","Disabled"))
126             if row is 2:
127                 if self.globalvolumes[col].selected():
128                     return 1
129                 return self.perchannelvolumes[col].getvalue()
130         return "%i,%i" % (row,col)
131
132     def setData(self, index, value, role=Qt.Qt.EditRole):
133         col = index.column()
134         row = index.row()
135         if row == 0:
136             if value == "Global":
137                 self.globalmutes[col].select(True)
138                 self.perchannelmutes[col].select(False)
139             else:
140                 self.globalmutes[col].select(False)
141                 if value == "True": value = True
142                 if value == "False": value = False
143                 self.perchannelmutes[col].select(value)
144             return True
145         if row == 1:
146             if value == "Enabled": value = True
147             if value == "Disabled": value = False
148             return self.globaldims[col].select(value)
149         if row == 2:
150             #print "setData() value=%s" % value.toString()
151             v = int(value.toString())
152             #print " integer is %i" % v
153             if v > 0:
154                 return self.globalvolumes[col].select(True)
155             else:
156                 self.globalvolumes[col].select(False)
157                 self.perchannelvolumes[col].setvalue(v)
158         return False
159
160     def flags(self, index):
161         ret = QtCore.QAbstractTableModel.flags(self, index)
162         if index.row() in (0,1,2):
163             ret |= Qt.Qt.ItemIsEditable
164         return ret
165
166
167
168 class MonitoringDelegate(QtGui.QItemDelegate):
169     def __init__(self, parent):
170         QtGui.QItemDelegate.__init__(self, parent)
171
172     def createEditor(self, parent, option, index):
173         if index.data(Qt.Qt.EditRole).type() == QtCore.QVariant.StringList:
174             combo = QtGui.QComboBox(parent)
175             self.connect(combo, QtCore.SIGNAL("activated(int)"), self.currentChanged)
176             return combo
177         else:
178             return QtGui.QItemDelegate.createEditor(self, parent, option, index)
179
180     def setEditorData(self, editor, index):
181         if isinstance(editor, QtGui.QComboBox):
182             list = index.data(Qt.Qt.EditRole).toStringList()
183             editor.addItems(list)
184             editor.setCurrentIndex(list.indexOf(index.data(Qt.Qt.DisplayRole).toString()))
185         else:
186             QtGui.QItemDelegate.setEditorData(self, editor, index)
187
188     def setModelData(self, editor, model, index):
189         if isinstance(editor, QtGui.QComboBox):
190             model.setData(index, editor.currentText(), Qt.Qt.EditRole)
191         else:
192             QtGui.QItemDelegate.setModelData(self, editor, model, index)
193
194     def currentChanged(self):
195         #print "currentChanged() sender=%s" % (str(self.sender()))
196         editor = self.sender()
197         self.emit(QtCore.SIGNAL("commitData(QWidget*)"), editor)
198         self.emit(QtCore.SIGNAL("closeEditor(QWidget*)"), editor)
199
200 class Saffire_Dice(Generic_Dice_EAP):
201     def __init__(self, parent=None):
202         Generic_Dice_EAP.__init__(self, parent)
203
204     def buildMixer(self):
205         #print self.hw
206         #print self.hw.getText("/Generic/Nickname")
207         Generic_Dice_EAP.buildMixer(self)
208
209         model = MonitoringModel(self.hw, self)
210
211         widget = QtGui.QWidget()
212         uicLoad("ffado/mixer/saffire_dice_monitoring.ui", widget)
213         widget.monitoringView.setModel(model)
214         widget.monitoringView.setItemDelegate(MonitoringDelegate(self))
215         self.tabs.addTab(widget, "Monitoring")
216
217         self.muteInterface = BooleanControl(self.hw, self.hw.basepath+"/EAP/Monitoring/GlobalMute/State")
218         widget.btnMute.setChecked(self.muteInterface.selected())
219         self.connect(widget.btnMute, QtCore.SIGNAL("toggled(bool)"), self.muteToggle)
220         self.dimInterface = BooleanControl(self.hw, self.hw.basepath+"/EAP/Monitoring/GlobalDim/State")
221         widget.btnDim.setChecked(self.dimInterface.selected())
222         self.connect(widget.btnDim, QtCore.SIGNAL("toggled(bool)"), self.dimToggle)
223
224         self.dimLevelInterface = DiscreteControl(self.hw, self.hw.basepath+"/EAP/Monitoring/GlobalDim/Level")
225         widget.dimLevel.setValue(self.dimLevelInterface.getvalue())
226         self.connect(widget.dimLevel, QtCore.SIGNAL("valueChanged(int)"), self.dimLevelChanged)
227         self.volumeInterface = DiscreteControl(self.hw, self.hw.basepath+"/EAP/Monitoring/GlobalVolume/Level")
228         widget.volumeKnob.setValue(self.volumeInterface.getvalue())
229         self.connect(widget.volumeKnob, QtCore.SIGNAL("valueChanged(int)"), self.volumeChanged)
230
231         if self.configrom.getModelName() == "SAFFIRE_PRO_24" or self.configrom.getModelName() == "SAFFIRE_PRO_24DSP":
232             widget.stacked.setCurrentWidget(widget.pagePro24)
233             self.ch1inst = BooleanControl(self.hw, self.hw.basepath + "/EAP/Ch1LineInst")
234             widget.chkInst1.setChecked(self.ch1inst.selected())
235             self.connect(widget.chkInst1, QtCore.SIGNAL("toggled(bool)"), self.ch1inst.select)
236             self.ch2inst = BooleanControl(self.hw, self.hw.basepath + "/EAP/Ch2LineInst")
237             widget.chkInst2.setChecked(self.ch2inst.selected())
238             self.connect(widget.chkInst2, QtCore.SIGNAL("toggled(bool)"), self.ch2inst.select)
239             self.ch3level = BooleanControl(self.hw, self.hw.basepath + "/EAP/Ch3Level")
240             widget.chkLevel3.setChecked(self.ch3level.selected())
241             self.connect(widget.chkLevel3, QtCore.SIGNAL("toggled(bool)"), self.ch3level.select)
242             self.ch4level = BooleanControl(self.hw, self.hw.basepath + "/EAP/Ch4Level")
243             widget.chkLevel4.setChecked(self.ch4level.selected())
244             self.connect(widget.chkLevel4, QtCore.SIGNAL("toggled(bool)"), self.ch4level.select)
245             #widget.chkSpdif.deleteLater()
246             #widget.btnPad.deleteLater()
247         elif self.configrom.getModelName() == "SAFFIRE_PRO_40":
248             widget.stacked.setCurrentWidget(widget.pagePro40)
249             #widget.chkInst1.deleteLater()
250             #widget.chkInst2.deleteLater()
251             #widget.chkLevel3.deleteLater()
252             #widget.chkLevel4.deleteLater()
253         else:
254             self.stacked.deleteLater()
255
256
257     def muteToggle(self, mute):
258         self.muteInterface.select(mute)
259     def dimToggle(self, mute):
260         self.dimInterface.select(mute)
261
262     def dimLevelChanged(self, value):
263         self.dimLevelInterface.setvalue(value)
264     def volumeChanged(self, value):
265         self.volumeInterface.setvalue(value)
266
267     def getDisplayTitle(self):
268         return "Saffire PRO40/PRO24 Mixer"
269
270 #
271 # vim: et ts=4 sw=4
Note: See TracBrowser for help on using the browser.