root/trunk/libffado/src/bebob/focusrite/focusrite_saffirepro.cpp

Revision 783, 32.2 kB (checked in by ppalmers, 14 years ago)

cleanup time/wait/sleep code

Line 
1 /*
2  * Copyright (C) 2005-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 program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #include "focusrite_saffirepro.h"
25 #include "focusrite_cmd.h"
26
27 #include "libutil/Time.h"
28
29 namespace BeBoB {
30 namespace Focusrite {
31
32 SaffireProDevice::SaffireProDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom ))
33     : FocusriteDevice( d, configRom )
34     , m_MixerContainer( NULL )
35     , m_ControlContainer( NULL )
36 {
37     debugOutput( DEBUG_LEVEL_VERBOSE, "Created BeBoB::Focusrite::SaffireProDevice (NodeID %d)\n",
38                  getConfigRom().getNodeId() );
39
40     addOption(Util::OptionContainer::Option("rebootOnSamplerateChange", true));
41     // the saffire pro doesn't seem to like it if the commands are too fast
42     if (AVC::AVCCommand::getSleepAfterAVCCommand() < 500) {
43         AVC::AVCCommand::setSleepAfterAVCCommand( 500 );
44     }
45 }
46
47 SaffireProDevice::~SaffireProDevice()
48 {
49     destroyMixer();
50 }
51
52 bool
53 SaffireProDevice::buildMixer()
54 {
55     bool result=true;
56     debugOutput(DEBUG_LEVEL_VERBOSE, "Building a Focusrite SaffirePro mixer...\n");
57    
58     destroyMixer();
59    
60     // create the mixer object container
61     m_MixerContainer = new Control::Container("Mixer");
62
63     if (!m_MixerContainer) {
64         debugError("Could not create mixer container...\n");
65         return false;
66     }
67
68     // output mute controls
69     result &= m_MixerContainer->addElement(
70         new BinaryControl(*this,
71                 FR_SAFFIREPRO_CMD_ID_BITFIELD_OUT12, FR_SAFFIREPRO_CMD_BITFIELD_BIT_MUTE,
72                 "Out12Mute", "Out1/2 Mute", "Output 1/2 Mute"));
73     result &= m_MixerContainer->addElement(
74         new BinaryControl(*this,
75                 FR_SAFFIREPRO_CMD_ID_BITFIELD_OUT34, FR_SAFFIREPRO_CMD_BITFIELD_BIT_MUTE,
76                 "Out34Mute", "Out3/4 Mute", "Output 3/4 Mute"));
77     result &= m_MixerContainer->addElement(
78         new BinaryControl(*this,
79                 FR_SAFFIREPRO_CMD_ID_BITFIELD_OUT56, FR_SAFFIREPRO_CMD_BITFIELD_BIT_MUTE,
80                 "Out56Mute", "Out5/6 Mute", "Output 5/6 Mute"));
81     result &= m_MixerContainer->addElement(
82         new BinaryControl(*this,
83                 FR_SAFFIREPRO_CMD_ID_BITFIELD_OUT78, FR_SAFFIREPRO_CMD_BITFIELD_BIT_MUTE,
84                 "Out78Mute", "Out7/8 Mute", "Output 7/8 Mute"));
85
86     // output front panel hw volume control
87     result &= m_MixerContainer->addElement(
88         new BinaryControl(*this,
89                 FR_SAFFIREPRO_CMD_ID_BITFIELD_OUT12, FR_SAFFIREPRO_CMD_BITFIELD_BIT_HWCTRL,
90                 "Out12HwCtrl", "Out1/2 HwCtrl", "Output 1/2 Front Panel Hardware volume control"));
91     result &= m_MixerContainer->addElement(
92         new BinaryControl(*this,
93                 FR_SAFFIREPRO_CMD_ID_BITFIELD_OUT34, FR_SAFFIREPRO_CMD_BITFIELD_BIT_HWCTRL,
94                 "Out34HwCtrl", "Out3/4 HwCtrl", "Output 3/4 Front Panel Hardware volume control"));
95     result &= m_MixerContainer->addElement(
96         new BinaryControl(*this,
97                 FR_SAFFIREPRO_CMD_ID_BITFIELD_OUT56, FR_SAFFIREPRO_CMD_BITFIELD_BIT_HWCTRL,
98                 "Out56HwCtrl", "Out5/6 HwCtrl", "Output 5/6 Front Panel Hardware volume control"));
99     result &= m_MixerContainer->addElement(
100         new BinaryControl(*this,
101                 FR_SAFFIREPRO_CMD_ID_BITFIELD_OUT78, FR_SAFFIREPRO_CMD_BITFIELD_BIT_HWCTRL,
102                 "Out78HwCtrl", "Out7/8 HwCtrl", "Output 7/8 Front Panel Hardware volume control"));
103
104     // output active monitor padding
105     result &= m_MixerContainer->addElement(
106         new BinaryControl(*this,
107                 FR_SAFFIREPRO_CMD_ID_BITFIELD_OUT12, FR_SAFFIREPRO_CMD_BITFIELD_BIT_PAD,
108                 "Out12Pad", "Out1/2 Pad", "Output 1/2 Active Monitor Pad"));
109     result &= m_MixerContainer->addElement(
110         new BinaryControl(*this,
111                 FR_SAFFIREPRO_CMD_ID_BITFIELD_OUT34, FR_SAFFIREPRO_CMD_BITFIELD_BIT_PAD,
112                 "Out34Pad", "Out3/4 Pad", "Output 3/4 Active Monitor Pad"));
113     result &= m_MixerContainer->addElement(
114         new BinaryControl(*this,
115                 FR_SAFFIREPRO_CMD_ID_BITFIELD_OUT56, FR_SAFFIREPRO_CMD_BITFIELD_BIT_PAD,
116                 "Out56Pad", "Out5/6 Pad", "Output 5/6 Active Monitor Pad"));
117     result &= m_MixerContainer->addElement(
118         new BinaryControl(*this,
119                 FR_SAFFIREPRO_CMD_ID_BITFIELD_OUT78, FR_SAFFIREPRO_CMD_BITFIELD_BIT_PAD,
120                 "Out78Pad", "Out7/8 Pad", "Output 7/8 Active Monitor Pad"));
121
122     // output level dim
123     result &= m_MixerContainer->addElement(
124         new BinaryControl(*this,
125                 FR_SAFFIREPRO_CMD_ID_BITFIELD_OUT12, FR_SAFFIREPRO_CMD_BITFIELD_BIT_DIM,
126                 "Out12Dim", "Out1/2 Dim", "Output 1/2 Level Dim"));
127     result &= m_MixerContainer->addElement(
128         new BinaryControl(*this,
129                 FR_SAFFIREPRO_CMD_ID_BITFIELD_OUT34, FR_SAFFIREPRO_CMD_BITFIELD_BIT_DIM,
130                 "Out34Dim", "Out3/4 Dim", "Output 3/4 Level Dim"));
131     result &= m_MixerContainer->addElement(
132         new BinaryControl(*this,
133                 FR_SAFFIREPRO_CMD_ID_BITFIELD_OUT56, FR_SAFFIREPRO_CMD_BITFIELD_BIT_DIM,
134                 "Out56Dim", "Out5/6 Dim", "Output 5/6 Level Dim"));
135     result &= m_MixerContainer->addElement(
136         new BinaryControl(*this,
137                 FR_SAFFIREPRO_CMD_ID_BITFIELD_OUT78, FR_SAFFIREPRO_CMD_BITFIELD_BIT_DIM,
138                 "Out78Dim", "Out7/8 Dim", "Output 7/8 Level Dim"));
139
140     // output level controls
141     result &= m_MixerContainer->addElement(
142         new VolumeControlLowRes(*this,
143                 FR_SAFFIREPRO_CMD_ID_BITFIELD_OUT12, 0,
144                 "Out12Level", "Out1/2 Level", "Output 1/2 Level"));
145     result &= m_MixerContainer->addElement(
146         new VolumeControlLowRes(*this,
147                 FR_SAFFIREPRO_CMD_ID_BITFIELD_OUT34, 0,
148                 "Out34Level", "Out3/4 Level", "Output 3/4 Level"));
149     result &= m_MixerContainer->addElement(
150         new VolumeControlLowRes(*this,
151                 FR_SAFFIREPRO_CMD_ID_BITFIELD_OUT56, 0,
152                 "Out56Level", "Out5/6 Level", "Output 5/6 Level"));
153     result &= m_MixerContainer->addElement(
154         new VolumeControlLowRes(*this,
155                 FR_SAFFIREPRO_CMD_ID_BITFIELD_OUT78, 0,
156                 "Out78Level", "Out7/8 Level", "Output 7/8 Level"));
157
158     // indicators
159     result &= m_MixerContainer->addElement(
160         new BinaryControl(*this,
161                 FR_SAFFIREPRO_CMD_ID_MUTE_INDICATOR, 0,
162                 "Out12MuteInd", "Out1/2 Mute Ind", "Output 1/2 Mute Indicator"));
163
164     result &= m_MixerContainer->addElement(
165         new BinaryControl(*this,
166                 FR_SAFFIREPRO_CMD_ID_DIM_INDICATOR, 0,
167                 "Out12DimInd", "Out1/2 Dim Ind", "Output 1/2 Level Dim Indicator"));
168
169     // matrix mix controls
170     result &= m_MixerContainer->addElement(
171         new SaffireProMatrixMixer(*this, SaffireProMatrixMixer::eMMT_InputMix, "InputMix"));
172
173     result &= m_MixerContainer->addElement(
174         new SaffireProMatrixMixer(*this, SaffireProMatrixMixer::eMMT_OutputMix, "OutputMix"));
175
176     if (!result) {
177         debugWarning("One or more mixer control elements could not be created.");
178         // clean up those that couldn't be created
179         destroyMixer();
180         return false;
181     }
182     if (!addElement(m_MixerContainer)) {
183         debugWarning("Could not register mixer to device\n");
184         // clean up
185         destroyMixer();
186         return false;
187     }
188
189     // special controls
190     m_ControlContainer = new Control::Container("Control");
191     if (!m_ControlContainer) {
192         debugError("Could not create mixer container...\n");
193         return false;
194     }
195
196     // create control objects for the saffire pro
197     result &= m_ControlContainer->addElement(
198         new BinaryControl(*this, FR_SAFFIREPRO_CMD_ID_PHANTOM14, 0,
199                  "Phantom_1to4", "Phantom 1-4", "Switch Phantom Power on channels 1-4"));
200    
201     result &= m_ControlContainer->addElement(
202         new BinaryControl(*this, FR_SAFFIREPRO_CMD_ID_PHANTOM58, 0,
203                  "Phantom_5to8", "Phantom 5-8", "Switch Phantom Power on channels 5-8"));
204    
205     result &= m_ControlContainer->addElement(
206         new BinaryControl(*this, FR_SAFFIREPRO_CMD_ID_INSERT1, 0,
207                 "Insert1", "Insert 1", "Switch Insert on Channel 1"));
208    
209     result &= m_ControlContainer->addElement(
210         new BinaryControl(*this, FR_SAFFIREPRO_CMD_ID_INSERT2, 0,
211                 "Insert2", "Insert 2", "Switch Insert on Channel 2"));
212    
213     result &= m_ControlContainer->addElement(
214         new BinaryControl(*this, FR_SAFFIREPRO_CMD_ID_AC3_PASSTHROUGH, 0,
215                 "AC3pass", "AC3 Passtrough", "Enable AC3 Passthrough"));
216    
217     result &= m_ControlContainer->addElement(
218         new BinaryControl(*this, FR_SAFFIREPRO_CMD_ID_MIDI_TRU, 0,
219                 "MidiTru", "Midi Tru", "Enable Midi Tru"));
220    
221     result &= m_ControlContainer->addElement(
222         new SaffireProMultiControl(*this, SaffireProMultiControl::eTCT_Reboot,
223             "Reboot", "Reboot", "Reboot Device"));
224
225     result &= m_ControlContainer->addElement(
226         new SaffireProMultiControl(*this, SaffireProMultiControl::eTCT_FlashLed,
227             "FlashLed", "Flash Led", "Flash power led"));
228
229     result &= m_ControlContainer->addElement(
230         new SaffireProMultiControl(*this, SaffireProMultiControl::eTCT_UseHighVoltageRail,
231             "UseHighVoltageRail", "Use High Supply", "Prefer the high voltage power supply rail"));
232
233     if (!result) {
234         debugWarning("One or more device control elements could not be created.");
235         // clean up those that couldn't be created
236         destroyMixer();
237         return false;
238     }
239     if (!addElement(m_ControlContainer)) {
240         debugWarning("Could not register controls to device\n");
241         // clean up
242         destroyMixer();
243         return false;
244     }
245
246
247     return true;
248 }
249
250 bool
251 SaffireProDevice::destroyMixer()
252 {
253     debugOutput(DEBUG_LEVEL_VERBOSE, "destroy mixer...\n");
254    
255     if (m_MixerContainer == NULL) {
256         debugOutput(DEBUG_LEVEL_VERBOSE, "no mixer to destroy...\n");
257         return true;
258     }
259    
260     if (!deleteElement(m_MixerContainer)) {
261         debugError("Mixer present but not registered to the avdevice\n");
262         return false;
263     }
264    
265     // remove and delete (as in free) child control elements
266     m_MixerContainer->clearElements(true);
267     delete m_MixerContainer;
268     m_MixerContainer = NULL;
269
270     // remove control container
271     if (m_ControlContainer == NULL) {
272         debugOutput(DEBUG_LEVEL_VERBOSE, "no controls to destroy...\n");
273         return true;
274     }
275    
276     if (!deleteElement(m_ControlContainer)) {
277         debugError("Controls present but not registered to the avdevice\n");
278         return false;
279     }
280    
281     // remove and delete (as in free) child control elements
282     m_ControlContainer->clearElements(true);
283     delete m_ControlContainer;
284     m_ControlContainer = NULL;
285
286     return true;
287 }
288
289 void
290 SaffireProDevice::showDevice()
291 {
292     debugOutput(DEBUG_LEVEL_VERBOSE, "This is a BeBoB::Focusrite::SaffireProDevice\n");
293     FocusriteDevice::showDevice();
294 }
295
296 void
297 SaffireProDevice::setVerboseLevel(int l)
298 {
299     debugOutput( DEBUG_LEVEL_VERBOSE, "Setting verbose level to %d...\n", l );
300
301     if (m_MixerContainer) m_MixerContainer->setVerboseLevel(l);
302
303     // FIXME: add the other elements here too
304
305     FocusriteDevice::setVerboseLevel(l);
306 }
307
308 int
309 SaffireProDevice::getSamplingFrequency( ) {
310     uint32_t sr;
311     if ( !getSpecificValue(FR_SAFFIREPRO_CMD_ID_SAMPLERATE, &sr ) ) {
312         debugError( "getSpecificValue failed\n" );
313         return 0;
314     }
315    
316     debugOutput( DEBUG_LEVEL_VERBOSE,
317                      "getSampleRate: %d\n", sr );
318
319     return convertDefToSr(sr);
320 }
321
322 bool
323 SaffireProDevice::setSamplingFrequencyDo( uint32_t value )
324 {
325     if ( !setSpecificValue(FR_SAFFIREPRO_CMD_ID_SAMPLERATE, value) ) {
326         debugError( "setSpecificValue failed\n" );
327         return false;
328     }
329     return true;
330 }
331
332 bool
333 SaffireProDevice::setSamplingFrequencyDoNoReboot( uint32_t value )
334 {
335     if ( !setSpecificValue(FR_SAFFIREPRO_CMD_ID_SAMPLERATE_NOREBOOT, value) ) {
336         debugError( "setSpecificValue failed\n" );
337         return false;
338     }
339     return true;
340 }
341
342 bool
343 SaffireProDevice::setSamplingFrequency( int s )
344 {
345     bool snoopMode=false;
346     if(!getOption("snoopMode", snoopMode)) {
347         debugWarning("Could not retrieve snoopMode parameter, defauling to false\n");
348     }
349
350     bool rebootOnSamplerateChange=false;
351     if(!getOption("rebootOnSamplerateChange", rebootOnSamplerateChange)) {
352         debugWarning("Could not retrieve rebootOnSamplerateChange parameter, defauling to false\n");
353     }
354
355     if(snoopMode) {
356         if (s != getSamplingFrequency()) {
357             debugError("In snoop mode it is impossible to set the sample rate.\n");
358             debugError("Please start the client with the correct setting.\n");
359             return false;
360         }
361         return true;
362     } else {
363         uint32_t value = convertSrToDef(s);
364         if ( value == 0 ) {
365             debugError("Unsupported samplerate: %u\n", s);
366             return false;
367         }
368    
369         if (s == getSamplingFrequency()) {
370             debugOutput( DEBUG_LEVEL_VERBOSE, "No need to change samplerate\n");
371             return true;
372         }
373
374         const int max_tries = 2;
375         int ntries = max_tries+1;
376        
377         unsigned int gen_before = get1394Service().getGeneration();
378        
379         while(--ntries) {
380             if (rebootOnSamplerateChange) {
381                 debugOutput( DEBUG_LEVEL_VERBOSE, "Setting samplerate with reboot\n");
382                 if(!setSamplingFrequencyDo( value )) {
383                     debugWarning("setSamplingFrequencyDo failed\n");
384                 }
385
386                 debugOutput( DEBUG_LEVEL_VERBOSE, "Waiting for device to finish rebooting...\n");
387
388                 // the device needs quite some time to reboot
389                 SleepRelativeUsec(2 * 1000 * 1000);
390
391                 int timeout = 5; // multiples of 1s
392                 // wait for a busreset to occur
393                 while ((gen_before == get1394Service().getGeneration())
394                        && --timeout)
395                 {
396                     // wait for a while
397                     SleepRelativeUsec(1000 * 1000);
398                 }
399                 if (!timeout) {
400                     debugOutput(DEBUG_LEVEL_VERBOSE, "Device did not reset itself, forcing reboot...\n");
401                     rebootDevice();
402
403                     // the device needs quite some time to reboot
404                     SleepRelativeUsec(2 * 1000 * 1000);
405
406                     // wait for the device to finish the reboot
407                     timeout = 10; // multiples of 1s
408                     while ((gen_before == get1394Service().getGeneration())
409                            && --timeout)
410                     {
411                         // wait for a while
412                         SleepRelativeUsec(1000 * 1000);
413                     }
414                     if (!timeout) {
415                         debugError( "Device did not reset itself after forced reboot...\n");
416                         return false;
417                     }
418                 }
419
420                 // so we know the device is rebooting
421                 // now wait until it stops generating busresets
422                 timeout = 10;
423                 unsigned int gen_current;
424                 do {
425                     gen_current=get1394Service().getGeneration();
426                     debugOutput(DEBUG_LEVEL_VERBOSE, "Waiting... (gen: %u)\n", gen_current);
427
428                     // wait for a while
429                     SleepRelativeUsec(4 * 1000 * 1000);
430                 } while (gen_current != get1394Service().getGeneration()
431                          && --timeout);
432
433                 if (!timeout) {
434                     debugError( "Device did not recover from reboot...\n");
435                     return false;
436                 }
437
438                 debugOutput(DEBUG_LEVEL_VERBOSE, "Device available (gen: %u => %u)...\n",
439                     gen_before, get1394Service().getGeneration());
440
441                 // wait some more
442                 SleepRelativeUsec(1 * 1000 * 1000);
443
444                 // we have to rediscover the device
445                 if (discover()) break;
446             } else {
447                 debugOutput( DEBUG_LEVEL_VERBOSE, "Setting samplerate without reboot\n");
448                 if(!setSamplingFrequencyDoNoReboot( value )) {
449                     debugWarning("setSamplingFrequencyDoNoReboot failed\n");
450                 }
451             }
452
453             int verify=getSamplingFrequency();
454             debugOutput( DEBUG_LEVEL_VERBOSE,
455                         "setSampleRate (try %d): requested samplerate %d, device now has %d\n",
456                         max_tries-ntries, s, verify );
457
458             if (s == verify) {
459                 break;
460             }
461             debugOutput( DEBUG_LEVEL_VERBOSE, "setSampleRate (try %d) failed. Try again...\n" );
462         }
463
464         if (ntries==0) {
465             debugError("Setting samplerate failed...\n");
466             return false;
467         }
468
469         return true;
470     }
471     // not executable
472     return false;
473
474 }
475
476 void
477 SaffireProDevice::rebootDevice() {
478     debugOutput( DEBUG_LEVEL_VERBOSE, "rebooting device...\n" );
479     if ( !setSpecificValue(FR_SAFFIREPRO_CMD_ID_REBOOT,
480                            FR_SAFFIREPRO_CMD_REBOOT_CODE ) ) {
481         debugError( "setSpecificValue failed\n" );
482     }
483 }
484
485 void
486 SaffireProDevice::flashLed() {
487     int ledFlashDuration=2;
488     if(!getOption("ledFlashDuration", ledFlashDuration)) {
489         debugWarning("Could not retrieve ledFlashDuration parameter, defaulting to 2sec\n");
490     }
491     int ledFlashFrequency=10;
492     if(!getOption("ledFlashFrequency", ledFlashFrequency)) {
493         debugWarning("Could not retrieve ledFlashFrequency parameter, defaulting to 10Hz\n");
494     }
495
496     uint32_t reg=0;
497     debugOutput( DEBUG_LEVEL_VERBOSE, "flashing led ...\n" );
498    
499     reg = FR_SAFFIREPRO_CMD_SET_FLASH_SECS(reg, ledFlashDuration);
500     reg = FR_SAFFIREPRO_CMD_SET_FLASH_FREQ(reg, ledFlashFrequency);
501    
502     if ( !setSpecificValue(FR_SAFFIREPRO_CMD_ID_FLASH_LED,
503                            reg ) ) {
504         debugError( "setSpecificValue failed\n" );
505     }
506 }
507
508 bool
509 SaffireProDevice::isAudioOn() {
510     uint32_t ready;
511     if ( !getSpecificValue(FR_SAFFIREPRO_CMD_ID_AUDIO_ON, &ready ) ) {
512         debugError( "getSpecificValue failed\n" );
513         return false;
514     }
515
516     debugOutput( DEBUG_LEVEL_VERBOSE,
517                      "isAudioOn: %d\n", ready!=0 );
518     return ready != 0;
519 }
520
521 bool
522 SaffireProDevice::isExtClockLocked() {
523     uint32_t ready;
524     if ( !getSpecificValue(FR_SAFFIREPRO_CMD_ID_EXT_CLOCK_LOCK, &ready ) ) {
525         debugError( "getSpecificValue failed\n" );
526         return false;
527     }
528
529     debugOutput( DEBUG_LEVEL_VERBOSE,
530                      "isExtClockLocked: %d\n", ready!=0 );
531     return ready != 0;
532 }
533
534 uint32_t
535 SaffireProDevice::getCount32() {
536     uint32_t v;
537     if ( !getSpecificValue(FR_SAFFIREPRO_CMD_ID_PLAYBACK_COUNT, &v ) ) {
538         debugError( "getSpecificValue failed\n" );
539         return false;
540     }
541
542     debugOutput( DEBUG_LEVEL_VERBOSE,
543                      "getCount32: %08lX\n", v );
544     return v;
545 }
546
547 void
548 SaffireProDevice::useHighVoltageRail(bool useIt) {
549     uint32_t reg=useIt;
550     debugOutput( DEBUG_LEVEL_VERBOSE, "%s high voltage rail ...\n",
551         (useIt?"Using":"Not using") );
552
553     if ( !setSpecificValue(FR_SAFFIREPRO_CMD_ID_USE_HIGHVOLTAGE_RAIL,
554                            reg ) ) {
555         debugError( "setSpecificValue failed\n" );
556     }
557 }
558
559 bool
560 SaffireProDevice::usingHighVoltageRail() {
561     uint32_t retval;
562     if ( !getSpecificValue(FR_SAFFIREPRO_CMD_ID_USING_HIGHVOLTAGE_RAIL, &retval ) ) {
563         debugError( "getSpecificValue failed\n" );
564         return false;
565     }
566
567     debugOutput( DEBUG_LEVEL_VERBOSE,
568                      "usingHighVoltageRail: %d\n", retval!=0 );
569     return retval != 0;
570 }
571
572 // swiss army knife control element
573 SaffireProMultiControl::SaffireProMultiControl(SaffireProDevice& parent, enum eTriggerControlType t)
574 : Control::Discrete()
575 , m_Parent(parent)
576 , m_type ( t )
577 {}
578 SaffireProMultiControl::SaffireProMultiControl(SaffireProDevice& parent, enum eTriggerControlType t,
579                 std::string name, std::string label, std::string descr)
580 : Control::Discrete()
581 , m_Parent(parent)
582 , m_type ( t )
583 {
584     setName(name);
585     setLabel(label);
586     setDescription(descr);
587 }
588
589 bool
590 SaffireProMultiControl::setValue(int v)
591 {
592     switch (m_type) {
593         case eTCT_Reboot: m_Parent.rebootDevice(); return true;
594         case eTCT_FlashLed: m_Parent.flashLed(); return true;
595         case eTCT_UseHighVoltageRail: m_Parent.useHighVoltageRail(v); return true;
596     }
597     return false;
598 }
599
600 int
601 SaffireProMultiControl::getValue()
602 {
603     switch (m_type) {
604         case eTCT_Reboot: return 0;
605         case eTCT_FlashLed: return 0;
606         case eTCT_UseHighVoltageRail: return m_Parent.usingHighVoltageRail();
607     }
608     return -1;
609 }
610
611
612 // Saffire pro matrix mixer element
613
614 SaffireProMatrixMixer::SaffireProMatrixMixer(SaffireProDevice& p,
615                                              enum eMatrixMixerType type)
616 : FocusriteMatrixMixer(p, "MatrixMixer")
617 , m_type(type)
618 {
619     init();
620 }
621
622 SaffireProMatrixMixer::SaffireProMatrixMixer(SaffireProDevice& p,
623                                              enum eMatrixMixerType type, std::string n)
624 : FocusriteMatrixMixer(p, n)
625 , m_type(type)
626 {
627     init();
628 }
629
630 void SaffireProMatrixMixer::init()
631 {
632     if (m_type==eMMT_OutputMix) {
633         addSignalInfo(m_RowInfo, "PC1", "PC 1", "PC Channel 1");
634         addSignalInfo(m_RowInfo, "PC2", "PC 2", "PC Channel 2");
635         addSignalInfo(m_RowInfo, "PC3", "PC 3", "PC Channel 3");
636         addSignalInfo(m_RowInfo, "PC4", "PC 4", "PC Channel 4");
637         addSignalInfo(m_RowInfo, "PC5", "PC 5", "PC Channel 5");
638         addSignalInfo(m_RowInfo, "PC6", "PC 6", "PC Channel 6");
639         addSignalInfo(m_RowInfo, "PC7", "PC 7", "PC Channel 7");
640         addSignalInfo(m_RowInfo, "PC8", "PC 8", "PC Channel 8");
641         addSignalInfo(m_RowInfo, "PC9", "PC 9", "PC Channel 9");
642         addSignalInfo(m_RowInfo, "PC10", "PC 10", "PC Channel 10");
643         addSignalInfo(m_RowInfo, "IMIXL", "IMix L", "Input Mix Left");
644         addSignalInfo(m_RowInfo, "IMIXR", "IMix R", "Input Mix Right");
645        
646         addSignalInfo(m_ColInfo, "OUT1", "OUT 1", "Output Channel 1");
647         addSignalInfo(m_ColInfo, "OUT2", "OUT 2", "Output Channel 2");
648         addSignalInfo(m_ColInfo, "OUT3", "OUT 3", "Output Channel 3");
649         addSignalInfo(m_ColInfo, "OUT4", "OUT 4", "Output Channel 4");
650         addSignalInfo(m_ColInfo, "OUT5", "OUT 5", "Output Channel 5");
651         addSignalInfo(m_ColInfo, "OUT6", "OUT 6", "Output Channel 6");
652         addSignalInfo(m_ColInfo, "OUT7", "OUT 7", "Output Channel 7");
653         addSignalInfo(m_ColInfo, "OUT8", "OUT 8", "Output Channel 8");
654         addSignalInfo(m_ColInfo, "OUT9", "OUT 9", "Output Channel 9");
655         addSignalInfo(m_ColInfo, "OUT10", "OUT 10", "Output Channel 10");
656        
657         // init the cell matrix
658         #define FOCUSRITE_SAFFIRE_PRO_OUTMIX_NB_COLS 10
659         #define FOCUSRITE_SAFFIRE_PRO_OUTMIX_NB_ROWS 12
660        
661         std::vector<struct sCellInfo> tmp_cols( FOCUSRITE_SAFFIRE_PRO_OUTMIX_NB_COLS );
662         std::vector< std::vector<struct sCellInfo> > tmp_all(FOCUSRITE_SAFFIRE_PRO_OUTMIX_NB_ROWS, tmp_cols);
663         m_CellInfo = tmp_all;
664    
665         struct sCellInfo c;
666         c.row=-1;
667         c.col=-1;
668         c.valid=false;
669         c.address=0;
670        
671         for (int i=0;i<FOCUSRITE_SAFFIRE_PRO_OUTMIX_NB_ROWS;i++) {
672             for (int j=0;j<FOCUSRITE_SAFFIRE_PRO_OUTMIX_NB_COLS;j++) {
673                 m_CellInfo[i][j]=c;
674             }
675         }
676    
677         // now set the cells that are valid
678         setCellInfo(0,0,FR_SAFFIREPRO_CMD_ID_PC1_TO_OUT1, true);
679         setCellInfo(1,1,FR_SAFFIREPRO_CMD_ID_PC2_TO_OUT2, true);
680         setCellInfo(10,0,FR_SAFFIREPRO_CMD_ID_MIX1_TO_OUT1, true);
681         setCellInfo(11,1,FR_SAFFIREPRO_CMD_ID_MIX2_TO_OUT2, true);
682         setCellInfo(0,2,FR_SAFFIREPRO_CMD_ID_PC1_TO_OUT3, true);
683         setCellInfo(1,3,FR_SAFFIREPRO_CMD_ID_PC2_TO_OUT4, true);
684         setCellInfo(2,2,FR_SAFFIREPRO_CMD_ID_PC3_TO_OUT3, true);
685         setCellInfo(3,3,FR_SAFFIREPRO_CMD_ID_PC4_TO_OUT4, true);
686         setCellInfo(10,2,FR_SAFFIREPRO_CMD_ID_MIX1_TO_OUT3, true);
687         setCellInfo(11,3,FR_SAFFIREPRO_CMD_ID_MIX2_TO_OUT4, true);
688         setCellInfo(0,4,FR_SAFFIREPRO_CMD_ID_PC1_TO_OUT5, true);
689         setCellInfo(1,5,FR_SAFFIREPRO_CMD_ID_PC2_TO_OUT6, true);
690         setCellInfo(4,4,FR_SAFFIREPRO_CMD_ID_PC5_TO_OUT5, true);
691         setCellInfo(5,5,FR_SAFFIREPRO_CMD_ID_PC6_TO_OUT6, true);
692         setCellInfo(10,4,FR_SAFFIREPRO_CMD_ID_MIX1_TO_OUT5, true);
693         setCellInfo(11,5,FR_SAFFIREPRO_CMD_ID_MIX2_TO_OUT6, true);
694         setCellInfo(0,6,FR_SAFFIREPRO_CMD_ID_PC1_TO_OUT7, true);
695         setCellInfo(1,7,FR_SAFFIREPRO_CMD_ID_PC2_TO_OUT8, true);
696         setCellInfo(6,6,FR_SAFFIREPRO_CMD_ID_PC7_TO_OUT7, true);
697         setCellInfo(7,7,FR_SAFFIREPRO_CMD_ID_PC8_TO_OUT8, true);
698         setCellInfo(10,6,FR_SAFFIREPRO_CMD_ID_MIX1_TO_OUT7, true);
699         setCellInfo(11,7,FR_SAFFIREPRO_CMD_ID_MIX2_TO_OUT8, true);
700         setCellInfo(0,8,FR_SAFFIREPRO_CMD_ID_PC1_TO_OUT9, true);
701         setCellInfo(1,9,FR_SAFFIREPRO_CMD_ID_PC2_TO_OUT10, true);
702         setCellInfo(8,8,FR_SAFFIREPRO_CMD_ID_PC9_TO_OUT9, true);
703         setCellInfo(9,9,FR_SAFFIREPRO_CMD_ID_PC10_TO_OUT10, true);
704         setCellInfo(10,8,FR_SAFFIREPRO_CMD_ID_MIX1_TO_OUT9, true);
705         setCellInfo(11,9,FR_SAFFIREPRO_CMD_ID_MIX2_TO_OUT10, true);
706
707     } else if (m_type==eMMT_InputMix) {
708         addSignalInfo(m_RowInfo, "AN1", "Analog 1", "Analog Input 1");
709         addSignalInfo(m_RowInfo, "AN2", "Analog 2", "Analog Input 2");
710         addSignalInfo(m_RowInfo, "AN3", "Analog 3", "Analog Input 3");
711         addSignalInfo(m_RowInfo, "AN4", "Analog 4", "Analog Input 4");
712         addSignalInfo(m_RowInfo, "AN5", "Analog 5", "Analog Input 5");
713         addSignalInfo(m_RowInfo, "AN6", "Analog 6", "Analog Input 6");
714         addSignalInfo(m_RowInfo, "AN7", "Analog 7", "Analog Input 7");
715         addSignalInfo(m_RowInfo, "AN8", "Analog 8", "Analog Input 8");
716         addSignalInfo(m_RowInfo, "SPDIFL", "SPDIF L", "SPDIF Left Input");
717         addSignalInfo(m_RowInfo, "SPDIFR", "SPDIF R", "SPDIF Right Input");
718        
719         addSignalInfo(m_RowInfo, "ADAT11", "ADAT1 1", "ADAT1 Channel 1");
720         addSignalInfo(m_RowInfo, "ADAT12", "ADAT1 2", "ADAT1 Channel 2");
721         addSignalInfo(m_RowInfo, "ADAT13", "ADAT1 3", "ADAT1 Channel 3");
722         addSignalInfo(m_RowInfo, "ADAT14", "ADAT1 4", "ADAT1 Channel 4");
723         addSignalInfo(m_RowInfo, "ADAT15", "ADAT1 5", "ADAT1 Channel 5");
724         addSignalInfo(m_RowInfo, "ADAT16", "ADAT1 6", "ADAT1 Channel 6");
725         addSignalInfo(m_RowInfo, "ADAT17", "ADAT1 7", "ADAT1 Channel 7");
726         addSignalInfo(m_RowInfo, "ADAT18", "ADAT1 8", "ADAT1 Channel 8");
727        
728         addSignalInfo(m_RowInfo, "ADAT21", "ADAT2 1", "ADAT2 Channel 1");
729         addSignalInfo(m_RowInfo, "ADAT22", "ADAT2 2", "ADAT2 Channel 2");
730         addSignalInfo(m_RowInfo, "ADAT23", "ADAT2 3", "ADAT2 Channel 3");
731         addSignalInfo(m_RowInfo, "ADAT24", "ADAT2 4", "ADAT2 Channel 4");
732         addSignalInfo(m_RowInfo, "ADAT25", "ADAT2 5", "ADAT2 Channel 5");
733         addSignalInfo(m_RowInfo, "ADAT26", "ADAT2 6", "ADAT2 Channel 6");
734         addSignalInfo(m_RowInfo, "ADAT27", "ADAT2 7", "ADAT2 Channel 7");
735         addSignalInfo(m_RowInfo, "ADAT28", "ADAT2 8", "ADAT2 Channel 8");
736        
737         addSignalInfo(m_ColInfo, "IMIXL", "IMix L", "Input Mix Left");
738         addSignalInfo(m_ColInfo, "IMIXR", "IMix R", "Input Mix Right");
739        
740         // init the cell matrix
741         #define FOCUSRITE_SAFFIRE_PRO_INMIX_NB_COLS 2
742         #define FOCUSRITE_SAFFIRE_PRO_INMIX_NB_ROWS 26
743        
744         std::vector<struct sCellInfo> tmp_cols( FOCUSRITE_SAFFIRE_PRO_INMIX_NB_COLS );
745         std::vector< std::vector<struct sCellInfo> > tmp_all(FOCUSRITE_SAFFIRE_PRO_INMIX_NB_ROWS,tmp_cols);
746         m_CellInfo = tmp_all;
747    
748         struct sCellInfo c;
749         c.row=-1;
750         c.col=-1;
751         c.valid=false;
752         c.address=0;
753        
754         for (int i=0;i<FOCUSRITE_SAFFIRE_PRO_INMIX_NB_ROWS;i++) {
755             for (int j=0;j<FOCUSRITE_SAFFIRE_PRO_INMIX_NB_COLS;j++) {
756                 m_CellInfo[i][j]=c;
757             }
758         }
759    
760         // now set the cells that are valid
761         setCellInfo(0,0,FR_SAFFIREPRO_CMD_ID_AN1_TO_IMIXL, true);
762         setCellInfo(0,1,FR_SAFFIREPRO_CMD_ID_AN1_TO_IMIXR, true);
763         setCellInfo(1,0,FR_SAFFIREPRO_CMD_ID_AN2_TO_IMIXL, true);
764         setCellInfo(1,1,FR_SAFFIREPRO_CMD_ID_AN2_TO_IMIXR, true);
765         setCellInfo(2,0,FR_SAFFIREPRO_CMD_ID_AN3_TO_IMIXL, true);
766         setCellInfo(2,1,FR_SAFFIREPRO_CMD_ID_AN3_TO_IMIXR, true);
767         setCellInfo(3,0,FR_SAFFIREPRO_CMD_ID_AN4_TO_IMIXL, true);
768         setCellInfo(3,1,FR_SAFFIREPRO_CMD_ID_AN4_TO_IMIXR, true);
769         setCellInfo(4,0,FR_SAFFIREPRO_CMD_ID_AN5_TO_IMIXL, true);
770         setCellInfo(4,1,FR_SAFFIREPRO_CMD_ID_AN5_TO_IMIXR, true);
771         setCellInfo(5,0,FR_SAFFIREPRO_CMD_ID_AN6_TO_IMIXL, true);
772         setCellInfo(5,1,FR_SAFFIREPRO_CMD_ID_AN6_TO_IMIXR, true);
773         setCellInfo(6,0,FR_SAFFIREPRO_CMD_ID_AN7_TO_IMIXL, true);
774         setCellInfo(6,1,FR_SAFFIREPRO_CMD_ID_AN7_TO_IMIXR, true);
775         setCellInfo(7,0,FR_SAFFIREPRO_CMD_ID_AN8_TO_IMIXL, true);
776         setCellInfo(7,1,FR_SAFFIREPRO_CMD_ID_AN8_TO_IMIXR, true);
777         setCellInfo(8,0,FR_SAFFIREPRO_CMD_ID_SPDIFL_TO_IMIXL, true);
778         setCellInfo(8,1,FR_SAFFIREPRO_CMD_ID_SPDIFL_TO_IMIXR, true);
779         setCellInfo(9,0,FR_SAFFIREPRO_CMD_ID_SPDIFR_TO_IMIXL, true);
780         setCellInfo(9,1,FR_SAFFIREPRO_CMD_ID_SPDIFR_TO_IMIXR, true);
781
782         setCellInfo(10,0,FR_SAFFIREPRO_CMD_ID_ADAT11_TO_IMIXL, true);
783         setCellInfo(10,1,FR_SAFFIREPRO_CMD_ID_ADAT11_TO_IMIXR, true);
784         setCellInfo(11,0,FR_SAFFIREPRO_CMD_ID_ADAT12_TO_IMIXL, true);
785         setCellInfo(11,1,FR_SAFFIREPRO_CMD_ID_ADAT12_TO_IMIXR, true);
786         setCellInfo(12,0,FR_SAFFIREPRO_CMD_ID_ADAT13_TO_IMIXL, true);
787         setCellInfo(12,1,FR_SAFFIREPRO_CMD_ID_ADAT13_TO_IMIXR, true);
788         setCellInfo(13,0,FR_SAFFIREPRO_CMD_ID_ADAT14_TO_IMIXL, true);
789         setCellInfo(13,1,FR_SAFFIREPRO_CMD_ID_ADAT14_TO_IMIXR, true);
790         setCellInfo(14,0,FR_SAFFIREPRO_CMD_ID_ADAT15_TO_IMIXL, true);
791         setCellInfo(14,1,FR_SAFFIREPRO_CMD_ID_ADAT15_TO_IMIXR, true);
792         setCellInfo(15,0,FR_SAFFIREPRO_CMD_ID_ADAT16_TO_IMIXL, true);
793         setCellInfo(15,1,FR_SAFFIREPRO_CMD_ID_ADAT16_TO_IMIXR, true);
794         setCellInfo(16,0,FR_SAFFIREPRO_CMD_ID_ADAT17_TO_IMIXL, true);
795         setCellInfo(16,1,FR_SAFFIREPRO_CMD_ID_ADAT17_TO_IMIXR, true);
796         setCellInfo(17,0,FR_SAFFIREPRO_CMD_ID_ADAT18_TO_IMIXL, true);
797         setCellInfo(17,1,FR_SAFFIREPRO_CMD_ID_ADAT18_TO_IMIXR, true);
798
799         setCellInfo(18,0,FR_SAFFIREPRO_CMD_ID_ADAT21_TO_IMIXL, true);
800         setCellInfo(18,1,FR_SAFFIREPRO_CMD_ID_ADAT21_TO_IMIXR, true);
801         setCellInfo(19,0,FR_SAFFIREPRO_CMD_ID_ADAT22_TO_IMIXL, true);
802         setCellInfo(19,1,FR_SAFFIREPRO_CMD_ID_ADAT22_TO_IMIXR, true);
803         setCellInfo(20,0,FR_SAFFIREPRO_CMD_ID_ADAT23_TO_IMIXL, true);
804         setCellInfo(20,1,FR_SAFFIREPRO_CMD_ID_ADAT23_TO_IMIXR, true);
805         setCellInfo(21,0,FR_SAFFIREPRO_CMD_ID_ADAT24_TO_IMIXL, true);
806         setCellInfo(21,1,FR_SAFFIREPRO_CMD_ID_ADAT24_TO_IMIXR, true);
807         setCellInfo(22,0,FR_SAFFIREPRO_CMD_ID_ADAT25_TO_IMIXL, true);
808         setCellInfo(22,1,FR_SAFFIREPRO_CMD_ID_ADAT25_TO_IMIXR, true);
809         setCellInfo(23,0,FR_SAFFIREPRO_CMD_ID_ADAT26_TO_IMIXL, true);
810         setCellInfo(23,1,FR_SAFFIREPRO_CMD_ID_ADAT26_TO_IMIXR, true);
811         setCellInfo(24,0,FR_SAFFIREPRO_CMD_ID_ADAT27_TO_IMIXL, true);
812         setCellInfo(24,1,FR_SAFFIREPRO_CMD_ID_ADAT27_TO_IMIXR, true);
813         setCellInfo(25,0,FR_SAFFIREPRO_CMD_ID_ADAT28_TO_IMIXL, true);
814         setCellInfo(25,1,FR_SAFFIREPRO_CMD_ID_ADAT28_TO_IMIXR, true);
815
816     } else {
817         debugError("Invalid mixer type\n");
818     }
819 }
820
821 void SaffireProMatrixMixer::show()
822 {
823     debugOutput(DEBUG_LEVEL_NORMAL, "Saffire Pro Matrix mixer type %d\n");
824 }
825
826 } // Focusrite
827 } // BeBoB
Note: See TracBrowser for help on using the browser.