Control Surface  1.2.0
MIDI Control Surface library for Arduino
Abstract/MIDIFilteredAnalog.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 #include <Def/Def.hpp>
6 
8 
16 template <class Sender>
18  protected:
31  const Sender &sender)
32  : filteredAnalog{analogPin}, address{address}, sender(sender) {}
33 
34  public:
35  void begin() override {}
36  void update() override {
37  if (filteredAnalog.update())
39  }
40 
54 
57 
63 
68  analog_t getValue() const { return filteredAnalog.getValue(); }
69 
70  private:
71  AH::FilteredAnalog<Sender::precision()> filteredAnalog;
73 
74  public:
75  Sender sender;
76 };
77 
78 // -------------------------------------------------------------------------- //
79 
88 template <class Sender>
90  protected:
103  const Sender &sender)
104  : filteredAnalog{analogPin}, address(address), sender(sender) {}
105 
106  public:
107  void begin() final override {}
108  void update() final override {
109  if (filteredAnalog.update())
111  }
112 
126 
129 
135 
140  analog_t getValue() const { return filteredAnalog.getValue(); }
141 
142  private:
143  AH::FilteredAnalog<Sender::precision()> filteredAnalog;
145 
146  public:
147  Sender sender;
148 };
149 
MIDIFilteredAnalog
A class for potentiometers and faders that send MIDI events (with only a channel, no address).
Definition: Abstract/MIDIFilteredAnalog.hpp:89
MIDIFilteredAnalogAddressable::MIDIFilteredAnalogAddressable
MIDIFilteredAnalogAddressable(pin_t analogPin, const MIDIAddress &address, const Sender &sender)
Construct a new MIDIFilteredAnalog.
Definition: Abstract/MIDIFilteredAnalog.hpp:30
MIDIAddress
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
Definition: MIDIAddress.hpp:91
MIDIFilteredAnalogAddressable::map
void map(MappingFunction fn)
Specify a mapping function that is applied to the raw analog value before sending.
Definition: Abstract/MIDIFilteredAnalog.hpp:53
MIDIFilteredAnalog::getValue
analog_t getValue() const
Get the value of the analog input (this is the value after first applying the mapping function).
Definition: Abstract/MIDIFilteredAnalog.hpp:140
AH::Updatable<>
MIDIFilteredAnalog::getRawValue
analog_t getRawValue() const
Get the raw value of the analog input (this is the value without applying the filter or the mapping f...
Definition: Abstract/MIDIFilteredAnalog.hpp:134
AH::pin_t
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
Definition: Hardware-Types.hpp:17
MIDIFilteredAnalog::filteredAnalog
AH::FilteredAnalog< Sender::precision()> filteredAnalog
Definition: Abstract/MIDIFilteredAnalog.hpp:143
MIDIOutputElement.hpp
MIDIFilteredAnalog::map
void map(MappingFunction fn)
Specify a mapping function that is applied to the raw analog value before sending.
Definition: Abstract/MIDIFilteredAnalog.hpp:125
MIDIFilteredAnalog::invert
void invert()
Invert the analog value.
Definition: Abstract/MIDIFilteredAnalog.hpp:128
Def.hpp
MIDIFilteredAnalog::address
const MIDIAddress address
Definition: Abstract/MIDIFilteredAnalog.hpp:144
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
MIDIFilteredAnalogAddressable::begin
void begin() override
Initialize this updatable.
Definition: Abstract/MIDIFilteredAnalog.hpp:35
AH::FilteredAnalog
A class that reads and filters an analog input.
Definition: FilteredAnalog.hpp:249
AH::GenericFilteredAnalog::getRawValue
AnalogType getRawValue() const
Read the raw value of the analog input without any filtering or mapping applied, but with its bit dep...
Definition: FilteredAnalog.hpp:142
AH::GenericFilteredAnalog::getValue
AnalogType getValue() const
Get the filtered value of the analog input (with the mapping function applied).
Definition: FilteredAnalog.hpp:125
MIDIFilteredAnalogAddressable::sender
Sender sender
Definition: Abstract/MIDIFilteredAnalog.hpp:75
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
MIDIFilteredAnalogAddressable::address
const MIDIAddress address
Definition: Abstract/MIDIFilteredAnalog.hpp:72
AH::GenericFilteredAnalog::update
bool update()
Read the analog input value, apply the mapping function, and update the average.
Definition: FilteredAnalog.hpp:107
MIDIFilteredAnalog::sender
Sender sender
Definition: Abstract/MIDIFilteredAnalog.hpp:147
MIDIFilteredAnalogAddressable::update
void update() override
Update this updatable.
Definition: Abstract/MIDIFilteredAnalog.hpp:36
MIDIFilteredAnalogAddressable::filteredAnalog
AH::FilteredAnalog< Sender::precision()> filteredAnalog
Definition: Abstract/MIDIFilteredAnalog.hpp:71
MIDIFilteredAnalogAddressable::invert
void invert()
Invert the analog value.
Definition: Abstract/MIDIFilteredAnalog.hpp:56
AH::GenericFilteredAnalog::map
void map(MappingFunction fn)
Specify a mapping function/functor that is applied to the analog value after filtering and before app...
Definition: FilteredAnalog.hpp:87
MIDIFilteredAnalog::update
void update() final override
Update this updatable.
Definition: Abstract/MIDIFilteredAnalog.hpp:108
MIDIFilteredAnalogAddressable::getValue
analog_t getValue() const
Get the value of the analog input (this is the value after first applying the mapping function).
Definition: Abstract/MIDIFilteredAnalog.hpp:68
MIDIFilteredAnalogAddressable
A class for potentiometers and faders that send MIDI events.
Definition: Abstract/MIDIFilteredAnalog.hpp:17
MIDIFilteredAnalogAddressable::getRawValue
analog_t getRawValue() const
Get the raw value of the analog input (this is the value without applying the filter or the mapping f...
Definition: Abstract/MIDIFilteredAnalog.hpp:62
AH::analog_t
uint16_t analog_t
The type returned from analogRead and similar functions.
Definition: Hardware-Types.hpp:15
MIDIFilteredAnalog::begin
void begin() final override
Initialize this updatable.
Definition: Abstract/MIDIFilteredAnalog.hpp:107
AH::FilteredAnalog::invert
void invert()
Invert the analog value.
Definition: FilteredAnalog.hpp:275
FilteredAnalog.hpp
MIDIFilteredAnalog::MIDIFilteredAnalog
MIDIFilteredAnalog(pin_t analogPin, const MIDIAddress &address, const Sender &sender)
Construct a new MIDIFilteredAnalog.
Definition: Abstract/MIDIFilteredAnalog.hpp:102
MappingFunction
analog_t(*)(analog_t) MappingFunction
Definition: Def.hpp:20