root/trunk/libffado/src/dice/focusrite/focusrite_eap.cpp

Revision 1730, 3.2 kB (checked in by arnonym, 14 years ago)

Save code by creating another class. Next step is unified monitoring and switches for both the pro40 and the pro24.

Line 
1 /*
2  * Copyright (C) 2009 by Pieter Palmers
3  * Copyright (C) 2009 by Arnold Krille
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
25 #include "focusrite_eap.h"
26
27 namespace Dice {
28 namespace Focusrite {
29
30 const int msgSet = 0x68;
31
32 FocusriteEAP::FocusriteEAP(Dice::Device& dev) : Dice::Device::EAP(dev) {
33 }
34
35 bool FocusriteEAP::readApplicationReg(unsigned offset, quadlet_t* quadlet) {
36     return readReg(eRT_Application, offset, quadlet);
37 }
38 bool FocusriteEAP::writeApplicationReg(unsigned offset, quadlet_t quadlet) {
39     bool ret = writeReg(eRT_Application, offset, quadlet);
40     if (!ret) return false;
41     return writeReg(eRT_Application, msgSet, commandToFix(offset));
42 }
43
44
45 FocusriteEAP::Switch::Switch(Dice::Focusrite::FocusriteEAP* eap, std::string name, size_t offset, int activevalue )
46     : Control::Boolean(eap, name)
47     , m_eap(eap)
48     , m_selected(0)
49     , m_offset(offset)
50     , m_activevalue(activevalue)
51 {
52     m_eap->readApplicationReg(m_offset, &m_state_tmp);
53     printf("%s: Active?%i\n", name.c_str(), m_state_tmp&m_activevalue);
54     debugOutput(DEBUG_LEVEL_VERBOSE, "Probably the initialization is the other way round.\n");
55     m_selected = (m_state_tmp&m_activevalue)?true:false;
56 }
57
58 bool FocusriteEAP::Switch::selected() {
59     return m_selected;
60 }
61
62 bool FocusriteEAP::Switch::select(bool n) {
63     if ( n != m_selected ) {
64         m_selected = n;
65         m_eap->readApplicationReg(m_offset, &m_state_tmp);
66         m_eap->writeApplicationReg(m_offset, m_state_tmp^m_activevalue);
67     }
68     return true;
69 }
70
71
72
73 FocusriteEAP::MonitorSection::MonitorSection(Dice::Focusrite::FocusriteEAP* eap, std::string name)
74     : Control::Container(eap, name)
75     , m_eap(eap)
76 {
77     m_mute = new Switch(m_eap, "Mute", 0x0C, 1);
78     addElement(m_mute);
79     m_dim = new Switch(m_eap, "Dim", 0x10, 1);
80     addElement(m_dim);
81     for (int i=0; i<10; ++i) {
82         std::stringstream stream;
83         stream << "MuteAffectsCh" << i;
84         Switch* s = new Switch(m_eap, stream.str(), 0x3C, 1<<i);
85         addElement(s);
86         m_mute_affected.push_back(s);
87         stream.str(std::string());
88         stream << "DimAffectsCh" << i;
89         s = new Switch(m_eap, stream.str(), 0x3C, 1<<(10+i));
90         addElement(s);
91         m_dim_affected.push_back(s);
92     }
93     for (int i=0; i<5; ++i) {
94         std::stringstream stream;
95         stream << "Mono_" << i*2 << "_" << i*2+1;
96         Switch* s = new Switch(m_eap, stream.str(), 0x3C, 1<<(20+i));
97         addElement(s);
98         m_mono.push_back(s);
99     }
100 }
101
102 }
103 }
104
105 // vim: et
Note: See TracBrowser for help on using the browser.