Control Surface  1.1.1
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:
32  const Sender &sender)
33  : filteredAnalog{analogPin}, address{address}, sender(sender) {}
34 
35  public:
36  void begin() override {}
37  void update() override {
38  if (filteredAnalog.update())
40  }
41 
55 
58 
64 
69  analog_t getValue() const { return filteredAnalog.getValue(); }
70 
71  private:
72  AH::FilteredAnalog<Sender::precision()> filteredAnalog;
74 
75  public:
76  Sender sender;
77 };
78 
79 // -------------------------------------------------------------------------- //
80 
89 template <class Sender>
91  protected:
104  const Sender &sender)
105  : filteredAnalog{analogPin}, address(address), sender(sender) {}
106 
107  public:
108  void begin() final override {}
109  void update() final override {
110  if (filteredAnalog.update())
112  }
113 
127 
130 
136 
141  analog_t getValue() const { return filteredAnalog.getValue(); }
142 
143  private:
144  AH::FilteredAnalog<Sender::precision()> filteredAnalog;
146 
147  public:
148  Sender sender;
149 };
150 
AH::FilteredAnalog::map
void map(MappingFunction fn)
Specify a mapping function that is applied to the raw analog value before filtering.
Definition: FilteredAnalog.hpp:86
MIDIFilteredAnalog::address
const MIDICNChannelAddress address
Definition: Abstract/MIDIFilteredAnalog.hpp:145
MIDIFilteredAnalog
A class for potentiometers and faders that send MIDI events (with only a channel, no address).
Definition: Abstract/MIDIFilteredAnalog.hpp:90
AH::FilteredAnalog::getValue
AnalogType getValue() const
Get the filtered value of the analog input (with the mapping function applied).
Definition: FilteredAnalog.hpp:128
MIDIFilteredAnalogAddressable::map
void map(MappingFunction fn)
Specify a mapping function that is applied to the raw analog value before sending.
Definition: Abstract/MIDIFilteredAnalog.hpp:54
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:141
AH::Updatable
A super class for object that have to be updated regularly.
Definition: Updatable.hpp:25
AH::FilteredAnalog::getRawValue
AnalogType getRawValue() const
Read the raw value of the analog input any filtering or mapping applied, but with its bit depth incre...
Definition: FilteredAnalog.hpp:145
MIDIFilteredAnalogAddressable::address
const MIDICNChannelAddress address
Definition: Abstract/MIDIFilteredAnalog.hpp:73
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:135
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:144
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:126
MIDIFilteredAnalog::invert
void invert()
Invert the analog value.
Definition: Abstract/MIDIFilteredAnalog.hpp:129
Def.hpp
MIDIFilteredAnalog::MIDIFilteredAnalog
MIDIFilteredAnalog(pin_t analogPin, const MIDICNChannel &address, const Sender &sender)
Construct a new MIDIFilteredAnalog.
Definition: Abstract/MIDIFilteredAnalog.hpp:103
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
MIDIFilteredAnalogAddressable::begin
void begin() override
Initialize this updatable.
Definition: Abstract/MIDIFilteredAnalog.hpp:36
AH::FilteredAnalog
A class that reads and filters an analog input.
Definition: FilteredAnalog.hpp:55
MIDIFilteredAnalogAddressable::sender
Sender sender
Definition: Abstract/MIDIFilteredAnalog.hpp:76
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
MIDIFilteredAnalog::sender
Sender sender
Definition: Abstract/MIDIFilteredAnalog.hpp:148
MIDIFilteredAnalogAddressable::update
void update() override
Update this updatable.
Definition: Abstract/MIDIFilteredAnalog.hpp:37
MIDICNChannelAddress
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
Definition: MIDICNChannelAddress.hpp:82
MIDIFilteredAnalogAddressable::filteredAnalog
AH::FilteredAnalog< Sender::precision()> filteredAnalog
Definition: Abstract/MIDIFilteredAnalog.hpp:72
MIDIFilteredAnalogAddressable::invert
void invert()
Invert the analog value.
Definition: Abstract/MIDIFilteredAnalog.hpp:57
MIDIFilteredAnalog::update
void update() final override
Update this updatable.
Definition: Abstract/MIDIFilteredAnalog.hpp:109
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:69
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:63
MIDICNChannel
A class for saving a MIDI channel and cable number.
Definition: MIDICNChannelAddress.hpp:19
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:108
AH::FilteredAnalog::invert
void invert()
Invert the analog value.
Definition: FilteredAnalog.hpp:95
FilteredAnalog.hpp
MIDIFilteredAnalogAddressable::MIDIFilteredAnalogAddressable
MIDIFilteredAnalogAddressable(pin_t analogPin, const MIDICNChannelAddress &address, const Sender &sender)
Construct a new MIDIFilteredAnalog.
Definition: Abstract/MIDIFilteredAnalog.hpp:30
MappingFunction
analog_t(*)(analog_t) MappingFunction
Definition: Def.hpp:19
AH::FilteredAnalog::update
bool update()
Read the analog input value, apply the mapping function, and update the average.
Definition: FilteredAnalog.hpp:109