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

Revision 2032, 9.9 kB (checked in by jwoithe, 9 years ago)

rme: implement SPDIF input mode selection via ffado-mixer. Whether this has the desired effect on the device remains to be seen - I do not have anything to test the mode of the optical port right now.

  • Property svn:mergeinfo set to
Line 
1 #
2 # Copyright (C) 2009, 2011 by Jonathan Woithe
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 import QtGui
24
25 from PyQt4.QtCore import SIGNAL, SLOT, QObject, Qt
26 from PyQt4.QtGui import QWidget, QApplication
27 from ffado.config import *
28
29 from ffado.widgets.matrixmixer import MatrixMixer
30
31 import logging
32 log = logging.getLogger('rme')
33
34 # Model defines.  These must agree with what is used in rme_avdevice.h.
35 RME_MODEL_NONE      = 0x0000
36 RME_MODEL_FF800     = 0x0001
37 RME_MODEL_FF400     = 0x0002
38
39 class Rme(QWidget):
40     def __init__(self,parent = None):
41         QWidget.__init__(self,parent)
42         uicLoad("ffado/mixer/rme", self)
43
44         self.init()
45
46     def init(self):
47
48         self.PhantomSwitches={
49             self.phantom_0: ['/Control/Phantom', 0],
50             self.phantom_1: ['/Control/Phantom', 1],
51             self.phantom_2: ['/Control/Phantom', 2],
52             self.phantom_3: ['/Control/Phantom', 3],
53         }
54
55         self.Switches={
56             self.ff400_chan3_opt_instr: ['/Control/Chan3_opt_instr'],
57             self.ff400_chan3_opt_pad:   ['/Control/Chan3_opt_pad'],
58             self.ff400_chan4_opt_instr: ['/Control/Chan4_opt_instr'],
59             self.ff400_chan4_opt_pad:   ['/Control/Chan4_opt_pad'],
60         }
61
62         self.Radiobuttons={
63             self.level_in_lo_gain: ['/Control/Input_level', 1],
64             self.level_in_p4dBu:   ['/Control/Input_level', 2],
65             self.level_in_m10dBV:  ['/Control/Input_level', 3],
66
67             self.level_out_hi_gain: ['/Control/Output_level', 1],
68             self.level_out_p4dBu:   ['/Control/Output_level', 2],
69             self.level_out_m10dBV:  ['/Control/Output_level', 3],
70
71             self.spdif_input_coax:    ['/Control/SPDIF_input_mode', 0],
72             self.spdif_input_optical: ['/Control/SPDIF_input_mode', 1],
73
74             self.phones_hi_gain: ['/Control/Phones_level', 1],
75             self.phones_p4dBu:   ['/Control/Phones_level', 2],
76             self.phones_m10dBV:  ['/Control/Phones_level', 3],
77         }
78
79
80         self.Gains={
81             self.gain_mic1: ['/Control/Gains', 0],
82             self.gain_mic2: ['/Control/Gains', 1],
83             self.gain_input3: ['/Control/Gains', 2],
84             self.gain_input4: ['/Control/Gains', 3],
85         }
86
87         # Other mixer variables
88         self.is_streaming = 0
89         self.sample_rate = 0
90         self.model = 0
91         self.tco_present = 0
92
93     # Public slot: update phantom power hardware switches
94     def updatePhantomSwitch(self, a0):
95         sender = self.sender()
96         # Value is the phantom switch value, with a corresponding enable
97         # bit in the high 16 bit word
98         val = (a0 << self.PhantomSwitches[sender][1]) | (0x00010000 << self.PhantomSwitches[sender][1])
99         log.debug("phantom switch %d set to %d" % (self.PhantomSwitches[sender][1], a0))
100         self.hw.setDiscrete(self.PhantomSwitches[sender][0], val)
101
102     # Public slot: update generic switches
103     def updateSwitch(self, a0):
104         sender = self.sender()
105         log.debug("switch %s set to %d" % (self.Switches[sender][0], a0))
106         self.hw.setDiscrete(self.Switches[sender][0], a0)
107
108     # Public slot: update generic radiobuttons
109     def updateRadiobutton(self, a0):
110         sender = self.sender()
111         if (a0 != 0):
112             # Only change the control state on a button being "checked"
113             log.debug("radiobutton group %s set to %d" % (self.Radiobuttons[sender][0], self.Radiobuttons[sender][1]))
114             self.hw.setDiscrete(self.Radiobuttons[sender][0], self.Radiobuttons[sender][1])
115
116     # Public slot: update gains
117     def updateGain(self, a0):
118         sender = self.sender()
119         log.debug("gain %s[%d] set to %d" % (self.Gains[sender][0], self.Gains[sender][1], a0))
120         self.hw.setMatrixMixerValue(self.Gains[sender][0], 0, self.Gains[sender][1], a0)
121
122     # Hide and disable a control
123     def disable_hide(self,widget):
124         widget.hide()
125         widget.setEnabled(False)
126
127     def initValues(self):
128
129         # print self.hw.servername
130         # print self.hw.basepath
131         self.inputmatrix = MatrixMixer(self.hw.servername, self.hw.basepath+"/Mixer/InputFaders", self, 0x8000, self.hw.basepath+"/Mixer/InputMutes", self.hw.basepath+"/Mixer/InputInverts")
132         layout = QtGui.QVBoxLayout()
133         scrollarea = QtGui.QScrollArea()
134         scrollarea.setWidgetResizable(True)
135         scrollarea.setWidget(self.inputmatrix)
136         layout.addWidget(scrollarea)
137         self.mixer.setLayout(layout)
138
139         self.playbackmatrix = MatrixMixer(self.hw.servername, self.hw.basepath+"/Mixer/PlaybackFaders", self, 0x8000, self.hw.basepath+"/Mixer/PlaybackMutes", self.hw.basepath+"/Mixer/PlaybackInverts")
140         layout = QtGui.QVBoxLayout()
141         scrollarea = QtGui.QScrollArea()
142         scrollarea.setWidgetResizable(True)
143         scrollarea.setWidget(self.playbackmatrix)
144         layout.addWidget(scrollarea)
145         self.playbackmixer.setLayout(layout)
146
147         self.outputmatrix = MatrixMixer(self.hw.servername, self.hw.basepath+"/Mixer/OutputFaders", self, 0x8000, self.hw.basepath+"/Mixer/OutputMutes")
148         layout = QtGui.QVBoxLayout()
149         scrollarea = QtGui.QScrollArea()
150         scrollarea.setWidgetResizable(True)
151         scrollarea.setWidget(self.outputmatrix)
152         layout.addWidget(scrollarea)
153         self.outputmixer.setLayout(layout)
154
155         # Is the device streaming?
156         #self.is_streaming = self.hw.getDiscrete('/Mixer/Info/IsStreaming')
157         self.is_streaming = 0
158         #log.debug("device streaming flag: %d" % (self.is_streaming))
159
160         # Retrieve other device settings as needed and customise the UI
161         # based on these options.
162         self.model = self.hw.getDiscrete('/Control/Model')
163         log.debug("device model identifier: %d" % (self.model))
164         self.tco_present = self.hw.getDiscrete('/Control/TCO_present')
165         log.debug("device has TCO: %d" % (self.tco_present))
166         #self.sample_rate = self.hw.getDiscrete('/Mixer/Info/SampleRate')
167         #log.debug("device sample rate: %d" % (self.sample_rate))
168
169         # The Fireface-400 only has 2 phantom-capable channels
170         if (self.model == RME_MODEL_FF400):
171             self.disable_hide(self.phantom_2)
172             self.disable_hide(self.phantom_3)
173         else:
174             self.phantom_0.setText("Mic 7")
175             self.phantom_1.setText("Mic 8")
176             self.phantom_2.setText("Mic 9")
177             self.phantom_3.setText("Mic 10")
178
179         # Instrument options, input jack selection controls and an ADAT2
180         # input are applicable only to the FF800
181         if (self.model != RME_MODEL_FF800):
182             self.instrument_options_group.setEnabled(False)
183             self.input_plug_select_group.setEnabled(False)
184             self.sync_ref_adat2.setEnabled(False)
185             self.sync_check_adat2_label.setEnabled(False)
186             self.sync_check_adat2_status.setEnabled(False)
187
188         # Only the FF400 has specific channel 3/4 options, input gain
189         # controls and switchable phones level
190         if (self.model != RME_MODEL_FF400):
191             self.disable_hide(self.input_gains_group)
192             self.disable_hide(self.channel_3_4_options_group)
193             self.phones_level_group.setEnabled(False)
194
195         # Get current hardware values and connect GUI element signals to
196         # their respective slots
197         for ctrl, info in self.PhantomSwitches.iteritems():
198             if (not(ctrl.isEnabled())):
199                 continue
200             val = (self.hw.getDiscrete(info[0]) >> info[1]) & 0x01
201             log.debug("phantom switch %d is %d" % (info[1], val))
202             if val:
203                 ctrl.setChecked(True)
204             else:
205                 ctrl.setChecked(False)
206             QObject.connect(ctrl, SIGNAL('toggled(bool)'), self.updatePhantomSwitch)
207
208         for ctrl, info in self.Switches.iteritems():
209             if (not(ctrl.isEnabled())):
210                 continue
211             val = self.hw.getDiscrete(info[0])
212             log.debug("switch %s is %d" % (info[0], val))
213             if val:
214                 ctrl.setChecked(True)
215             else:
216                 ctrl.setChecked(False)
217             QObject.connect(ctrl, SIGNAL('toggled(bool)'), self.updateSwitch)
218
219         for ctrl, info in self.Radiobuttons.iteritems():
220             if (not(ctrl.isEnabled())):
221                 continue;
222             # This is a touch wasteful since it means we retrieve the control
223             # value once per radio button rather than once per radio button
224             # group.  In time we might introduce radiobutton groupings in the
225             # self.* datastructures to avoid this, but for the moment this is
226             # easy and it works.
227             val = self.hw.getDiscrete(info[0])
228             if (val == info[1]):
229                 val = 1
230             else:
231                 val = 0
232             ctrl.setChecked(val)
233             log.debug("Radiobutton %s[%d] is %d" % (info[0], info[1], val))
234             QObject.connect(ctrl, SIGNAL('toggled(bool)'), self.updateRadiobutton)
235
236         for ctrl, info in self.Gains.iteritems():
237             if (not(ctrl.isEnabled())):
238                 continue
239             val = self.hw.getMatrixMixerValue(info[0], 0, info[1])
240             log.debug("gain %s[%d] is %d" % (info[0], info[1], val))
241             ctrl.setValue(val);
242             QObject.connect(ctrl, SIGNAL('valueChanged(int)'), self.updateGain)
243
244 # vim: et
Note: See TracBrowser for help on using the browser.