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 control change messages with a
10 : * resolution of 7 bits.
11 : *
12 : * @ingroup MIDI_Senders
13 : */
14 : class ContinuousCCSender {
15 : public:
16 : /// Send a 7-bit CC message to the given address.
17 10 : void send(uint8_t value, MIDIAddress address) {
18 10 : Control_Surface.sendControlChange(address, value);
19 10 : }
20 :
21 : /// Get the resolution of the sender in bits (always returns 7).
22 : constexpr static uint8_t precision() { return 7; }
23 : };
24 :
25 : /**
26 : * @brief Class that sends continuous MIDI control change messages with a
27 : * resolution of 14 bits.
28 : *
29 : * @tparam INPUT_PRECISION_BITS
30 : * The resolution of the input values. For example, if
31 : * @p INPUT_PRECISION_BITS == 10, the send function expects a @p value
32 : * between 0 and 1023.
33 : *
34 : * @ingroup MIDI_Senders
35 : */
36 : template <uint8_t INPUT_PRECISION_BITS>
37 : class ContinuousCCSender14 {
38 : public:
39 : /// Send a 14-bit CC message to the given address.
40 : /// Sends two 7-bit CC packets, one for @p address (MSB), and one for
41 : /// @p address + 0x20 (LSB).
42 : void send(uint16_t value, MIDIAddress address) {
43 : value = AH::increaseBitDepth<14, precision(), uint16_t>(value);
44 : Control_Surface.sendControlChange(address + 0x00, (value >> 7) & 0x7F);
45 : Control_Surface.sendControlChange(address + 0x20, (value >> 0) & 0x7F);
46 : }
47 :
48 : /// Get this sender's precision.
49 : constexpr static uint8_t precision() {
50 : static_assert(INPUT_PRECISION_BITS <= 14,
51 : "Maximum resolution is 14 bits");
52 : return INPUT_PRECISION_BITS;
53 : }
54 : };
55 :
56 : END_CS_NAMESPACE
|