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 7351e8845c..7834259db6 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 @@ -28,19 +28,17 @@ SPIShiftRegisterOut<8> sreg = { MSBFIRST, // Byte order }; -using namespace MIDI_Notes; - // 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), note(C, 4)}, // LED pin, address (note number, channel, cable) - {sreg.pin(1), note(D, 4)}, // - {sreg.pin(2), note(E, 4)}, // - {sreg.pin(3), note(F, 4)}, // - {sreg.pin(4), note(G, 4)}, // - {sreg.pin(5), note(A, 4)}, // - {sreg.pin(6), note(B, 4)}, // - {sreg.pin(7), note(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 43286d1bda..c4bdab8da8 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 @@ -35,12 +35,10 @@ // Instantiate a MIDI over USB interface. USBMIDI_Interface midi; -using namespace MIDI_Notes; - // Instantiate a NoteButton object NoteButton button = { 5, // Push button on pin 5 - {note(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 a7541a7ee7..97dad19288 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 @@ -32,12 +32,10 @@ // Instantiate a MIDI over USB interface. USBMIDI_Interface midi; -using namespace MIDI_Notes; - // Instantiate the LED that will light up when middle C is playing NoteLED led = { - LED_BUILTIN, // Pin of built-in LED - {note(C, 4), CHANNEL_1}, // Note C4 on MIDI channel 1 + LED_BUILTIN, // Pin of built-in LED + {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 1dba405b63..4989a6fd65 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 @@ -50,9 +50,11 @@ struct RainbowColorMapper { return CHSV(255 * index / leds.length, 255, 255u * velocity / 127u); } }; - -using namespace MIDI_Notes; -NoteRangeFastLED midiled = {leds, note(C, 4)}; + +NoteRangeFastLED midiled = { + leds, + MIDI_Notes::C(4), +}; void setup() { // See FastLED examples and documentation for more information. 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 5f93d7a0a8..6079c209e8 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 @@ -51,11 +51,9 @@ SPIShiftRegisterOut<8> sreg = { MSBFIRST, // Byte order }; -using namespace MIDI_Notes; - // 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(), note(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 d5c2ca7d11..4898f062b6 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 @@ -47,11 +47,9 @@ SPIShiftRegisterOut<8> sreg = { MSBFIRST, // Byte order }; -using namespace MIDI_Notes; - // 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(), note(C, 4) }; +NoteLEDBar<8> leds = { sreg.pins(), MIDI_Notes::C(4) }; // Initialize the Control Surface void setup() { @@ -76,7 +74,7 @@ void loop() { * * NoteLEDBar<8> leds = { * {{2, 3, 4, 5, 6, 7, 8, 9}}, - * note(C, 4), + * MIDI_Notes::C(4), * }; * * Note the use of double braces for the list of numbers. @@ -85,6 +83,6 @@ void loop() { * * NoteLEDBar<8> leds = { * {{2, 3, 4, 5, 6, 7, sreg.pin(0), sreg.pin(1) }}, - * note(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 5a733d35d6..e9dd644776 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 @@ -35,12 +35,10 @@ USBMIDI_Interface midi; const pin_t ledPin = LED_BUILTIN; // Change this to your PWM pin <------ -using namespace MIDI_Notes; - // Instantiate the LED that will light up when middle C is playing NoteLEDPWM led = { - ledPin, // Pin of the LED, must be PWM pin - {note(C, 4), CHANNEL_1}, // Note C4 on MIDI channel 1 + ledPin, // Pin of the LED, must be PWM pin + {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 ebe37167f2..4f71be79d1 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 @@ -34,8 +34,6 @@ // Instantiate a MIDI over USB interface. USBMIDI_Interface midi; -using namespace MIDI_Notes; - // Instantiate a MAX7219 with the SPI slave select pin as latch pin // There's just 1 MAX7219 in the chain, if you have more of them daisy-chained // together, you can increase the template argument (between angled brackets) @@ -43,8 +41,8 @@ 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 - {note(C, 4), CHANNEL_1}, // Note C4 on MIDI channel 1 + max7219.pin(0), // First pin of the MAX7219 + {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 1d62fbc58d..c296271e55 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 @@ -43,11 +43,9 @@ constexpr uint8_t ledpin = 2; USBMIDI_Interface midi; -using namespace MIDI_Notes; - // 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, note(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 b0ec15913f..9271f1ccca 100644 --- a/examples/3. MIDI Interfaces/AppleMIDI/AppleMIDI.ino +++ b/examples/3. MIDI Interfaces/AppleMIDI/AppleMIDI.ino @@ -134,14 +134,14 @@ FortySevenEffectsMIDI_Interface AppleMIDI_interface = MIDI; // ------------------------------ MIDI Elements ----------------------------- // // Add some MIDI elements for testing -using namespace MIDI_Notes; NoteButton button = { - 0, note(C, 4), // GPIO0 has a push button connected on most boards + 0, // GPIO0 has a push button connected on most boards + MIDI_Notes::C(4), }; NoteLED led = { - LED_BUILTIN, - note(C, 4), + LED_BUILTIN, // If your board has one, otherwise, specify a pin number here + 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 49da7c3104..94bae1bf3f 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 @@ -37,18 +37,16 @@ // Instantiate a MIDI Debug interface at 115200 baud. USBDebugMIDI_Interface midi = 115200; -using namespace MIDI_Notes; - // Instantiate a NoteButton object NoteButton button = { - 5, // Push button on pin 5 - {note(C, 4), CHANNEL_1}, // Note C4 on MIDI channel 1 + 5, // Push button on pin 5 + {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 - {note(C, 4), CHANNEL_1}, // Note C4 on MIDI channel 1 + LED_BUILTIN, // Pin of built-in LED + {MIDI_Notes::C(4), CHANNEL_1}, // Note C4 on MIDI channel 1 }; void setup() { diff --git a/examples/3. MIDI Interfaces/MIDI-Output/MIDI-Output.ino b/examples/3. MIDI Interfaces/MIDI-Output/MIDI-Output.ino index 32777009fe..6331c6ccbf 100644 --- a/examples/3. MIDI Interfaces/MIDI-Output/MIDI-Output.ino +++ b/examples/3. MIDI Interfaces/MIDI-Output/MIDI-Output.ino @@ -33,9 +33,8 @@ void setup() { midi.begin(); // Initialize the MIDI interface } -using namespace MIDI_Notes; // MIDI note number, channel, and velocity to use -const MIDIAddress address = {note(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-MIDI-Notes/Send-MIDI-Notes.ino b/examples/3. MIDI Interfaces/Send-MIDI-Notes/Send-MIDI-Notes.ino index 21a1f48a36..2369061926 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 @@ -13,10 +13,8 @@ USBMIDI_Interface midi; // Note message is sent when pressed. Button pushbutton = {2}; -using namespace MIDI_Notes; - // MIDI address of the note to send -const MIDIAddress noteAddress = {note(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 3f24d86b28..21f1b8f1a2 100644 --- a/examples/3. MIDI Interfaces/Serial-Interface/Serial-Interface.ino +++ b/examples/3. MIDI Interfaces/Serial-Interface/Serial-Interface.ino @@ -33,27 +33,25 @@ auto &serial = Serial; SerialMIDI_Interface midi = {serial, MIDI_BAUD}; // You can also use the following serial MIDI interfaces: -// +// // The Serial port that is connected to your computer over USB: // // USBSerialMIDI_Interface midi = 115200; // // A hardware serial port: -// +// // HardwareSerialMIDI_Interface midi = {Serial1, MIDI_BAUD}; -using namespace MIDI_Notes; - // Instantiate a NoteButton object NoteButton button = { - 5, // Push button on pin 5 - {note(C, 4), CHANNEL_1}, // Note C4 on MIDI channel 1 + 5, // Push button on pin 5 + {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 - {note(C, 4), CHANNEL_1}, // Note C4 on MIDI channel 1 + LED_BUILTIN, // Pin of built-in LED + {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 f7cfb65f7f..9d4971621d 100644 --- a/examples/5.Banks/Transposer/Transposer.ino +++ b/examples/5.Banks/Transposer/Transposer.ino @@ -39,8 +39,6 @@ // Instantiate a MIDI over USB interface. USBMIDI_Interface midi; -using namespace MIDI_Notes; - // Instantiate a Transposer that can transpose from one octave down to one // octave up Transposer<-12, +12> transposer; @@ -54,10 +52,10 @@ IncrementDecrementSelector selector = { // Instantiate an array of NoteButton objects Bankable::NoteButton buttons[] = { - {transposer, 2, note(C, 4)}, {transposer, 3, note(D, 4)}, - {transposer, 4, note(E, 4)}, {transposer, 5, note(F, 4)}, - {transposer, 6, note(G, 4)}, {transposer, 7, note(A, 4)}, - {transposer, 8, note(B, 4)}, {transposer, 9, note(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 21ec359572..4e1c723c89 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 @@ -67,7 +67,7 @@ class MyNoteButton : public MIDIOutputElement { * @param velocity * The MIDI note velocity [0, 127]. */ - MyNoteButton(OutputBankConfig<> bankConfig, pin_t pin, + MyNoteButton(OutputBankConfig<> bankConfig, pin_t pin, MIDIAddress baseAddress, uint8_t velocity) : address(bankConfig, baseAddress), button(pin), velocity(velocity) {} @@ -79,12 +79,12 @@ class MyNoteButton : public MIDIOutputElement { // Update: read the button and send MIDI messages when appropriate. // This method is called continuously by `Control_Surface.loop()`. void update() final override { - AH::Button::State state = button.update(); // Read the button - if (state == AH::Button::Falling) { // if pressed + AH::Button::State state = button.update(); // Read the button + if (state == AH::Button::Falling) { // if pressed // Don't allow changing the bank setting as long as the button is pressed: address.lock(); Control_Surface.sendNoteOn(address.getActiveAddress(), velocity); - } else if (state == AH::Button::Rising) { // if released + } else if (state == AH::Button::Rising) { // if released Control_Surface.sendNoteOff(address.getActiveAddress(), velocity); // Button is released, so the bank setting can be changed again. address.unlock(); @@ -142,7 +142,7 @@ END_CS_NAMESPACE // Instantiate a MIDI over USB interface. USBMIDI_Interface midi; -// Instantiate four Banks, with twelve tracks per bank (12 semitones = 1 octave). +// Instantiate four Banks, with twelve tracks per bank (12 semitones = 1 octave). Bank<4> bank(12); // Instantiate a Bank selector to control which one of the four Banks is active. IncrementSelector<4> selector = { @@ -150,13 +150,11 @@ IncrementSelector<4> selector = { 6, // push button pin }; -using namespace MIDI_Notes; - // Instantiate a MyNoteButton object MyNoteButton button = { {bank, BankType::CHANGE_ADDRESS}, // bank changes the note number (address) 5, // Push button on pin 5 - {note(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 3bd203d840..42e75887ec 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 @@ -67,11 +67,11 @@ class MyNoteButton : public MIDIOutputElement { // Update: read the button and send MIDI messages when appropriate. // This method is called continuously by `Control_Surface.loop()`. void update() final override { - AH::Button::State state = button.update(); // Read the button - if (state == AH::Button::Falling) { // if pressed - Control_Surface.sendNoteOn(address, velocity); // → note on - } else if (state == AH::Button::Rising) { // if released - Control_Surface.sendNoteOff(address, velocity); // → note off + AH::Button::State state = button.update(); // Read the button + if (state == AH::Button::Falling) { // if pressed + Control_Surface.sendNoteOn(address, velocity); // → note on + } else if (state == AH::Button::Rising) { // if released + Control_Surface.sendNoteOff(address, velocity); // → note off } } @@ -88,13 +88,11 @@ END_CS_NAMESPACE // Instantiate a MIDI over USB interface. USBMIDI_Interface midi; -using namespace MIDI_Notes; - // Instantiate a MyNoteButton object MyNoteButton button = { - 5, // Push button on pin 5 - {note(C, 4), CHANNEL_1}, // Note C4 on MIDI channel 1 - 0x7F, // Maximum velocity + 5, // Push button on pin 5 + {MIDI_Notes::C(4), CHANNEL_1}, // Note C4 on MIDI channel 1 + 0x7F, // Maximum velocity }; void setup() { 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 906c5bb5a7..97110e8471 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 @@ -43,47 +43,45 @@ USBMIDI_Interface midi; // For example, a continuous CC sender just has a send(value, address) // method. class CustomNoteSender { - public: - CustomNoteSender(uint8_t onVelocity, uint8_t offVelocity) - : onVelocity(onVelocity), offVelocity(offVelocity) {} + public: + CustomNoteSender(uint8_t onVelocity, uint8_t offVelocity) + : onVelocity(onVelocity), offVelocity(offVelocity) {} - void sendOn(MIDIAddress address) { - Control_Surface.sendNoteOn(address, onVelocity); - } + void sendOn(MIDIAddress address) { + Control_Surface.sendNoteOn(address, onVelocity); + } - void sendOff(MIDIAddress address) { - Control_Surface.sendNoteOff(address, offVelocity); - } + void sendOff(MIDIAddress address) { + Control_Surface.sendNoteOff(address, offVelocity); + } - private: - uint8_t onVelocity, offVelocity; + private: + uint8_t onVelocity, offVelocity; }; // Now tell the MIDIButton class template (included with the Control // Surface library) that it has to use your custom sender class. // -// We wrap it in another class so we can easily construct it later, +// We wrap it in another class so we can easily construct it later, // without having to write `MIDIButton` all the time, // and so we have more control over the constructor arguments. // The colon (:) indicates inheritance. struct CustomNoteButton : MIDIButton { // Constructor - CustomNoteButton(pin_t pin, MIDIAddress address, - uint8_t onVelocity, uint8_t offVelocity) + CustomNoteButton(pin_t pin, MIDIAddress address, uint8_t onVelocity, + uint8_t offVelocity) : MIDIButton(pin, address, {onVelocity, offVelocity}) {} // ^~~~~~~~~~ Initialization of the base class MIDIButton }; -using namespace MIDI_Notes; - // Now we can instantiate an object of our custom class. // The four arguments match the ones of the CustomNoteButton // constructor we wrote a couple of lines back. CustomNoteButton button = { - 5, // button pin - note(C, 4), // MIDI address - 0x40, // on velocity - 0x10, // off velocity + 5, // button pin + MIDI_Notes::C(4), // MIDI address + 0x40, // on velocity + 0x10, // off velocity }; void setup() { 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 0b65517f8d..e568813a7e 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 @@ -37,8 +37,6 @@ // Instantiate a MIDI over USB interface. USBMIDI_Interface midi; -using namespace MIDI_Notes; - // Custom MIDI Input Element to handle incoming note events and control the LEDs. template class CustomNoteLED : public MatchingMIDIInputElement midiled = {leds.data, note(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 1d95e50a35..dc6be9685d 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 @@ -32,8 +32,6 @@ // Instantiate a MIDI over USB interface. USBMIDI_Interface midi; -using namespace MIDI_Notes; - // MIDI Input Element that listens for MIDI Note events that turns on the LED at // full brightness if the note value (velocity) is above the threshold, // and turns on the LED at a lower brightness if the value is below the @@ -70,7 +68,7 @@ class CustomNoteLED ExtIO::analogWrite(ledPin, lowBrightness); } - // Called when the input element is reset (e.g. by an "All notes off" MIDI + // Called when the input element is reset (e.g. by an "All notes off" MIDI // event). void reset() override { ExtIO::analogWrite(ledPin, lowBrightness); } @@ -82,9 +80,9 @@ class CustomNoteLED // Instantiate the LED that will light up when middle C is playing. CustomNoteLED led = { - 3, // Pin with the LED connected (PWM capable) - {note(C, 4), CHANNEL_1}, // Note C4 on MIDI channel 1 - 10, // Intensity when off + 3, // Pin with the LED connected (PWM capable) + {MIDI_Notes::C(4), CHANNEL_1}, // Note C4 on MIDI channel 1 + 10, // Intensity when off }; void setup() { 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 eba20aebbc..18efe08767 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 @@ -18,21 +18,19 @@ IncrementDecrementSelector<2> scaleSelector = { Wrap::Clamp, }; -using namespace MIDI_Notes; - Bankable::ManyAddresses::ManyAddressBankNoteButton<2> buttons[] = { { - {scaleBank, {note(F, 4), note(Gb, 4)}}, + {scaleBank, {MIDI_Notes::F_(4), note(nt::Gb, 4)}}, transposer, 2, // pin }, { - {scaleBank, {note(C, 4), note(Db, 4)}}, + {scaleBank, {MIDI_Notes::C(4), note(nt::Db, 4)}}, transposer, 3, // pin }, { - {scaleBank, {note(G, 4), note(Ab, 4)}}, + {scaleBank, {MIDI_Notes::G(4), note(nt::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 b87f729754..045356ddba 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 @@ -13,11 +13,10 @@ Transposer<0, +1> transposer(12); // Push button on pin 2 to transpose. IncrementSelector<2> selector = {transposer, 2}; -using namespace MIDI_Notes; Bankable::NoteButton notebutton = { - transposer, // bank/transposer - 3, // pin - note(C, 4), // address/note + transposer, // bank/transposer + 3, // pin + MIDI_Notes::C(4), // address/note }; void setup() { diff --git a/src/MIDI_Constants/Notes.hpp b/src/MIDI_Constants/Notes.hpp index b61fedac06..88abba5cdb 100644 --- a/src/MIDI_Constants/Notes.hpp +++ b/src/MIDI_Constants/Notes.hpp @@ -13,25 +13,48 @@ BEGIN_CS_NAMESPACE /// MIDI note names. namespace MIDI_Notes { -constexpr int8_t C = 0; ///< C (Do) -constexpr int8_t Db = 1; ///< C♯, D♭ (Do sharp, Re flat) -constexpr int8_t D = 2; ///< D (Re) -constexpr int8_t Eb = 3; ///< D♯, E♭ (Re sharp, Mi flat) -constexpr int8_t E = 4; ///< E (Mi) -constexpr int8_t F = 5; ///< F (Fa) -constexpr int8_t Gb = 6; ///< F♯, G♭ (Fa sharp, Sol flat) -constexpr int8_t G = 7; ///< G (Sol) -constexpr int8_t Ab = 8; ///< G♯, A♭ (Sol sharp, La flat) -constexpr int8_t A = 9; ///< A (La) -constexpr int8_t Bb = 10; ///< A♯, B♭ (La sharp, Si flat) -constexpr int8_t B = 11; ///< B (Si) - -/// Get the first MIDI note in the given octave. -constexpr int8_t octave(int8_t numOctave) { return 12 * (numOctave + 1); } +class Note { + private: + int8_t base; + constexpr Note(int8_t base) : base(base) {} + + public: + constexpr int8_t operator()(int8_t octave = -1) const { + return base + 12 * (octave + 1); + } + + 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) /// Get the MIDI note in the given octave. -constexpr int8_t note(int8_t note, int8_t numOctave) { - return note + octave(numOctave); +[[deprecated("Instead of `note(C, 4)`, use `MIDI_Notes::C(4)`")]] // +constexpr int8_t +note(Note note, int8_t numOctave) { + return note(numOctave); } } // namespace MIDI_Notes