diff --git a/README.md b/README.md index 0b7ef56d55..cb57a9dfd7 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ received: #include 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(); } diff --git a/doxygen/pages/FAQ.md b/doxygen/pages/FAQ.md index fa511b9e73..5b498df604 100644 --- a/doxygen/pages/FAQ.md +++ b/doxygen/pages/FAQ.md @@ -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() { @@ -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(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), diff --git a/doxygen/pages/Getting-Started.md b/doxygen/pages/Getting-Started.md index 7363031f06..3be14034c6 100644 --- a/doxygen/pages/Getting-Started.md +++ b/doxygen/pages/Getting-Started.md @@ -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 @@ -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]}, }; ``` @@ -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 @@ -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 diff --git a/doxygen/pages/MIDI.md b/doxygen/pages/MIDI.md index 67bfd607ea..997b536cfd 100644 --- a/doxygen/pages/MIDI.md +++ b/doxygen/pages/MIDI.md @@ -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() { @@ -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. @@ -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♭). @@ -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 " @@ -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 " @@ -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 @@ -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 @@ -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, @@ -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 @@ -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 @@ -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. diff --git a/examples/0. Getting-Started/2.First-Input/2.First-Input.ino b/examples/0. Getting-Started/2.First-Input/2.First-Input.ino index 55d77c50e1..5676c86717 100644 --- a/examples/0. Getting-Started/2.First-Input/2.First-Input.ino +++ b/examples/0. Getting-Started/2.First-Input/2.First-Input.ino @@ -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 diff --git a/examples/1. MIDI Output/2. Buttons & Switches/1. Momentary Push Buttons/NoteButton/NoteButton.ino b/examples/1. MIDI Output/2. Buttons & Switches/1. Momentary Push Buttons/NoteButton/NoteButton.ino index 612955ae54..77a8d00384 100644 --- a/examples/1. MIDI Output/2. Buttons & Switches/1. Momentary Push Buttons/NoteButton/NoteButton.ino +++ b/examples/1. MIDI Output/2. Buttons & Switches/1. Momentary Push Buttons/NoteButton/NoteButton.ino @@ -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() { diff --git a/examples/2. MIDI Input/1. LEDs/1.Note-LED/1.Note-LED.ino b/examples/2. MIDI Input/1. LEDs/1.Note-LED/1.Note-LED.ino index f59c0fc5d8..c0b2aec617 100644 --- a/examples/2. MIDI Input/1. LEDs/1.Note-LED/1.Note-LED.ino +++ b/examples/2. MIDI Input/1. LEDs/1.Note-LED/1.Note-LED.ino @@ -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() { diff --git a/examples/2. MIDI Input/1. LEDs/10.Note-FastLED-ColorMapper/10.Note-FastLED-ColorMapper.ino b/examples/2. MIDI Input/1. LEDs/10.Note-FastLED-ColorMapper/10.Note-FastLED-ColorMapper.ino index 3366e97df5..22e34a6101 100644 --- a/examples/2. MIDI Input/1. LEDs/10.Note-FastLED-ColorMapper/10.Note-FastLED-ColorMapper.ino +++ b/examples/2. MIDI Input/1. LEDs/10.Note-FastLED-ColorMapper/10.Note-FastLED-ColorMapper.ino @@ -53,7 +53,7 @@ struct RainbowColorMapper { NoteRangeFastLED midiled { leds, - MIDI_Notes::C(4), + MIDI_Notes::C[4], }; void setup() { diff --git a/examples/2. MIDI Input/1. LEDs/2.Note-Range-LEDs/2.Note-Range-LEDs.ino b/examples/2. MIDI Input/1. LEDs/2.Note-Range-LEDs/2.Note-Range-LEDs.ino index 89d0b7bc92..6eb7aeac66 100644 --- a/examples/2. MIDI Input/1. LEDs/2.Note-Range-LEDs/2.Note-Range-LEDs.ino +++ b/examples/2. MIDI Input/1. LEDs/2.Note-Range-LEDs/2.Note-Range-LEDs.ino @@ -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() { diff --git a/examples/2. MIDI Input/1. LEDs/3.NoteLEDBar/3.NoteLEDBar.ino b/examples/2. MIDI Input/1. LEDs/3.NoteLEDBar/3.NoteLEDBar.ino index 296d18d188..79d3c0a5ac 100644 --- a/examples/2. MIDI Input/1. LEDs/3.NoteLEDBar/3.NoteLEDBar.ino +++ b/examples/2. MIDI Input/1. LEDs/3.NoteLEDBar/3.NoteLEDBar.ino @@ -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() { @@ -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. @@ -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], * }; */ diff --git a/examples/2. MIDI Input/1. LEDs/5.Note-LED-PWM/5.Note-LED-PWM.ino b/examples/2. MIDI Input/1. LEDs/5.Note-LED-PWM/5.Note-LED-PWM.ino index 597622cc6b..4db500c4ec 100644 --- a/examples/2. MIDI Input/1. LEDs/5.Note-LED-PWM/5.Note-LED-PWM.ino +++ b/examples/2. MIDI Input/1. LEDs/5.Note-LED-PWM/5.Note-LED-PWM.ino @@ -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() { diff --git a/examples/2. MIDI Input/1. LEDs/6.MAX7219-NoteLED/6.MAX7219-NoteLED.ino b/examples/2. MIDI Input/1. LEDs/6.MAX7219-NoteLED/6.MAX7219-NoteLED.ino index 2a897bf314..3a5ee3616c 100644 --- a/examples/2. MIDI Input/1. LEDs/6.MAX7219-NoteLED/6.MAX7219-NoteLED.ino +++ b/examples/2. MIDI Input/1. LEDs/6.MAX7219-NoteLED/6.MAX7219-NoteLED.ino @@ -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() { diff --git a/examples/2. MIDI Input/1. LEDs/9.Note-FastLED/9.Note-FastLED.ino b/examples/2. MIDI Input/1. LEDs/9.Note-FastLED/9.Note-FastLED.ino index bbb5c08b8e..a3e1fa63bc 100644 --- a/examples/2. MIDI Input/1. LEDs/9.Note-FastLED/9.Note-FastLED.ino +++ b/examples/2. MIDI Input/1. LEDs/9.Note-FastLED/9.Note-FastLED.ino @@ -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 midiled {leds, MIDI_Notes::C(4)}; +NoteRangeFastLED midiled {leds, MIDI_Notes::C[4]}; void setup() { // See FastLED examples and documentation for more information. diff --git a/examples/3. MIDI Interfaces/AppleMIDI/AppleMIDI.ino b/examples/3. MIDI Interfaces/AppleMIDI/AppleMIDI.ino index 07532999f5..e4eae84761 100644 --- a/examples/3. MIDI Interfaces/AppleMIDI/AppleMIDI.ino +++ b/examples/3. MIDI Interfaces/AppleMIDI/AppleMIDI.ino @@ -136,12 +136,12 @@ FortySevenEffectsMIDI_Interface 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 -------------------------- // diff --git a/examples/3. MIDI Interfaces/Debug-MIDI-Interface/Debug-MIDI-Interface.ino b/examples/3. MIDI Interfaces/Debug-MIDI-Interface/Debug-MIDI-Interface.ino index fdb089903e..44ad41d1d2 100644 --- a/examples/3. MIDI Interfaces/Debug-MIDI-Interface/Debug-MIDI-Interface.ino +++ b/examples/3. MIDI Interfaces/Debug-MIDI-Interface/Debug-MIDI-Interface.ino @@ -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() { diff --git a/examples/3. MIDI Interfaces/MIDI-Monitor-OLED/MIDI-Monitor-OLED.ino b/examples/3. MIDI Interfaces/MIDI-Monitor-OLED/MIDI-Monitor-OLED.ino index e45fd66e13..3058f5a984 100644 --- a/examples/3. MIDI Interfaces/MIDI-Monitor-OLED/MIDI-Monitor-OLED.ino +++ b/examples/3. MIDI Interfaces/MIDI-Monitor-OLED/MIDI-Monitor-OLED.ino @@ -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(); diff --git a/examples/3. MIDI Interfaces/MIDI-Output/MIDI-Output.ino b/examples/3. MIDI Interfaces/MIDI-Output/MIDI-Output.ino index c1ca010b43..34f819f378 100644 --- a/examples/3. MIDI Interfaces/MIDI-Output/MIDI-Output.ino +++ b/examples/3. MIDI Interfaces/MIDI-Output/MIDI-Output.ino @@ -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() { diff --git a/examples/3. MIDI Interfaces/Send-All-MIDI-Messages/Send-All-MIDI-Messages.ino b/examples/3. MIDI Interfaces/Send-All-MIDI-Messages/Send-All-MIDI-Messages.ino index c259dd090b..aea28ad508 100644 --- a/examples/3. MIDI Interfaces/Send-All-MIDI-Messages/Send-All-MIDI-Messages.ino +++ b/examples/3. MIDI Interfaces/Send-All-MIDI-Messages/Send-All-MIDI-Messages.ino @@ -47,7 +47,7 @@ void setup() { ; { // Channel voice messages - MIDIAddress note = {MIDI_Notes::C(4), Channel_6}; + MIDIAddress note = {MIDI_Notes::C[4], Channel_6}; uint8_t velocity = 127; midi.sendNoteOff(note, velocity); midi.sendNoteOn(note, velocity); diff --git a/examples/3. MIDI Interfaces/Send-MIDI-Notes/Send-MIDI-Notes.ino b/examples/3. MIDI Interfaces/Send-MIDI-Notes/Send-MIDI-Notes.ino index 41acc478bc..596f991e40 100644 --- a/examples/3. MIDI Interfaces/Send-MIDI-Notes/Send-MIDI-Notes.ino +++ b/examples/3. MIDI Interfaces/Send-MIDI-Notes/Send-MIDI-Notes.ino @@ -17,7 +17,7 @@ USBMIDI_Interface midi; Button pushbutton {2}; // MIDI address of the note to send -const MIDIAddress noteAddress {MIDI_Notes::C(4), Channel_1}; +const MIDIAddress noteAddress {MIDI_Notes::C[4], Channel_1}; // The velocity of the note events const uint8_t velocity = 0x7F; diff --git a/examples/3. MIDI Interfaces/Serial-Interface/Serial-Interface.ino b/examples/3. MIDI Interfaces/Serial-Interface/Serial-Interface.ino index e2bb5fc34a..f6833080da 100644 --- a/examples/3. MIDI Interfaces/Serial-Interface/Serial-Interface.ino +++ b/examples/3. MIDI Interfaces/Serial-Interface/Serial-Interface.ino @@ -45,13 +45,13 @@ SerialMIDI_Interface midi {serial, MIDI_BAUD}; // 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() { diff --git a/examples/5.Banks/Transposer/Transposer.ino b/examples/5.Banks/Transposer/Transposer.ino index 31b1dfd3de..7a50dfeeec 100644 --- a/examples/5.Banks/Transposer/Transposer.ino +++ b/examples/5.Banks/Transposer/Transposer.ino @@ -52,10 +52,10 @@ IncrementDecrementSelector selector { // Instantiate an array of NoteButton objects Bankable::NoteButton buttons[] { - {transposer, 2, MIDI_Notes::C(4)}, {transposer, 3, MIDI_Notes::D(4)}, - {transposer, 4, MIDI_Notes::E(4)}, {transposer, 5, MIDI_Notes::F_(4)}, - {transposer, 6, MIDI_Notes::G(4)}, {transposer, 7, MIDI_Notes::A(4)}, - {transposer, 8, MIDI_Notes::B(4)}, {transposer, 9, MIDI_Notes::C(5)}, + {transposer, 2, MIDI_Notes::C[4]}, {transposer, 3, MIDI_Notes::D[4]}, + {transposer, 4, MIDI_Notes::E[4]}, {transposer, 5, MIDI_Notes::F[4]}, + {transposer, 6, MIDI_Notes::G[4]}, {transposer, 7, MIDI_Notes::A[4]}, + {transposer, 8, MIDI_Notes::B[4]}, {transposer, 9, MIDI_Notes::C[5]}, }; void setup() { diff --git a/examples/Extending-the-library/Custom-MIDI-Output-Element-Bankable/Custom-MIDI-Output-Element-Bankable.ino b/examples/Extending-the-library/Custom-MIDI-Output-Element-Bankable/Custom-MIDI-Output-Element-Bankable.ino index b3b2e50f21..82a4f7ae2e 100644 --- a/examples/Extending-the-library/Custom-MIDI-Output-Element-Bankable/Custom-MIDI-Output-Element-Bankable.ino +++ b/examples/Extending-the-library/Custom-MIDI-Output-Element-Bankable/Custom-MIDI-Output-Element-Bankable.ino @@ -154,7 +154,7 @@ IncrementSelector<4> selector { MyNoteButton button { {bank, BankType::ChangeAddress}, // bank changes the note number (address) 5, // Push button on pin 5 - {MIDI_Notes::C(2), Channel_1}, // Base address: Note C2 on MIDI channel 1 + {MIDI_Notes::C[2], Channel_1}, // Base address: Note C2 on MIDI channel 1 0x7F, // Maximum velocity }; diff --git a/examples/Extending-the-library/Custom-MIDI-Output-Element/Custom-MIDI-Output-Element.ino b/examples/Extending-the-library/Custom-MIDI-Output-Element/Custom-MIDI-Output-Element.ino index e1495e965b..35b194a2e3 100644 --- a/examples/Extending-the-library/Custom-MIDI-Output-Element/Custom-MIDI-Output-Element.ino +++ b/examples/Extending-the-library/Custom-MIDI-Output-Element/Custom-MIDI-Output-Element.ino @@ -91,7 +91,7 @@ USBMIDI_Interface midi; // Instantiate a MyNoteButton object MyNoteButton 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 0x7F, // Maximum velocity }; diff --git a/examples/Extending-the-library/Custom-MIDI-Sender/Custom-MIDI-Sender.ino b/examples/Extending-the-library/Custom-MIDI-Sender/Custom-MIDI-Sender.ino index ffd3b33f5c..50fdafff69 100644 --- a/examples/Extending-the-library/Custom-MIDI-Sender/Custom-MIDI-Sender.ino +++ b/examples/Extending-the-library/Custom-MIDI-Sender/Custom-MIDI-Sender.ino @@ -79,7 +79,7 @@ struct CustomNoteButton : MIDIButton { // constructor we wrote a couple of lines back. CustomNoteButton button { 5, // button pin - MIDI_Notes::C(4), // MIDI address + MIDI_Notes::C[4], // MIDI address 0x40, // on velocity 0x10, // off velocity }; diff --git a/examples/Extending-the-library/Custom-Note-LED-Input-Element-Callback-FastLED/Custom-Note-LED-Input-Element-Callback-FastLED.ino b/examples/Extending-the-library/Custom-Note-LED-Input-Element-Callback-FastLED/Custom-Note-LED-Input-Element-Callback-FastLED.ino index 2b67e309ad..fd76724258 100644 --- a/examples/Extending-the-library/Custom-Note-LED-Input-Element-Callback-FastLED/Custom-Note-LED-Input-Element-Callback-FastLED.ino +++ b/examples/Extending-the-library/Custom-Note-LED-Input-Element-Callback-FastLED/Custom-Note-LED-Input-Element-Callback-FastLED.ino @@ -91,7 +91,7 @@ constexpr uint8_t ledpin = 2; // Note C#4 is the green channel of the first LED, // Note D4 is the blue channel of the first LED, // Note D#4 is the red channel of the second LED, etc. -CustomNoteLED midiled {leds.data, MIDI_Notes::C(4)}; +CustomNoteLED midiled {leds.data, MIDI_Notes::C[4]}; void setup() { // See FastLED examples and documentation for more information. diff --git a/examples/Extending-the-library/Custom-Note-LED-Input-Element-Callback/Custom-Note-LED-Input-Element-Callback.ino b/examples/Extending-the-library/Custom-Note-LED-Input-Element-Callback/Custom-Note-LED-Input-Element-Callback.ino index f39c48c77f..31f2a9115f 100644 --- a/examples/Extending-the-library/Custom-Note-LED-Input-Element-Callback/Custom-Note-LED-Input-Element-Callback.ino +++ b/examples/Extending-the-library/Custom-Note-LED-Input-Element-Callback/Custom-Note-LED-Input-Element-Callback.ino @@ -81,7 +81,7 @@ class CustomNoteLED // Instantiate the LED that will light up when middle C is playing. CustomNoteLED led { 3, // Pin with the LED connected (PWM capable) - {MIDI_Notes::C(4), Channel_1}, // Note C4 on MIDI channel 1 + {MIDI_Notes::C[4], Channel_1}, // Note C4 on MIDI channel 1 10, // Intensity when off }; diff --git a/examples/Other/GitHub-issues/Note-ManyAddresses-Transposer/Note-ManyAddresses-Transposer.ino b/examples/Other/GitHub-issues/Note-ManyAddresses-Transposer/Note-ManyAddresses-Transposer.ino index 14c9e109ba..48e612ce80 100644 --- a/examples/Other/GitHub-issues/Note-ManyAddresses-Transposer/Note-ManyAddresses-Transposer.ino +++ b/examples/Other/GitHub-issues/Note-ManyAddresses-Transposer/Note-ManyAddresses-Transposer.ino @@ -20,17 +20,17 @@ IncrementDecrementSelector<2> scaleSelector { Bankable::ManyAddresses::ManyAddressBankNoteButton<2> buttons[] { { - {scaleBank, {MIDI_Notes::F_(4), MIDI_Notes::Gb(4)}}, + {scaleBank, {MIDI_Notes::F[4], MIDI_Notes::Gb[4]}}, transposer, 2, // pin }, { - {scaleBank, {MIDI_Notes::C(4), MIDI_Notes::Db(4)}}, + {scaleBank, {MIDI_Notes::C[4], MIDI_Notes::Db[4]}}, transposer, 3, // pin }, { - {scaleBank, {MIDI_Notes::G(4), MIDI_Notes::Ab(4)}}, + {scaleBank, {MIDI_Notes::G[4], MIDI_Notes::Ab[4]}}, transposer, 4, // pin }, diff --git a/examples/Other/GitHub-issues/Transpose-Octave-NC-Button/Transpose-Octave-NC-Button.ino b/examples/Other/GitHub-issues/Transpose-Octave-NC-Button/Transpose-Octave-NC-Button.ino index 75260db46f..8603e091cf 100644 --- a/examples/Other/GitHub-issues/Transpose-Octave-NC-Button/Transpose-Octave-NC-Button.ino +++ b/examples/Other/GitHub-issues/Transpose-Octave-NC-Button/Transpose-Octave-NC-Button.ino @@ -16,7 +16,7 @@ IncrementSelector<2> selector {transposer, 2}; Bankable::NoteButton notebutton { transposer, // bank/transposer 3, // pin - MIDI_Notes::C(4), // address/note + MIDI_Notes::C[4], // address/note }; void setup() { diff --git a/src/MIDI_Constants/Notes.hpp b/src/MIDI_Constants/Notes.hpp index 7dbe91fd07..9ce258d4cb 100644 --- a/src/MIDI_Constants/Notes.hpp +++ b/src/MIDI_Constants/Notes.hpp @@ -37,33 +37,37 @@ class Note { constexpr int8_t operator()(int8_t octave = -1) const { return base + 12 * (octave + 1); } + constexpr int8_t operator[](int8_t octave) const { return (*this)(octave); } - constexpr static Note C() { return Note {0}; } - constexpr static Note Db() { return Note {1}; } - constexpr static Note D() { return Note {2}; } - constexpr static Note Eb() { return Note {3}; } - constexpr static Note E() { return Note {4}; } - constexpr static Note F_() { return Note {5}; } - constexpr static Note Gb() { return Note {6}; } - constexpr static Note G() { return Note {7}; } - constexpr static Note Ab() { return Note {8}; } - constexpr static Note A() { return Note {9}; } - constexpr static Note Bb() { return Note {10}; } - constexpr static Note B() { return Note {11}; } + constexpr static Note(C)() { return Note {0}; } + constexpr static Note(Db)() { return Note {1}; } + constexpr static Note(D)() { return Note {2}; } + constexpr static Note(Eb)() { return Note {3}; } + constexpr static Note(E)() { return Note {4}; } + constexpr static Note(F)() { return Note {5}; } + constexpr static Note(Gb)() { return Note {6}; } + constexpr static Note(G)() { return Note {7}; } + constexpr static Note(Ab)() { return Note {8}; } + constexpr static Note(A)() { return Note {9}; } + constexpr static Note(Bb)() { return Note {10}; } + constexpr static Note(B)() { return Note {11}; } }; -constexpr Note C = Note::C(); ///< C (Do) -constexpr Note Db = Note::Db(); ///< C♯, D♭ (Do sharp, Re flat) -constexpr Note D = Note::D(); ///< D (Re) -constexpr Note Eb = Note::Eb(); ///< D♯, E♭ (Re sharp, Mi flat) -constexpr Note E = Note::E(); ///< E (Mi) -constexpr Note F_ = Note::F_(); ///< F (Fa) -constexpr Note Gb = Note::Gb(); ///< F♯, G♭ (Fa sharp, Sol flat) -constexpr Note G = Note::G(); ///< G (Sol) -constexpr Note Ab = Note::Ab(); ///< G♯, A♭ (Sol sharp, La flat) -constexpr Note A = Note::A(); ///< A (La) -constexpr Note Bb = Note::Bb(); ///< A♯, B♭ (La sharp, Si flat) -constexpr Note B = Note::B(); ///< B (Si) +constexpr Note C = (Note::C)(); ///< C (Do) +constexpr Note Db = (Note::Db)(); ///< C♯, D♭ (Do sharp, Re flat) +constexpr Note D = (Note::D)(); ///< D (Re) +constexpr Note Eb = (Note::Eb)(); ///< D♯, E♭ (Re sharp, Mi flat) +constexpr Note E = (Note::E)(); ///< E (Mi) +constexpr Note F = (Note::F)(); ///< F (Fa) +constexpr Note Gb = (Note::Gb)(); ///< F♯, G♭ (Fa sharp, Sol flat) +constexpr Note G = (Note::G)(); ///< G (Sol) +constexpr Note Ab = (Note::Ab)(); ///< G♯, A♭ (Sol sharp, La flat) +constexpr Note A = (Note::A)(); ///< A (La) +constexpr Note Bb = (Note::Bb)(); ///< A♯, B♭ (La sharp, Si flat) +constexpr Note B = (Note::B)(); ///< B (Si) + +CS_DEPREC("Instead of `MIDI_Notes::F_(4)`, use `MIDI_Notes::F[4]`") +constexpr Note F_ = (Note::F)(); ///< F (Fa) /// Get the MIDI note in the given octave. CS_DEPREC("Instead of `note(C, 4)`, use `MIDI_Notes::C(4)`") diff --git a/test/MIDI_Constants/test-Notes.cpp b/test/MIDI_Constants/test-Notes.cpp index cff3b8edc2..fa621c435f 100644 --- a/test/MIDI_Constants/test-Notes.cpp +++ b/test/MIDI_Constants/test-Notes.cpp @@ -4,8 +4,8 @@ TEST(Notes, noteNumbers) { // See https://en.wikipedia.org/wiki/Scientific_pitch_notation // and page 48 of MIDI 1.0 Detailed Specification 4.2 - EXPECT_EQ(cs::MIDI_Notes::C(-1), 0x00); - EXPECT_EQ(cs::MIDI_Notes::C(0), 0x0C); - EXPECT_EQ(cs::MIDI_Notes::C(4), 0x3C); - EXPECT_EQ(cs::MIDI_Notes::A(4), 0x45); // 440 Hz + EXPECT_EQ(cs::MIDI_Notes::C[-1], 0x00); + EXPECT_EQ(cs::MIDI_Notes::C[0], 0x0C); + EXPECT_EQ(cs::MIDI_Notes::C[4], 0x3C); + EXPECT_EQ(cs::MIDI_Notes::A[4], 0x45); // 440 Hz } \ No newline at end of file