5#include <AH/STL/algorithm>
27template <u
int8_t NumBanks,
class BankAddress,
class Sender>
43 : address(bankAddress), filteredAnalog(analogPin), sender(sender) {}
62 filteredAnalog.resetToCurrentValue();
63 previousBank = address.getSelection();
64 std::fill(std::begin(previousValues), std::end(previousValues),
69 auto activeBank = address.getSelection();
70 if (filteredAnalog.update() || activeBank != previousBank) {
71 auto previousValue = previousValues[activeBank];
72 auto value = filteredAnalog.getValue();
73 if (activeBank == previousBank && state == Higher) {
74 if (value <= previousValue)
76 }
else if (activeBank == previousBank && state == Lower) {
77 if (value >= previousValue)
79 }
else if (activeBank != previousBank) {
80 if (value == previousValue || previousValue == initial)
82 else if (value > previousValue)
86 previousBank = activeBank;
88 if (activeBank == previousBank && state == Active) {
89 sender.send(value, address.getActiveAddress());
90 previousValues[activeBank] = value;
122 void invert() { filteredAnalog.invert(); }
140 return previousValues[bank];
147 return getPreviousValue(address.getSelection());
154 Sender::precision() <= 14,
155 "Sender precision must be 14 or less, because larger values are "
uint8_t setting_t
The type used for Selectors.
analog_t(*)(analog_t) MappingFunction
#define BEGIN_CS_NAMESPACE
#define AH_DIAGNOSTIC_POP()
#define AH_DIAGNOSTIC_WERROR()
A class that reads and filters an analog input.
A super class for object that have to be updated regularly.
A class for potentiometers and faders that send MIDI events.
analog_t getValue() const
Get the value of the analog input (this is the value after first applying the mapping function).
void update() override
Update this updatable.
void map(MappingFunction fn)
Specify a mapping function that is applied to the raw analog value before sending.
State
State of the smart potentiometer.
@ Active
The potentiometer is active, the position changes will be sent over MIDI.
@ Higher
The value of the potentiometer is higher than the previously recorded value for the current bank.
@ Lower
The value of the potentiometer is lower than the previously recorded value for the current bank.
void begin() override
Initialize this updatable.
void invert()
Invert the analog value.
void activate()
Activate the potentiometer in the current bank, regardless of its current and previous position.
State getState() const
Get the state of the smart potentiometer, to know whether the position has to be lower or higher in o...
AH::FilteredAnalog< Sender::precision()> filteredAnalog
analog_t getRawValue() const
Get the raw value of the analog input (this is the value without applying the filter or the mapping f...
analog_t getPreviousValue(setting_t bank) const
Get the previous value of the analog input of the given bank.
SmartMIDIFilteredAnalog(BankAddress bankAddress, pin_t analogPin, const Sender &sender)
Construct a new SmartMIDIFilteredAnalog.
analog_t getPreviousValue() const
Get the previous value of the analog input of the active bank.
uint16_t analog_t
The type returned from analogRead and similar functions.
A namespace for MIDI elements that can be added to a Bank, to change their address or channel.
Type for storing pin numbers of Extended Input/Output elements.