Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
Bankable/Abstract/MIDIAbsoluteEncoder.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <AH/STL/utility> // std::forward
5#include <Def/Def.hpp>
6#include <Def/TypeTraits.hpp>
9
10#ifdef ARDUINO
12#else
13#include <Encoder.h> // Mock
14#endif
15
17
18namespace Bankable {
19
24template <class Enc, uint8_t NumBanks, class BankAddress, class Sender>
26 public:
28 int16_t speedMultiply, uint8_t pulsesPerStep,
29 const Sender &sender)
31 encstate(speedMultiply, pulsesPerStep), sender(sender) {}
32
33 void begin() override { begin_if_possible(encoder); }
34
35 void update() override {
36 auto encval = encoder.read();
38 address.lock();
39 int16_t oldValue = values[address.getSelection()];
42 if (oldValue != newValue) {
43 values[address.getSelection()] = newValue;
45 }
46 address.unlock();
47 }
48 }
49
52 void forcedUpdate() {
53 sender.send(values[address.getSelection()], address.getActiveAddress());
54 }
56 sender.send(values[bank], address.getActiveAddress(bank));
57 }
58
62 uint16_t getValue(setting_t bank) const { return values[bank]; }
66 uint16_t getValue() const { return getValue(address.getSelection()); }
67
71 void setValue(uint16_t value, setting_t bank) { values[bank] = value; }
75 void setValue(uint16_t value) { setValue(value, address.getSelection()); }
76
78 static int16_t getMaxValue() { return maxValue; }
79
80 void setSpeedMultiply(int16_t speedMultiply) {
81 encstate.setSpeedMultiply(speedMultiply);
82 }
84
86 auto encval = encoder.read();
87 return encstate.update(encval);
88 }
89
90 protected:
94 EncoderState<decltype(encoder.read())> encstate;
95
96 constexpr static int16_t maxValue = uint16_t(1u << Sender::precision()) - 1;
97
98 public:
99 Sender sender;
100};
101
102template <uint8_t NumBanks, class BankAddress, class Sender>
105
106template <uint8_t NumBanks, class BankAddress, class Sender>
109
110} // namespace Bankable
111
#define END_CS_NAMESPACE
#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.
A super class for object that have to be updated regularly.
An abstract class for rotary encoders that send absolute MIDI events.
static int16_t getMaxValue()
Get the maximum possible value that can be returned by getValue.
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 in the active bank.
void setValue(uint16_t value, setting_t bank)
Set the absolute value of the encoder in the given bank.
void setValue(uint16_t value)
Set the absolute value of the encoder in the active bank.
void begin() override
Initialize this updatable.
GenericMIDIAbsoluteEncoder(const BankAddress &address, Enc &&encoder, int16_t speedMultiply, uint8_t pulsesPerStep, const Sender &sender)
uint16_t getValue(setting_t bank) const
Get the absolute value of the encoder in the given bank.
Class to keep track of relative position changes of rotary encoders.
int16_t getSpeedMultiply() const
void setSpeedMultiply(int16_t speedMultiply)
int16_t update(Enc_t encval)
A namespace for MIDI elements that can be added to a Bank, to change their address or channel.
An array wrapper for easy copying, comparing, and iterating.
Definition Array.hpp:32