This is an old version of the documentation. View the latest version here.
Control Surface  1.0.0
MIDI Control Surface library for Arduino
Bankable/Abstract/MIDIFilteredAnalog.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 #include <Def/Def.hpp>
7 
9 
10 namespace Bankable {
11 
20 template <class BankAddress, class Sender>
22  protected:
34  MIDIFilteredAnalogAddressable(const BankAddress &bankAddress,
35  pin_t analogPin, const Sender &sender)
36  : address{bankAddress}, filteredAnalog{analogPin}, sender{sender} {}
37 
38  public:
39  void begin() override {}
40  void update() override {
41  if (filteredAnalog.update())
42  sender.send(filteredAnalog.getValue(), address.getActiveAddress());
43  }
44 
58 
60  void invert() { filteredAnalog.invert(); }
61 
67 
72  analog_t getValue() const { return filteredAnalog.getValue(); }
73 
74  private:
75  BankAddress address;
76  FilteredAnalog<Sender::precision()> filteredAnalog;
77 
78  public:
79  Sender sender;
80 };
81 
82 // -------------------------------------------------------------------------- //
83 
92 template <class BankAddress, class Sender>
94  protected:
106  MIDIFilteredAnalog(const BankAddress &bankAddress, pin_t analogPin,
107  const Sender &sender)
108  : address{bankAddress}, filteredAnalog{analogPin}, sender{sender} {}
109 
110  public:
111  void begin() final override {}
112  void update() final override {
113  if (filteredAnalog.update())
114  sender.send(filteredAnalog.getValue(), address.getActiveAddress());
115  }
116 
130 
133 
139 
144  analog_t getValue() const { return filteredAnalog.getValue(); }
145 
146  private:
147  BankAddress address;
148  FilteredAnalog<Sender::precision()> filteredAnalog;
149 
150  public:
151  Sender sender;
152 };
153 
154 } // namespace Bankable
155 
Bankable::MIDIFilteredAnalogAddressable::filteredAnalog
FilteredAnalog< Sender::precision()> filteredAnalog
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:76
Updatable
A super class for object that have to be updated regularly.
Definition: Updatable.hpp:20
Bankable::MIDIFilteredAnalog::filteredAnalog
FilteredAnalog< Sender::precision()> filteredAnalog
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:148
BankableMIDIOutput.hpp
Bankable
A namespace for MIDI elements that can be added to a Bank, to change their address or channel.
Definition: BankAddresses.hpp:7
Bankable::MIDIFilteredAnalogAddressable::address
BankAddress address
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:75
Bankable::MIDIFilteredAnalogAddressable::sender
Sender sender
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:79
FilteredAnalog
A class that reads and filters an analog input.
Definition: FilteredAnalog.hpp:47
Bankable::MIDIFilteredAnalog
A class for potentiometers and faders that send MIDI events (with only a channel, no address) and tha...
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:93
Bankable::MIDIFilteredAnalogAddressable::getValue
analog_t getValue() const
Get the value of the analog input (this is the value after first applying the mapping function).
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:72
pin_t
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
Definition: Def.hpp:17
MIDIOutputElement.hpp
Def.hpp
Bankable::MIDIFilteredAnalog::map
void map(MappingFunction fn)
Specify a mapping function that is applied to the raw analog value before sending.
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:129
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
Bankable::MIDIFilteredAnalog::update
void update() final override
Update this updatable.
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:112
Bankable::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: Bankable/Abstract/MIDIFilteredAnalog.hpp:66
Bankable::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: Bankable/Abstract/MIDIFilteredAnalog.hpp:138
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
Bankable::MIDIFilteredAnalogAddressable::MIDIFilteredAnalogAddressable
MIDIFilteredAnalogAddressable(const BankAddress &bankAddress, pin_t analogPin, const Sender &sender)
Construct a new MIDIFilteredAnalog.
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:34
Bankable::MIDIFilteredAnalogAddressable::update
void update() override
Update this updatable.
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:40
Bankable::MIDIFilteredAnalog::sender
Sender sender
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:151
FilteredAnalog::getValue
analog_t getValue() const
Get the filtered value of the analog input with the mapping function applied.
Definition: FilteredAnalog.hpp:113
Bankable::MIDIFilteredAnalog::begin
void begin() final override
Initialize this updatable.
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:111
Bankable::MIDIFilteredAnalog::MIDIFilteredAnalog
MIDIFilteredAnalog(const BankAddress &bankAddress, pin_t analogPin, const Sender &sender)
Construct a new MIDIFilteredAnalog.
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:106
Bankable::MIDIFilteredAnalogAddressable::begin
void begin() override
Initialize this updatable.
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:39
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: NamespaceSettings.hpp:10
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
Bankable::MIDIFilteredAnalogAddressable::map
void map(MappingFunction fn)
Specify a mapping function that is applied to the raw analog value before sending.
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:57
Bankable::MIDIFilteredAnalogAddressable
A class for potentiometers and faders that send MIDI events and that can be added to a Bank.
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:21
Bankable::MIDIFilteredAnalog::address
BankAddress address
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:147
Bankable::MIDIFilteredAnalog::getValue
analog_t getValue() const
Get the value of the analog input (this is the value after first applying the mapping function).
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:144
FilteredAnalog.hpp
MappingFunction
analog_t(*)(analog_t) MappingFunction
A function pointer to a mapping function to map analog values.
Definition: Def.hpp:28
Bankable::MIDIFilteredAnalogAddressable::invert
void invert()
Invert the analog value.
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:60
Bankable::MIDIFilteredAnalog::invert
void invert()
Invert the analog value.
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:132