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

Revision 2802, 29.0 kB (checked in by jwoithe, 3 years ago)

Cosmetic: "Firewire" becomes "FireWire?".

Officially both the "F" and "W" were capitalised in the FireWire? name, so
reflect this throughout FFADO's source tree. This mostly affects comments.

This patch originated from pander on the ffado-devel mailing list. To
maintain consistency, the committed version has been expanded to include
files not originally included in the original patch.

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     if (m_type>=RME_CTRL_TCO_FIRST && m_type<=RME_CTRL_TCO_LAST) {
62     }
63
64     switch (m_type) {
65         case RME_CTRL_NONE:
66             debugOutput(DEBUG_LEVEL_ERROR, "control has no type set\n");
67             err = 1;
68             break;
69         case RME_CTRL_PHANTOM_SW:
70             // Lowest 16 bits are phantom status bits (max 16 channels).
71             // High 16 bits are "write enable" bits for the corresponding
72             // channel represented in the low 16 bits.  This way changes can
73             // be made to one channel without needing to first read the
74             // existing value.
75             //
76             // At present there are at most 4 phantom-capable channels.
77             // Flag attempts to write to the bits corresponding to channels
78             // beyond this.
79             if (v & 0xfff00000) {
80                 debugOutput(DEBUG_LEVEL_WARNING, "Ignored out-of-range phantom set request: mask=0x%04x, value=0x%04x\n",
81                   (v >> 16) & 0xfff0, v && 0xfff0);
82             }
83
84             for (i=0; i<4; i++) {
85                 if (v & (0x00010000 << i)) {
86                     unsigned int on = (v & (0x00000001 << i)) != 0;
87                     err = m_parent.setPhantom(i, on);
88                     if (!err) {
89                         if (on) {
90                             m_value |= (0x01 << i);
91                         } else {
92                             m_value &= ~(0x01 << i);
93                         }
94                     }
95                 }
96             }
97             break;
98         case RME_CTRL_INPUT_LEVEL:
99             switch (v) {
100               case 0: i = FF_SWPARAM_ILEVEL_LOGAIN; break;
101               case 1: i = FF_SWPARAM_ILEVEL_m10dBV; break;
102               default: i = FF_SWPARAM_ILEVEL_4dBU;
103             }
104             if (m_parent.setInputLevel(i) == 0) {
105                 m_value = v;
106             }
107             break;
108         case RME_CTRL_OUTPUT_LEVEL:
109             switch (v) {
110               case 0: i = FF_SWPARAM_OLEVEL_m10dBV; break;
111               case 1: i = FF_SWPARAM_OLEVEL_4dBU; break;
112               default: i = FF_SWPARAM_OLEVEL_HIGAIN; break;
113             }
114             if (m_parent.setOutputLevel(i) == 0) {
115                 m_value = v;
116             }
117             break;
118         case RME_CTRL_FF400_PAD_SW:
119             // Object's "m_info" field is the channel
120             if (m_parent.setInputPadOpt(m_info, v) == 0) {
121                 m_value = (v != 0);
122             }
123             break;
124         case RME_CTRL_FF400_INSTR_SW:
125             // Object's "m_info" field is the channel
126             if (m_parent.setInputInstrOpt(m_info, v) == 0) {
127                 m_value = (v != 0);
128             }
129             break;
130         case RME_CTRL_INPUT_SOURCE: {
131             // m_info is the channel number
132             signed int src = 0;
133             if (v==0 || v==2)
134                 src |= FF_SWPARAM_FF800_INPUT_OPT_FRONT;
135             if (v==1 || v==2)
136                 src |= FF_SWPARAM_FF800_INPUT_OPT_REAR;
137             if (m_parent.setInputSource(m_info, src) == 0)
138                 m_value = src;
139             break;
140         }
141         case RME_CTRL_INSTRUMENT_OPTIONS:
142             // m_info is the channel number, v is expected to be a bitmap
143             // comprised of the FF800_INSTR_OPT_* values.
144             if (m_parent.setInputInstrOpt(m_info, v) == 0)
145                 m_value = v;
146             break;
147         case RME_CTRL_SPDIF_INPUT_MODE:
148             if (m_parent.setSpdifInputMode(v==0?FF_SWPARAM_SPDIF_INPUT_COAX:FF_SWPARAM_SPDIF_INPUT_OPTICAL)) {
149                 m_value = v;
150             }
151             break;
152         case RME_CTRL_SPDIF_OUTPUT_OPTICAL:
153             if (m_parent.setSpdifOutputIsOptical(v!=0) == 0) {
154                m_value = (v != 0);
155             }
156             break;
157         case RME_CTRL_SPDIF_OUTPUT_PRO:
158             if (m_parent.setSpdifOutputProOn(v!=0) == 0) {
159                m_value = (v != 0);
160             }
161             break;
162         case RME_CTRL_SPDIF_OUTPUT_EMPHASIS:
163             if (m_parent.setSpdifOutputEmphasisOn(v!=0) == 0) {
164                m_value = (v != 0);
165             }
166             break;
167         case RME_CTRL_SPDIF_OUTPUT_NONAUDIO:
168             if (m_parent.setSpdifOutputNonAudioOn(v!=0) == 0) {
169                m_value = (v != 0);
170             }
171             break;
172         case RME_CTRL_PHONES_LEVEL:
173             switch (v) {
174               case 0: i = FF_SWPARAM_PHONESLEVEL_HIGAIN; break;
175               case 1: i = FF_SWPARAM_PHONESLEVEL_4dBU; break;
176               default: i = FF_SWPARAM_PHONESLEVEL_m10dBV;
177             }
178             if (m_parent.setPhonesLevel(i) == 0) {
179                 m_value = v;
180             }
181             break;
182
183         case RME_CTRL_CLOCK_MODE:
184             if (m_parent.setClockMode(v==1?FF_SWPARAM_CLOCK_MODE_AUTOSYNC:FF_SWPARAM_CLOCK_MODE_MASTER) == 0) {
185                 m_value = v;
186             }
187             break;
188         case RME_CTRL_SYNC_REF: {
189             signed int val;
190             switch (v) {
191               case 0: val = FF_SWPARAM_SYNCREF_WORDCLOCK; break;
192               case 1: val = FF_SWPARAM_SYNCREF_ADAT1; break;
193               case 2: val = FF_SWPARAM_SYNCREF_ADAT2; break;
194               case 3: val = FF_SWPARAM_SYNCREF_SPDIF; break;
195               case 4: val = FF_SWPARAM_SYNCREC_TCO; break;
196               default:
197                 val = FF_SWPARAM_SYNCREF_WORDCLOCK;
198             }
199             if (m_parent.setSyncRef(val) == 0) {
200               m_value = v;
201             }
202             break;
203         }
204
205         case RME_CTRL_LIMIT_BANDWIDTH: {
206             signed int val;
207             switch (v) {
208               case 0: val = FF_DEV_FLASH_BWLIMIT_SEND_ALL_CHANNELS; break;
209               case 1: val = FF_DEV_FLASH_BWLIMIT_NO_ADAT2; break;
210               case 2: val = FF_DEV_FLASH_BWLIMIT_ANALOG_SPDIF_ONLY; break;
211               case 3: val = FF_DEV_FLASH_BWLIMIT_ANALOG_ONLY; break;
212               default:
213                 val = FF_DEV_FLASH_BWLIMIT_SEND_ALL_CHANNELS;
214             }
215             if (m_parent.setBandwidthLimit(val) == 0) {
216               m_value = v;
217             }
218             break;
219         }
220
221         case RME_CTRL_FLASH:
222             switch (v) {
223                 case RME_CTRL_FLASH_SETTINGS_LOAD:
224                     m_parent.read_device_flash_settings(NULL);
225                     break;
226                 case RME_CTRL_FLASH_SETTINGS_SAVE:
227                     m_parent.write_device_flash_settings(NULL);
228                     break;
229                 case RME_CTRL_FLASH_MIXER_LOAD:
230                     m_parent.read_device_mixer_settings(NULL);
231                     break;
232                 case RME_CTRL_FLASH_MIXER_SAVE:
233                     m_parent.write_device_mixer_settings(NULL);
234                     break;
235                 default:
236                     debugOutput(DEBUG_LEVEL_ERROR, "unknown command value %d for flash control type 0x%04x\n", v, m_type);
237                     err = 1;
238             }
239             break;
240         case RME_CTRL_MIXER_PRESET:
241             debugOutput(DEBUG_LEVEL_VERBOSE, "mixer presets not implemented yet\n");
242             break;
243
244         // All RME_CTRL_INFO_* controls are read-only.  Warn on attempts to
245         // set these.
246         case RME_CTRL_INFO_MODEL:
247         case RME_CTRL_INFO_TCO_PRESENT:
248         case RME_CTRL_INFO_SYSCLOCK_MODE:
249         case RME_CTRL_INFO_SYSCLOCK_FREQ:
250         case RME_CTRL_INFO_AUTOSYNC_FREQ:
251         case RME_CTRL_INFO_AUTOSYNC_SRC:
252         case RME_CTRL_INFO_SYNC_STATUS:
253         case RME_CTRL_INFO_SPDIF_FREQ:
254             debugOutput(DEBUG_LEVEL_ERROR, "Attempt to set readonly info control 0x%08x\n", m_type);
255             err = 1;
256             break;
257
258         case RME_CTRL_TCO_LTC_IN:
259         case RME_CTRL_TCO_INPUT_LTC_VALID:
260         case RME_CTRL_TCO_INPUT_LTC_FPS:
261         case RME_CTRL_TCO_INPUT_LTC_DROPFRAME:
262         case RME_CTRL_TCO_INPUT_VIDEO_TYPE:
263         case RME_CTRL_TCO_INPUT_WORD_CLK:
264         case RME_CTRL_TCO_INPUT_LOCK:
265         case RME_CTRL_TCO_FREQ:
266             debugOutput(DEBUG_LEVEL_ERROR, "Attempt to set readonly TCO control 0x%08x\n", m_type);
267             err = 1;
268             break;
269         case RME_CTRL_TCO_SYNC_SRC:
270             switch (v) {
271                 case 0: i = FF_TCOPARAM_INPUT_LTC; break;
272                 case 1: i = FF_TCOPARAM_INPUT_VIDEO; break;
273                 case 2: i = FF_TCOPARAM_INPUT_VIDEO; break;
274                 default: i = FF_TCOPARAM_INPUT_VIDEO;
275             }
276             return m_parent.setTcoSyncSrc(i);
277             break;
278         case RME_CTRL_TCO_FRAME_RATE:
279             switch (v) {
280                 case 0: i = FF_TCOPARAM_FRAMERATE_24fps; break;
281                 case 1: i = FF_TCOPARAM_FRAMERATE_25fps; break;
282                 case 2: i = FF_TCOPARAM_FRAMERATE_29_97fps; break;
283                 case 3: i = FF_TCOPARAM_FRAMERATE_29_97dfps; break;
284                 case 4: i = FF_TCOPARAM_FRAMERATE_30fps; break;
285                 case 5: i = FF_TCOPARAM_FRAMERATE_30dfps; break;
286                 default: i = FF_TCOPARAM_FRAMERATE_25fps; break;
287             }
288             return m_parent.setTcoFrameRate(i);
289             break;
290         case RME_CTRL_TCO_SAMPLE_RATE:
291             switch (v) {
292                 case 0: i = FF_TCOPARAM_SRATE_44_1; break;
293                 case 1: i = FF_TCOPARAM_SRATE_48; break;
294                 default: i = FF_TCOPARAM_SRATE_48; break;
295             }
296             return m_parent.setTcoSampleRate(i);
297             break;
298         case RME_CTRL_TCO_SAMPLE_RATE_OFS:
299             switch (v) {
300                 case 0: i = FF_TCOPARAM_PULL_NONE; break;
301                 case 1: i = FF_TCOPARAM_PULL_UP_01; break;
302                 case 2: i = FF_TCOPARAM_PULL_DOWN_01; break;
303                 case 3: i = FF_TCOPARAM_PULL_UP_40; break;
304                 case 4: i = FF_TCOPARAM_PULL_DOWN_40; break;
305                 default: i = FF_TCOPARAM_PULL_NONE;
306             }
307             return m_parent.setTcoPull(i);
308             break;
309         case RME_CTRL_TCO_VIDEO_IN_TERM:
310             return m_parent.setTcoTermination(v == 1);
311             break;
312         case RME_CTRL_TCO_WORD_CLK_CONV:
313             switch (v) {
314                 case 0: i = FF_TCOPARAM_WORD_CLOCK_CONV_1_1; break;
315                 case 1: i = FF_TCOPARAM_WORD_CLOCK_CONV_44_48; break;
316                 case 2: i = FF_TCOPARAM_WORD_CLOCK_CONV_48_44; break;
317                 default: i =  FF_TCOPARAM_WORD_CLOCK_CONV_1_1;
318             }
319             return m_parent.setTcoWordClkConv(i);
320             break;
321
322         default:
323             debugOutput(DEBUG_LEVEL_ERROR, "Unknown control type 0x%08x\n", m_type);
324             err = 1;
325     }
326
327     return err==0?true:false;
328 }
329
330 int
331 RmeSettingsCtrl::getValue() {
332
333 signed int i;
334 signed int val = 0;
335 FF_state_t ff_state;
336
337     switch (m_type) {
338         case RME_CTRL_NONE:
339             debugOutput(DEBUG_LEVEL_ERROR, "control has no type set\n");
340             break;
341
342         case RME_CTRL_PHANTOM_SW:
343             for (i=0; i<3; i++)
344                 val |= (m_parent.getPhantom(i) << i);
345             return val;
346             break;
347         case RME_CTRL_INPUT_LEVEL:
348             switch (m_parent.getInputLevel()) {
349                 case FF_SWPARAM_ILEVEL_LOGAIN: return 0;
350                 case FF_SWPARAM_ILEVEL_m10dBV: return 1;
351                 default: return 2;
352             }
353             break;
354         case RME_CTRL_OUTPUT_LEVEL:
355             switch (m_parent.getOutputLevel()) {
356                 case FF_SWPARAM_OLEVEL_m10dBV: return 0;
357                 case FF_SWPARAM_OLEVEL_4dBU: return 1;
358                 default: return 2;
359             }
360             break;
361         case RME_CTRL_FF400_PAD_SW:
362             return m_parent.getInputPadOpt(m_info);
363             break;
364         case RME_CTRL_FF400_INSTR_SW:
365             return m_parent.getInputInstrOpt(m_info);
366             break;
367         case RME_CTRL_INPUT_SOURCE: {
368             signed int src;
369             src = m_parent.getInputSource(m_info);
370             if (src == FF_SWPARAM_FF800_INPUT_OPT_FRONT)
371                 return 0;
372             if (src == FF_SWPARAM_FF800_INPUT_OPT_REAR)
373                 return 1;
374             return 2;
375             break;
376         }
377         case RME_CTRL_INSTRUMENT_OPTIONS:
378             return m_parent.getInputInstrOpt(m_info);
379             break;
380         case RME_CTRL_SPDIF_INPUT_MODE:
381             i = m_parent.getSpdifInputMode();
382             return i==FF_SWPARAM_SPDIF_INPUT_COAX?0:1;
383             break;
384         case RME_CTRL_SPDIF_OUTPUT_OPTICAL:
385             return m_parent.getSpdifOutputIsOptical();
386             break;
387         case RME_CTRL_SPDIF_OUTPUT_PRO:
388             return m_parent.getSpdifOutputProOn();
389             break;
390         case RME_CTRL_SPDIF_OUTPUT_EMPHASIS:
391             return m_parent.getSpdifOutputEmphasisOn();
392             break;
393         case RME_CTRL_SPDIF_OUTPUT_NONAUDIO:
394             return m_parent.getSpdifOutputNonAudioOn();
395             break;
396         case RME_CTRL_PHONES_LEVEL:
397             return m_parent.getPhonesLevel();
398             break;
399         case RME_CTRL_CLOCK_MODE:
400             return m_parent.getClockMode()==FF_SWPARAM_CLOCK_MODE_AUTOSYNC?1:0;
401             break;
402         case RME_CTRL_SYNC_REF: {
403             signed int val = m_parent.getSyncRef();
404             switch (val) {
405               case FF_SWPARAM_SYNCREF_WORDCLOCK: return 0;
406               case FF_SWPARAM_SYNCREF_ADAT1: return 1;
407               case FF_SWPARAM_SYNCREF_ADAT2: return 2;
408               case FF_SWPARAM_SYNCREF_SPDIF: return 3;
409               case FF_SWPARAM_SYNCREC_TCO: return 4;
410               default:
411                 return 0;
412             }
413             break;
414         }
415         case RME_CTRL_LIMIT_BANDWIDTH: {
416             signed int val = m_parent.getBandwidthLimit();
417             switch (val) {
418               case FF_DEV_FLASH_BWLIMIT_SEND_ALL_CHANNELS: return 0;
419               case FF_DEV_FLASH_BWLIMIT_NO_ADAT2: return 1;
420               case FF_DEV_FLASH_BWLIMIT_ANALOG_SPDIF_ONLY: return 2;
421               case FF_DEV_FLASH_BWLIMIT_ANALOG_ONLY: return 3;
422               default:
423                 return 0;
424             }
425             break;
426         }
427         case RME_CTRL_INFO_MODEL:
428             return m_parent.getRmeModel();
429             break;
430
431         case RME_CTRL_FLASH:
432         case RME_CTRL_MIXER_PRESET:
433             debugOutput(DEBUG_LEVEL_ERROR, "read requested for write-only control type 0x%04x\n", m_type);
434             return 0;
435             break;
436
437         case RME_CTRL_INFO_TCO_PRESENT:
438             return m_parent.getTcoPresent();
439
440         case RME_CTRL_INFO_SYSCLOCK_MODE:
441             if (m_parent.get_hardware_state(&ff_state) == 0)
442                 return ff_state.clock_mode;
443             else
444                 debugOutput(DEBUG_LEVEL_ERROR, "failed to read device state\n");
445             break;
446         case RME_CTRL_INFO_SYSCLOCK_FREQ:
447             return m_parent.getSamplingFrequency();
448         case RME_CTRL_INFO_AUTOSYNC_FREQ:
449             if (m_parent.get_hardware_state(&ff_state) == 0)
450                 return ff_state.autosync_freq;
451             else
452                 debugOutput(DEBUG_LEVEL_ERROR, "failed to read device state\n");
453             break;
454         case RME_CTRL_INFO_AUTOSYNC_SRC:
455             if (m_parent.get_hardware_state(&ff_state) == 0)
456                 return ff_state.autosync_source;
457             else
458                 debugOutput(DEBUG_LEVEL_ERROR, "failed to read device state\n");
459             break;
460         case RME_CTRL_INFO_SYNC_STATUS:
461             if (m_parent.get_hardware_state(&ff_state) == 0)
462                 return (ff_state.adat1_sync_status) |
463                        (ff_state.adat2_sync_status << 2) |
464                        (ff_state.spdif_sync_status << 4) |
465                        (ff_state.wclk_sync_status << 6) |
466                        (ff_state.tco_sync_status << 8);
467             else
468                 debugOutput(DEBUG_LEVEL_ERROR, "failed to read device state\n");
469             break;
470         case RME_CTRL_INFO_SPDIF_FREQ:
471             if (m_parent.get_hardware_state(&ff_state) == 0)
472                 return ff_state.spdif_freq;
473             else
474                 debugOutput(DEBUG_LEVEL_ERROR, "failed to read device state\n");
475             break;
476
477         case RME_CTRL_TCO_LTC_IN:
478             return m_parent.getTcoLtc();
479         case RME_CTRL_TCO_INPUT_LTC_VALID:
480             return m_parent.getTcoLtcValid();
481             break;
482         case RME_CTRL_TCO_INPUT_LTC_FPS:
483             switch (m_parent.getTcoLtcFrameRate()) {
484                 case FF_TCOSTATE_FRAMERATE_24fps: return 0;
485                 case FF_TCOSTATE_FRAMERATE_25fps: return 1;
486                 case FF_TCOSTATE_FRAMERATE_29_97fps: return 2;
487                 case FF_TCOSTATE_FRAMERATE_30fps: return 3;
488                 default: return 1;
489             }
490             break;
491         case RME_CTRL_TCO_INPUT_LTC_DROPFRAME:
492             return m_parent.getTcoLtcDropFrame();
493         case RME_CTRL_TCO_INPUT_VIDEO_TYPE:
494             switch (m_parent.getTcoVideoType()) {
495                 case FF_TCOSTATE_VIDEO_NONE: return 0;
496                 case FF_TCOSTATE_VIDEO_PAL: return 1;
497                 case FF_TCOSTATE_VIDEO_NTSC: return 2;
498                 default: return 1;
499             }
500             break;
501         case RME_CTRL_TCO_INPUT_WORD_CLK:
502             switch (m_parent.getTcoWordClk()) {
503                 case FF_TCOSTATE_WORDCLOCK_NONE: return 0;
504                 case FF_TCOSTATE_WORDCLOCK_1x: return 1;
505                 case FF_TCOSTATE_WORDCLOCK_2x: return 2;
506                 case FF_TCOSTATE_WORDCLOCK_4x: return 3;
507                 default: return 0;
508             }
509             break;
510         case RME_CTRL_TCO_INPUT_LOCK:
511             return m_parent.getTcoLock();
512             break;
513         case RME_CTRL_TCO_FREQ:
514             return m_parent.getTcoFrequency();
515             break;
516         case RME_CTRL_TCO_SYNC_SRC:
517             switch (m_parent.getTcoSyncSrc()) {
518                 case FF_TCOPARAM_INPUT_LTC: return 0;
519                 case FF_TCOPARAM_INPUT_VIDEO: return 1;
520                 case FF_TCOPARAM_INPUT_WCK: return 2;
521                 default: return 1;
522             }
523             break;
524         case RME_CTRL_TCO_FRAME_RATE:
525             switch (m_parent.getTcoFrameRate()) {
526                 case FF_TCOPARAM_FRAMERATE_24fps: return 0;
527                 case FF_TCOPARAM_FRAMERATE_25fps: return 1;
528                 case FF_TCOPARAM_FRAMERATE_29_97fps: return 2;
529                 case FF_TCOPARAM_FRAMERATE_29_97dfps: return 3;
530                 case FF_TCOPARAM_FRAMERATE_30fps: return 4;
531                 case FF_TCOPARAM_FRAMERATE_30dfps: return 5;
532                 default: return 1;
533             }
534             break;
535         case RME_CTRL_TCO_SAMPLE_RATE:
536             switch (m_parent.getTcoSampleRate()) {
537                 case FF_TCOPARAM_SRATE_44_1: return 0;
538                 case FF_TCOPARAM_SRATE_48: return 1;
539                 default: return 1;
540             }
541             break;
542         case RME_CTRL_TCO_SAMPLE_RATE_OFS:
543             switch (m_parent.getTcoPull()) {
544                 case FF_TCOPARAM_PULL_NONE: return 0;
545                 case FF_TCOPARAM_PULL_UP_01: return 1;
546                 case FF_TCOPARAM_PULL_DOWN_01: return 2;
547                 case FF_TCOPARAM_PULL_UP_40: return 3;
548                 case FF_TCOPARAM_PULL_DOWN_40: return 4;
549                 default: return 0;
550             }
551             break;
552         case RME_CTRL_TCO_VIDEO_IN_TERM:
553             return m_parent.getTcoTermination();
554             break;
555         case RME_CTRL_TCO_WORD_CLK_CONV:
556             switch (m_parent.getTcoWordClkConv()) {
557                 case FF_TCOPARAM_WORD_CLOCK_CONV_1_1: return 0;
558                 case FF_TCOPARAM_WORD_CLOCK_CONV_44_48: return 1;
559                 case FF_TCOPARAM_WORD_CLOCK_CONV_48_44: return 2;
560                 default: return 0;
561             }
562             break;
563
564         default:
565             debugOutput(DEBUG_LEVEL_ERROR, "Unknown control type 0x%08x\n", m_type);
566     }
567
568     return 0;
569 }
570
571
572 static std::string getOutputName(const signed int model, const int idx)
573 {
574     char buf[64];
575     switch(model) {
576         case RME_MODEL_FIREFACE400:
577             if (idx >= 10)
578                 snprintf(buf, sizeof(buf), "ADAT out %d", idx-9);
579             else
580             if (idx >= 8)
581                 snprintf(buf, sizeof(buf), "SPDIF out %d", idx-7);
582             else
583             if (idx >= 6)
584                 snprintf(buf, sizeof(buf), "Mon out %d", idx+1);
585             else
586                 snprintf(buf, sizeof(buf), "Line out %d", idx+1);
587             break;
588         case RME_MODEL_FIREFACE800:
589             if (idx >= 20)
590                 snprintf(buf, sizeof(buf), "ADAT-2 out %d", idx-19);
591             else
592             if (idx >= 12)
593                 snprintf(buf, sizeof(buf), "ADAT-1 out %d", idx-11);
594             else
595             if (idx >= 10)
596                 snprintf(buf, sizeof(buf), "SPDIF out %d", idx-9);
597             else
598             if (idx >= 8)
599                 snprintf(buf, sizeof(buf), "Mon, ch %d", idx+1);
600             else
601                 snprintf(buf, sizeof(buf), "Line out %d", idx+1);
602             break;
603         default:
604             snprintf(buf, sizeof(buf), "out %d", idx);
605     }
606     return buf;
607 }
608
609 static std::string getInputName(const signed int model, const int idx)
610 {
611     char buf[64];
612     switch (model) {
613         case RME_MODEL_FIREFACE400:
614             if (idx >= 10)
615                 snprintf(buf, sizeof(buf), "ADAT in %d", idx-9);
616             else
617             if (idx >= 8)
618                 snprintf(buf, sizeof(buf), "SPDIF in %d", idx-7);
619             else
620             if (idx >= 4)
621                 snprintf(buf, sizeof(buf), "Line in %d", idx+1);
622             else
623             if (idx >= 2)
624                 snprintf(buf, sizeof(buf), "Inst/line %d", idx+1);
625             else
626                 snprintf(buf, sizeof(buf), "Mic/line %d", idx+1);
627             break;
628         case RME_MODEL_FIREFACE800:
629             if (idx >= 20)
630                 snprintf(buf, sizeof(buf), "ADAT-2 in %d", idx-19);
631             else
632             if (idx >= 12)
633                 snprintf(buf, sizeof(buf), "ADAT-1 in %d", idx-11);
634             else
635             if (idx >= 10)
636                 snprintf(buf, sizeof(buf), "SPDIF in %d", idx-9);
637             else
638             if (idx >= 6)
639                 snprintf(buf, sizeof(buf), "Mic/line %d", idx+1);
640             else
641             if (idx >= 1)
642                 snprintf(buf, sizeof(buf), "Line %d", idx+1);
643             else
644                 snprintf(buf, sizeof(buf), "Instr/line %d", idx+1);
645             break;
646         default:
647             snprintf(buf, sizeof(buf), "in %d", idx);
648     }
649     return buf;
650 }
651
652 RmeSettingsMatrixCtrl::RmeSettingsMatrixCtrl(Device &parent, unsigned int type)
653 : Control::MatrixMixer(&parent)
654 , m_parent(parent)
655 , m_type(type)
656 {
657 }
658
659 RmeSettingsMatrixCtrl::RmeSettingsMatrixCtrl(Device &parent, unsigned int type,
660     std::string name)
661 : Control::MatrixMixer(&parent)
662 , m_parent(parent)
663 , m_type(type)
664 {
665     setName(name);
666 }
667
668 void RmeSettingsMatrixCtrl::show()
669 {
670     debugOutput(DEBUG_LEVEL_NORMAL, "RME matrix mixer type %d\n", m_type);
671 }
672
673 std::string RmeSettingsMatrixCtrl::getRowName(const int row)
674 {
675     if (m_type == RME_MATRIXCTRL_OUTPUT_FADER)
676         return "";
677     return getOutputName(m_parent.getRmeModel(), row);
678 }
679
680 std::string RmeSettingsMatrixCtrl::getColName(const int col)
681 {
682     if (m_type == RME_MATRIXCTRL_PLAYBACK_FADER)
683         return "";
684     if (m_type == RME_MATRIXCTRL_OUTPUT_FADER)
685         return getOutputName(m_parent.getRmeModel(), col);
686
687     return getInputName(m_parent.getRmeModel(), col);
688 }
689
690 int RmeSettingsMatrixCtrl::getRowCount()
691 {
692     switch (m_type) {
693         case RME_MATRIXCTRL_GAINS:
694             if (m_parent.getRmeModel() == RME_MODEL_FIREFACE400)
695                 return 1;
696             break;
697         case RME_MATRIXCTRL_INPUT_FADER:
698         case RME_MATRIXCTRL_PLAYBACK_FADER:
699             if (m_parent.getRmeModel() == RME_MODEL_FIREFACE400)
700                 return RME_FF400_MAX_CHANNELS;
701             else
702                 return RME_FF800_MAX_CHANNELS;
703             break;
704         case RME_MATRIXCTRL_OUTPUT_FADER:
705             return 1;
706             break;
707     }
708
709     return 0;
710 }
711
712 int RmeSettingsMatrixCtrl::getColCount()
713 {
714     switch (m_type) {
715         case RME_MATRIXCTRL_GAINS:
716             if (m_parent.getRmeModel() == RME_MODEL_FIREFACE400)
717                 return 22;
718             break;
719         case RME_MATRIXCTRL_INPUT_FADER:
720         case RME_MATRIXCTRL_PLAYBACK_FADER:
721         case RME_MATRIXCTRL_OUTPUT_FADER:
722             if (m_parent.getRmeModel() == RME_MODEL_FIREFACE400)
723                 return RME_FF400_MAX_CHANNELS;
724             else
725                 return RME_FF800_MAX_CHANNELS;
726             break;
727     }
728
729     return 0;
730 }
731
732 double RmeSettingsMatrixCtrl::setValue(const int row, const int col, const double val)
733 {
734     signed int ret = true;
735     signed int i;
736
737     switch (m_type) {
738         case RME_MATRIXCTRL_GAINS:
739             i = val;
740             if (i >= 0)
741                 ret = m_parent.setAmpGain(col, val);
742             else
743                 ret = -1;
744             break;
745
746         // For values originating from the input, playback or output faders,
747         // the MatrixMixer widget uses a value of 0x004000 for 0 dB gain.
748         // The RME hardware (via setMixerGain()) uses 0x008000 as the 0 dB
749         // reference point.  Correct for this mismatch when calling
750         // setMixerGain().
751         case RME_MATRIXCTRL_INPUT_FADER:
752           return m_parent.setMixerGain(RME_FF_MM_INPUT, col, row, val*2);
753           break;
754         case RME_MATRIXCTRL_PLAYBACK_FADER:
755           return m_parent.setMixerGain(RME_FF_MM_PLAYBACK, col, row, val*2);
756           break;
757         case RME_MATRIXCTRL_OUTPUT_FADER:
758           return m_parent.setMixerGain(RME_FF_MM_OUTPUT, col, row, val*2);
759           break;
760
761         case RME_MATRIXCTRL_INPUT_MUTE:
762           return m_parent.setMixerFlags(RME_FF_MM_INPUT, col, row, FF_SWPARAM_MF_MUTED, val!=0);
763           break;
764         case RME_MATRIXCTRL_PLAYBACK_MUTE:
765           return m_parent.setMixerFlags(RME_FF_MM_PLAYBACK, col, row, FF_SWPARAM_MF_MUTED, val!=0);
766           break;
767         case RME_MATRIXCTRL_OUTPUT_MUTE:
768           return m_parent.setMixerFlags(RME_FF_MM_OUTPUT, col, row, FF_SWPARAM_MF_MUTED, val!=0);
769           break;
770         case RME_MATRIXCTRL_INPUT_INVERT:
771           return m_parent.setMixerFlags(RME_FF_MM_INPUT, col, row, FF_SWPARAM_MF_INVERTED, val!=0);
772           break;
773         case RME_MATRIXCTRL_PLAYBACK_INVERT:
774           return m_parent.setMixerFlags(RME_FF_MM_PLAYBACK, col, row, FF_SWPARAM_MF_INVERTED, val!=0);
775           break;
776
777     }
778
779     return ret;
780 }
781
782 double RmeSettingsMatrixCtrl::getValue(const int row, const int col)
783 {
784     double val = 0.0;
785     switch (m_type) {
786         case RME_MATRIXCTRL_GAINS:
787             val = m_parent.getAmpGain(col);
788             break;
789
790         // The MatrixMixer widget (as used for the input, playback and
791         // output faders) uses a value of 0x004000 for 0 dB gain, but the
792         // gain value from the RME hardware (received getMixerGain()) uses
793         // 0x008000 as the 0 dB reference point.  Correct for this mismatch
794         // as the value is obtained.
795         case RME_MATRIXCTRL_INPUT_FADER:
796             val = m_parent.getMixerGain(RME_FF_MM_INPUT, col, row) / 2;
797             break;
798         case RME_MATRIXCTRL_PLAYBACK_FADER:
799             val = m_parent.getMixerGain(RME_FF_MM_PLAYBACK, col, row) / 2;
800             break;
801         case RME_MATRIXCTRL_OUTPUT_FADER:
802             val = m_parent.getMixerGain(RME_FF_MM_OUTPUT, col, row) / 2;
803             break;
804
805         case RME_MATRIXCTRL_INPUT_MUTE:
806           return m_parent.getMixerFlags(RME_FF_MM_INPUT, col, row, FF_SWPARAM_MF_MUTED) != 0;
807           break;
808         case RME_MATRIXCTRL_PLAYBACK_MUTE:
809           return m_parent.getMixerFlags(RME_FF_MM_PLAYBACK, col, row, FF_SWPARAM_MF_MUTED) != 0;
810           break;
811         case RME_MATRIXCTRL_OUTPUT_MUTE:
812           return m_parent.getMixerFlags(RME_FF_MM_OUTPUT, col, row, FF_SWPARAM_MF_MUTED) != 0;
813           break;
814         case RME_MATRIXCTRL_INPUT_INVERT:
815           return m_parent.getMixerFlags(RME_FF_MM_INPUT, col, row, FF_SWPARAM_MF_INVERTED) != 0;
816           break;
817         case RME_MATRIXCTRL_PLAYBACK_INVERT:
818           return m_parent.getMixerFlags(RME_FF_MM_PLAYBACK, col, row, FF_SWPARAM_MF_INVERTED) != 0;
819           break;
820     }
821
822     return val;
823 }
824      
825
826 }
Note: See TracBrowser for help on using the browser.