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

Revision 2011, 10.1 kB (checked in by jwoithe, 9 years ago)

rme: implement the output fader controls in ffado-mixer. There's still some work to do on sizing and labelling but the basic fader functionality is there.

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_PHONES_LEVEL:
118             if (m_parent.setPhonesLevel(v)) {
119                 m_value = v;
120             }
121             break;
122
123         // All RME_CTRL_INFO_* controls are read-only.  Warn on attempts to
124         // set these.
125         case RME_CTRL_INFO_MODEL:
126         case RME_CTRL_INFO_TCO_PRESENT:
127             debugOutput(DEBUG_LEVEL_ERROR, "Attempt to set readonly info control 0x%08x\n", m_type);
128             err = 1;
129             break;
130
131         default:
132             debugOutput(DEBUG_LEVEL_ERROR, "Unknown control type 0x%08x\n", m_type);
133             err = 1;
134     }
135
136     return err==0?true:false;
137 }
138
139 int
140 RmeSettingsCtrl::getValue() {
141
142 signed int i;
143 signed int val = 0;
144
145     switch (m_type) {
146         case RME_CTRL_NONE:
147             debugOutput(DEBUG_LEVEL_ERROR, "control has no type set\n");
148             break;
149
150         case RME_CTRL_PHANTOM_SW:
151             for (i=0; i<3; i++)
152                 val |= (m_parent.getPhantom(i) << i);
153             return val;
154             break;
155         case RME_CTRL_INPUT_LEVEL:
156             return m_parent.getInputLevel();
157             break;
158         case RME_CTRL_OUTPUT_LEVEL:
159             return m_parent.getOutputLevel();
160             break;
161         case RME_CTRL_FF400_PAD_SW:
162             return m_parent.getInputPadOpt(m_info);
163             break;
164         case RME_CTRL_FF400_INSTR_SW:
165             return m_parent.getInputInstrOpt(m_info);
166             break;
167         case RME_CTRL_PHONES_LEVEL:
168             return m_parent.getPhonesLevel();
169             break;
170
171         case RME_CTRL_INFO_MODEL:
172             return m_parent.getRmeModel();
173             break;
174
175         case RME_CTRL_INFO_TCO_PRESENT:
176             return m_parent.getTcoPresent();
177
178         default:
179             debugOutput(DEBUG_LEVEL_ERROR, "Unknown control type 0x%08x\n", m_type);
180     }
181
182     return 0;
183 }
184
185
186 static std::string getOutputName(const signed int model, const int idx)
187 {
188     char buf[64];
189     if (model == RME_MODEL_FIREFACE400) {
190         if (idx >= 10)
191             snprintf(buf, sizeof(buf), "ADAT out %d", idx-9);
192         else
193         if (idx >= 8)
194             snprintf(buf, sizeof(buf), "SPDIF out %d", idx-7);
195         else
196         if (idx >= 6)
197             snprintf(buf, sizeof(buf), "Mon out %d", idx+1);
198         else
199             snprintf(buf, sizeof(buf), "Line out %d", idx+1);
200     } else {
201         snprintf(buf, sizeof(buf), "out %d", idx);
202     }
203     return buf;
204 }
205
206 static std::string getInputName(const signed int model, const int idx)
207 {
208     char buf[64];
209     if (model == RME_MODEL_FIREFACE400) {
210         if (idx >= 10)
211             snprintf(buf, sizeof(buf), "ADAT in %d", idx-9);
212         else
213         if (idx >= 8)
214             snprintf(buf, sizeof(buf), "SPDIF in %d", idx-7);
215         else
216         if (idx >= 4)
217             snprintf(buf, sizeof(buf), "Line in %d", idx+1);
218         else
219         if (idx >= 2)
220             snprintf(buf, sizeof(buf), "Inst/line %d", idx+1);
221         else
222             snprintf(buf, sizeof(buf), "Mic/line %d", idx+1);
223     } else {
224         snprintf(buf, sizeof(buf), "in %d", idx);
225     }
226     return buf;
227 }
228
229 RmeSettingsMatrixCtrl::RmeSettingsMatrixCtrl(Device &parent, unsigned int type)
230 : Control::MatrixMixer(&parent)
231 , m_parent(parent)
232 , m_type(type)
233 {
234 }
235
236 RmeSettingsMatrixCtrl::RmeSettingsMatrixCtrl(Device &parent, unsigned int type,
237     std::string name)
238 : Control::MatrixMixer(&parent)
239 , m_parent(parent)
240 , m_type(type)
241 {
242     setName(name);
243 }
244
245 void RmeSettingsMatrixCtrl::show()
246 {
247     debugOutput(DEBUG_LEVEL_NORMAL, "RME matrix mixer type %d\n", m_type);
248 }
249
250 std::string RmeSettingsMatrixCtrl::getRowName(const int row)
251 {
252     if (m_type == RME_MATRIXCTRL_OUTPUT_FADER)
253         return "";
254     return getOutputName(m_parent.getRmeModel(), row);
255 }
256
257 std::string RmeSettingsMatrixCtrl::getColName(const int col)
258 {
259     if (m_type == RME_MATRIXCTRL_PLAYBACK_FADER)
260         return "";
261     if (m_type == RME_MATRIXCTRL_OUTPUT_FADER)
262         return getOutputName(m_parent.getRmeModel(), col);
263
264     return getInputName(m_parent.getRmeModel(), col);
265 }
266
267 int RmeSettingsMatrixCtrl::getRowCount()
268 {
269     switch (m_type) {
270         case RME_MATRIXCTRL_GAINS:
271             if (m_parent.getRmeModel() == RME_MODEL_FIREFACE400)
272                 return 1;
273             break;
274         case RME_MATRIXCTRL_INPUT_FADER:
275         case RME_MATRIXCTRL_PLAYBACK_FADER:
276             if (m_parent.getRmeModel() == RME_MODEL_FIREFACE400)
277                 return RME_FF400_MAX_CHANNELS;
278             else
279                 return RME_FF800_MAX_CHANNELS;
280             break;
281         case RME_MATRIXCTRL_OUTPUT_FADER:
282             return 1;
283             break;
284     }
285
286     return 0;
287 }
288
289 int RmeSettingsMatrixCtrl::getColCount()
290 {
291     switch (m_type) {
292         case RME_MATRIXCTRL_GAINS:
293             if (m_parent.getRmeModel() == RME_MODEL_FIREFACE400)
294                 return 22;
295             break;
296         case RME_MATRIXCTRL_INPUT_FADER:
297         case RME_MATRIXCTRL_PLAYBACK_FADER:
298         case RME_MATRIXCTRL_OUTPUT_FADER:
299             if (m_parent.getRmeModel() == RME_MODEL_FIREFACE400)
300                 return RME_FF400_MAX_CHANNELS;
301             else
302                 return RME_FF800_MAX_CHANNELS;
303             break;
304     }
305
306     return 0;
307 }
308
309 double RmeSettingsMatrixCtrl::setValue(const int row, const int col, const double val)
310 {
311     signed int ret = true;
312     signed int i;
313
314     switch (m_type) {
315         case RME_MATRIXCTRL_GAINS:
316             i = val;
317             if (i >= 0)
318                 ret = m_parent.setAmpGain(col, val);
319             else
320                 ret = -1;
321             break;
322         case RME_MATRIXCTRL_INPUT_FADER:
323           return m_parent.setMixerGain(RME_FF_MM_INPUT, col, row, val);
324           break;
325         case RME_MATRIXCTRL_PLAYBACK_FADER:
326           return m_parent.setMixerGain(RME_FF_MM_PLAYBACK, col, row, val);
327           break;
328         case RME_MATRIXCTRL_OUTPUT_FADER:
329           return m_parent.setMixerGain(RME_FF_MM_OUTPUT, col, row, val);
330           break;
331     }
332
333     return ret;
334 }
335
336 double RmeSettingsMatrixCtrl::getValue(const int row, const int col)
337 {
338     double val = 0.0;
339     switch (m_type) {
340         case RME_MATRIXCTRL_GAINS:
341             val = m_parent.getAmpGain(col);
342             break;
343         case RME_MATRIXCTRL_INPUT_FADER:
344             val = m_parent.getMixerGain(RME_FF_MM_INPUT, col, row);
345             break;
346         case RME_MATRIXCTRL_PLAYBACK_FADER:
347             val = m_parent.getMixerGain(RME_FF_MM_PLAYBACK, col, row);
348             break;
349         case RME_MATRIXCTRL_OUTPUT_FADER:
350             val = m_parent.getMixerGain(RME_FF_MM_OUTPUT, col, row);
351             break;
352     }
353
354     return val;
355 }
356      
357
358 }
Note: See TracBrowser for help on using the browser.