LCOV - code coverage report
Current view: top level - src/MIDI_Inputs/LEDs/MCU - VULEDs.hpp (source / functions) Hit Total Coverage
Test: 3a807a259ebe0769dd942f7f612dca5273937539 Lines: 29 34 85.3 %
Date: 2024-03-24 17:16:54 Functions: 8 9 88.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include <AH/Hardware/LEDs/DotBarDisplayLEDs.hpp>
       4             : #include <MIDI_Inputs/MCU/VU.hpp>
       5             : 
       6             : BEGIN_CS_NAMESPACE
       7             : 
       8             : namespace MCU {
       9             : 
      10             : /// Small helper to display the VU meters on an LED bar display.
      11             : template <uint16_t NumLEDs>
      12             : class VULEDsDriver : public AH::DotBarDisplayLEDs<NumLEDs> {
      13             :   public:
      14             :     /// Constructor
      15           1 :     VULEDsDriver(const PinList<NumLEDs> &leds)
      16           1 :         : AH::DotBarDisplayLEDs<NumLEDs>(leds) {}
      17             : 
      18             :     /// @param  value
      19             :     ///         [0, 12]
      20           4 :     void displayVU(uint16_t value) {
      21           4 :         value = (value * NumLEDs + FLOOR_CORRECTION) / 12; // [0, N]
      22           4 :         this->display(value);
      23           4 :     }
      24             : 
      25             :   private:
      26             :     /// @see    doc/VU-LED-mapping.ods
      27             :     constexpr static uint8_t FLOOR_CORRECTION = 5;
      28             : };
      29             : 
      30             : // -------------------------------------------------------------------------- //
      31             : 
      32             : /** 
      33             :  * @brief   A MIDI input element that represents a Mackie Control Universal VU
      34             :  *          meter and displays its value using LEDs.
      35             :  * 
      36             :  * @tparam  NumLEDs
      37             :  *          The number of LEDs for the VU meter display. Recommended value is 
      38             :  *          12, because this is the range that's sent over MIDI.
      39             :  * 
      40             :  * @ingroup midi-input-elements-leds
      41             :  */
      42             : template <uint8_t NumLEDs>
      43             : class VULEDs : public VU, public VULEDsDriver<NumLEDs> {
      44             :   public:
      45             :     using Parent = VU;
      46             :     using Matcher = typename Parent::Matcher;
      47             : 
      48             :     /// @param  leds
      49             :     ///         The pins with the LEDs connected.
      50             :     /// @param  track
      51             :     ///         The track of the VU meter. [1, 8]
      52             :     /// @param  channelCN
      53             :     ///         The MIDI channel [Channel_1, Channel_16] and Cable
      54             :     ///         Number [Cable_1, Cable_16].
      55             :     /// @param  decayTime
      56             :     ///         The time in milliseconds it takes for the value to decay one
      57             :     ///         step.  
      58             :     ///         The MCU protocol uses 300 ms per division, and two steps
      59             :     ///         per division, so the default is 150 ms per step.  
      60             :     ///         Some software doesn't work if the VU meter decays automatically,
      61             :     ///         in that case, you can set the decay time to zero to disable
      62             :     ///         the decay.
      63             :     ///         @see    @ref MCU::VUDecay
      64             :     VULEDs(const PinList<NumLEDs> &leds, uint8_t track,
      65             :            MIDIChannelCable channelCN,
      66             :            unsigned int decayTime = VUDecay::Default)
      67             :         : Parent(track, channelCN, decayTime), VULEDsDriver<NumLEDs>(leds) {}
      68             : 
      69             :     /// @param  leds
      70             :     ///         The pins with the LEDs connected.
      71             :     /// @param  track
      72             :     ///         The track of the VU meter. [1, 8]
      73             :     /// @param  decayTime
      74             :     ///         The time in milliseconds it takes for the value to decay one
      75             :     ///         step.  
      76             :     ///         The MCU protocol uses 300 ms per division, and two steps
      77             :     ///         per division, so the default is 150 ms per step.  
      78             :     ///         Some software doesn't work if the VU meter decays automatically,
      79             :     ///         in that case, you can set the decay time to zero to disable
      80             :     ///         the decay.
      81             :     ///         @see    @ref MCU::VUDecay
      82             :     VULEDs(const PinList<NumLEDs> &leds, uint8_t track,
      83             :            unsigned int decayTime = VUDecay::Default)
      84             :         : Parent(track, decayTime), VULEDsDriver<NumLEDs>(leds) {}
      85             : 
      86             :   protected:
      87             :     void handleUpdate(typename Matcher::Result match) override {
      88             :         bool newdirty = Parent::handleUpdateImpl(match);
      89             :         if (newdirty)
      90             :             updateDisplay();
      91             :         this->dirty |= newdirty;
      92             :     }
      93             : 
      94             :     void updateDisplay() { this->displayVU(getValue()); }
      95             : 
      96             :   public:
      97             :     void begin() override {
      98             :         Parent::begin();
      99             :         VULEDsDriver<NumLEDs>::begin();
     100             :         updateDisplay();
     101             :     }
     102             : 
     103             :     void reset() override {
     104             :         Parent::reset();
     105             :         updateDisplay();
     106             :     }
     107             : 
     108             :     void update() override {
     109             :         bool newdirty = Parent::decay();
     110             :         if (newdirty)
     111             :             updateDisplay();
     112             :         this->dirty |= newdirty;
     113             :     }
     114             : };
     115             : 
     116             : // -------------------------------------------------------------------------- //
     117             : 
     118             : namespace Bankable {
     119             : 
     120             : /** 
     121             :  * @brief   A MIDI input element that represents a Mackie Control Universal VU
     122             :  *          meter and displays its value using LEDs.
     123             :  *          This version can be banked.
     124             :  * 
     125             :  * @tparam  BankSize
     126             :  *          The number of banks.
     127             :  * @tparam  NumLEDs
     128             :  *          The number of LEDs for the VU meter display. Recommended value is 
     129             :  *          12, because this is the range that's sent over MIDI.
     130             :  * 
     131             :  * @ingroup BankableMIDIInputElementsLEDs
     132             :  */
     133             : template <uint8_t BankSize, uint8_t NumLEDs>
     134             : class VULEDs : public VU<BankSize>, public VULEDsDriver<NumLEDs> {
     135             :   public:
     136             :     using Parent = VU<BankSize>;
     137             :     using Matcher = typename Parent::Matcher;
     138             : 
     139             :     /// @param  config
     140             :     ///         The bank configuration to use.
     141             :     /// @param  leds
     142             :     ///         The pins with the LEDs connected.
     143             :     /// @param  track
     144             :     ///         The track of the VU meter. [1, 8]
     145             :     /// @param  channelCN
     146             :     ///         The MIDI channel [Channel_1, Channel_16] and Cable
     147             :     ///         Number [Cable_1, Cable_16].
     148             :     /// @param  decayTime
     149             :     ///         The time in milliseconds it takes for the value to decay one
     150             :     ///         step.  
     151             :     ///         The MCU protocol uses 300 ms per division, and two steps
     152             :     ///         per division, so the default is 150 ms per step.  
     153             :     ///         Some software doesn't work if the VU meter decays automatically,
     154             :     ///         in that case, you can set the decay time to zero to disable
     155             :     ///         the decay.
     156             :     ///         @see    @ref MCU::VUDecay
     157           1 :     VULEDs(BankConfig<BankSize> config, const PinList<NumLEDs> &leds,
     158             :            uint8_t track, MIDIChannelCable channelCN,
     159             :            unsigned int decayTime = VUDecay::Default)
     160             :         : Parent(config, track, channelCN, decayTime),
     161           1 :           VULEDsDriver<NumLEDs>(leds) {}
     162             : 
     163             :     /// @param  config
     164             :     ///         The bank configuration to use.
     165             :     /// @param  leds
     166             :     ///         The pins with the LEDs connected.
     167             :     /// @param  track
     168             :     ///         The track of the VU meter. [1, 8]
     169             :     /// @param  decayTime
     170             :     ///         The time in milliseconds it takes for the value to decay one
     171             :     ///         step.  
     172             :     ///         The MCU protocol uses 300 ms per division, and two steps
     173             :     ///         per division, so the default is 150 ms per step.  
     174             :     ///         Some software doesn't work if the VU meter decays automatically,
     175             :     ///         in that case, you can set the decay time to zero to disable
     176             :     ///         the decay.
     177             :     ///         @see    @ref MCU::VUDecay
     178             :     VULEDs(BankConfig<BankSize> config, const PinList<NumLEDs> &leds,
     179             :            uint8_t track, unsigned int decayTime = VUDecay::Default)
     180             :         : Parent(config, track, decayTime), VULEDsDriver<NumLEDs>(leds) {}
     181             : 
     182             :   protected:
     183           2 :     void handleUpdate(typename Matcher::Result match) override {
     184           2 :         bool newdirty = Parent::handleUpdateImpl(match);
     185           2 :         if (newdirty)
     186           1 :             updateDisplay();
     187           2 :         this->dirty |= newdirty;
     188           2 :     }
     189             : 
     190           4 :     void updateDisplay() { this->displayVU(this->getValue()); }
     191             : 
     192             :   public:
     193           1 :     void begin() override {
     194           1 :         Parent::begin();
     195           1 :         VULEDsDriver<NumLEDs>::begin();
     196           1 :         updateDisplay();
     197           1 :     }
     198             : 
     199           0 :     void reset() override {
     200           0 :         Parent::reset();
     201           0 :         updateDisplay();
     202           0 :     }
     203             : 
     204           2 :     void update() override {
     205           2 :         bool newdirty = Parent::decay();
     206           2 :         if (newdirty)
     207           0 :             updateDisplay();
     208           2 :         this->dirty |= newdirty;
     209           2 :     }
     210             : 
     211             :   protected:
     212           2 :     void onBankSettingChange() override {
     213           2 :         Parent::onBankSettingChange();
     214           2 :         updateDisplay();
     215           2 :     }
     216             : };
     217             : 
     218             : } // namespace Bankable
     219             : 
     220             : } // namespace MCU
     221             : 
     222             : END_CS_NAMESPACE

Generated by: LCOV version 1.15