Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
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
18namespace Bankable {
19
24template <class Enc, class BankAddress, class Sender>
26 protected:
32 GenericMIDIRotaryEncoder(BankAddress bankAddress, Enc &&encoder,
33 int16_t speedMultiply, uint8_t pulsesPerStep,
34 const Sender &sender)
35 : address(bankAddress), encoder(std::forward<Enc>(encoder)),
36 encstate(speedMultiply, pulsesPerStep), sender(sender) {}
37
38 public:
39 void begin() override { begin_if_possible(encoder); }
40
41 void update() override {
42 auto encval = encoder.read();
43 if (int16_t delta = encstate.update(encval)) {
44 sender.send(delta, address.getActiveAddress());
45 }
46 }
47
48 void setSpeedMultiply(int16_t speedMultiply) {
49 encstate.setSpeedMultiply(speedMultiply);
50 }
51 int16_t getSpeedMultiply() const { return encstate.getSpeedMultiply(); }
52
54 auto encval = encoder.read();
55 return encstate.update(encval);
56 }
57
58 protected:
59 BankAddress address;
61 EncoderState<decltype(encoder.read())> encstate;
62
63 public:
64 Sender sender;
65};
66
67template <class BankAddress, class Sender>
70
71template <class BankAddress, class Sender>
74
75} // namespace Bankable
76
#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 MIDI events and that can be added to a Bank.
void begin() override
Initialize this updatable.
EncoderState< decltype(encoder.read())> encstate
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)
A namespace for MIDI elements that can be added to a Bank, to change their address or channel.