This is an old version of the documentation. View the latest version here.
Control Surface  1.0.0
MIDI Control Surface library for Arduino
RelativeCCSender.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include <Arduino.h> // for constrain
6 
8 
63 };
64 
66  public:
69  static uint8_t toTwosComplement7bit(int8_t value) { return value & 0x7F; }
73  static uint8_t toBinaryOffset7bit(int8_t value) { return value + 64; }
76  static uint8_t toSignedMagnitude7bit(int8_t value) {
77  uint8_t mask = value >> 7;
78  uint8_t abs = (value + mask) ^ mask;
79  uint8_t sign = mask & 0b01000000;
80  return (abs & 0b00111111) | sign;
81  }
84  static uint8_t mapRelativeCC(int8_t value) {
85  switch (mode) {
86  case TWOS_COMPLEMENT: return toTwosComplement7bit(value);
87  case BINARY_OFFSET: return toBinaryOffset7bit(value);
88  case SIGN_MAGNITUDE: return toSignedMagnitude7bit(value);
89  default: return 0; // Keeps the compiler happy
90  }
91  }
92 
93  static void send(long delta, MIDICNChannelAddress address) {
94  while (delta != 0) {
95  // Constrain relative movement to +/-15 for
96  // Mackie Control Universal compatibility
97  long thisDelta = constrain(delta, -15, 15);
98  uint8_t msgVal = mapRelativeCC(thisDelta);
99  // send a Control Change MIDI event
100  Control_Surface.MIDI().sendCC(address, msgVal);
101  delta -= thisDelta;
102  }
103  }
104 
106 
107  private:
109 };
110 
MACKIE_CONTROL_RELATIVE
Relative mode used by the Mackie Control Universal protocol.
Definition: RelativeCCSender.hpp:62
TWOS_COMPLEMENT
Encode negative MIDI CC values as 7-bit two's complement.
Definition: RelativeCCSender.hpp:23
Control_Surface_::MIDI
MIDI_Interface & MIDI()
Get the MIDI interface of the Control Surface.
Definition: Control_Surface_Class.cpp:55
MIDI_Interface::sendCC
void sendCC(MIDICNChannelAddress address, uint8_t value)
Send a MIDI Control Change event.
Definition: MIDI_Interface.cpp:75
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:73
Control_Surface_Class.hpp
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: NamespaceSettings.hpp:9
MIDICNChannelAddress
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
Definition: MIDICNChannelAddress.hpp:82
RelativeCCSender::setMode
static void setMode(relativeCCmode mode)
Definition: RelativeCCSender.hpp:105
Control_Surface
Control_Surface_ & Control_Surface
A predefined instance of the Control Surface to use in the Arduino sketches.
Definition: Control_Surface_Class.cpp:171
RelativeCCSender::mode
static relativeCCmode mode
Definition: RelativeCCSender.hpp:108
BINARY_OFFSET
Encode negative MIDI CC values by adding a fixed offset of .
Definition: RelativeCCSender.hpp:37
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: NamespaceSettings.hpp:10
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:69
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:84
RelativeCCSender
Definition: RelativeCCSender.hpp:65
TRACKTION_RELATIVE
Relative mode in Tracktion.
Definition: RelativeCCSender.hpp:60
REAPER_RELATIVE_2
Second relative mode in Reaper.
Definition: RelativeCCSender.hpp:56
REAPER_RELATIVE_1
First relative mode in Reaper.
Definition: RelativeCCSender.hpp:54
REAPER_RELATIVE_3
Third relative mode in Reaper.
Definition: RelativeCCSender.hpp:58
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:76
relativeCCmode
relativeCCmode
The encoding to use for relative control change value.
Definition: RelativeCCSender.hpp:10
RelativeCCSender::send
static void send(long delta, MIDICNChannelAddress address)
Definition: RelativeCCSender.hpp:93
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