Control Surface  1.1.0
MIDI Control Surface library for Arduino
AudioVULEDs.hpp
Go to the documentation of this file.
1 /* ✔ */
2 
3 #pragma once
4 
6 #include <Audio/AudioVU.hpp>
7 #include <Def/Def.hpp>
8 
10 
11 /**
12  * @brief A VU meter that reads from an Audio stream using the
13  * AudioAnalyzePeak class, and displays it on an LED bar graph.
14  *
15  * @tparam N
16  * The number of LEDs.
17  *
18  * @ingroup Audio
19  */
20 template <uint8_t N>
21 class AudioVULEDs : public AudioVU, public AH::Updatable<AudioVU> {
22  public:
23  /**
24  * @brief Create a new AudioVULEDs object.
25  *
26  * @param vuleds
27  * The LEDs to display the VU meter to.
28  * @param level
29  * The Teensy Audio peak analyzer object.
30  * Note that it is kept by reference, so it must outlive the
31  * AudioVU instance.
32  * @param gain
33  * A multiplier to calibrate the VU meter.
34  */
35  AudioVULEDs(const AH::DotBarDisplayLEDs<N> &vuleds, AudioAnalyzePeak &level,
36  float gain = 1.0)
37  : AudioVU(level, gain, N), vuleds(vuleds) {}
38 
39  /**
40  * @brief Initialize.
41  */
42  void begin() override { vuleds.begin(); }
43 
44  /**
45  * @brief Update the LEDs with the latest level.
46  */
47  void update() override {
48  uint8_t newValue = this->getValue();
49  if (newValue != previousValue) {
50  vuleds.display(newValue);
51  previousValue = newValue;
52  }
53  }
54 
55  /**
56  * @brief Set the mode to either dot or bar mode.
57  *
58  * @param mode
59  * The mode.
60  */
61  void setMode(AH::DotBarMode mode) { vuleds.setMode(mode); }
62 
63  /**
64  * @brief Set the mode to dot mode.
65  */
66  void dotMode() { vuleds.dotMode(); }
67 
68  /**
69  * @brief Set the mode to bar mode.
70  */
71  void barMode() { vuleds.barMode(); }
72 
73  private:
75  uint8_t previousValue = 0;
76 };
77 
AudioVULEDs::begin
void begin() override
Initialize.
Definition: AudioVULEDs.hpp:42
AH::Updatable
A super class for object that have to be updated regularly.
Definition: Updatable.hpp:25
AudioVU::getValue
uint8_t getValue() override
Get the value of the VU meter.
Definition: AudioVU.hpp:60
AudioVULEDs::dotMode
void dotMode()
Set the mode to dot mode.
Definition: AudioVULEDs.hpp:66
Def.hpp
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
AudioVULEDs::barMode
void barMode()
Set the mode to bar mode.
Definition: AudioVULEDs.hpp:71
AudioVU::level
class AudioVU::Analyzer level
AudioVU.hpp
AudioVU
A VU meter that reads from an Audio stream using the Analyzer class.
Definition: AudioVU.hpp:16
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
AudioVULEDs::setMode
void setMode(AH::DotBarMode mode)
Set the mode to either dot or bar mode.
Definition: AudioVULEDs.hpp:61
AudioVULEDs::previousValue
uint8_t previousValue
Definition: AudioVULEDs.hpp:75
DotBarDisplayLEDs.hpp
AudioVULEDs::vuleds
AH::DotBarDisplayLEDs< N > vuleds
Definition: AudioVULEDs.hpp:74
AudioVULEDs::AudioVULEDs
AudioVULEDs(const AH::DotBarDisplayLEDs< N > &vuleds, AudioAnalyzePeak &level, float gain=1.0)
Create a new AudioVULEDs object.
Definition: AudioVULEDs.hpp:35
AudioVU::gain
float gain
Definition: AudioVU.hpp:134
AH::DotBarMode
DotBarMode
An enumeration type to set an LED display to either bar or dot mode.
Definition: DotBarDisplayLEDs.hpp:15
AudioVULEDs
A VU meter that reads from an Audio stream using the AudioAnalyzePeak class, and displays it on an LE...
Definition: AudioVULEDs.hpp:21
AudioVULEDs::update
void update() override
Update the LEDs with the latest level.
Definition: AudioVULEDs.hpp:47
AH::DotBarDisplayLEDs
A class for LED bars.
Definition: DotBarDisplayLEDs.hpp:29