Control Surface  1.2.0
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.sendCC(address, msgVal);
128  delta -= thisDelta;
129  }
130  }
131 
135 
136  private:
138 };
139 
MACKIE_CONTROL_RELATIVE
@ MACKIE_CONTROL_RELATIVE
Relative mode used by the Mackie Control Universal protocol.
Definition: RelativeCCSender.hpp:72
MIDIAddress
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
Definition: MIDIAddress.hpp:91
NEXT_ADDRESS
@ NEXT_ADDRESS
Encode negative MIDI CC values by incrementing the address if the number is negative,...
Definition: RelativeCCSender.hpp:62
RelativeCCSender::toBinaryOffset7bit
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.
Definition: RelativeCCSender.hpp:96
RelativeCCSender::setMode
static void setMode(relativeCCmode mode)
Set the relative CC mode that's used.
Definition: RelativeCCSender.hpp:134
TWOS_COMPLEMENT
@ TWOS_COMPLEMENT
Encode negative MIDI CC values as 7-bit two's complement.
Definition: RelativeCCSender.hpp:23
KORG_KONTROL_INC_DEC_1
@ KORG_KONTROL_INC_DEC_1
Korg KONTROL in Inc/Dec mode 1.
Definition: RelativeCCSender.hpp:74
RelativeCCSender::send
static void send(long delta, MIDIAddress address)
Send a relative CC message.
Definition: RelativeCCSender.hpp:118
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
Control_Surface_Class.hpp
RelativeCCSender::toSignedMagnitude7bit
static uint8_t toSignedMagnitude7bit(int8_t value)
Convert an 8-bit two's complement integer to 7-bit sign-magnitude format.
Definition: RelativeCCSender.hpp:99
RelativeCCSender::mapRelativeCC
static uint8_t mapRelativeCC(int8_t value)
Convert an 8-bit two's complement integer to a 7-bit value to send over MIDI.
Definition: RelativeCCSender.hpp:107
RelativeCCSender::toTwosComplement7bit
static uint8_t toTwosComplement7bit(int8_t value)
Convert an 8-bit two's complement integer to a 7-bit two's complement integer.
Definition: RelativeCCSender.hpp:92
Control_Surface
Control_Surface_ & Control_Surface
A predefined instance of the Control Surface to use in the Arduino sketches.
Definition: Control_Surface_Class.cpp:203
Arduino-Wrapper.h
BINARY_OFFSET
@ BINARY_OFFSET
Encode negative MIDI CC values by adding a fixed offset of .
Definition: RelativeCCSender.hpp:37
RelativeCCSender::mode
static relativeCCmode mode
Definition: RelativeCCSender.hpp:137
MIDI_Sender::sendCC
void sendCC(MIDIAddress address, uint8_t value)
Send a MIDI Control Change event.
Definition: MIDI_Interface.ipp:67
RelativeCCSender
Class that sends relative/incremental MIDI control change messages.
Definition: RelativeCCSender.hpp:88
TRACKTION_RELATIVE
@ TRACKTION_RELATIVE
Relative mode in Tracktion.
Definition: RelativeCCSender.hpp:70
REAPER_RELATIVE_2
@ REAPER_RELATIVE_2
Second relative mode in Reaper.
Definition: RelativeCCSender.hpp:66
REAPER_RELATIVE_1
@ REAPER_RELATIVE_1
First relative mode in Reaper.
Definition: RelativeCCSender.hpp:64
REAPER_RELATIVE_3
@ REAPER_RELATIVE_3
Third relative mode in Reaper.
Definition: RelativeCCSender.hpp:68
relativeCCmode
relativeCCmode
The encoding to use for relative control change value.
Definition: RelativeCCSender.hpp:10
SIGN_MAGNITUDE
@ SIGN_MAGNITUDE
Encode negative MIDI CC values by using the most significant bit as a sign bit, and the six least sig...
Definition: RelativeCCSender.hpp:52