Control Surface main
MIDI Control Surface library for Arduino
Abstract/MIDIRotaryEncoder.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <AH/STL/utility> // std::forward
4#include <Def/Def.hpp>
5#include <Def/TypeTraits.hpp>
8
9#ifdef ARDUINO
11#else
12#include <Encoder.h> // Mock
13#endif
14
16
18
22template <class Enc, class Sender>
24 public:
30 GenericMIDIRotaryEncoder(Enc &&encoder, MIDIAddress address,
31 int16_t speedMultiply, uint8_t pulsesPerStep,
32 const Sender &sender)
33 : encoder(std::forward<Enc>(encoder)), address(address),
34 encstate(speedMultiply, pulsesPerStep), sender(sender) {}
35
36 void begin() override { begin_if_possible(encoder); }
37
38 void update() override {
39 auto encval = encoder.read();
40 if (int16_t delta = encstate.update(encval)) {
41 sender.send(delta, address);
42 }
43 }
44
45 void setSpeedMultiply(int16_t speedMultiply) {
46 encstate.setSpeedMultiply(speedMultiply);
47 }
48 int16_t getSpeedMultiply() const { return encstate.getSpeedMultiply(); }
49
51 MIDIAddress getAddress() const { return this->address; }
53 void setAddress(MIDIAddress address) { this->address = address; }
54
55 private:
58 EncoderState<decltype(encoder.read())> encstate;
59
60 public:
61 Sender sender;
62};
63
64template <class Sender>
66
67template <class Sender>
69
71
#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
Class to keep track of relative position changes of rotary encoders.
An abstract class for rotary encoders that send MIDI events.
void setAddress(MIDIAddress address)
Set the MIDI address.
void setSpeedMultiply(int16_t speedMultiply)
void update() override
Update this updatable.
void begin() override
Initialize this updatable.
MIDIAddress getAddress() const
Get the MIDI address.
GenericMIDIRotaryEncoder(Enc &&encoder, MIDIAddress address, int16_t speedMultiply, uint8_t pulsesPerStep, const Sender &sender)
Construct a new MIDIRotaryEncoder.
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...