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

Revision 1616, 6.6 kB (checked in by jwoithe, 14 years ago)

RME: minor documentation corrections
RME: the Fireface-400 input gain mixer controls now drive the hardware. Control of the output gains is also included in this infrastructure but is not connected to any mixer controls yet - they will be controlled by the mixer proper once that's implemented.

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 "rme/rme_avdevice.h"
25 #include "rme/fireface_settings_ctrls.h"
26
27 namespace Rme {
28
29 RmeSettingsCtrl::RmeSettingsCtrl(Device &parent, unsigned int type,
30     unsigned int info)
31 : Control::Discrete(&parent)
32 , m_parent(parent)
33 , m_type(type)
34 , m_value(0)
35 , m_info(info)
36 {
37 }
38
39 RmeSettingsCtrl::RmeSettingsCtrl(Device &parent, unsigned int type,
40     unsigned int info,
41     std::string name, std::string label, std::string descr)
42 : Control::Discrete(&parent)
43 , m_parent(parent)
44 , m_type(type)
45 , m_value(0)
46 , m_info(info)
47 {
48     setName(name);
49     setLabel(label);
50     setDescription(descr);
51 }
52
53 bool
54 RmeSettingsCtrl::setValue(int v) {
55
56 signed int i;
57 signed int err = 0;
58
59     switch (m_type) {
60         case RME_CTRL_NONE:
61             debugOutput(DEBUG_LEVEL_ERROR, "control has no type set\n");
62             err = 1;
63             break;
64         case RME_CTRL_PHANTOM_SW:
65             // Lowest 16 bits are phantom status bits (max 16 channels).
66             // High 16 bits are "write enable" bits for the corresponding
67             // channel represented in the low 16 bits.  This way changes can
68             // be made to one channel without needing to first read the
69             // existing value.
70             //
71             // At present there are at most 4 phantom-capable channels.
72             // Flag attempts to write to the bits corresponding to channels
73             // beyond this.
74             if (v & 0xfff00000) {
75                 debugOutput(DEBUG_LEVEL_WARNING, "Ignored out-of-range phantom set request: mask=0x%04x, value=0x%04x\n",
76                   (v >> 16) & 0xfff0, v && 0xfff0);
77             }
78
79             for (i=0; i<4; i++) {
80                 if (v & (0x00010000 << i)) {
81                     unsigned int on = (v & (0x00000001 << i)) != 0;
82                     err = m_parent.setPhantom(i, on);
83                     if (!err) {
84                         if (on) {
85                             m_value |= (0x01 << i);
86                         } else {
87                             m_value &= ~(0x01 << i);
88                         }
89                     }
90                 }
91             }
92             break;
93         case RME_CTRL_FF400_PAD_SW:
94             // Object's "m_info" field is the channel
95             if (m_parent.setInputPadOpt(m_info, v)) {
96                 m_value = (v != 0);
97             }
98             break;
99         case RME_CTRL_FF400_INSTR_SW:
100             // Object's "m_info" field is the channel
101             if (m_parent.setInputInstrOpt(m_info, v)) {
102                 m_value = (v != 0);
103             }
104             break;
105
106         // All RME_CTRL_INFO_* controls are read-only.  Warn on attempts to
107         // set these.
108         case RME_CTRL_INFO_MODEL:
109         case RME_CTRL_INFO_TCO_PRESENT:
110             debugOutput(DEBUG_LEVEL_ERROR, "Attempt to set readonly info control 0x%08x\n", m_type);
111             err = 1;
112             break;
113
114         default:
115             debugOutput(DEBUG_LEVEL_ERROR, "Unknown control type 0x%08x\n", m_type);
116             err = 1;
117     }
118
119     return err==0?true:false;
120 }
121
122 int
123 RmeSettingsCtrl::getValue() {
124
125 signed int i;
126 signed int val = 0;
127
128     switch (m_type) {
129         case RME_CTRL_NONE:
130             debugOutput(DEBUG_LEVEL_ERROR, "control has no type set\n");
131             break;
132
133         case RME_CTRL_PHANTOM_SW:
134             for (i=0; i<3; i++)
135                 val |= (m_parent.getPhantom(i) << i);
136             return val;
137             break;
138         case RME_CTRL_FF400_PAD_SW:
139             return m_parent.getInputPadOpt(m_info);
140             break;
141         case RME_CTRL_FF400_INSTR_SW:
142             return m_parent.getInputInstrOpt(m_info);
143             break;
144
145         case RME_CTRL_INFO_MODEL:
146             return m_parent.getRmeModel();
147             break;
148
149         case RME_CTRL_INFO_TCO_PRESENT:
150             return m_parent.getTcoPresent();
151
152         default:
153             debugOutput(DEBUG_LEVEL_ERROR, "Unknown control type 0x%08x\n", m_type);
154     }
155
156     return 0;
157 }
158
159
160 RmeSettingsMatrixCtrl::RmeSettingsMatrixCtrl(Device &parent, unsigned int type)
161 : Control::MatrixMixer(&parent)
162 , m_parent(parent)
163 , m_type(type)
164 {
165 }
166
167 RmeSettingsMatrixCtrl::RmeSettingsMatrixCtrl(Device &parent, unsigned int type,
168     std::string name)
169 : Control::MatrixMixer(&parent)
170 , m_parent(parent)
171 , m_type(type)
172 {
173     setName(name);
174 }
175
176 void RmeSettingsMatrixCtrl::show()
177 {
178     debugOutput(DEBUG_LEVEL_NORMAL, "RME matrix mixer type %d\n", m_type);
179 }
180
181 std::string RmeSettingsMatrixCtrl::getRowName(const int row)
182 {
183     char buf[64];
184     snprintf(buf, sizeof(buf), "RmeSettingsMatrixCtrl type %d, row %d", m_type, row);
185     return buf;
186 }
187
188 std::string RmeSettingsMatrixCtrl::getColName(const int col)
189 {
190     char buf[64];
191     snprintf(buf, sizeof(buf), "RmeSettingsMatrixCtrl type %d, column %d", m_type, col);
192     return buf;
193 }
194
195 int RmeSettingsMatrixCtrl::getRowCount()
196 {
197     switch (m_type) {
198         case RME_MATRIXCTRL_GAINS:
199             if (m_parent.getRmeModel() == RME_MODEL_FIREFACE400)
200                 return 1;
201             break;
202     }
203
204     return 0;
205 }
206
207 int RmeSettingsMatrixCtrl::getColCount()
208 {
209     switch (m_type) {
210         case RME_MATRIXCTRL_GAINS:
211             if (m_parent.getRmeModel() == RME_MODEL_FIREFACE400)
212                 return 22;
213             break;
214     }
215
216     return 0;
217 }
218
219 double RmeSettingsMatrixCtrl::setValue(const int row, const int col, const double val)
220 {
221     signed int ret = true;
222     signed int i;
223
224     switch (m_type) {
225         case RME_MATRIXCTRL_GAINS:
226             i = val;
227             if (i >= 0)
228                 ret = m_parent.setAmpGain(col, val);
229             else
230                 ret = -1;
231             break;
232     }
233
234     return ret;
235 }
236
237 double RmeSettingsMatrixCtrl::getValue(const int row, const int col)
238 {
239     double val = 0.0;
240     switch (m_type) {
241         case RME_MATRIXCTRL_GAINS:
242             val = m_parent.getAmpGain(col);
243             break;
244     }
245
246     return val;
247 }
248      
249
250 }
Note: See TracBrowser for help on using the browser.