This is an old version of the documentation. View the latest version here.
Control Surface  1.0.0
MIDI Control Surface library for Arduino
Abstract/MIDIFilteredAnalog.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #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  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 
129  void invert() { filteredAnalog.invert(); }
130 
136 
141  analog_t getValue() const { return filteredAnalog.getValue(); }
142 
143  private:
144  FilteredAnalog<Sender::precision()> filteredAnalog;
146 
147  public:
148  Sender sender;
149 };
150 
MIDIFilteredAnalogAddressable::address
const MIDICNChannelAddress address
Definition: Abstract/MIDIFilteredAnalog.hpp:73
MIDIFilteredAnalog
A class for potentiometers and faders that send MIDI events (with only a channel, no address).
Definition: Abstract/MIDIFilteredAnalog.hpp:90
Updatable
A super class for object that have to be updated regularly.
Definition: Updatable.hpp:20
MIDIFilteredAnalogAddressable::filteredAnalog
FilteredAnalog< Sender::precision()> filteredAnalog
Definition: Abstract/MIDIFilteredAnalog.hpp:72
FilteredAnalog
A class that reads and filters an analog input.
Definition: FilteredAnalog.hpp:47
MIDIFilteredAnalog::address
const MIDICNChannelAddress address
Definition: Abstract/MIDIFilteredAnalog.hpp:145
pin_t
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
Definition: Def.hpp:17
MIDIFilteredAnalogAddressable::invert
void invert()
Invert the analog value.
Definition: Abstract/MIDIFilteredAnalog.hpp:57
MIDIOutputElement.hpp
MIDIFilteredAnalog::begin
void begin() final override
Initialize this updatable.
Definition: Abstract/MIDIFilteredAnalog.hpp:108
Def.hpp
MIDIFilteredAnalog::filteredAnalog
FilteredAnalog< Sender::precision()> filteredAnalog
Definition: Abstract/MIDIFilteredAnalog.hpp:144
FilteredAnalog::getRawValue
analog_t getRawValue() const
Read the raw value of the analog input any filtering or mapping applied, but with its bit depth incre...
Definition: FilteredAnalog.hpp:130
FilteredAnalog::update
bool update()
Read the analog input value, apply the mapping function, and update the average.
Definition: FilteredAnalog.hpp:97
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
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::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
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: NamespaceSettings.hpp:9
analog_t
uint16_t analog_t
The type returned from analogRead and similar functions.
Definition: Def.hpp:15
MIDIFilteredAnalog::sender
Sender sender
Definition: Abstract/MIDIFilteredAnalog.hpp:148
MIDICNChannelAddress
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
Definition: MIDICNChannelAddress.hpp:82
FilteredAnalog::getValue
analog_t getValue() const
Get the filtered value of the analog input with the mapping function applied.
Definition: FilteredAnalog.hpp:113
MIDIFilteredAnalogAddressable
A class for potentiometers and faders that send MIDI events.
Definition: Abstract/MIDIFilteredAnalog.hpp:17
MIDIFilteredAnalogAddressable::MIDIFilteredAnalogAddressable
MIDIFilteredAnalogAddressable(pin_t analogPin, const MIDICNChannelAddress &address, const Sender &sender)
Construct a new MIDIFilteredAnalog.
Definition: Abstract/MIDIFilteredAnalog.hpp:30
MIDICNChannel
A class for saving a MIDI channel and cable number.
Definition: MIDICNChannelAddress.hpp:19
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: NamespaceSettings.hpp:10
MIDIFilteredAnalog::MIDIFilteredAnalog
MIDIFilteredAnalog(pin_t analogPin, const MIDICNChannel &address, const Sender &sender)
Construct a new MIDIFilteredAnalog.
Definition: Abstract/MIDIFilteredAnalog.hpp:103
FilteredAnalog::map
void map(MappingFunction fn)
Specify a mapping function that is applied to the raw analog value before filtering.
Definition: FilteredAnalog.hpp:74
FilteredAnalog::invert
void invert()
Invert the analog value.
Definition: FilteredAnalog.hpp:83
MIDIFilteredAnalogAddressable::update
void update() override
Update this updatable.
Definition: Abstract/MIDIFilteredAnalog.hpp:37
MIDIFilteredAnalogAddressable::begin
void begin() override
Initialize this updatable.
Definition: Abstract/MIDIFilteredAnalog.hpp:36
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
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
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
MIDIFilteredAnalog::invert
void invert()
Invert the analog value.
Definition: Abstract/MIDIFilteredAnalog.hpp:129
MIDIFilteredAnalog::update
void update() final override
Update this updatable.
Definition: Abstract/MIDIFilteredAnalog.hpp:109
MIDIFilteredAnalogAddressable::sender
Sender sender
Definition: Abstract/MIDIFilteredAnalog.hpp:76
FilteredAnalog.hpp
MappingFunction
analog_t(*)(analog_t) MappingFunction
A function pointer to a mapping function to map analog values.
Definition: Def.hpp:28