1 |
/* |
---|
2 |
* Copyright (C) 2007 by Pieter Palmers |
---|
3 |
* |
---|
4 |
* This file is part of FFADO |
---|
5 |
* FFADO = Free Firewire (pro-)audio drivers for linux |
---|
6 |
* |
---|
7 |
* FFADO is based upon FreeBoB. |
---|
8 |
* |
---|
9 |
* This library is free software; you can redistribute it and/or |
---|
10 |
* modify it under the terms of the GNU Lesser General Public |
---|
11 |
* License version 2.1, as published by the Free Software Foundation; |
---|
12 |
* |
---|
13 |
* This library is distributed in the hope that it will be useful, |
---|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 |
* Lesser General Public License for more details. |
---|
17 |
* |
---|
18 |
* You should have received a copy of the GNU Lesser General Public |
---|
19 |
* License along with this library; if not, write to the Free Software |
---|
20 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
---|
21 |
* MA 02110-1301 USA |
---|
22 |
*/ |
---|
23 |
|
---|
24 |
#include "focusrite_saffirepro.h" |
---|
25 |
#include "focusrite_cmd.h" |
---|
26 |
|
---|
27 |
namespace BeBoB { |
---|
28 |
namespace Focusrite { |
---|
29 |
|
---|
30 |
FocusriteDevice::FocusriteDevice( Ieee1394Service& ieee1394Service, |
---|
31 |
std::auto_ptr<ConfigRom>( configRom )) |
---|
32 |
: BeBoB::AvDevice( ieee1394Service, configRom) |
---|
33 |
{ |
---|
34 |
debugOutput( DEBUG_LEVEL_VERBOSE, "Created BeBoB::Focusrite::FocusriteDevice (NodeID %d)\n", |
---|
35 |
getConfigRom().getNodeId() ); |
---|
36 |
|
---|
37 |
} |
---|
38 |
|
---|
39 |
void |
---|
40 |
FocusriteDevice::showDevice() |
---|
41 |
{ |
---|
42 |
debugOutput(DEBUG_LEVEL_NORMAL, "This is a BeBoB::Focusrite::FocusriteDevice\n"); |
---|
43 |
BeBoB::AvDevice::showDevice(); |
---|
44 |
} |
---|
45 |
|
---|
46 |
void |
---|
47 |
FocusriteDevice::setVerboseLevel(int l) |
---|
48 |
{ |
---|
49 |
debugOutput( DEBUG_LEVEL_VERBOSE, "Setting verbose level to %d...\n", l ); |
---|
50 |
|
---|
51 |
BeBoB::AvDevice::setVerboseLevel(l); |
---|
52 |
} |
---|
53 |
|
---|
54 |
bool |
---|
55 |
FocusriteDevice::setSpecificValue(uint32_t id, uint32_t v) |
---|
56 |
{ |
---|
57 |
|
---|
58 |
FocusriteVendorDependentCmd cmd( get1394Service() ); |
---|
59 |
cmd.setCommandType( AVC::AVCCommand::eCT_Control ); |
---|
60 |
cmd.setNodeId( getConfigRom().getNodeId() ); |
---|
61 |
cmd.setSubunitType( AVC::eST_Unit ); |
---|
62 |
cmd.setSubunitId( 0xff ); |
---|
63 |
|
---|
64 |
cmd.setVerbose( getDebugLevel() ); |
---|
65 |
// cmd.setVerbose( DEBUG_LEVEL_VERY_VERBOSE ); |
---|
66 |
|
---|
67 |
cmd.m_id=id; |
---|
68 |
cmd.m_value=v; |
---|
69 |
|
---|
70 |
if ( !cmd.fire() ) { |
---|
71 |
debugError( "FocusriteVendorDependentCmd info command failed\n" ); |
---|
72 |
return false; |
---|
73 |
} |
---|
74 |
|
---|
75 |
return true; |
---|
76 |
} |
---|
77 |
|
---|
78 |
bool |
---|
79 |
FocusriteDevice::getSpecificValue(uint32_t id, uint32_t *v) |
---|
80 |
{ |
---|
81 |
|
---|
82 |
FocusriteVendorDependentCmd cmd( get1394Service() ); |
---|
83 |
cmd.setCommandType( AVC::AVCCommand::eCT_Status ); |
---|
84 |
cmd.setNodeId( getConfigRom().getNodeId() ); |
---|
85 |
cmd.setSubunitType( AVC::eST_Unit ); |
---|
86 |
cmd.setSubunitId( 0xff ); |
---|
87 |
|
---|
88 |
cmd.setVerbose( getDebugLevel() ); |
---|
89 |
// cmd.setVerbose( DEBUG_LEVEL_VERY_VERBOSE ); |
---|
90 |
|
---|
91 |
cmd.m_id=id; |
---|
92 |
|
---|
93 |
if ( !cmd.fire() ) { |
---|
94 |
debugError( "FocusriteVendorDependentCmd info command failed\n" ); |
---|
95 |
return false; |
---|
96 |
} |
---|
97 |
|
---|
98 |
*v=cmd.m_value; |
---|
99 |
|
---|
100 |
return true; |
---|
101 |
} |
---|
102 |
|
---|
103 |
int |
---|
104 |
FocusriteDevice::convertDefToSr( uint32_t def ) { |
---|
105 |
switch(def) { |
---|
106 |
case FOCUSRITE_CMD_SAMPLERATE_44K1: return 44100; |
---|
107 |
case FOCUSRITE_CMD_SAMPLERATE_48K: return 48000; |
---|
108 |
case FOCUSRITE_CMD_SAMPLERATE_88K2: return 88200; |
---|
109 |
case FOCUSRITE_CMD_SAMPLERATE_96K: return 96000; |
---|
110 |
case FOCUSRITE_CMD_SAMPLERATE_176K4: return 176400; |
---|
111 |
case FOCUSRITE_CMD_SAMPLERATE_192K: return 192000; |
---|
112 |
default: return 0; |
---|
113 |
} |
---|
114 |
} |
---|
115 |
|
---|
116 |
uint32_t |
---|
117 |
FocusriteDevice::convertSrToDef( int sr ) { |
---|
118 |
switch(sr) { |
---|
119 |
case 44100: return FOCUSRITE_CMD_SAMPLERATE_44K1; |
---|
120 |
case 48000: return FOCUSRITE_CMD_SAMPLERATE_48K; |
---|
121 |
case 88200: return FOCUSRITE_CMD_SAMPLERATE_88K2; |
---|
122 |
case 96000: return FOCUSRITE_CMD_SAMPLERATE_96K; |
---|
123 |
case 176400: return FOCUSRITE_CMD_SAMPLERATE_176K4; |
---|
124 |
case 192000: return FOCUSRITE_CMD_SAMPLERATE_192K; |
---|
125 |
default: |
---|
126 |
debugWarning("Unsupported samplerate: %d\n", sr); |
---|
127 |
return 0; |
---|
128 |
} |
---|
129 |
} |
---|
130 |
|
---|
131 |
// --- element implementation classes |
---|
132 |
|
---|
133 |
BinaryControl::BinaryControl(FocusriteDevice& parent, int id) |
---|
134 |
: Control::Discrete() |
---|
135 |
, m_Parent(parent) |
---|
136 |
, m_cmd_id ( id ) |
---|
137 |
{} |
---|
138 |
BinaryControl::BinaryControl(FocusriteDevice& parent, int id, |
---|
139 |
std::string name, std::string label, std::string descr) |
---|
140 |
: Control::Discrete() |
---|
141 |
, m_Parent(parent) |
---|
142 |
, m_cmd_id ( id ) |
---|
143 |
{ |
---|
144 |
setName(name); |
---|
145 |
setLabel(label); |
---|
146 |
setDescription(descr); |
---|
147 |
} |
---|
148 |
|
---|
149 |
bool |
---|
150 |
BinaryControl::setValue(int v) |
---|
151 |
{ |
---|
152 |
uint32_t val=0; |
---|
153 |
if (v) val=1; |
---|
154 |
debugOutput(DEBUG_LEVEL_VERBOSE, "setValue for id %d to %d\n", |
---|
155 |
m_cmd_id, v); |
---|
156 |
|
---|
157 |
if ( !m_Parent.setSpecificValue(m_cmd_id, val) ) { |
---|
158 |
debugError( "setSpecificValue failed\n" ); |
---|
159 |
return false; |
---|
160 |
} else return true; |
---|
161 |
} |
---|
162 |
|
---|
163 |
int |
---|
164 |
BinaryControl::getValue() |
---|
165 |
{ |
---|
166 |
uint32_t val=0; |
---|
167 |
|
---|
168 |
if ( !m_Parent.getSpecificValue(m_cmd_id, &val) ) { |
---|
169 |
debugError( "getSpecificValue failed\n" ); |
---|
170 |
return 0; |
---|
171 |
} else { |
---|
172 |
debugOutput(DEBUG_LEVEL_VERBOSE, "getValue for %d = %d\n", |
---|
173 |
m_cmd_id, val); |
---|
174 |
return val; |
---|
175 |
} |
---|
176 |
} |
---|
177 |
|
---|
178 |
// --- element implementation classes |
---|
179 |
|
---|
180 |
VolumeControl::VolumeControl(FocusriteDevice& parent, int id) |
---|
181 |
: Control::Discrete() |
---|
182 |
, m_Parent(parent) |
---|
183 |
, m_cmd_id ( id ) |
---|
184 |
{} |
---|
185 |
VolumeControl::VolumeControl(FocusriteDevice& parent, int id, |
---|
186 |
std::string name, std::string label, std::string descr) |
---|
187 |
: Control::Discrete() |
---|
188 |
, m_Parent(parent) |
---|
189 |
, m_cmd_id ( id ) |
---|
190 |
{ |
---|
191 |
setName(name); |
---|
192 |
setLabel(label); |
---|
193 |
setDescription(descr); |
---|
194 |
} |
---|
195 |
|
---|
196 |
|
---|
197 |
bool |
---|
198 |
VolumeControl::setValue(int v) |
---|
199 |
{ |
---|
200 |
if (v>0x07FFF) v=0x07FFF; |
---|
201 |
else if (v<0) v=0; |
---|
202 |
|
---|
203 |
debugOutput(DEBUG_LEVEL_VERBOSE, "setValue for id %d to %d\n", |
---|
204 |
m_cmd_id, v); |
---|
205 |
|
---|
206 |
if ( !m_Parent.setSpecificValue(m_cmd_id, v) ) { |
---|
207 |
debugError( "setSpecificValue failed\n" ); |
---|
208 |
return false; |
---|
209 |
} else return true; |
---|
210 |
} |
---|
211 |
|
---|
212 |
int |
---|
213 |
VolumeControl::getValue() |
---|
214 |
{ |
---|
215 |
uint32_t val=0; |
---|
216 |
|
---|
217 |
if ( !m_Parent.getSpecificValue(m_cmd_id, &val) ) { |
---|
218 |
debugError( "getSpecificValue failed\n" ); |
---|
219 |
return 0; |
---|
220 |
} else { |
---|
221 |
debugOutput(DEBUG_LEVEL_VERBOSE, "getValue for %d = %d\n", |
---|
222 |
m_cmd_id, val); |
---|
223 |
return val; |
---|
224 |
} |
---|
225 |
} |
---|
226 |
|
---|
227 |
} // Focusrite |
---|
228 |
} // BeBoB |
---|