Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
Abstract/MIDIFilteredAnalog.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <Def/Def.hpp>
6
8
16template <class Sender>
18 protected:
31 const Sender &sender)
32 : filteredAnalog(analogPin), address(address), sender(sender) {}
33
34 public:
35 void begin() final override { filteredAnalog.resetToCurrentValue(); }
36
37 void update() final override {
38 if (filteredAnalog.update())
40 }
41
44 void forcedUpdate() { sender.send(filteredAnalog.getValue(), address); }
45
58 void map(MappingFunction fn) { filteredAnalog.map(fn); }
59
61 void invert() { filteredAnalog.invert(); }
62
67 analog_t getRawValue() const { return filteredAnalog.getRawValue(); }
68
72 static constexpr analog_t getMaxRawValue() {
74 }
75
80 analog_t getValue() const { return filteredAnalog.getValue(); }
81
83 MIDIAddress getAddress() const { return this->address; }
85 void setAddress(MIDIAddress address) { this->address = address; }
86
87 private:
88 using FilteredAnalog = AH::FilteredAnalog<Sender::precision()>;
91
92 public:
93 Sender sender;
94};
95
analog_t(*)(analog_t) MappingFunction
Definition Def.hpp:23
AH::Updatable<> MIDIOutputElement
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
A class that reads and filters an analog input.
static constexpr analog_t getMaxRawValue()
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
void setAddress(MIDIAddress address)
Set the MIDI address.
void forcedUpdate()
Send the value of the analog input over MIDI, even if the value didn't change.
analog_t getValue() const
Get the value of the analog input (this is the value after first applying the mapping function).
static constexpr analog_t getMaxRawValue()
Get the maximum value that can be returned from getRawValue.
void map(MappingFunction fn)
Specify a mapping function that is applied to the raw analog value before sending.
AH::FilteredAnalog< Sender::precision()> FilteredAnalog
void invert()
Invert the analog value.
MIDIFilteredAnalog(pin_t analogPin, MIDIAddress address, const Sender &sender)
Construct a new MIDIFilteredAnalog.
MIDIAddress getAddress() const
Get the MIDI address.
void begin() final override
Initialize this updatable.
analog_t getRawValue() const
Get the raw value of the analog input (this is the value without applying the filter or the mapping f...
void update() final override
Update this updatable.
uint16_t analog_t
The type returned from analogRead and similar functions.
Type for storing pin numbers of Extended Input/Output elements.