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 |
#include <netinet/in.h> |
---|
28 |
|
---|
29 |
namespace BeBoB { |
---|
30 |
namespace Focusrite { |
---|
31 |
|
---|
32 |
FocusriteDevice::FocusriteDevice( Ieee1394Service& ieee1394Service, |
---|
33 |
std::auto_ptr<ConfigRom>( configRom )) |
---|
34 |
: BeBoB::AvDevice( ieee1394Service, configRom) |
---|
35 |
{ |
---|
36 |
debugOutput( DEBUG_LEVEL_VERBOSE, "Created BeBoB::Focusrite::FocusriteDevice (NodeID %d)\n", |
---|
37 |
getConfigRom().getNodeId() ); |
---|
38 |
addOption(Util::OptionContainer::Option("useAvcForParameters", false)); |
---|
39 |
} |
---|
40 |
|
---|
41 |
void |
---|
42 |
FocusriteDevice::showDevice() |
---|
43 |
{ |
---|
44 |
debugOutput(DEBUG_LEVEL_NORMAL, "This is a BeBoB::Focusrite::FocusriteDevice\n"); |
---|
45 |
BeBoB::AvDevice::showDevice(); |
---|
46 |
} |
---|
47 |
|
---|
48 |
void |
---|
49 |
FocusriteDevice::setVerboseLevel(int l) |
---|
50 |
{ |
---|
51 |
debugOutput( DEBUG_LEVEL_VERBOSE, "Setting verbose level to %d...\n", l ); |
---|
52 |
|
---|
53 |
BeBoB::AvDevice::setVerboseLevel(l); |
---|
54 |
} |
---|
55 |
|
---|
56 |
bool |
---|
57 |
FocusriteDevice::setSpecificValue(uint32_t id, uint32_t v) |
---|
58 |
{ |
---|
59 |
bool use_avc=false; |
---|
60 |
if(!getOption("useAvcForParameters", use_avc)) { |
---|
61 |
debugWarning("Could not retrieve useAvcForParameters parameter, defauling to false\n"); |
---|
62 |
} |
---|
63 |
if (use_avc) { |
---|
64 |
return setSpecificValueAvc(id, v); |
---|
65 |
} else { |
---|
66 |
return setSpecificValueARM(id, v); |
---|
67 |
} |
---|
68 |
} |
---|
69 |
|
---|
70 |
bool |
---|
71 |
FocusriteDevice::getSpecificValue(uint32_t id, uint32_t *v) |
---|
72 |
{ |
---|
73 |
bool use_avc=false; |
---|
74 |
if(!getOption("useAvcForParameters", use_avc)) { |
---|
75 |
debugWarning("Could not retrieve useAvcForParameters parameter, defauling to false\n"); |
---|
76 |
} |
---|
77 |
if (use_avc) { |
---|
78 |
return getSpecificValueAvc(id, v); |
---|
79 |
} else { |
---|
80 |
return getSpecificValueARM(id, v); |
---|
81 |
} |
---|
82 |
} |
---|
83 |
|
---|
84 |
// The AV/C methods to set parameters |
---|
85 |
bool |
---|
86 |
FocusriteDevice::setSpecificValueAvc(uint32_t id, uint32_t v) |
---|
87 |
{ |
---|
88 |
|
---|
89 |
FocusriteVendorDependentCmd cmd( get1394Service() ); |
---|
90 |
cmd.setCommandType( AVC::AVCCommand::eCT_Control ); |
---|
91 |
cmd.setNodeId( getConfigRom().getNodeId() ); |
---|
92 |
cmd.setSubunitType( AVC::eST_Unit ); |
---|
93 |
cmd.setSubunitId( 0xff ); |
---|
94 |
|
---|
95 |
cmd.setVerbose( getDebugLevel() ); |
---|
96 |
// cmd.setVerbose( DEBUG_LEVEL_VERY_VERBOSE ); |
---|
97 |
|
---|
98 |
cmd.m_id=id; |
---|
99 |
cmd.m_value=v; |
---|
100 |
|
---|
101 |
if ( !cmd.fire() ) { |
---|
102 |
debugError( "FocusriteVendorDependentCmd info command failed\n" ); |
---|
103 |
return false; |
---|
104 |
} |
---|
105 |
return true; |
---|
106 |
} |
---|
107 |
|
---|
108 |
bool |
---|
109 |
FocusriteDevice::getSpecificValueAvc(uint32_t id, uint32_t *v) |
---|
110 |
{ |
---|
111 |
|
---|
112 |
FocusriteVendorDependentCmd cmd( get1394Service() ); |
---|
113 |
cmd.setCommandType( AVC::AVCCommand::eCT_Status ); |
---|
114 |
cmd.setNodeId( getConfigRom().getNodeId() ); |
---|
115 |
cmd.setSubunitType( AVC::eST_Unit ); |
---|
116 |
cmd.setSubunitId( 0xff ); |
---|
117 |
|
---|
118 |
cmd.setVerbose( getDebugLevel() ); |
---|
119 |
// cmd.setVerbose( DEBUG_LEVEL_VERY_VERBOSE ); |
---|
120 |
|
---|
121 |
cmd.m_id=id; |
---|
122 |
|
---|
123 |
if ( !cmd.fire() ) { |
---|
124 |
debugError( "FocusriteVendorDependentCmd info command failed\n" ); |
---|
125 |
return false; |
---|
126 |
} |
---|
127 |
|
---|
128 |
*v=cmd.m_value; |
---|
129 |
return true; |
---|
130 |
} |
---|
131 |
|
---|
132 |
// The ARM methods to set parameters |
---|
133 |
bool |
---|
134 |
FocusriteDevice::setSpecificValueARM(uint32_t id, uint32_t v) |
---|
135 |
{ |
---|
136 |
fb_quadlet_t data=v; |
---|
137 |
debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"Writing parameter address space id 0x%08lX, data: 0x%08llX\n", |
---|
138 |
id, data); |
---|
139 |
|
---|
140 |
fb_nodeaddr_t addr = FR_PARAM_SPACE_START + (id * 4); |
---|
141 |
fb_nodeid_t nodeId = getNodeId() | 0xFFC0; |
---|
142 |
|
---|
143 |
if(!m_p1394Service->write_quadlet( nodeId, addr, htonl(data) ) ) { |
---|
144 |
debugError("Could not write to node 0x%04X addr 0x%012X\n", nodeId, addr); |
---|
145 |
return false; |
---|
146 |
} |
---|
147 |
return true; |
---|
148 |
} |
---|
149 |
|
---|
150 |
bool |
---|
151 |
FocusriteDevice::getSpecificValueARM(uint32_t id, uint32_t *v) |
---|
152 |
{ |
---|
153 |
fb_quadlet_t result; |
---|
154 |
debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"Reading parameter address space id 0x%08lX\n", id); |
---|
155 |
|
---|
156 |
fb_nodeaddr_t addr = FR_PARAM_SPACE_START + (id * 4); |
---|
157 |
fb_nodeid_t nodeId = getNodeId() | 0xFFC0; |
---|
158 |
|
---|
159 |
if(!m_p1394Service->read_quadlet( nodeId, addr, &result ) ) { |
---|
160 |
debugError("Could not read from node 0x%04llX addr 0x%012llX\n", nodeId, addr); |
---|
161 |
return false; |
---|
162 |
} |
---|
163 |
|
---|
164 |
result=ntohl(result); |
---|
165 |
debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"Read result: 0x%08llX\n", result); |
---|
166 |
|
---|
167 |
*v = result; |
---|
168 |
return true; |
---|
169 |
} |
---|
170 |
|
---|
171 |
int |
---|
172 |
FocusriteDevice::convertDefToSr( uint32_t def ) { |
---|
173 |
switch(def) { |
---|
174 |
case FOCUSRITE_CMD_SAMPLERATE_44K1: return 44100; |
---|
175 |
case FOCUSRITE_CMD_SAMPLERATE_48K: return 48000; |
---|
176 |
case FOCUSRITE_CMD_SAMPLERATE_88K2: return 88200; |
---|
177 |
case FOCUSRITE_CMD_SAMPLERATE_96K: return 96000; |
---|
178 |
case FOCUSRITE_CMD_SAMPLERATE_176K4: return 176400; |
---|
179 |
case FOCUSRITE_CMD_SAMPLERATE_192K: return 192000; |
---|
180 |
default: |
---|
181 |
debugWarning("Unsupported samplerate def: %08X\n", def); |
---|
182 |
return 0; |
---|
183 |
} |
---|
184 |
} |
---|
185 |
|
---|
186 |
uint32_t |
---|
187 |
FocusriteDevice::convertSrToDef( int sr ) { |
---|
188 |
switch(sr) { |
---|
189 |
case 44100: return FOCUSRITE_CMD_SAMPLERATE_44K1; |
---|
190 |
case 48000: return FOCUSRITE_CMD_SAMPLERATE_48K; |
---|
191 |
case 88200: return FOCUSRITE_CMD_SAMPLERATE_88K2; |
---|
192 |
case 96000: return FOCUSRITE_CMD_SAMPLERATE_96K; |
---|
193 |
case 176400: return FOCUSRITE_CMD_SAMPLERATE_176K4; |
---|
194 |
case 192000: return FOCUSRITE_CMD_SAMPLERATE_192K; |
---|
195 |
default: |
---|
196 |
debugWarning("Unsupported samplerate: %d\n", sr); |
---|
197 |
return 0; |
---|
198 |
} |
---|
199 |
} |
---|
200 |
|
---|
201 |
// --- element implementation classes |
---|
202 |
|
---|
203 |
BinaryControl::BinaryControl(FocusriteDevice& parent, int id, int bit) |
---|
204 |
: Control::Discrete() |
---|
205 |
, m_Parent(parent) |
---|
206 |
, m_cmd_id ( id ) |
---|
207 |
, m_cmd_bit ( bit ) |
---|
208 |
{} |
---|
209 |
BinaryControl::BinaryControl(FocusriteDevice& parent, int id, int bit, |
---|
210 |
std::string name, std::string label, std::string descr) |
---|
211 |
: Control::Discrete() |
---|
212 |
, m_Parent(parent) |
---|
213 |
, m_cmd_id ( id ) |
---|
214 |
, m_cmd_bit ( bit ) |
---|
215 |
{ |
---|
216 |
setName(name); |
---|
217 |
setLabel(label); |
---|
218 |
setDescription(descr); |
---|
219 |
} |
---|
220 |
|
---|
221 |
bool |
---|
222 |
BinaryControl::setValue(int v) |
---|
223 |
{ |
---|
224 |
uint32_t reg; |
---|
225 |
uint32_t old_reg; |
---|
226 |
|
---|
227 |
if ( !m_Parent.getSpecificValue(m_cmd_id, ®) ) { |
---|
228 |
debugError( "getSpecificValue failed\n" ); |
---|
229 |
return 0; |
---|
230 |
} |
---|
231 |
|
---|
232 |
old_reg=reg; |
---|
233 |
if (v) { |
---|
234 |
reg |= (1<<m_cmd_bit); |
---|
235 |
} else { |
---|
236 |
reg &= ~(1<<m_cmd_bit); |
---|
237 |
} |
---|
238 |
debugOutput(DEBUG_LEVEL_VERBOSE, "setValue for id %d to %d (reg: 0x%08X => 0x%08X)\n", |
---|
239 |
m_cmd_id, v, old_reg, reg); |
---|
240 |
|
---|
241 |
if ( !m_Parent.setSpecificValue(m_cmd_id, reg) ) { |
---|
242 |
debugError( "setSpecificValue failed\n" ); |
---|
243 |
return false; |
---|
244 |
} else return true; |
---|
245 |
} |
---|
246 |
|
---|
247 |
int |
---|
248 |
BinaryControl::getValue() |
---|
249 |
{ |
---|
250 |
uint32_t reg; |
---|
251 |
|
---|
252 |
if ( !m_Parent.getSpecificValue(m_cmd_id, ®) ) { |
---|
253 |
debugError( "getSpecificValue failed\n" ); |
---|
254 |
return 0; |
---|
255 |
} else { |
---|
256 |
bool val= (reg & (1<<m_cmd_bit)) != 0; |
---|
257 |
debugOutput(DEBUG_LEVEL_VERBOSE, "getValue for %d: reg: 0x%08X, result=%d\n", |
---|
258 |
m_cmd_id, reg, val); |
---|
259 |
return val; |
---|
260 |
} |
---|
261 |
} |
---|
262 |
|
---|
263 |
// --- element implementation classes |
---|
264 |
|
---|
265 |
VolumeControl::VolumeControl(FocusriteDevice& parent, int id) |
---|
266 |
: Control::Discrete() |
---|
267 |
, m_Parent(parent) |
---|
268 |
, m_cmd_id ( id ) |
---|
269 |
{} |
---|
270 |
VolumeControl::VolumeControl(FocusriteDevice& parent, int id, |
---|
271 |
std::string name, std::string label, std::string descr) |
---|
272 |
: Control::Discrete() |
---|
273 |
, m_Parent(parent) |
---|
274 |
, m_cmd_id ( id ) |
---|
275 |
{ |
---|
276 |
setName(name); |
---|
277 |
setLabel(label); |
---|
278 |
setDescription(descr); |
---|
279 |
} |
---|
280 |
|
---|
281 |
|
---|
282 |
bool |
---|
283 |
VolumeControl::setValue(int v) |
---|
284 |
{ |
---|
285 |
if (v>0x07FFF) v=0x07FFF; |
---|
286 |
else if (v<0) v=0; |
---|
287 |
|
---|
288 |
debugOutput(DEBUG_LEVEL_VERBOSE, "setValue for id %d to %d\n", |
---|
289 |
m_cmd_id, v); |
---|
290 |
|
---|
291 |
if ( !m_Parent.setSpecificValue(m_cmd_id, v) ) { |
---|
292 |
debugError( "setSpecificValue failed\n" ); |
---|
293 |
return false; |
---|
294 |
} else return true; |
---|
295 |
} |
---|
296 |
|
---|
297 |
int |
---|
298 |
VolumeControl::getValue() |
---|
299 |
{ |
---|
300 |
uint32_t val=0; |
---|
301 |
|
---|
302 |
if ( !m_Parent.getSpecificValue(m_cmd_id, &val) ) { |
---|
303 |
debugError( "getSpecificValue failed\n" ); |
---|
304 |
return 0; |
---|
305 |
} else { |
---|
306 |
debugOutput(DEBUG_LEVEL_VERBOSE, "getValue for %d = %d\n", |
---|
307 |
m_cmd_id, val); |
---|
308 |
return val; |
---|
309 |
} |
---|
310 |
} |
---|
311 |
|
---|
312 |
// low resolution volume control |
---|
313 |
VolumeControlLowRes::VolumeControlLowRes(FocusriteDevice& parent, int id, int shift) |
---|
314 |
: Control::Discrete() |
---|
315 |
, m_Parent(parent) |
---|
316 |
, m_cmd_id ( id ) |
---|
317 |
, m_bit_shift( shift ) |
---|
318 |
{} |
---|
319 |
VolumeControlLowRes::VolumeControlLowRes(FocusriteDevice& parent, int id, int shift, |
---|
320 |
std::string name, std::string label, std::string descr) |
---|
321 |
: Control::Discrete() |
---|
322 |
, m_Parent(parent) |
---|
323 |
, m_cmd_id ( id ) |
---|
324 |
, m_bit_shift( shift ) |
---|
325 |
{ |
---|
326 |
setName(name); |
---|
327 |
setLabel(label); |
---|
328 |
setDescription(descr); |
---|
329 |
} |
---|
330 |
|
---|
331 |
|
---|
332 |
bool |
---|
333 |
VolumeControlLowRes::setValue(int v) |
---|
334 |
{ |
---|
335 |
uint32_t reg; |
---|
336 |
uint32_t old_reg; |
---|
337 |
|
---|
338 |
if (v>0xFF) v=0xFF; |
---|
339 |
else if (v<0) v=0; |
---|
340 |
|
---|
341 |
if ( !m_Parent.getSpecificValue(m_cmd_id, ®) ) { |
---|
342 |
debugError( "getSpecificValue failed\n" ); |
---|
343 |
return 0; |
---|
344 |
} |
---|
345 |
|
---|
346 |
old_reg=reg; |
---|
347 |
reg &= ~(0xFF<<m_bit_shift); |
---|
348 |
reg |= (v<<m_bit_shift); |
---|
349 |
|
---|
350 |
debugOutput(DEBUG_LEVEL_VERBOSE, "setValue for id %d to %d, shift %d (reg: 0x%08X => 0x%08X)\n", |
---|
351 |
m_cmd_id, v, m_bit_shift, old_reg, reg); |
---|
352 |
|
---|
353 |
if ( !m_Parent.setSpecificValue(m_cmd_id, reg) ) { |
---|
354 |
debugError( "setSpecificValue failed\n" ); |
---|
355 |
return false; |
---|
356 |
} else return true; |
---|
357 |
} |
---|
358 |
|
---|
359 |
int |
---|
360 |
VolumeControlLowRes::getValue() |
---|
361 |
{ |
---|
362 |
uint32_t val, reg; |
---|
363 |
|
---|
364 |
if ( !m_Parent.getSpecificValue(m_cmd_id, ®) ) { |
---|
365 |
debugError( "getSpecificValue failed\n" ); |
---|
366 |
return 0; |
---|
367 |
} else { |
---|
368 |
val = (reg & 0xFF)>>m_bit_shift; |
---|
369 |
debugOutput(DEBUG_LEVEL_VERBOSE, "getValue for %d: reg: 0x%08X, result=%d\n", |
---|
370 |
m_cmd_id, reg, val); |
---|
371 |
return val; |
---|
372 |
} |
---|
373 |
} |
---|
374 |
|
---|
375 |
|
---|
376 |
// Saffire pro matrix mixer element |
---|
377 |
|
---|
378 |
FocusriteMatrixMixer::FocusriteMatrixMixer(FocusriteDevice& p) |
---|
379 |
: Control::MatrixMixer("MatrixMixer") |
---|
380 |
, m_Parent(p) |
---|
381 |
{ |
---|
382 |
} |
---|
383 |
|
---|
384 |
FocusriteMatrixMixer::FocusriteMatrixMixer(FocusriteDevice& p,std::string n) |
---|
385 |
: Control::MatrixMixer(n) |
---|
386 |
, m_Parent(p) |
---|
387 |
{ |
---|
388 |
} |
---|
389 |
|
---|
390 |
void FocusriteMatrixMixer::addSignalInfo(std::vector<struct sSignalInfo> &target, |
---|
391 |
std::string name, std::string label, std::string descr) |
---|
392 |
{ |
---|
393 |
struct sSignalInfo s; |
---|
394 |
s.name=name; |
---|
395 |
s.label=label; |
---|
396 |
s.description=descr; |
---|
397 |
|
---|
398 |
target.push_back(s); |
---|
399 |
} |
---|
400 |
|
---|
401 |
void FocusriteMatrixMixer::setCellInfo(int row, int col, int addr, bool valid) |
---|
402 |
{ |
---|
403 |
struct sCellInfo c; |
---|
404 |
c.row=row; |
---|
405 |
c.col=col; |
---|
406 |
c.valid=valid; |
---|
407 |
c.address=addr; |
---|
408 |
|
---|
409 |
m_CellInfo[row][col]=c; |
---|
410 |
} |
---|
411 |
|
---|
412 |
void FocusriteMatrixMixer::show() |
---|
413 |
{ |
---|
414 |
debugOutput(DEBUG_LEVEL_NORMAL, "Focusrite Matrix mixer\n"); |
---|
415 |
} |
---|
416 |
|
---|
417 |
std::string FocusriteMatrixMixer::getRowName( const int row ) |
---|
418 |
{ |
---|
419 |
debugOutput(DEBUG_LEVEL_VERBOSE, "name for row %d is %s\n", |
---|
420 |
row, m_RowInfo.at(row).name.c_str()); |
---|
421 |
return m_RowInfo.at(row).name; |
---|
422 |
} |
---|
423 |
|
---|
424 |
std::string FocusriteMatrixMixer::getColName( const int col ) |
---|
425 |
{ |
---|
426 |
debugOutput(DEBUG_LEVEL_VERBOSE, "name for col %d is %s\n", |
---|
427 |
col, m_ColInfo.at(col).name.c_str()); |
---|
428 |
return m_ColInfo.at(col).name; |
---|
429 |
} |
---|
430 |
|
---|
431 |
int FocusriteMatrixMixer::canWrite( const int row, const int col ) |
---|
432 |
{ |
---|
433 |
debugOutput(DEBUG_LEVEL_VERBOSE, "canWrite for row %d col %d is %d\n", |
---|
434 |
row, col, m_CellInfo.at(row).at(col).valid); |
---|
435 |
return m_CellInfo.at(row).at(col).valid; |
---|
436 |
} |
---|
437 |
|
---|
438 |
double FocusriteMatrixMixer::setValue( const int row, const int col, const double val ) |
---|
439 |
{ |
---|
440 |
int32_t v=val; |
---|
441 |
struct sCellInfo c=m_CellInfo.at(row).at(col); |
---|
442 |
|
---|
443 |
debugOutput(DEBUG_LEVEL_VERBOSE, "setValue for id %d row %d col %d to %lf (%ld)\n", |
---|
444 |
c.address, row, col, val, v); |
---|
445 |
|
---|
446 |
if (v>0x07FFF) v=0x07FFF; |
---|
447 |
else if (v<0) v=0; |
---|
448 |
|
---|
449 |
if ( !m_Parent.setSpecificValue(c.address, v) ) { |
---|
450 |
debugError( "setSpecificValue failed\n" ); |
---|
451 |
return false; |
---|
452 |
} else return true; |
---|
453 |
} |
---|
454 |
|
---|
455 |
double FocusriteMatrixMixer::getValue( const int row, const int col ) |
---|
456 |
{ |
---|
457 |
struct sCellInfo c=m_CellInfo.at(row).at(col); |
---|
458 |
uint32_t val=0; |
---|
459 |
|
---|
460 |
if ( !m_Parent.getSpecificValue(c.address, &val) ) { |
---|
461 |
debugError( "getSpecificValue failed\n" ); |
---|
462 |
return 0; |
---|
463 |
} else { |
---|
464 |
debugOutput(DEBUG_LEVEL_VERBOSE, "getValue for id %d row %d col %d = %lu\n", |
---|
465 |
c.address, row, col, val); |
---|
466 |
return val; |
---|
467 |
} |
---|
468 |
} |
---|
469 |
|
---|
470 |
int FocusriteMatrixMixer::getRowCount( ) |
---|
471 |
{ |
---|
472 |
return m_RowInfo.size(); |
---|
473 |
} |
---|
474 |
|
---|
475 |
int FocusriteMatrixMixer::getColCount( ) |
---|
476 |
{ |
---|
477 |
return m_ColInfo.size(); |
---|
478 |
} |
---|
479 |
|
---|
480 |
|
---|
481 |
} // Focusrite |
---|
482 |
} // BeBoB |
---|