Control Surface stm32
MIDI Control Surface library for Arduino
Bankable/Abstract/MIDIRotaryEncoder.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
19
20namespace Bankable {
21
26template <class Enc, class BankAddress, class Sender>
28 protected:
34 GenericMIDIRotaryEncoder(BankAddress bankAddress, Enc &&encoder,
35 int16_t speedMultiply, uint8_t pulsesPerStep,
36 const Sender &sender)
37 : address(bankAddress), encoder(std::forward<Enc>(encoder)),
38 encstate(speedMultiply, pulsesPerStep), sender(sender) {}
39
40 public:
41 void begin() override { begin_if_possible(encoder); }
42
43 void update() override {
44 auto encval = encoder.read();
45 if (int16_t delta = encstate.update(encval)) {
46 sender.send(delta, address.getActiveAddress());
47 }
48 }
49
50 void setSpeedMultiply(int16_t speedMultiply) {
51 encstate.setSpeedMultiply(speedMultiply);
52 }
53 int16_t getSpeedMultiply() const { return encstate.getSpeedMultiply(); }
54
55 protected:
56 BankAddress address;
58 EncoderState<decltype(encoder.read())> encstate;
59
60 public:
61 Sender sender;
62};
63
64template <class BankAddress, class Sender>
67
68template <class BankAddress, class Sender>
71
72} // namespace Bankable
73
75
#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.
Definition: TypeTraits.hpp:23
#define AH_DIAGNOSTIC_POP()
Definition: Warnings.hpp:37
#define AH_DIAGNOSTIC_WERROR()
Definition: Warnings.hpp:36
A super class for object that have to be updated regularly.
Definition: Updatable.hpp:173
An abstract class for rotary encoders that send MIDI events and that can be added to a Bank.
void update() override
Update this updatable.
void begin() override
Initialize this updatable.
GenericMIDIRotaryEncoder(BankAddress bankAddress, Enc &&encoder, int16_t speedMultiply, uint8_t pulsesPerStep, const Sender &sender)
Construct a new GenericMIDIRotaryEncoder.
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)
EncoderState< decltype(encoder.read())> encstate
A namespace for MIDI elements that can be added to a Bank, to change their address or channel.