Line data Source code
1 : #pragma once 2 : 3 : #include <AH/Math/IncreaseBitDepth.hpp> 4 : #include <Control_Surface/Control_Surface_Class.hpp> 5 : 6 : BEGIN_CS_NAMESPACE 7 : 8 : /** 9 : * @brief Class that sends continuous MIDI pitch bend messages with a 10 : * resolution of 14 bits. 11 : * 12 : * @tparam INPUT_PRECISION_BITS 13 : * The resolution of the input values. For example, if 14 : * @p INPUT_PRECISION_BITS == 10, the send function expects a @p value 15 : * between 0 and 1023. 16 : * 17 : * @ingroup MIDI_Senders 18 : */ 19 : template <uint8_t INPUT_PRECISION_BITS> 20 : class PitchBendSender { 21 : public: 22 : /// Send a MIDI pitch bend message with the given value and channel+CN. 23 : /// address.getAddress() is ignored. 24 : /// Value should be @p INPUT_PRECISION_BITS wide. 25 9 : static void send(uint16_t value, MIDIAddress address) { 26 9 : value = AH::increaseBitDepth<14, precision(), uint16_t>(value); 27 : // ignore address byte, just use channel and cable numbers 28 18 : MIDIChannelCN channelCN = {address.getChannel(), 29 9 : address.getCableNumber()}; 30 9 : Control_Surface.sendPB(channelCN, value); 31 9 : } 32 : 33 : /// Get this sender's precision. 34 : constexpr static uint8_t precision() { 35 : static_assert(INPUT_PRECISION_BITS <= 14, 36 : "Maximum pitch bend resolution is 14 bits"); 37 : return INPUT_PRECISION_BITS; 38 : } 39 : }; 40 : 41 : END_CS_NAMESPACE