Control Surface main
MIDI Control Surface library for Arduino
RelativeCCSender.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include <AH/Arduino-Wrapper.h> // for constrain
6
8
75};
76
89 public:
92 static uint8_t toTwosComplement7bit(int8_t value) { return value & 0x7F; }
96 static uint8_t toBinaryOffset7bit(int8_t value) { return value + 64; }
99 static uint8_t toSignedMagnitude7bit(int8_t value) {
100 uint8_t mask = value >> 7;
101 uint8_t abs = (value + mask) ^ mask;
102 uint8_t sign = mask & 0b01000000;
103 return (abs & 0b00111111) | sign;
104 }
107 static uint8_t mapRelativeCC(int8_t value) {
108 switch (mode) {
109 case TWOS_COMPLEMENT: return toTwosComplement7bit(value);
110 case BINARY_OFFSET: return toBinaryOffset7bit(value);
111 case SIGN_MAGNITUDE: return toSignedMagnitude7bit(value);
112 case NEXT_ADDRESS: return value < 0 ? -value : value;
113 default: return 0; // Keeps the compiler happy
114 }
115 }
116
118 static void send(long delta, MIDIAddress address) {
119 if (delta < 0 && mode == NEXT_ADDRESS)
120 address = address + 1;
121 while (delta != 0) {
122 // Constrain relative movement to +/-15 for
123 // Mackie Control Universal compatibility
124 long thisDelta = constrain(delta, -15, 15);
125 uint8_t msgVal = mapRelativeCC(thisDelta);
126 // send a Control Change MIDI event
127 Control_Surface.sendControlChange(address, msgVal);
128 delta -= thisDelta;
129 }
130 }
131
135
136 private:
138};
139
Control_Surface_ & Control_Surface
A predefined instance of the Control Surface to use in the Arduino sketches.
relativeCCmode
The encoding to use for relative control change value.
@ KORG_KONTROL_INC_DEC_1
Korg KONTROL in Inc/Dec mode 1.
@ BINARY_OFFSET
Encode negative MIDI CC values by adding a fixed offset of .
@ NEXT_ADDRESS
Encode negative MIDI CC values by incrementing the address if the number is negative,...
@ REAPER_RELATIVE_2
Second relative mode in Reaper.
@ TRACKTION_RELATIVE
Relative mode in Tracktion.
@ REAPER_RELATIVE_1
First relative mode in Reaper.
@ TWOS_COMPLEMENT
Encode negative MIDI CC values as 7-bit two's complement.
@ SIGN_MAGNITUDE
Encode negative MIDI CC values by using the most significant bit as a sign bit, and the six least sig...
@ REAPER_RELATIVE_3
Third relative mode in Reaper.
@ MACKIE_CONTROL_RELATIVE
Relative mode used by the Mackie Control Universal protocol.
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
void sendControlChange(MIDIAddress address, uint8_t value)
Send a MIDI Control Change event.
Definition: MIDI_Sender.ipp:54
Class that sends relative/incremental MIDI control change messages.
static uint8_t mapRelativeCC(int8_t value)
Convert an 8-bit two's complement integer to a 7-bit value to send over MIDI.
static relativeCCmode mode
static void setMode(relativeCCmode mode)
Set the relative CC mode that's used.
static uint8_t toTwosComplement7bit(int8_t value)
Convert an 8-bit two's complement integer to a 7-bit two's complement integer.
static uint8_t toBinaryOffset7bit(int8_t value)
Convert an 8-bit two's complement integer to a 7-bit integer with a binary offset of 64.
static void send(long delta, MIDIAddress address)
Send a relative CC message.
static uint8_t toSignedMagnitude7bit(int8_t value)
Convert an 8-bit two's complement integer to 7-bit sign-magnitude format.