Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
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
20template <class Enc, class Sender>
22 public:
29 int16_t speedMultiply, uint8_t pulsesPerStep,
30 const Sender &sender)
31 : encoder(std::forward<Enc>(encoder)), address(address),
32 encstate(speedMultiply, pulsesPerStep), sender(sender) {}
33
34 void begin() override { begin_if_possible(encoder); }
35
36 void update() override {
37 auto encval = encoder.read();
38 if (int16_t delta = encstate.update(encval)) {
39 sender.send(delta, address);
40 }
41 }
42
43 void setSpeedMultiply(int16_t speedMultiply) {
44 encstate.setSpeedMultiply(speedMultiply);
45 }
46 int16_t getSpeedMultiply() const { return encstate.getSpeedMultiply(); }
47
49 MIDIAddress getAddress() const { return this->address; }
51 void setAddress(MIDIAddress address) { this->address = address; }
52
54 auto encval = encoder.read();
55 return encstate.update(encval);
56 }
57
58 private:
61 EncoderState<decltype(encoder.read())> encstate;
62
63 public:
64 Sender sender;
65};
66
67template <class Sender>
69
70template <class Sender>
72
GenericMIDIRotaryEncoder< AHEncoder &, Sender > BorrowedMIDIRotaryEncoder
GenericMIDIRotaryEncoder< AHEncoder, Sender > MIDIRotaryEncoder
AH::Updatable<> MIDIOutputElement
#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.
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.
EncoderState< decltype(encoder.read())> encstate
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...