#pragma once #include #include #include #include #include #include BEGIN_CS_NAMESPACE template class GenericMIDIRotaryEncoder : public MIDIOutputElement { public: GenericMIDIRotaryEncoder(Enc &&encoder, MIDIAddress address, int16_t speedMultiply, uint8_t pulsesPerStep, const Sender &sender) : encoder(std::forward(encoder)), address(address), encstate(speedMultiply, pulsesPerStep), sender(sender) {} void begin() override { begin_if_possible(encoder); } void update() override { auto encval = encoder.read(); if (int16_t delta = encstate.update(encval)) { sender.send(delta, address); } } void setSpeedMultiply(int16_t speedMultiply) { encstate.setSpeedMultiply(speedMultiply); } int16_t getSpeedMultiply() const { return encstate.getSpeedMultiply(); } MIDIAddress getAddress() const { return this->address; } void setAddress(MIDIAddress address) { this->address = address; } int16_t resetPositionOffset() { auto encval = encoder.read(); return encstate.update(encval); } private: Enc encoder; MIDIAddress address; EncoderState encstate; public: Sender sender; }; template using MIDIRotaryEncoder = GenericMIDIRotaryEncoder; template using BorrowedMIDIRotaryEncoder = GenericMIDIRotaryEncoder; END_CS_NAMESPACE