root/trunk/libffado/src/rme/fireface_settings_ctrls.cpp

Revision 2033, 13.1 kB (checked in by jwoithe, 9 years ago)

rme: implement SPDIF output option control via ffado-mixer. Again, I haven't the means to confirm whether these settings have the desired effect on the SPDIF bitstream yet.

Line 
1 /*
2  * Copyright (C) 2005-2008 by Pieter Palmers
3  * Copyright (C) 2008-2009 by Jonathan Woithe
4  *
5  * This file is part of FFADO
6  * FFADO = Free Firewire (pro-)audio drivers for linux
7  *
8  * FFADO is based upon FreeBoB.
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 2 of the License, or
13  * (at your option) version 3 of the License.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  */
24 #include <math.h>
25
26 #include "rme/rme_avdevice.h"
27 #include "rme/fireface_settings_ctrls.h"
28
29 namespace Rme {
30
31 RmeSettingsCtrl::RmeSettingsCtrl(Device &parent, unsigned int type,
32     unsigned int info)
33 : Control::Discrete(&parent)
34 , m_parent(parent)
35 , m_type(type)
36 , m_value(0)
37 , m_info(info)
38 {
39 }
40
41 RmeSettingsCtrl::RmeSettingsCtrl(Device &parent, unsigned int type,
42     unsigned int info,
43     std::string name, std::string label, std::string descr)
44 : Control::Discrete(&parent)
45 , m_parent(parent)
46 , m_type(type)
47 , m_value(0)
48 , m_info(info)
49 {
50     setName(name);
51     setLabel(label);
52     setDescription(descr);
53 }
54
55 bool
56 RmeSettingsCtrl::setValue(int v) {
57
58 signed int i;
59 signed int err = 0;
60
61     switch (m_type) {
62         case RME_CTRL_NONE:
63             debugOutput(DEBUG_LEVEL_ERROR, "control has no type set\n");
64             err = 1;
65             break;
66         case RME_CTRL_PHANTOM_SW:
67             // Lowest 16 bits are phantom status bits (max 16 channels).
68             // High 16 bits are "write enable" bits for the corresponding
69             // channel represented in the low 16 bits.  This way changes can
70             // be made to one channel without needing to first read the
71             // existing value.
72             //
73             // At present there are at most 4 phantom-capable channels.
74             // Flag attempts to write to the bits corresponding to channels
75             // beyond this.
76             if (v & 0xfff00000) {
77                 debugOutput(DEBUG_LEVEL_WARNING, "Ignored out-of-range phantom set request: mask=0x%04x, value=0x%04x\n",
78                   (v >> 16) & 0xfff0, v && 0xfff0);
79             }
80
81             for (i=0; i<4; i++) {
82                 if (v & (0x00010000 << i)) {
83                     unsigned int on = (v & (0x00000001 << i)) != 0;
84                     err = m_parent.setPhantom(i, on);
85                     if (!err) {
86                         if (on) {
87                             m_value |= (0x01 << i);
88                         } else {
89                             m_value &= ~(0x01 << i);
90                         }
91                     }
92                 }
93             }
94             break;
95         case RME_CTRL_INPUT_LEVEL:
96             if (m_parent.setInputLevel(v)) {
97                 m_value = v;
98             }
99             break;
100         case RME_CTRL_OUTPUT_LEVEL:
101             if (m_parent.setOutputLevel(v)) {
102                 m_value = v;
103             }
104             break;
105         case RME_CTRL_FF400_PAD_SW:
106             // Object's "m_info" field is the channel
107             if (m_parent.setInputPadOpt(m_info, v)) {
108                 m_value = (v != 0);
109             }
110             break;
111         case RME_CTRL_FF400_INSTR_SW:
112             // Object's "m_info" field is the channel
113             if (m_parent.setInputInstrOpt(m_info, v)) {
114                 m_value = (v != 0);
115             }
116             break;
117         case RME_CTRL_SPDIF_INPUT_MODE:
118             if (m_parent.setSpdifInputMode(v==0?FF_SWPARAM_SPDIF_INPUT_COAX:FF_SWPARAM_SPDIF_INPUT_OPTICAL)) {
119                 m_value = v;
120             }
121             break;
122         case RME_CTRL_SPDIF_OUTPUT_OPTICAL:
123             if (m_parent.setSpdifOutputIsOptical(v!=0) == 0) {
124                m_value = (v != 0);
125             }
126             break;
127         case RME_CTRL_SPDIF_OUTPUT_PRO:
128             if (m_parent.setSpdifOutputProOn(v!=0) == 0) {
129                m_value = (v != 0);
130             }
131             break;
132         case RME_CTRL_SPDIF_OUTPUT_EMPHASIS:
133             if (m_parent.setSpdifOutputEmphasisOn(v!=0) == 0) {
134                m_value = (v != 0);
135             }
136             break;
137         case RME_CTRL_SPDIF_OUTPUT_NONAUDIO:
138             if (m_parent.setSpdifOutputNonAudioOn(v!=0) == 0) {
139                m_value = (v != 0);
140             }
141             break;
142         case RME_CTRL_PHONES_LEVEL:
143             if (m_parent.setPhonesLevel(v)) {
144                 m_value = v;
145             }
146             break;
147
148         // All RME_CTRL_INFO_* controls are read-only.  Warn on attempts to
149         // set these.
150         case RME_CTRL_INFO_MODEL:
151         case RME_CTRL_INFO_TCO_PRESENT:
152             debugOutput(DEBUG_LEVEL_ERROR, "Attempt to set readonly info control 0x%08x\n", m_type);
153             err = 1;
154             break;
155
156         default:
157             debugOutput(DEBUG_LEVEL_ERROR, "Unknown control type 0x%08x\n", m_type);
158             err = 1;
159     }
160
161     return err==0?true:false;
162 }
163
164 int
165 RmeSettingsCtrl::getValue() {
166
167 signed int i;
168 signed int val = 0;
169
170     switch (m_type) {
171         case RME_CTRL_NONE:
172             debugOutput(DEBUG_LEVEL_ERROR, "control has no type set\n");
173             break;
174
175         case RME_CTRL_PHANTOM_SW:
176             for (i=0; i<3; i++)
177                 val |= (m_parent.getPhantom(i) << i);
178             return val;
179             break;
180         case RME_CTRL_INPUT_LEVEL:
181             return m_parent.getInputLevel();
182             break;
183         case RME_CTRL_OUTPUT_LEVEL:
184             return m_parent.getOutputLevel();
185             break;
186         case RME_CTRL_FF400_PAD_SW:
187             return m_parent.getInputPadOpt(m_info);
188             break;
189         case RME_CTRL_FF400_INSTR_SW:
190             return m_parent.getInputInstrOpt(m_info);
191             break;
192         case RME_CTRL_SPDIF_INPUT_MODE:
193             i = m_parent.getSpdifInputMode();
194             return i==FF_SWPARAM_SPDIF_INPUT_COAX?0:1;
195             break;
196         case RME_CTRL_SPDIF_OUTPUT_OPTICAL:
197             return m_parent.getSpdifOutputIsOptical();
198             break;
199         case RME_CTRL_SPDIF_OUTPUT_PRO:
200             return m_parent.getSpdifOutputProOn();
201             break;
202         case RME_CTRL_SPDIF_OUTPUT_EMPHASIS:
203             return m_parent.getSpdifOutputEmphasisOn();
204             break;
205         case RME_CTRL_SPDIF_OUTPUT_NONAUDIO:
206             return m_parent.getSpdifOutputNonAudioOn();
207             break;
208         case RME_CTRL_PHONES_LEVEL:
209             return m_parent.getPhonesLevel();
210             break;
211
212         case RME_CTRL_INFO_MODEL:
213             return m_parent.getRmeModel();
214             break;
215
216         case RME_CTRL_INFO_TCO_PRESENT:
217             return m_parent.getTcoPresent();
218
219         default:
220             debugOutput(DEBUG_LEVEL_ERROR, "Unknown control type 0x%08x\n", m_type);
221     }
222
223     return 0;
224 }
225
226
227 static std::string getOutputName(const signed int model, const int idx)
228 {
229     char buf[64];
230     if (model == RME_MODEL_FIREFACE400) {
231         if (idx >= 10)
232             snprintf(buf, sizeof(buf), "ADAT out %d", idx-9);
233         else
234         if (idx >= 8)
235             snprintf(buf, sizeof(buf), "SPDIF out %d", idx-7);
236         else
237         if (idx >= 6)
238             snprintf(buf, sizeof(buf), "Mon out %d", idx+1);
239         else
240             snprintf(buf, sizeof(buf), "Line out %d", idx+1);
241     } else {
242         snprintf(buf, sizeof(buf), "out %d", idx);
243     }
244     return buf;
245 }
246
247 static std::string getInputName(const signed int model, const int idx)
248 {
249     char buf[64];
250     if (model == RME_MODEL_FIREFACE400) {
251         if (idx >= 10)
252             snprintf(buf, sizeof(buf), "ADAT in %d", idx-9);
253         else
254         if (idx >= 8)
255             snprintf(buf, sizeof(buf), "SPDIF in %d", idx-7);
256         else
257         if (idx >= 4)
258             snprintf(buf, sizeof(buf), "Line in %d", idx+1);
259         else
260         if (idx >= 2)
261             snprintf(buf, sizeof(buf), "Inst/line %d", idx+1);
262         else
263             snprintf(buf, sizeof(buf), "Mic/line %d", idx+1);
264     } else {
265         snprintf(buf, sizeof(buf), "in %d", idx);
266     }
267     return buf;
268 }
269
270 RmeSettingsMatrixCtrl::RmeSettingsMatrixCtrl(Device &parent, unsigned int type)
271 : Control::MatrixMixer(&parent)
272 , m_parent(parent)
273 , m_type(type)
274 {
275 }
276
277 RmeSettingsMatrixCtrl::RmeSettingsMatrixCtrl(Device &parent, unsigned int type,
278     std::string name)
279 : Control::MatrixMixer(&parent)
280 , m_parent(parent)
281 , m_type(type)
282 {
283     setName(name);
284 }
285
286 void RmeSettingsMatrixCtrl::show()
287 {
288     debugOutput(DEBUG_LEVEL_NORMAL, "RME matrix mixer type %d\n", m_type);
289 }
290
291 std::string RmeSettingsMatrixCtrl::getRowName(const int row)
292 {
293     if (m_type == RME_MATRIXCTRL_OUTPUT_FADER)
294         return "";
295     return getOutputName(m_parent.getRmeModel(), row);
296 }
297
298 std::string RmeSettingsMatrixCtrl::getColName(const int col)
299 {
300     if (m_type == RME_MATRIXCTRL_PLAYBACK_FADER)
301         return "";
302     if (m_type == RME_MATRIXCTRL_OUTPUT_FADER)
303         return getOutputName(m_parent.getRmeModel(), col);
304
305     return getInputName(m_parent.getRmeModel(), col);
306 }
307
308 int RmeSettingsMatrixCtrl::getRowCount()
309 {
310     switch (m_type) {
311         case RME_MATRIXCTRL_GAINS:
312             if (m_parent.getRmeModel() == RME_MODEL_FIREFACE400)
313                 return 1;
314             break;
315         case RME_MATRIXCTRL_INPUT_FADER:
316         case RME_MATRIXCTRL_PLAYBACK_FADER:
317             if (m_parent.getRmeModel() == RME_MODEL_FIREFACE400)
318                 return RME_FF400_MAX_CHANNELS;
319             else
320                 return RME_FF800_MAX_CHANNELS;
321             break;
322         case RME_MATRIXCTRL_OUTPUT_FADER:
323             return 1;
324             break;
325     }
326
327     return 0;
328 }
329
330 int RmeSettingsMatrixCtrl::getColCount()
331 {
332     switch (m_type) {
333         case RME_MATRIXCTRL_GAINS:
334             if (m_parent.getRmeModel() == RME_MODEL_FIREFACE400)
335                 return 22;
336             break;
337         case RME_MATRIXCTRL_INPUT_FADER:
338         case RME_MATRIXCTRL_PLAYBACK_FADER:
339         case RME_MATRIXCTRL_OUTPUT_FADER:
340             if (m_parent.getRmeModel() == RME_MODEL_FIREFACE400)
341                 return RME_FF400_MAX_CHANNELS;
342             else
343                 return RME_FF800_MAX_CHANNELS;
344             break;
345     }
346
347     return 0;
348 }
349
350 double RmeSettingsMatrixCtrl::setValue(const int row, const int col, const double val)
351 {
352     signed int ret = true;
353     signed int i;
354
355     switch (m_type) {
356         case RME_MATRIXCTRL_GAINS:
357             i = val;
358             if (i >= 0)
359                 ret = m_parent.setAmpGain(col, val);
360             else
361                 ret = -1;
362             break;
363         case RME_MATRIXCTRL_INPUT_FADER:
364           return m_parent.setMixerGain(RME_FF_MM_INPUT, col, row, val);
365           break;
366         case RME_MATRIXCTRL_PLAYBACK_FADER:
367           return m_parent.setMixerGain(RME_FF_MM_PLAYBACK, col, row, val);
368           break;
369         case RME_MATRIXCTRL_OUTPUT_FADER:
370           return m_parent.setMixerGain(RME_FF_MM_OUTPUT, col, row, val);
371           break;
372
373         case RME_MATRIXCTRL_INPUT_MUTE:
374           return m_parent.setMixerFlags(RME_FF_MM_INPUT, col, row, FF_SWPARAM_MF_MUTED, val!=0);
375           break;
376         case RME_MATRIXCTRL_PLAYBACK_MUTE:
377           return m_parent.setMixerFlags(RME_FF_MM_PLAYBACK, col, row, FF_SWPARAM_MF_MUTED, val!=0);
378           break;
379         case RME_MATRIXCTRL_OUTPUT_MUTE:
380           return m_parent.setMixerFlags(RME_FF_MM_OUTPUT, col, row, FF_SWPARAM_MF_MUTED, val!=0);
381           break;
382         case RME_MATRIXCTRL_INPUT_INVERT:
383           return m_parent.setMixerFlags(RME_FF_MM_INPUT, col, row, FF_SWPARAM_MF_INVERTED, val!=0);
384           break;
385         case RME_MATRIXCTRL_PLAYBACK_INVERT:
386           return m_parent.setMixerFlags(RME_FF_MM_PLAYBACK, col, row, FF_SWPARAM_MF_INVERTED, val!=0);
387           break;
388
389     }
390
391     return ret;
392 }
393
394 double RmeSettingsMatrixCtrl::getValue(const int row, const int col)
395 {
396     double val = 0.0;
397     switch (m_type) {
398         case RME_MATRIXCTRL_GAINS:
399             val = m_parent.getAmpGain(col);
400             break;
401         case RME_MATRIXCTRL_INPUT_FADER:
402             val = m_parent.getMixerGain(RME_FF_MM_INPUT, col, row);
403             break;
404         case RME_MATRIXCTRL_PLAYBACK_FADER:
405             val = m_parent.getMixerGain(RME_FF_MM_PLAYBACK, col, row);
406             break;
407         case RME_MATRIXCTRL_OUTPUT_FADER:
408             val = m_parent.getMixerGain(RME_FF_MM_OUTPUT, col, row);
409             break;
410
411         case RME_MATRIXCTRL_INPUT_MUTE:
412           return m_parent.getMixerFlags(RME_FF_MM_INPUT, col, row, FF_SWPARAM_MF_MUTED) != 0;
413           break;
414         case RME_MATRIXCTRL_PLAYBACK_MUTE:
415           return m_parent.getMixerFlags(RME_FF_MM_PLAYBACK, col, row, FF_SWPARAM_MF_MUTED) != 0;
416           break;
417         case RME_MATRIXCTRL_OUTPUT_MUTE:
418           return m_parent.getMixerFlags(RME_FF_MM_OUTPUT, col, row, FF_SWPARAM_MF_MUTED) != 0;
419           break;
420         case RME_MATRIXCTRL_INPUT_INVERT:
421           return m_parent.getMixerFlags(RME_FF_MM_INPUT, col, row, FF_SWPARAM_MF_INVERTED) != 0;
422           break;
423         case RME_MATRIXCTRL_PLAYBACK_INVERT:
424           return m_parent.getMixerFlags(RME_FF_MM_PLAYBACK, col, row, FF_SWPARAM_MF_INVERTED) != 0;
425           break;
426     }
427
428     return val;
429 }
430      
431
432 }
Note: See TracBrowser for help on using the browser.