Control Surface  1.1.1
MIDI Control Surface library for Arduino
Bankable/Abstract/MIDIFilteredAnalog.hpp
Go to the documentation of this file.
1 #pragma once
2 
5 #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 
61 
67 
72  analog_t getValue() const { return filteredAnalog.getValue(); }
73 
74  private:
75  BankAddress address;
76  AH::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  AH::FilteredAnalog<Sender::precision()> filteredAnalog;
149 
150  public:
151  Sender sender;
152 };
153 
154 } // namespace Bankable
155 
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
Bankable::MIDIFilteredAnalog::filteredAnalog
AH::FilteredAnalog< Sender::precision()> filteredAnalog
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:148
AH::FilteredAnalog::getValue
AnalogType getValue() const
Get the filtered value of the analog input (with the mapping function applied).
Definition: FilteredAnalog.hpp:128
AH::Updatable<>
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
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::MIDIFilteredAnalog::begin
void begin() final override
Initialize this updatable.
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:111
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::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
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
AH::pin_t
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
Definition: Hardware-Types.hpp:17
MIDIOutputElement.hpp
Def.hpp
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
Bankable::MIDIFilteredAnalogAddressable::sender
Sender sender
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:79
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
Bankable::MIDIFilteredAnalog::invert
void invert()
Invert the analog value.
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:132
AH::FilteredAnalog
A class that reads and filters an analog input.
Definition: FilteredAnalog.hpp:55
Bankable::MIDIFilteredAnalog::sender
Sender sender
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:151
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::begin
void begin() override
Initialize this updatable.
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:39
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
Bankable::MIDIFilteredAnalog::update
void update() final override
Update this updatable.
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:112
Bankable::MIDIFilteredAnalog::address
BankAddress address
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:147
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::address
BankAddress address
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:75
AH::analog_t
uint16_t analog_t
The type returned from analogRead and similar functions.
Definition: Hardware-Types.hpp:15
Bankable::MIDIFilteredAnalogAddressable::invert
void invert()
Invert the analog value.
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:60
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
Bankable::MIDIFilteredAnalogAddressable::filteredAnalog
AH::FilteredAnalog< Sender::precision()> filteredAnalog
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:76
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
AH::FilteredAnalog::invert
void invert()
Invert the analog value.
Definition: FilteredAnalog.hpp:95
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.hpp
MappingFunction
analog_t(*)(analog_t) MappingFunction
Definition: Def.hpp:19
Bankable::MIDIFilteredAnalog::MIDIFilteredAnalog
MIDIFilteredAnalog(const BankAddress &bankAddress, pin_t analogPin, const Sender &sender)
Construct a new MIDIFilteredAnalog.
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:106
AH::FilteredAnalog::update
bool update()
Read the analog input value, apply the mapping function, and update the average.
Definition: FilteredAnalog.hpp:109
Bankable::MIDIFilteredAnalogAddressable::update
void update() override
Update this updatable.
Definition: Bankable/Abstract/MIDIFilteredAnalog.hpp:40