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

Revision 2037, 13.5 kB (checked in by jwoithe, 9 years ago)

rme: make clock mode control active. Note that this isn't overly useful without the other clock-related controls and indicators being active. They will follow soon.

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) == 0) {
97                 m_value = v;
98             }
99             break;
100         case RME_CTRL_OUTPUT_LEVEL:
101             if (m_parent.setOutputLevel(v) == 0) {
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) == 0) {
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) == 0) {
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) == 0) {
144                 m_value = v;
145             }
146             break;
147
148         case RME_CTRL_CLOCK_MODE:
149             if (m_parent.setClockMode(v==1?FF_SWPARAM_CLOCK_MODE_AUTOSYNC:FF_SWPARAM_CLOCK_MODE_MASTER) == 0) {
150                 m_value = v;
151             }
152             break;
153
154         // All RME_CTRL_INFO_* controls are read-only.  Warn on attempts to
155         // set these.
156         case RME_CTRL_INFO_MODEL:
157         case RME_CTRL_INFO_TCO_PRESENT:
158             debugOutput(DEBUG_LEVEL_ERROR, "Attempt to set readonly info control 0x%08x\n", m_type);
159             err = 1;
160             break;
161
162         default:
163             debugOutput(DEBUG_LEVEL_ERROR, "Unknown control type 0x%08x\n", m_type);
164             err = 1;
165     }
166
167     return err==0?true:false;
168 }
169
170 int
171 RmeSettingsCtrl::getValue() {
172
173 signed int i;
174 signed int val = 0;
175
176     switch (m_type) {
177         case RME_CTRL_NONE:
178             debugOutput(DEBUG_LEVEL_ERROR, "control has no type set\n");
179             break;
180
181         case RME_CTRL_PHANTOM_SW:
182             for (i=0; i<3; i++)
183                 val |= (m_parent.getPhantom(i) << i);
184             return val;
185             break;
186         case RME_CTRL_INPUT_LEVEL:
187             return m_parent.getInputLevel();
188             break;
189         case RME_CTRL_OUTPUT_LEVEL:
190             return m_parent.getOutputLevel();
191             break;
192         case RME_CTRL_FF400_PAD_SW:
193             return m_parent.getInputPadOpt(m_info);
194             break;
195         case RME_CTRL_FF400_INSTR_SW:
196             return m_parent.getInputInstrOpt(m_info);
197             break;
198         case RME_CTRL_SPDIF_INPUT_MODE:
199             i = m_parent.getSpdifInputMode();
200             return i==FF_SWPARAM_SPDIF_INPUT_COAX?0:1;
201             break;
202         case RME_CTRL_SPDIF_OUTPUT_OPTICAL:
203             return m_parent.getSpdifOutputIsOptical();
204             break;
205         case RME_CTRL_SPDIF_OUTPUT_PRO:
206             return m_parent.getSpdifOutputProOn();
207             break;
208         case RME_CTRL_SPDIF_OUTPUT_EMPHASIS:
209             return m_parent.getSpdifOutputEmphasisOn();
210             break;
211         case RME_CTRL_SPDIF_OUTPUT_NONAUDIO:
212             return m_parent.getSpdifOutputNonAudioOn();
213             break;
214         case RME_CTRL_PHONES_LEVEL:
215             return m_parent.getPhonesLevel();
216             break;
217         case RME_CTRL_CLOCK_MODE:
218             return m_parent.getClockMode()==FF_SWPARAM_CLOCK_MODE_AUTOSYNC?1:0;
219             break;
220
221         case RME_CTRL_INFO_MODEL:
222             return m_parent.getRmeModel();
223             break;
224
225         case RME_CTRL_INFO_TCO_PRESENT:
226             return m_parent.getTcoPresent();
227
228         default:
229             debugOutput(DEBUG_LEVEL_ERROR, "Unknown control type 0x%08x\n", m_type);
230     }
231
232     return 0;
233 }
234
235
236 static std::string getOutputName(const signed int model, const int idx)
237 {
238     char buf[64];
239     if (model == RME_MODEL_FIREFACE400) {
240         if (idx >= 10)
241             snprintf(buf, sizeof(buf), "ADAT out %d", idx-9);
242         else
243         if (idx >= 8)
244             snprintf(buf, sizeof(buf), "SPDIF out %d", idx-7);
245         else
246         if (idx >= 6)
247             snprintf(buf, sizeof(buf), "Mon out %d", idx+1);
248         else
249             snprintf(buf, sizeof(buf), "Line out %d", idx+1);
250     } else {
251         snprintf(buf, sizeof(buf), "out %d", idx);
252     }
253     return buf;
254 }
255
256 static std::string getInputName(const signed int model, const int idx)
257 {
258     char buf[64];
259     if (model == RME_MODEL_FIREFACE400) {
260         if (idx >= 10)
261             snprintf(buf, sizeof(buf), "ADAT in %d", idx-9);
262         else
263         if (idx >= 8)
264             snprintf(buf, sizeof(buf), "SPDIF in %d", idx-7);
265         else
266         if (idx >= 4)
267             snprintf(buf, sizeof(buf), "Line in %d", idx+1);
268         else
269         if (idx >= 2)
270             snprintf(buf, sizeof(buf), "Inst/line %d", idx+1);
271         else
272             snprintf(buf, sizeof(buf), "Mic/line %d", idx+1);
273     } else {
274         snprintf(buf, sizeof(buf), "in %d", idx);
275     }
276     return buf;
277 }
278
279 RmeSettingsMatrixCtrl::RmeSettingsMatrixCtrl(Device &parent, unsigned int type)
280 : Control::MatrixMixer(&parent)
281 , m_parent(parent)
282 , m_type(type)
283 {
284 }
285
286 RmeSettingsMatrixCtrl::RmeSettingsMatrixCtrl(Device &parent, unsigned int type,
287     std::string name)
288 : Control::MatrixMixer(&parent)
289 , m_parent(parent)
290 , m_type(type)
291 {
292     setName(name);
293 }
294
295 void RmeSettingsMatrixCtrl::show()
296 {
297     debugOutput(DEBUG_LEVEL_NORMAL, "RME matrix mixer type %d\n", m_type);
298 }
299
300 std::string RmeSettingsMatrixCtrl::getRowName(const int row)
301 {
302     if (m_type == RME_MATRIXCTRL_OUTPUT_FADER)
303         return "";
304     return getOutputName(m_parent.getRmeModel(), row);
305 }
306
307 std::string RmeSettingsMatrixCtrl::getColName(const int col)
308 {
309     if (m_type == RME_MATRIXCTRL_PLAYBACK_FADER)
310         return "";
311     if (m_type == RME_MATRIXCTRL_OUTPUT_FADER)
312         return getOutputName(m_parent.getRmeModel(), col);
313
314     return getInputName(m_parent.getRmeModel(), col);
315 }
316
317 int RmeSettingsMatrixCtrl::getRowCount()
318 {
319     switch (m_type) {
320         case RME_MATRIXCTRL_GAINS:
321             if (m_parent.getRmeModel() == RME_MODEL_FIREFACE400)
322                 return 1;
323             break;
324         case RME_MATRIXCTRL_INPUT_FADER:
325         case RME_MATRIXCTRL_PLAYBACK_FADER:
326             if (m_parent.getRmeModel() == RME_MODEL_FIREFACE400)
327                 return RME_FF400_MAX_CHANNELS;
328             else
329                 return RME_FF800_MAX_CHANNELS;
330             break;
331         case RME_MATRIXCTRL_OUTPUT_FADER:
332             return 1;
333             break;
334     }
335
336     return 0;
337 }
338
339 int RmeSettingsMatrixCtrl::getColCount()
340 {
341     switch (m_type) {
342         case RME_MATRIXCTRL_GAINS:
343             if (m_parent.getRmeModel() == RME_MODEL_FIREFACE400)
344                 return 22;
345             break;
346         case RME_MATRIXCTRL_INPUT_FADER:
347         case RME_MATRIXCTRL_PLAYBACK_FADER:
348         case RME_MATRIXCTRL_OUTPUT_FADER:
349             if (m_parent.getRmeModel() == RME_MODEL_FIREFACE400)
350                 return RME_FF400_MAX_CHANNELS;
351             else
352                 return RME_FF800_MAX_CHANNELS;
353             break;
354     }
355
356     return 0;
357 }
358
359 double RmeSettingsMatrixCtrl::setValue(const int row, const int col, const double val)
360 {
361     signed int ret = true;
362     signed int i;
363
364     switch (m_type) {
365         case RME_MATRIXCTRL_GAINS:
366             i = val;
367             if (i >= 0)
368                 ret = m_parent.setAmpGain(col, val);
369             else
370                 ret = -1;
371             break;
372         case RME_MATRIXCTRL_INPUT_FADER:
373           return m_parent.setMixerGain(RME_FF_MM_INPUT, col, row, val);
374           break;
375         case RME_MATRIXCTRL_PLAYBACK_FADER:
376           return m_parent.setMixerGain(RME_FF_MM_PLAYBACK, col, row, val);
377           break;
378         case RME_MATRIXCTRL_OUTPUT_FADER:
379           return m_parent.setMixerGain(RME_FF_MM_OUTPUT, col, row, val);
380           break;
381
382         case RME_MATRIXCTRL_INPUT_MUTE:
383           return m_parent.setMixerFlags(RME_FF_MM_INPUT, col, row, FF_SWPARAM_MF_MUTED, val!=0);
384           break;
385         case RME_MATRIXCTRL_PLAYBACK_MUTE:
386           return m_parent.setMixerFlags(RME_FF_MM_PLAYBACK, col, row, FF_SWPARAM_MF_MUTED, val!=0);
387           break;
388         case RME_MATRIXCTRL_OUTPUT_MUTE:
389           return m_parent.setMixerFlags(RME_FF_MM_OUTPUT, col, row, FF_SWPARAM_MF_MUTED, val!=0);
390           break;
391         case RME_MATRIXCTRL_INPUT_INVERT:
392           return m_parent.setMixerFlags(RME_FF_MM_INPUT, col, row, FF_SWPARAM_MF_INVERTED, val!=0);
393           break;
394         case RME_MATRIXCTRL_PLAYBACK_INVERT:
395           return m_parent.setMixerFlags(RME_FF_MM_PLAYBACK, col, row, FF_SWPARAM_MF_INVERTED, val!=0);
396           break;
397
398     }
399
400     return ret;
401 }
402
403 double RmeSettingsMatrixCtrl::getValue(const int row, const int col)
404 {
405     double val = 0.0;
406     switch (m_type) {
407         case RME_MATRIXCTRL_GAINS:
408             val = m_parent.getAmpGain(col);
409             break;
410         case RME_MATRIXCTRL_INPUT_FADER:
411             val = m_parent.getMixerGain(RME_FF_MM_INPUT, col, row);
412             break;
413         case RME_MATRIXCTRL_PLAYBACK_FADER:
414             val = m_parent.getMixerGain(RME_FF_MM_PLAYBACK, col, row);
415             break;
416         case RME_MATRIXCTRL_OUTPUT_FADER:
417             val = m_parent.getMixerGain(RME_FF_MM_OUTPUT, col, row);
418             break;
419
420         case RME_MATRIXCTRL_INPUT_MUTE:
421           return m_parent.getMixerFlags(RME_FF_MM_INPUT, col, row, FF_SWPARAM_MF_MUTED) != 0;
422           break;
423         case RME_MATRIXCTRL_PLAYBACK_MUTE:
424           return m_parent.getMixerFlags(RME_FF_MM_PLAYBACK, col, row, FF_SWPARAM_MF_MUTED) != 0;
425           break;
426         case RME_MATRIXCTRL_OUTPUT_MUTE:
427           return m_parent.getMixerFlags(RME_FF_MM_OUTPUT, col, row, FF_SWPARAM_MF_MUTED) != 0;
428           break;
429         case RME_MATRIXCTRL_INPUT_INVERT:
430           return m_parent.getMixerFlags(RME_FF_MM_INPUT, col, row, FF_SWPARAM_MF_INVERTED) != 0;
431           break;
432         case RME_MATRIXCTRL_PLAYBACK_INVERT:
433           return m_parent.getMixerFlags(RME_FF_MM_PLAYBACK, col, row, FF_SWPARAM_MF_INVERTED) != 0;
434           break;
435     }
436
437     return val;
438 }
439      
440
441 }
Note: See TracBrowser for help on using the browser.