Skip to content

Commit

Permalink
Change MIDI_Notes::X(n) by MIDI_Notes::X[n]
Browse files Browse the repository at this point in the history
  • Loading branch information
tttapa committed Feb 17, 2024
1 parent bc599fa commit b0f4d63
Show file tree
Hide file tree
Showing 30 changed files with 111 additions and 135 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ received:
#include <Control_Surface.h>

USBMIDI_Interface midi;
NoteLED led { LED_BUILTIN, MIDI_Notes::C(4) };
NoteLED led { LED_BUILTIN, MIDI_Notes::C[4] };

void setup() { Control_Surface.begin(); }
void loop() { Control_Surface.loop(); }
Expand Down
22 changes: 1 addition & 21 deletions doxygen/pages/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Here's a basic MIDI output example:
```cpp
USBMIDI_Interface midi; // Instantiate the MIDI over USB interface

const MIDIAddress noteAddress = {MIDI_Notes::C(4), Channel_1};
const MIDIAddress noteAddress = {MIDI_Notes::C[4], Channel_1};
const uint8_t velocity = 0x7F;

void setup() {
Expand Down Expand Up @@ -252,26 +252,6 @@ defining `Control_Surface` as a global variable. This allows the optimizer and
the linker to optimize out parts of the library more effectively, but may reduce
the quality of code completion. It does not affect the behavior of the library.
## Why do I get a compiler error when using the note F? {#faq-midi-note-f}
The Arduino core defines a global preprocessor macro `F(...)` which places
string literals in flash memory. Unfortunately, macros do not follow the C++
syntax and scoping rules, so it means that it is impossible to create a constant
or function with the name `F`, even in a separate namespace. Therefore, the note
F can be referenced using the name `F_` (F underscore) instead of `F`.
If you get this wrong, you might get an error saying the following:
```
In file included from /home/user/.arduino15/packages/arduino/hardware/avr/1.8.3/cores/arduino/Arduino.h:232:0,
from /tmp/arduino-sketch-XXXXX/sketch/sketch.ino.cpp:1:
/home/user/.arduino15/packages/arduino/hardware/avr/1.8.3/cores/arduino/WString.h:38:27: error: expected unqualified-id before '(' token
#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))
^
sketch.ino: note: in expansion of macro 'F'
{ pin, MIDI_Notes::F(4) }
^
```
## What's the difference between the Control Surface and MIDI Controller libraries? {#faq-control-surface-vs-midi-controller}
You might already have found my other Arduino MIDI library, [MIDI Controller](https://github.com/tttapa/MIDI_Controller),
Expand Down
38 changes: 19 additions & 19 deletions doxygen/pages/Getting-Started.md
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ function in the @ref MIDI_Notes namespace,
or you can just use a number.
```cpp
NoteLED noteLed { 13, {MIDI_Notes::C(4), Channel_1} }; // C4 = middle C
NoteLED noteLed { 13, {MIDI_Notes::C[4], Channel_1} }; // C4 = middle C
```
In our case, we don't want a single LED, we want eight. It's much easier to
Expand All @@ -362,14 +362,14 @@ default channel, `Channel_1`.
```cpp
NoteLED leds[] {
{sreg.pin(0), MIDI_Notes::C(4)},
{sreg.pin(1), MIDI_Notes::D(4)},
{sreg.pin(2), MIDI_Notes::E(4)},
{sreg.pin(3), MIDI_Notes::F_(4)}, // F is an exception :(
{sreg.pin(4), MIDI_Notes::G(4)},
{sreg.pin(5), MIDI_Notes::A(4)},
{sreg.pin(6), MIDI_Notes::B(4)},
{sreg.pin(7), MIDI_Notes::C(5)},
{sreg.pin(0), MIDI_Notes::C[4]},
{sreg.pin(1), MIDI_Notes::D[4]},
{sreg.pin(2), MIDI_Notes::E[4]},
{sreg.pin(3), MIDI_Notes::F[4]},
{sreg.pin(4), MIDI_Notes::G[4]},
{sreg.pin(5), MIDI_Notes::A[4]},
{sreg.pin(6), MIDI_Notes::B[4]},
{sreg.pin(7), MIDI_Notes::C[5]},
};
```
Expand Down Expand Up @@ -416,14 +416,14 @@ SPIShiftRegisterOut<8> sreg {
// Create an array of LEDs that listen to MIDI Note messages, turning on and off
// the LEDs connected to the eight output pins of the shift register
NoteLED leds[] {
{sreg.pin(0), MIDI_Notes::C(4)}, // LED pin, address (note number, channel, cable)
{sreg.pin(1), MIDI_Notes::D(4)}, //
{sreg.pin(2), MIDI_Notes::E(4)}, //
{sreg.pin(3), MIDI_Notes::F_(4)}, // F is an exception :(
{sreg.pin(4), MIDI_Notes::G(4)}, //
{sreg.pin(5), MIDI_Notes::A(4)}, //
{sreg.pin(6), MIDI_Notes::B(4)}, //
{sreg.pin(7), MIDI_Notes::C(5)}, //
{sreg.pin(0), MIDI_Notes::C[4]}, // LED pin, address (note number, channel, cable)
{sreg.pin(1), MIDI_Notes::D[4]}, //
{sreg.pin(2), MIDI_Notes::E[4]}, //
{sreg.pin(3), MIDI_Notes::F[4]}, //
{sreg.pin(4), MIDI_Notes::G[4]}, //
{sreg.pin(5), MIDI_Notes::A[4]}, //
{sreg.pin(6), MIDI_Notes::B[4]}, //
{sreg.pin(7), MIDI_Notes::C[5]}, //
};
// Initialize the Control Surface
Expand Down Expand Up @@ -457,8 +457,8 @@ before initializing Control Surface. For example:
// Oops! We forgot to instantiate a MIDI interface!
NoteButton button {2, MIDI_Notes::C(4)};
NoteLED led {13, MIDI_Notes::C(4)};
NoteButton button {2, MIDI_Notes::C[4]};
NoteLED led {13, MIDI_Notes::C[4]};
void setup() {
#ifdef DEBUG_OUT
Expand Down
42 changes: 17 additions & 25 deletions doxygen/pages/MIDI.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void setup() {
// Specify the MIDI note number to trigger, and the velocity with which to
// trigger it
const MIDIAddress note = MIDI_Notes::C(4); // C(4) is middle C
const MIDIAddress note = MIDI_Notes::C[4]; // C4 is middle C
const uint8_t velocity = 127; // 127 is maximum velocity
void loop() {
Expand All @@ -179,7 +179,7 @@ interface are exactly the same.
The second thing you'll notice are the two constants, `note` and `velocity`:
these define the MIDI note number and the velocity (how hard the key is struck)
to be used when sending the MIDI messages later.
The function `MIDI_Notes::C(4)` gives you the note C in the fourth octave, or
The expression `MIDI_Notes::C[4]` gives you the note C in the fourth octave, or
middle C. The velocity is a value between 1 and 127, with higher values being
louder and harder.

Expand Down Expand Up @@ -259,17 +259,9 @@ For entering MIDI note numbers, you can use the note names in the
@ref MIDI_Notes namespace:
~~~cpp
// MIDI Note middle C (C in the fourth octave) on MIDI Channel 16:
MIDIAddress myAddress = {MIDI_Notes::C(4), Channel_16};
MIDIAddress myAddress = {MIDI_Notes::C[4], Channel_16};
~~~
For reasons explained [here](@ref faq-midi-note-f), the note F is an exception,
you have to add a trailing underscore to avoid conflicts with Arduino's `F(...)`
macro:
~~~cpp
// MIDI Note F in the fourth octave on MIDI Channel 16:
MIDIAddress myAddress = {MIDI_Notes::F_(4), Channel_16};
// note the underscore here ^
~~~
If you look at the full list of note names in the @ref MIDI_Notes namespace,
you'll see that the sharps are missing: you can simply use the flats instead
(e.g. instead of using G♯, you can use A♭).
Expand Down Expand Up @@ -511,7 +503,7 @@ struct MyMIDI_Callbacks : MIDI_Callbacks {
// Check if it's a note message:
bool note_msg = type == msg.NOTE_ON || type == msg.NOTE_OFF;
// Check if it's the specific note and channel we're looking for
bool our_note = channel == Channel_1 && note == MIDI_Notes::C(4);
bool our_note = channel == Channel_1 && note == MIDI_Notes::C[4];
// If both conditions are satisfies, print the message
if (note_msg && our_note)
Serial << type << " middle C on Channel 1 with velocity "
Expand Down Expand Up @@ -542,7 +534,7 @@ struct MyMIDI_Callbacks : MIDI_Callbacks {
// Check if it's a note message:
bool note_msg = type == msg.NOTE_ON || type == msg.NOTE_OFF;
// Define the address we're interested in
const MIDIAddress our_special_note = {MIDI_Notes::C(4), Channel_1};
const MIDIAddress our_special_note = {MIDI_Notes::C[4], Channel_1};
// If it's a note message that matches our specific address, print it
if (note_msg && msg.getAddress() == our_special_note)
Serial << type << " middle C on Channel 1 with velocity "
Expand Down Expand Up @@ -571,8 +563,8 @@ Let's start with a very simple example:
// Instantiate a MIDI over USB interface with the name `midi_usb`
USBMIDI_Interface midi_usb;
NoteButton button {2, MIDI_Notes::C(4)};
NoteLED led {13, MIDI_Notes::C(4)};
NoteButton button {2, MIDI_Notes::C[4]};
NoteLED led {13, MIDI_Notes::C[4]};
void setup() {
// Initialize everything, including MIDI interfaces and default routes
Expand Down Expand Up @@ -617,8 +609,8 @@ USBMIDI_Interface midi_usb;
// Instantiate the two pipes to connect the interface to Control_Surface
MIDI_Pipe pipe_tx, pipe_rx;
NoteButton button {2, MIDI_Notes::C(4)};
NoteLED led {13, MIDI_Notes::C(4)};
NoteButton button {2, MIDI_Notes::C[4]};
NoteLED led {13, MIDI_Notes::C[4]};
void setup() {
// Manually route MIDI output from Control_Surface to the MIDI interface
Expand Down Expand Up @@ -671,8 +663,8 @@ USBMIDI_Interface midi_usb;
// Instantiate the pipe to connect the interface to Control_Surface
BidirectionalMIDI_Pipe pipe_txrx;
NoteButton button {2, MIDI_Notes::C(4)};
NoteLED led {13, MIDI_Notes::C(4)};
NoteButton button {2, MIDI_Notes::C[4]};
NoteLED led {13, MIDI_Notes::C[4]};
void setup() {
// Manually route MIDI output from Control_Surface to the MIDI interface,
Expand Down Expand Up @@ -713,8 +705,8 @@ HardwareSerialMIDI_Interface midi_ser = Serial1;
// Instantiate the three pipes to connect the interfaces to Control_Surface
MIDI_Pipe pipe_tx_u, pipe_rx_u, pipe_tx_s;
NoteButton button {2, MIDI_Notes::C(4)};
NoteLED led {13, MIDI_Notes::C(4)};
NoteButton button {2, MIDI_Notes::C[4]};
NoteLED led {13, MIDI_Notes::C[4]};
void setup() {
// Manually route MIDI output from Control_Surface to the USB MIDI interface
Expand Down Expand Up @@ -750,8 +742,8 @@ HardwareSerialMIDI_Interface midi_ser = Serial1;
// Instantiate a factory that can produce three pipes
MIDI_PipeFactory<3> pipes;
NoteButton button {2, MIDI_Notes::C(4)};
NoteLED led {13, MIDI_Notes::C(4)};
NoteButton button {2, MIDI_Notes::C[4]};
NoteLED led {13, MIDI_Notes::C[4]};
void setup() {
// Manually route MIDI output from Control_Surface to the USB MIDI interface
Expand Down Expand Up @@ -859,8 +851,8 @@ USBDebugMIDI_Output midimon { 115200 };
MIDI_Pipe mpipe;
// You can add normal Control Surface MIDI elements:
NoteButton btn { 2, MIDI_Notes::C(4) };
NoteLED led { 13, MIDI_Notes::C(4) };
NoteButton btn { 2, MIDI_Notes::C[4] };
NoteLED led { 13, MIDI_Notes::C[4] };
void setup() {
midi.setAsDefault(); // Make this the primary interface.
Expand Down
16 changes: 8 additions & 8 deletions examples/0. Getting-Started/2.First-Input/2.First-Input.ino
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ SPIShiftRegisterOut<8> sreg {
// Create an array of LEDs that listen to MIDI Note messages, turning on and off
// the LEDs connected to the eight output pins of the shift register
NoteLED leds[] {
{sreg.pin(0), MIDI_Notes::C(4)}, // LED pin, address (note number, channel, cable)
{sreg.pin(1), MIDI_Notes::D(4)}, //
{sreg.pin(2), MIDI_Notes::E(4)}, //
{sreg.pin(3), MIDI_Notes::F_(4)}, // F is an exception :(
{sreg.pin(4), MIDI_Notes::G(4)}, //
{sreg.pin(5), MIDI_Notes::A(4)}, //
{sreg.pin(6), MIDI_Notes::B(4)}, //
{sreg.pin(7), MIDI_Notes::C(5)}, //
{sreg.pin(0), MIDI_Notes::C[4]}, // LED pin, address (note number, channel, cable)
{sreg.pin(1), MIDI_Notes::D[4]}, //
{sreg.pin(2), MIDI_Notes::E[4]}, //
{sreg.pin(3), MIDI_Notes::F[4]}, //
{sreg.pin(4), MIDI_Notes::G[4]}, //
{sreg.pin(5), MIDI_Notes::A[4]}, //
{sreg.pin(6), MIDI_Notes::B[4]}, //
{sreg.pin(7), MIDI_Notes::C[5]}, //
};

// Initialize the Control Surface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ USBMIDI_Interface midi;
// Instantiate a NoteButton object
NoteButton button {
5, // Push button on pin 5
{MIDI_Notes::C(4), Channel_1}, // Note C4 on MIDI channel 1
{MIDI_Notes::C[4], Channel_1}, // Note C4 on MIDI channel 1
};

void setup() {
Expand Down
2 changes: 1 addition & 1 deletion examples/2. MIDI Input/1. LEDs/1.Note-LED/1.Note-LED.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ USBMIDI_Interface midi;
// Instantiate the LED that will light up when middle C is playing
NoteLED led {
LED_BUILTIN, // Pin of built-in LED
{MIDI_Notes::C(4), Channel_1}, // Note C4 on MIDI channel 1
{MIDI_Notes::C[4], Channel_1}, // Note C4 on MIDI channel 1
};

void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct RainbowColorMapper {

NoteRangeFastLED<leds.length, RainbowColorMapper> midiled {
leds,
MIDI_Notes::C(4),
MIDI_Notes::C[4],
};

void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ SPIShiftRegisterOut<8> sreg {

// Create a range of LEDs that listens for MIDI Note messages, turning on and off
// the LEDs connected to the eight output pins of the shift register
NoteRangeLEDs<8> leds {sreg.pins(), MIDI_Notes::C(4)};
NoteRangeLEDs<8> leds {sreg.pins(), MIDI_Notes::C[4]};

// Initialize the Control Surface
void setup() {
Expand Down
6 changes: 3 additions & 3 deletions examples/2. MIDI Input/1. LEDs/3.NoteLEDBar/3.NoteLEDBar.ino
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ SPIShiftRegisterOut<8> sreg {

// Create a LED bar driver that listens for MIDI Note C4 that drives
// the LEDs connected to the eight output pins of the shift register
NoteLEDBar<8> leds {sreg.pins(), MIDI_Notes::C(4)};
NoteLEDBar<8> leds {sreg.pins(), MIDI_Notes::C[4]};

// Initialize the Control Surface
void setup() {
Expand All @@ -74,7 +74,7 @@ void loop() {
*
* NoteLEDBar<8> leds {
* {{2, 3, 4, 5, 6, 7, 8, 9}},
* MIDI_Notes::C(4),
* MIDI_Notes::C[4],
* };
*
* Note the use of double braces for the list of numbers.
Expand All @@ -83,6 +83,6 @@ void loop() {
*
* NoteLEDBar<8> leds {
* {{2, 3, 4, 5, 6, 7, sreg.pin(0), sreg.pin(1) }},
* MIDI_Notes::C(4),
* MIDI_Notes::C[4],
* };
*/
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const pin_t ledPin = LED_BUILTIN; // Change this to your PWM pin <------
// Instantiate the LED that will light up when middle C is playing
NoteLEDPWM led {
ledPin, // Pin of the LED, must be PWM pin
{MIDI_Notes::C(4), Channel_1}, // Note C4 on MIDI channel 1
{MIDI_Notes::C[4], Channel_1}, // Note C4 on MIDI channel 1
};

void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ MAX7219<1> max7219 {SPI, SS};
// Instantiate the LED that will light up when middle C is playing
NoteLED led {
max7219.pin(0), // First pin of the MAX7219
{MIDI_Notes::C(4), Channel_1}, // Note C4 on MIDI channel 1
{MIDI_Notes::C[4], Channel_1}, // Note C4 on MIDI channel 1
};

void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ USBMIDI_Interface midi;

// Create a MIDI input element that listens to all notes in the range C4 - G4
// (the range starts at C4 and has a length equal to `leds.length` == 8).
NoteRangeFastLED<leds.length> midiled {leds, MIDI_Notes::C(4)};
NoteRangeFastLED<leds.length> midiled {leds, MIDI_Notes::C[4]};

void setup() {
// See FastLED examples and documentation for more information.
Expand Down
4 changes: 2 additions & 2 deletions examples/3. MIDI Interfaces/AppleMIDI/AppleMIDI.ino
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ FortySevenEffectsMIDI_Interface<decltype(MIDI) &> AppleMIDI_interface = MIDI;
// Add some MIDI elements for testing
NoteButton button {
0, // GPIO0 has a push button connected on most boards
MIDI_Notes::C(4),
MIDI_Notes::C[4],
};

NoteLED led {
LED_BUILTIN, // If your board has one, otherwise, specify a pin number here
MIDI_Notes::C(4),
MIDI_Notes::C[4],
};

// --------------------------- AppleMIDI callbacks -------------------------- //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ USBDebugMIDI_Interface midi = 115200;
// Instantiate a NoteButton object
NoteButton button {
5, // Push button on pin 5
{MIDI_Notes::C(4), Channel_1}, // Note C4 on MIDI channel 1
{MIDI_Notes::C[4], Channel_1}, // Note C4 on MIDI channel 1
};

// Instantiate the LED that will light up when middle C is playing
NoteLED led {
LED_BUILTIN, // Pin of built-in LED
{MIDI_Notes::C(4), Channel_1}, // Note C4 on MIDI channel 1
{MIDI_Notes::C[4], Channel_1}, // Note C4 on MIDI channel 1
};

void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ OLEDDebugMIDI_Output midi_disp_out {"\x1b"}; // prefix="←"
MIDI_PipeFactory<2> pipes;

// MIDI element to send messages for testing
NoteButton button {5, MIDI_Notes::C(4)};
NoteButton button {5, MIDI_Notes::C[4]};

void setup() {
init_display();
Expand Down
2 changes: 1 addition & 1 deletion examples/3. MIDI Interfaces/MIDI-Output/MIDI-Output.ino
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void setup() {
}

// MIDI note number, channel, and velocity to use
const MIDIAddress address {MIDI_Notes::C(4), Channel_1};
const MIDIAddress address {MIDI_Notes::C[4], Channel_1};
const uint8_t velocity = 0x7F;

void loop() {
Expand Down
Loading

0 comments on commit b0f4d63

Please sign in to comment.