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

Revision 1776, 5.5 kB (checked in by arnonym, 11 years ago)

Reduce the LOC:

  • Use only strings as identifiers for the Dice::EAP::Router. Updating the router doesn't happen that often, using strings only is acceptable. And it eases handling so much.
  • Adapt the control interface.
  • Adapt the dbus interface.
  • Adapt the routers gui.
  • The peak-space is not yet working (I didn't actually test it), the peak-functions of EAP::Router return nothing.
  • And the test for the dice has to be adopted when the peaks are working again.

TODO:

  • Re-activate the peaks.
  • Adopt the mixer interface.
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 "saffire_pro24.h"
26 #include "focusrite_eap.h"
27
28 namespace Dice {
29 namespace Focusrite {
30
31 int SaffirePro24::SaffirePro24EAP::commandToFix(unsigned offset) {
32     if (offset<0x14) return 2;
33     if (offset<0x3C && offset>=0x14) return 1;
34     if (offset<0x58 && offset>=0x50) return 1;
35     if (offset<0x40 && offset>=0x3C) return 3;
36     if (offset<0x60 && offset>=0x58) return 4;
37     return 0;
38 }
39 FocusriteEAP::Poti* SaffirePro24::SaffirePro24EAP::getMonitorPoti(std::string name) {
40     return new FocusriteEAP::Poti(this, name, 0x50);
41 }
42 FocusriteEAP::Poti* SaffirePro24::SaffirePro24EAP::getDimPoti(std::string name) {
43     return new FocusriteEAP::Poti(this, name, 0x54);
44 }
45
46 void SaffirePro24::SaffirePro24EAP::setupSources() {
47     addSource("SPDIF",  6, 2, eRS_AES);
48     addSource("ADAT",   0, 8, eRS_ADAT);
49     addSource("Analog", 0, 4, eRS_InS0);
50     addSource("Mixer",  0, 16, eRS_Mixer);
51     addSource("1394",   0, 8, eRS_ARX0);
52 }
53 void SaffirePro24::SaffirePro24EAP::setupDestinations() {
54     addDestination("SPDIF",  6, 2, eRD_AES);
55     addDestination("Analog", 0, 6, eRD_InS0);
56     addDestination("Mixer",  0, 16, eRD_Mixer0);
57     addDestination("Mixer",  0, 2, eRD_Mixer1, 16);
58     addDestination("1394",   0, 16, eRD_ATX0);
59 }
60
61
62 class SaffirePro24::LineInstSwitch : public Dice::Focusrite::FocusriteEAP::Switch
63 {
64 public:
65     LineInstSwitch(Dice::Focusrite::FocusriteEAP* eap, std::string name, size_t offset, int activevalue)
66         : Dice::Focusrite::FocusriteEAP::Switch(eap, name, offset, activevalue) {}
67     std::string getBooleanLabel(bool n) {
68         if ( n ) return "Instrument";
69         return "Line";
70     }
71 };
72 class SaffirePro24::LevelSwitch : public Dice::Focusrite::FocusriteEAP::Switch
73 {
74 public:
75     LevelSwitch(Dice::Focusrite::FocusriteEAP* eap, std::string name, size_t offset, int activevalue)
76         : Dice::Focusrite::FocusriteEAP::Switch(eap, name, offset, activevalue) {}
77     std::string getBooleanLabel(bool n) {
78         if ( n ) return "High";
79         return "Low";
80     }
81 };
82
83 SaffirePro24::SaffirePro24( DeviceManager& d,
84                             std::auto_ptr<ConfigRom>( configRom ))
85     : Dice::Device(d , configRom)
86     , m_ch1(NULL)
87     , m_ch2(NULL)
88 {
89     debugOutput(DEBUG_LEVEL_VERBOSE, "Created Dice::Focusrite::SaffirePro24 (NodeID %d)\n",
90                 getConfigRom().getNodeId());
91 }
92
93 SaffirePro24::~SaffirePro24()
94 {
95     //debugOutput(DEBUG_LEVEL_VERBOSE, "Deleting the saffirePro24\n");
96     /// I wonder whether we should really save only on clean exits or also each time a setting is
97     //  changed. Or should we provide a function (and thus gui-button) to save the state of the
98     //  device?
99     getEAP()->storeFlashConfig();
100     getEAP()->deleteElement(m_ch1);
101     getEAP()->deleteElement(m_ch2);
102     if (m_ch1) delete m_ch1;
103     if (m_ch2) delete m_ch2;
104 }
105
106 bool SaffirePro24::discover() {
107     if (Dice::Device::discover()) {
108         fb_quadlet_t* tmp = (fb_quadlet_t *)calloc(2, sizeof(fb_quadlet_t));
109         getEAP()->readRegBlock(Dice::EAP::eRT_Application, 0x00, tmp, 1*sizeof(fb_quadlet_t));
110         //hexDumpQuadlets(tmp, 2); // DEBUG
111         if (tmp[0] != 0x00010004 ) {
112             debugError("This is a Focusrite Saffire Pro24 but not the right firmware. Better stop here before something goes wrong.\n");
113             debugError("This device has firmware 0x%x while we only know about version 0x%x.\n", tmp[0], 0x10004);
114             return false;
115         }
116         //getEAP()->readRegBlock(Dice::EAP::eRT_Command, 0x00, tmp, 2*sizeof(fb_quadlet_t)); // DEBUG
117         //hexDumpQuadlets(tmp, 2); // DEBUG
118
119         FocusriteEAP* eap = dynamic_cast<FocusriteEAP*>(getEAP());
120         m_ch1 = new LineInstSwitch(eap, "Ch1LineInst", 0x58, 2);
121         getEAP()->addElement(m_ch1);
122         m_ch2 = new LineInstSwitch(eap, "Ch2LineInst", 0x58, 2<<16);
123         getEAP()->addElement(m_ch2);
124         m_ch3 = new LevelSwitch(eap, "Ch3Level", 0x5C, 1);
125         getEAP()->addElement(m_ch3);
126         m_ch4 = new LevelSwitch(eap, "Ch4Level", 0x5C, 1<<16);
127         getEAP()->addElement(m_ch4);
128
129         m_monitor = new FocusriteEAP::MonitorSection(eap, "Monitoring");
130         getEAP()->addElement(m_monitor);
131         return true;
132     }
133     return false;
134 }
135
136 void SaffirePro24::showDevice()
137 {
138     debugOutput(DEBUG_LEVEL_VERBOSE, "This is a Dice::Focusrite::SaffirePro24\n");
139     Dice::Device::showDevice();
140 }
141 Dice::EAP* SaffirePro24::createEAP() {
142     return new SaffirePro24EAP(*this);
143 }
144
145 bool SaffirePro24::setNickName( std::string name ) {
146     return getEAP()->writeRegBlock( Dice::EAP::eRT_Application, 0x40, (fb_quadlet_t*)name.c_str(), name.size() );
147 }
148
149 std::string SaffirePro24::getNickName() {
150     char name[16];
151     getEAP()->readRegBlock( Dice::EAP::eRT_Application, 0x40, (fb_quadlet_t*)name, 16 );
152     return std::string( name );
153 }
154
155 }
156 }
157
158 // vim: et
Note: See TracBrowser for help on using the browser.