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

Revision 1730, 4.7 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 "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<0x40 && offset>=0x3C) return 3;
35     if (offset<0x60 && offset>=0x58) return 4;
36     return 0;
37 }
38
39
40 class SaffirePro24::LineInstSwitch : public Dice::Focusrite::FocusriteEAP::Switch
41 {
42 public:
43     LineInstSwitch(Dice::Focusrite::FocusriteEAP* eap, std::string name, size_t offset, int activevalue)
44         : Dice::Focusrite::FocusriteEAP::Switch(eap, name, offset, activevalue) {}
45     std::string getBooleanLabel(bool n) {
46         if ( n ) return "Instrument";
47         return "Line";
48     }
49 };
50 class SaffirePro24::LevelSwitch : public Dice::Focusrite::FocusriteEAP::Switch
51 {
52 public:
53     LevelSwitch(Dice::Focusrite::FocusriteEAP* eap, std::string name, size_t offset, int activevalue)
54         : Dice::Focusrite::FocusriteEAP::Switch(eap, name, offset, activevalue) {}
55     std::string getBooleanLabel(bool n) {
56         if ( n ) return "High";
57         return "Low";
58     }
59 };
60
61 SaffirePro24::SaffirePro24( DeviceManager& d,
62                             std::auto_ptr<ConfigRom>( configRom ))
63     : Dice::Device(d , configRom)
64     , m_ch1(NULL)
65     , m_ch2(NULL)
66 {
67     debugOutput(DEBUG_LEVEL_VERBOSE, "Created Dice::Focusrite::SaffirePro24 (NodeID %d)\n",
68                 getConfigRom().getNodeId());
69 }
70
71 SaffirePro24::~SaffirePro24()
72 {
73     //debugOutput(DEBUG_LEVEL_VERBOSE, "Deleting the saffirePro24\n");
74     /// I wonder whether we should really save only on clean exits or also each time a setting is
75     //  changed. Or should we provide a function (and thus gui-button) to save the state of the
76     //  device?
77     getEAP()->storeFlashConfig();
78     getEAP()->deleteElement(m_ch1);
79     getEAP()->deleteElement(m_ch2);
80     if (m_ch1) delete m_ch1;
81     if (m_ch2) delete m_ch2;
82 }
83
84 bool SaffirePro24::discover() {
85     if (Dice::Device::discover()) {
86         fb_quadlet_t* tmp = (fb_quadlet_t *)calloc(2, sizeof(fb_quadlet_t));
87         getEAP()->readRegBlock(Dice::Device::EAP::eRT_Application, 0x00, tmp, 1*sizeof(fb_quadlet_t));
88         //hexDumpQuadlets(tmp, 2); // DEBUG
89         if (tmp[0] != 0x00010004 ) {
90             debugError("This is a Focusrite Saffire Pro24 but not the right firmware. Better stop here before something goes wrong.\n");
91             debugError("This device has firmware 0x%x while we only know about version 0x%x.\n", tmp[0], 0x10004);
92             return false;
93         }
94         //getEAP()->readRegBlock(Dice::Device::EAP::eRT_Command, 0x00, tmp, 2*sizeof(fb_quadlet_t)); // DEBUG
95         //hexDumpQuadlets(tmp, 2); // DEBUG
96
97         FocusriteEAP* eap = dynamic_cast<FocusriteEAP*>(getEAP());
98         m_ch1 = new LineInstSwitch(eap, "Ch1LineInst", 0x58, 2);
99         getEAP()->addElement(m_ch1);
100         m_ch2 = new LineInstSwitch(eap, "Ch2LineInst", 0x58, 2<<16);
101         getEAP()->addElement(m_ch2);
102         m_ch3 = new LevelSwitch(eap, "Ch3Level", 0x5C, 1);
103         getEAP()->addElement(m_ch3);
104         m_ch4 = new LevelSwitch(eap, "Ch4Level", 0x5C, 1<<16);
105         getEAP()->addElement(m_ch4);
106
107         m_monitor = new FocusriteEAP::MonitorSection(eap, "Monitoring");
108         getEAP()->addElement(m_monitor);
109         return true;
110     }
111     return false;
112 }
113
114 void SaffirePro24::showDevice()
115 {
116     debugOutput(DEBUG_LEVEL_VERBOSE, "This is a Dice::Focusrite::SaffirePro24\n");
117     Dice::Device::showDevice();
118 }
119 Dice::Device::EAP* SaffirePro24::createEAP() {
120     return new SaffirePro24EAP(*this);
121 }
122
123 bool SaffirePro24::setNickName( std::string name ) {
124     return getEAP()->writeRegBlock( Dice::Device::EAP::eRT_Application, 0x40, (fb_quadlet_t*)name.c_str(), name.size() );
125 }
126
127 std::string SaffirePro24::getNickName() {
128     char name[16];
129     getEAP()->readRegBlock( Dice::Device::EAP::eRT_Application, 0x40, (fb_quadlet_t*)name, 16 );
130     return std::string( name );
131 }
132
133 }
134 }
135
136 // vim: et
Note: See TracBrowser for help on using the browser.