LCOV - code coverage report
Current view: top level - src/MIDI_Inputs/LEDs - NoteCCKPLEDBar.hpp (source / functions) Coverage Total Hit
Test: 73449d9b107c772cf65493691543348214e5d5eb Lines: 92.3 % 13 12
Test Date: 2026-06-06 17:44:35 Functions: 83.3 % 6 5
Legend: Lines:     hit not hit

            Line data    Source code
       1              : #include <AH/Hardware/ExtendedInputOutput/ExtendedInputOutput.hpp>
       2              : #include <AH/Hardware/LEDs/DotBarDisplayLEDs.hpp>
       3              : #include <MIDI_Inputs/NoteCCKPValue.hpp>
       4              : 
       5              : BEGIN_CS_NAMESPACE
       6              : 
       7              : /**
       8              :  * @brief   Callback class that drives a LED dot/bar display based on a note or
       9              :  *          control change value.
      10              :  * 
      11              :  * @tparam  NumLEDs 
      12              :  *          The number of LEDs the display has.
      13              :  */
      14              : template <uint8_t NumLEDs>
      15              : class NoteCCKPLEDBarDriver : public AH::DotBarDisplayLEDs<NumLEDs> {
      16              :   public:
      17            1 :     NoteCCKPLEDBarDriver(const AH::PinList<NumLEDs> &leds)
      18            1 :         : AH::DotBarDisplayLEDs<NumLEDs>(leds) {}
      19              : 
      20            3 :     void displayBar(uint8_t value) { this->display(value / 128.0f); }
      21              : };
      22              : 
      23              : // -------------------------------------------------------------------------- //
      24              : 
      25              : /// Class that turns on a different number of LEDs depending on the received
      26              : /// MIDI velocity, key pressure or Control Change value. Similar to a digital
      27              : /// LED VU meter.
      28              : /// Can be configured in either bar or dot mode.
      29              : template <MIDIMessageType Type, uint8_t NumLEDs>
      30              : class NoteCCKPLEDBar
      31              :     : public MatchingMIDIInputElement<Type, TwoByteMIDIMatcher>,
      32              :       public NoteCCKPLEDBarDriver<NumLEDs> {
      33              :   public:
      34              :     using Matcher = TwoByteMIDIMatcher;
      35              :     using Parent = MatchingMIDIInputElement<Type, Matcher>;
      36              : 
      37              :     /// @param  leds
      38              :     ///         A list of LED pins.
      39              :     /// @param  address
      40              :     ///         The MIDI address to listen to.
      41            1 :     NoteCCKPLEDBar(const AH::PinList<NumLEDs> &leds, MIDIAddress address)
      42            1 :         : Parent(address), NoteCCKPLEDBarDriver<NumLEDs>(leds) {}
      43              : 
      44              :   protected:
      45            2 :     void handleUpdate(typename Matcher::Result match) override {
      46            2 :         this->displayBar(match.value);
      47            2 :     }
      48              : 
      49              :   public:
      50            1 :     void begin() override {
      51            1 :         NoteCCKPLEDBarDriver<NumLEDs>::begin();
      52            1 :         this->displayBar(0);
      53            1 :     }
      54              : 
      55            0 :     void reset() override { this->displayBar(0); }
      56              : };
      57              : 
      58              : // -------------------------------------------------------------------------- //
      59              : 
      60              : /// Class that listens for **Note** events and displays the velocity on an
      61              : /// **LED Bar Graph**, turning on a different number of LEDs depending on the
      62              : /// velocity. Similar to a digital LED VU meter.
      63              : /// Can be configured in either bar or dot mode.
      64              : /// @tparam  NumLEDs
      65              : ///          The number of LEDs the display has.
      66              : /// @ingroup midi-input-elements-leds
      67              : template <uint8_t NumLEDs>
      68              : using NoteLEDBar = NoteCCKPLEDBar<MIDIMessageType::NoteOn, NumLEDs>;
      69              : 
      70              : /// Class that listens for **Control Change** events and displays the
      71              : /// value on an **LED Bar Graph**, turning on a different number of LEDs
      72              : /// depending on the value. Similar to a digital LED VU meter.
      73              : /// Can be configured in either bar or dot mode.
      74              : /// @tparam  NumLEDs
      75              : ///          The number of LEDs the display has.
      76              : /// @ingroup midi-input-elements-leds
      77              : template <uint8_t NumLEDs>
      78              : using CCLEDBar = NoteCCKPLEDBar<MIDIMessageType::ControlChange, NumLEDs>;
      79              : 
      80              : /// Class that listens for **Key Pressure** events and displays the pressure on
      81              : /// an **LED Bar Graph**, turning on a different number of LEDs
      82              : /// depending on the value. Similar to a digital LED VU meter.
      83              : /// Can be configured in either bar or dot mode.
      84              : /// @tparam  NumLEDs
      85              : ///          The number of LEDs the display has.
      86              : /// @ingroup midi-input-elements-leds
      87              : template <uint8_t NumLEDs>
      88              : using KPLEDBar = NoteCCKPLEDBar<MIDIMessageType::KeyPressure, NumLEDs>;
      89              : 
      90              : // :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //
      91              : 
      92              : namespace Bankable {
      93              : 
      94              : /// Class that turns on a different number of LEDs depending on the received
      95              : /// MIDI velocity, key pressure or Control Change value. Similar to a digital
      96              : /// LED VU meter.
      97              : /// Can be configured in either bar or dot mode.
      98              : /// This version can be banked.
      99              : template <MIDIMessageType Type, uint8_t BankSize, uint8_t NumLEDs>
     100              : class NoteCCKPLEDBar : public NoteCCKPValue<Type, BankSize>,
     101              :                        public NoteCCKPLEDBarDriver<NumLEDs> {
     102              :   public:
     103              :     using Parent = NoteCCKPValue<Type, BankSize>;
     104              :     using Matcher = typename Parent::Matcher;
     105              : 
     106              :     /// @param  config
     107              :     ///         The bank configuration to use.
     108              :     /// @param  leds
     109              :     ///         A list of LED pins.
     110              :     /// @param  address
     111              :     ///         The MIDI address to listen to.
     112              :     NoteCCKPLEDBar(BankConfig<BankSize> config,
     113              :                    const AH::PinList<NumLEDs> &leds, MIDIAddress address)
     114              :         : Parent(config, address), NoteCCKPLEDBarDriver<NumLEDs>(leds) {}
     115              : 
     116              :   protected:
     117              :     void handleUpdate(typename Matcher::Result match) override {
     118              :         bool newdirty = Parent::handleUpdateImpl(match);
     119              :         if (newdirty)
     120              :             updateDisplay();
     121              :         this->dirty |= newdirty;
     122              :     }
     123              : 
     124              :     void updateDisplay() { this->displayBar(this->getValue()); }
     125              : 
     126              :   public:
     127              :     void begin() override {
     128              :         Parent::begin();
     129              :         NoteCCKPLEDBarDriver<NumLEDs>::begin();
     130              :         this->displayBar(0);
     131              :     }
     132              : 
     133              :     void reset() override {
     134              :         Parent::reset();
     135              :         this->displayBar(0);
     136              :     }
     137              : 
     138              :   protected:
     139              :     void onBankSettingChange() override {
     140              :         Parent::onBankSettingChange();
     141              :         updateDisplay();
     142              :     }
     143              : };
     144              : 
     145              : // :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //
     146              : 
     147              : /// Class that listens for **Note** events and displays the velocity on an
     148              : /// **LED Bar Graph**, turning on a different number of LEDs
     149              : /// depending on the velocity. Similar to a digital LED VU meter.
     150              : /// Can be configured in either bar or dot mode.
     151              : /// This version can be banked.
     152              : /// @tparam BankSize
     153              : ///         The number of banks.
     154              : /// @tparam  NumLEDs
     155              : ///          The number of LEDs the display has.
     156              : /// @ingroup BankableMIDIInputElementsLEDs
     157              : template <uint8_t BankSize, uint8_t NumLEDs>
     158              : using NoteLEDBar = NoteCCKPLEDBar<MIDIMessageType::NoteOn, BankSize, NumLEDs>;
     159              : 
     160              : /// Class that listens for **Control Change** events and displays the
     161              : /// value on an **LED Bar Graph**, turning on a different number of LEDs
     162              : /// depending on the value. Similar to a digital LED VU meter.
     163              : /// Can be configured in either bar or dot mode.
     164              : /// This version can be banked.
     165              : /// @tparam BankSize
     166              : ///         The number of banks.
     167              : /// @tparam  NumLEDs
     168              : ///          The number of LEDs the display has.
     169              : /// @ingroup BankableMIDIInputElementsLEDs
     170              : template <uint8_t BankSize, uint8_t NumLEDs>
     171              : using CCLEDBar =
     172              :     NoteCCKPLEDBar<MIDIMessageType::ControlChange, BankSize, NumLEDs>;
     173              : 
     174              : /// Class that listens for **Key Pressure** events and displays the pressure on
     175              : /// an **LED Bar Graph**, turning on a different number of LEDs
     176              : /// depending on the value. Similar to a digital LED VU meter.
     177              : /// Can be configured in either bar or dot mode.
     178              : /// This version can be banked.
     179              : /// @tparam BankSize
     180              : ///         The number of banks.
     181              : /// @tparam  NumLEDs
     182              : ///          The number of LEDs the display has.
     183              : /// @ingroup BankableMIDIInputElementsLEDs
     184              : template <uint8_t BankSize, uint8_t NumLEDs>
     185              : using KPLEDBar =
     186              :     NoteCCKPLEDBar<MIDIMessageType::KeyPressure, BankSize, NumLEDs>;
     187              : 
     188              : } // namespace Bankable
     189              : 
     190              : END_CS_NAMESPACE
        

Generated by: LCOV version 2.4-beta