Changeset 1730 for trunk

Show
Ignore:
Timestamp:
11/23/09 13:55:36 (14 years ago)
Author:
arnonym
Message:

Save code by creating another class. Next step is unified monitoring and switches for both the pro40 and the pro24.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/src/dice/focusrite/focusrite_eap.cpp

    r1726 r1730  
    2323 */ 
    2424 
    25 #include "saffire_pro24.h" 
     25#include "focusrite_eap.h" 
    2626 
    2727namespace Dice { 
     
    3030const int msgSet = 0x68; 
    3131 
    32 SaffirePro24::Switch::Switch(Dice::Device::EAP* eap, std::string name, size_t offset, int activevalue ) 
     32FocusriteEAP::FocusriteEAP(Dice::Device& dev) : Dice::Device::EAP(dev) { 
     33
     34 
     35bool FocusriteEAP::readApplicationReg(unsigned offset, quadlet_t* quadlet) { 
     36    return readReg(eRT_Application, offset, quadlet); 
     37
     38bool FocusriteEAP::writeApplicationReg(unsigned offset, quadlet_t quadlet) { 
     39    bool ret = writeReg(eRT_Application, offset, quadlet); 
     40    if (!ret) return false; 
     41    return writeReg(eRT_Application, msgSet, commandToFix(offset)); 
     42
     43 
     44 
     45FocusriteEAP::Switch::Switch(Dice::Focusrite::FocusriteEAP* eap, std::string name, size_t offset, int activevalue ) 
    3346    : Control::Boolean(eap, name) 
    3447    , m_eap(eap) 
     
    3750    , m_activevalue(activevalue) 
    3851{ 
    39     m_eap->readReg(Dice::Device::EAP::eRT_Application, m_offset, &m_state_tmp); 
     52    m_eap->readApplicationReg(m_offset, &m_state_tmp); 
    4053    printf("%s: Active?%i\n", name.c_str(), m_state_tmp&m_activevalue); 
    4154    debugOutput(DEBUG_LEVEL_VERBOSE, "Probably the initialization is the other way round.\n"); 
     
    4356} 
    4457 
    45 bool SaffirePro24::Switch::selected() { 
     58bool FocusriteEAP::Switch::selected() { 
    4659    return m_selected; 
    4760} 
    4861 
    49 bool SaffirePro24::Switch::select(bool n) { 
     62bool FocusriteEAP::Switch::select(bool n) { 
    5063    if ( n != m_selected ) { 
    5164        m_selected = n; 
    52         m_eap->readReg(Dice::Device::EAP::eRT_Application, m_offset, &m_state_tmp); 
    53         m_eap->writeReg(Dice::Device::EAP::eRT_Application, m_offset, m_state_tmp^m_activevalue); 
    54         int msg = 0; 
    55         if (m_offset<0x14) msg = 2; 
    56         if (m_offset<0x3C && m_offset>=0x14) msg = 1; 
    57         if (m_offset<0x40 && m_offset>=0x3C) msg = 3; 
    58         if (m_offset<0x60 && m_offset>=0x58) msg = 4; 
    59         debugOutput(DEBUG_LEVEL_VERBOSE, "Switch will write the msg %i.\n", msg); 
    60         m_eap->writeReg(Dice::Device::EAP::eRT_Application, msgSet, msg); 
     65        m_eap->readApplicationReg(m_offset, &m_state_tmp); 
     66        m_eap->writeApplicationReg(m_offset, m_state_tmp^m_activevalue); 
    6167    } 
    6268    return true; 
    6369} 
    6470 
    65 class SaffirePro24::LineInstSwitch : public Switch 
    66 { 
    67 public: 
    68     LineInstSwitch(Dice::Device::EAP* eap, std::string name, size_t offset, int activevalue) 
    69         : Switch(eap, name, offset, activevalue) {} 
    70     std::string getBooleanLabel(bool n) { 
    71         if ( n ) return "Instrument"; 
    72         return "Line"; 
    73     } 
    74 }; 
    75 class SaffirePro24::LevelSwitch : public Switch 
    76 { 
    77 public: 
    78     LevelSwitch(Dice::Device::EAP* eap, std::string name, size_t offset, int activevalue) 
    79         : Switch(eap, name, offset, activevalue) {} 
    80     std::string getBooleanLabel(bool n) { 
    81         if ( n ) return "High"; 
    82         return "Low"; 
    83     } 
    84 }; 
    85  
    86 SaffirePro24::SaffirePro24( DeviceManager& d, 
    87                             std::auto_ptr<ConfigRom>( configRom )) 
    88     : Dice::Device(d , configRom) 
    89     , m_ch1(NULL) 
    90     , m_ch2(NULL) 
    91 { 
    92     debugOutput(DEBUG_LEVEL_VERBOSE, "Created Dice::Focusrite::SaffirePro24 (NodeID %d)\n", 
    93                 getConfigRom().getNodeId()); 
    94 } 
    95  
    96 SaffirePro24::~SaffirePro24() 
    97 { 
    98     //debugOutput(DEBUG_LEVEL_VERBOSE, "Deleting the saffirePro24\n"); 
    99     /// I wonder whether we should really save only on clean exits or also each time a setting is 
    100     //  changed. Or should we provide a function (and thus gui-button) to save the state of the 
    101     //  device? 
    102     getEAP()->storeFlashConfig(); 
    103     getEAP()->deleteElement(m_ch1); 
    104     getEAP()->deleteElement(m_ch2); 
    105     if (m_ch1) delete m_ch1; 
    106     if (m_ch2) delete m_ch2; 
    107 } 
    108  
    109 bool SaffirePro24::discover() { 
    110     if (Dice::Device::discover()) { 
    111         fb_quadlet_t* tmp = (fb_quadlet_t *)calloc(2, sizeof(fb_quadlet_t)); 
    112         getEAP()->readRegBlock(Dice::Device::EAP::eRT_Application, 0x00, tmp, 1*sizeof(fb_quadlet_t)); 
    113         //hexDumpQuadlets(tmp, 2); // DEBUG 
    114         if (tmp[0] != 0x00010004 ) { 
    115             debugError("This is a Focusrite Saffire Pro24 but not the right firmware. Better stop here before something goes wrong.\n"); 
    116             debugError("This device has firmware 0x%x while we only know about version 0x%x.\n", tmp[0], 0x10004); 
    117             return false; 
    118         } 
    119         //getEAP()->readRegBlock(Dice::Device::EAP::eRT_Command, 0x00, tmp, 2*sizeof(fb_quadlet_t)); // DEBUG 
    120         //hexDumpQuadlets(tmp, 2); // DEBUG 
    121  
    122         m_ch1 = new LineInstSwitch(getEAP(), "Ch1LineInst", 0x58, 2); 
    123         getEAP()->addElement(m_ch1); 
    124         m_ch2 = new LineInstSwitch(getEAP(), "Ch2LineInst", 0x58, 2<<16); 
    125         getEAP()->addElement(m_ch2); 
    126         m_ch3 = new LevelSwitch(getEAP(), "Ch3Level", 0x5C, 1); 
    127         getEAP()->addElement(m_ch3); 
    128         m_ch4 = new LevelSwitch(getEAP(), "Ch4Level", 0x5C, 1<<16); 
    129         getEAP()->addElement(m_ch4); 
    130  
    131         m_monitor = new MonitorSection(getEAP(), "Monitoring"); 
    132         getEAP()->addElement(m_monitor); 
    133         return true; 
    134     } 
    135     return false; 
    136 } 
    137  
    138 void SaffirePro24::showDevice() 
    139 { 
    140     debugOutput(DEBUG_LEVEL_VERBOSE, "This is a Dice::Focusrite::SaffirePro24\n"); 
    141     Dice::Device::showDevice(); 
    142 } 
    143  
    144 bool SaffirePro24::setNickName( std::string name ) { 
    145     return getEAP()->writeRegBlock( Dice::Device::EAP::eRT_Application, 0x40, (fb_quadlet_t*)name.c_str(), name.size() ); 
    146 } 
    147  
    148 std::string SaffirePro24::getNickName() { 
    149     char name[16]; 
    150     getEAP()->readRegBlock( Dice::Device::EAP::eRT_Application, 0x40, (fb_quadlet_t*)name, 16 ); 
    151     return std::string( name ); 
    152 } 
    15371 
    15472 
    155 SaffirePro24::MonitorSection::MonitorSection(Dice::Device::EAP* eap, std::string name) 
     73FocusriteEAP::MonitorSection::MonitorSection(Dice::Focusrite::FocusriteEAP* eap, std::string name) 
    15674    : Control::Container(eap, name) 
    15775    , m_eap(eap) 
  • trunk/libffado/src/dice/focusrite/focusrite_eap.h

    r1726 r1730  
    2323 */ 
    2424 
    25 #ifndef DICE_FOCUSRITE_SAFFIRE_PRO24_H 
    26 #define DICE_FOCUSRITE_SAFFIRE_PRO24_H 
     25#ifndef DICE_FOCUSRITE_FOCUSRITE_EAP_H 
     26#define DICE_FOCUSRITE_FOCUSRITE_EAP_H 
    2727 
    2828#include "dice/dice_avdevice.h" 
     
    3333namespace Focusrite { 
    3434 
    35 class SaffirePro24 : public Dice::Device { 
     35class FocusriteEAP : public Dice::Device::EAP 
     36
    3637public: 
    37     SaffirePro24( DeviceManager& d, 
    38                   std::auto_ptr<ConfigRom>( configRom )); 
    39     ~SaffirePro24(); 
    40  
    41     bool discover(); 
    42  
    43     void showDevice(); 
    44  
    45     bool canChangeNickname() { return true; } 
    46     bool setNickName( std::string name ); 
    47     std::string getNickName(); 
    48  
    4938    /** 
    5039     * @brief A standard-switch for boolean. 
     
    5443    class Switch : public Control::Boolean 
    5544    { 
    56     protected
    57         friend class Dice::Focusrite::SaffirePro24
     45    public
     46        Switch(Dice::Focusrite::FocusriteEAP*, std::string name, size_t offset, int activevalue)
    5847 
    59         Switch(Dice::Device::EAP*, std::string name, size_t offset, int activevalue); 
    60     public: 
    6148        bool selected(); 
    6249        bool select(bool); 
     50 
    6351    private: 
    64         Dice::Device::EAP* m_eap; 
     52        Dice::Focusrite::FocusriteEAP* m_eap; 
    6553        bool m_selected; 
    6654        size_t m_offset; 
     
    7159    class MonitorSection : public Control::Container 
    7260    { 
    73     protected
    74         friend class Dice::Focusrite::SaffirePro24
     61    public
     62        MonitorSection(Dice::Focusrite::FocusriteEAP*, std::string name)
    7563 
    76         MonitorSection(Dice::Device::EAP*, std::string name); 
    7764    private: 
    78         Dice::Device::EAP* m_eap; 
     65        Dice::Focusrite::FocusriteEAP* m_eap; 
    7966        Switch *m_mute, *m_dim; 
    8067        std::vector<Switch*> m_mute_affected; 
     
    8269        std::vector<Switch*> m_mono; 
    8370    }; 
    84 private: 
    85     class LineInstSwitch; 
    86     LineInstSwitch *m_ch1, *m_ch2; 
    87     class LevelSwitch; 
    88     LevelSwitch *m_ch3, *m_ch4; 
    89     MonitorSection *m_monitor; 
     71 
     72 
     73public: 
     74    FocusriteEAP(Dice::Device&); 
     75 
     76    bool readApplicationReg(unsigned offset, quadlet_t*); 
     77    bool writeApplicationReg(unsigned offset, quadlet_t); 
     78 
     79protected: 
     80    virtual int commandToFix(unsigned offset) =0; 
    9081}; 
    9182 
  • trunk/libffado/src/dice/focusrite/saffire_pro24.cpp

    r1726 r1730  
    2424 
    2525#include "saffire_pro24.h" 
     26#include "focusrite_eap.h" 
    2627 
    2728namespace Dice { 
    2829namespace Focusrite { 
    2930 
    30 const int msgSet = 0x68; 
    31  
    32 SaffirePro24::Switch::Switch(Dice::Device::EAP* eap, std::string name, size_t offset, int activevalue ) 
    33     : Control::Boolean(eap, name) 
    34     , m_eap(eap) 
    35     , m_selected(0) 
    36     , m_offset(offset) 
    37     , m_activevalue(activevalue) 
    38 
    39     m_eap->readReg(Dice::Device::EAP::eRT_Application, m_offset, &m_state_tmp); 
    40     printf("%s: Active?%i\n", name.c_str(), m_state_tmp&m_activevalue); 
    41     debugOutput(DEBUG_LEVEL_VERBOSE, "Probably the initialization is the other way round.\n"); 
    42     m_selected = (m_state_tmp&m_activevalue)?true:false; 
     31int 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; 
    4337} 
    4438 
    45 bool SaffirePro24::Switch::selected() { 
    46     return m_selected; 
    47 } 
    4839 
    49 bool SaffirePro24::Switch::select(bool n) { 
    50     if ( n != m_selected ) { 
    51         m_selected = n; 
    52         m_eap->readReg(Dice::Device::EAP::eRT_Application, m_offset, &m_state_tmp); 
    53         m_eap->writeReg(Dice::Device::EAP::eRT_Application, m_offset, m_state_tmp^m_activevalue); 
    54         int msg = 0; 
    55         if (m_offset<0x14) msg = 2; 
    56         if (m_offset<0x3C && m_offset>=0x14) msg = 1; 
    57         if (m_offset<0x40 && m_offset>=0x3C) msg = 3; 
    58         if (m_offset<0x60 && m_offset>=0x58) msg = 4; 
    59         debugOutput(DEBUG_LEVEL_VERBOSE, "Switch will write the msg %i.\n", msg); 
    60         m_eap->writeReg(Dice::Device::EAP::eRT_Application, msgSet, msg); 
    61     } 
    62     return true; 
    63 
    64  
    65 class SaffirePro24::LineInstSwitch : public Switch 
     40class SaffirePro24::LineInstSwitch : public Dice::Focusrite::FocusriteEAP::Switch 
    6641{ 
    6742public: 
    68     LineInstSwitch(Dice::Device::EAP* eap, std::string name, size_t offset, int activevalue) 
    69         : Switch(eap, name, offset, activevalue) {} 
     43    LineInstSwitch(Dice::Focusrite::FocusriteEAP* eap, std::string name, size_t offset, int activevalue) 
     44        : Dice::Focusrite::FocusriteEAP::Switch(eap, name, offset, activevalue) {} 
    7045    std::string getBooleanLabel(bool n) { 
    7146        if ( n ) return "Instrument"; 
     
    7348    } 
    7449}; 
    75 class SaffirePro24::LevelSwitch : public Switch 
     50class SaffirePro24::LevelSwitch : public Dice::Focusrite::FocusriteEAP::Switch 
    7651{ 
    7752public: 
    78     LevelSwitch(Dice::Device::EAP* eap, std::string name, size_t offset, int activevalue) 
    79         : Switch(eap, name, offset, activevalue) {} 
     53    LevelSwitch(Dice::Focusrite::FocusriteEAP* eap, std::string name, size_t offset, int activevalue) 
     54        : Dice::Focusrite::FocusriteEAP::Switch(eap, name, offset, activevalue) {} 
    8055    std::string getBooleanLabel(bool n) { 
    8156        if ( n ) return "High"; 
     
    12095        //hexDumpQuadlets(tmp, 2); // DEBUG 
    12196 
    122         m_ch1 = new LineInstSwitch(getEAP(), "Ch1LineInst", 0x58, 2); 
     97        FocusriteEAP* eap = dynamic_cast<FocusriteEAP*>(getEAP()); 
     98        m_ch1 = new LineInstSwitch(eap, "Ch1LineInst", 0x58, 2); 
    12399        getEAP()->addElement(m_ch1); 
    124         m_ch2 = new LineInstSwitch(getEAP(), "Ch2LineInst", 0x58, 2<<16); 
     100        m_ch2 = new LineInstSwitch(eap, "Ch2LineInst", 0x58, 2<<16); 
    125101        getEAP()->addElement(m_ch2); 
    126         m_ch3 = new LevelSwitch(getEAP(), "Ch3Level", 0x5C, 1); 
     102        m_ch3 = new LevelSwitch(eap, "Ch3Level", 0x5C, 1); 
    127103        getEAP()->addElement(m_ch3); 
    128         m_ch4 = new LevelSwitch(getEAP(), "Ch4Level", 0x5C, 1<<16); 
     104        m_ch4 = new LevelSwitch(eap, "Ch4Level", 0x5C, 1<<16); 
    129105        getEAP()->addElement(m_ch4); 
    130106 
    131         m_monitor = new MonitorSection(getEAP(), "Monitoring"); 
     107        m_monitor = new FocusriteEAP::MonitorSection(eap, "Monitoring"); 
    132108        getEAP()->addElement(m_monitor); 
    133109        return true; 
     
    140116    debugOutput(DEBUG_LEVEL_VERBOSE, "This is a Dice::Focusrite::SaffirePro24\n"); 
    141117    Dice::Device::showDevice(); 
     118} 
     119Dice::Device::EAP* SaffirePro24::createEAP() { 
     120    return new SaffirePro24EAP(*this); 
    142121} 
    143122 
     
    152131} 
    153132 
    154  
    155 SaffirePro24::MonitorSection::MonitorSection(Dice::Device::EAP* eap, std::string name) 
    156     : Control::Container(eap, name) 
    157     , m_eap(eap) 
    158 { 
    159     m_mute = new Switch(m_eap, "Mute", 0x0C, 1); 
    160     addElement(m_mute); 
    161     m_dim = new Switch(m_eap, "Dim", 0x10, 1); 
    162     addElement(m_dim); 
    163     for (int i=0; i<10; ++i) { 
    164         std::stringstream stream; 
    165         stream << "MuteAffectsCh" << i; 
    166         Switch* s = new Switch(m_eap, stream.str(), 0x3C, 1<<i); 
    167         addElement(s); 
    168         m_mute_affected.push_back(s); 
    169         stream.str(std::string()); 
    170         stream << "DimAffectsCh" << i; 
    171         s = new Switch(m_eap, stream.str(), 0x3C, 1<<(10+i)); 
    172         addElement(s); 
    173         m_dim_affected.push_back(s); 
    174     } 
    175     for (int i=0; i<5; ++i) { 
    176         std::stringstream stream; 
    177         stream << "Mono_" << i*2 << "_" << i*2+1; 
    178         Switch* s = new Switch(m_eap, stream.str(), 0x3C, 1<<(20+i)); 
    179         addElement(s); 
    180         m_mono.push_back(s); 
    181     } 
    182 } 
    183  
    184133} 
    185134} 
  • trunk/libffado/src/dice/focusrite/saffire_pro24.h

    r1726 r1730  
    3030#include "libieee1394/configrom.h" 
    3131 
     32#include "focusrite_eap.h" 
     33 
    3234namespace Dice { 
    3335namespace Focusrite { 
     
    4749    std::string getNickName(); 
    4850 
    49     /** 
    50      * @brief A standard-switch for boolean. 
    51      * 
    52      * If you don't like True and False for the labels, subclass and return your own. 
    53     */ 
    54     class Switch : public Control::Boolean 
     51private: 
     52 
     53    class SaffirePro24EAP : public FocusriteEAP 
    5554    { 
    56     protected: 
    57         friend class Dice::Focusrite::SaffirePro24; 
     55    public: 
     56        SaffirePro24EAP(Dice::Device& dev) : FocusriteEAP(dev) { 
     57        } 
    5858 
    59         Switch(Dice::Device::EAP*, std::string name, size_t offset, int activevalue); 
    60     public: 
    61         bool selected(); 
    62         bool select(bool); 
    63     private: 
    64         Dice::Device::EAP* m_eap; 
    65         bool m_selected; 
    66         size_t m_offset; 
    67         int m_activevalue; 
    68         fb_quadlet_t m_state_tmp; 
     59        int commandToFix(unsigned offset); 
    6960    }; 
     61    Dice::Device::EAP* createEAP(); 
    7062 
    71     class MonitorSection : public Control::Container 
    72     { 
    73     protected: 
    74         friend class Dice::Focusrite::SaffirePro24; 
    75  
    76         MonitorSection(Dice::Device::EAP*, std::string name); 
    77     private: 
    78         Dice::Device::EAP* m_eap; 
    79         Switch *m_mute, *m_dim; 
    80         std::vector<Switch*> m_mute_affected; 
    81         std::vector<Switch*> m_dim_affected; 
    82         std::vector<Switch*> m_mono; 
    83     }; 
    84 private: 
    8563    class LineInstSwitch; 
    8664    LineInstSwitch *m_ch1, *m_ch2; 
    8765    class LevelSwitch; 
    8866    LevelSwitch *m_ch3, *m_ch4; 
    89     MonitorSection *m_monitor; 
     67    Dice::Focusrite::FocusriteEAP::MonitorSection *m_monitor; 
    9068}; 
    9169