3#include <AH/STL/type_traits>
4#include <AH/STL/utility>
24template <class Enc, class Sender>
28 int16_t speedMultiply, uint8_t pulsesPerStep,
30 : encoder(std::forward<Enc>(encoder)), address(address),
31 encstate(speedMultiply, pulsesPerStep), sender(sender) {}
36 auto encval = encoder.read();
37 if (int16_t delta = encstate.update(encval)) {
38 int16_t oldValue = value;
39 int16_t newValue = oldValue + delta;
40 newValue = constrain(newValue, 0, maxValue);
41 if (oldValue != newValue) {
60 void setValue(uint16_t value) { this->value = value; }
66 encstate.setSpeedMultiply(speedMultiply);
76 auto encval = encoder.read();
77 return encstate.update(encval);
86 constexpr static int16_t maxValue = uint16_t(1u << Sender::precision()) - 1;
92template <
class Sender>
95template <
class Sender>
#define BEGIN_CS_NAMESPACE
std::enable_if< has_method_begin< T >::value >::type begin_if_possible(T &t)
Calls the begin() method of t if that method exists.
#define AH_DIAGNOSTIC_POP()
#define AH_DIAGNOSTIC_WERROR()
A super class for object that have to be updated regularly.
Class to keep track of relative position changes of rotary encoders.
An abstract class for rotary encoders that send absolute MIDI events.
int16_t resetPositionOffset()
void setAddress(MIDIAddress address)
Set the MIDI address.
static int16_t getMaxValue()
Get the maximum possible value that can be returned by getValue.
int16_t getSpeedMultiply() const
void forcedUpdate()
Send the current value over MIDI, even if the position of the encoder didn't change.
uint16_t getValue() const
Get the absolute value of the encoder.
void setSpeedMultiply(int16_t speedMultiply)
void update() override
Update this updatable.
void setValue(uint16_t value)
Set the absolute value of the encoder.
GenericMIDIAbsoluteEncoder(Enc &&encoder, MIDIAddress address, int16_t speedMultiply, uint8_t pulsesPerStep, const Sender &sender)
void begin() override
Initialize this updatable.
MIDIAddress getAddress() const
Get the MIDI address.
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...