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