Skip to content

Commit

Permalink
Use different system for notes, and F → F_
Browse files Browse the repository at this point in the history
This is necessary to avoid conflicts with the F() macro, which is a
function in the new Arduino API
  • Loading branch information
tttapa committed Jun 24, 2021
1 parent ad3a277 commit b727931
Show file tree
Hide file tree
Showing 23 changed files with 128 additions and 141 deletions.
18 changes: 8 additions & 10 deletions examples/0. Getting-Started/2.First-Input/2.First-Input.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 2 additions & 4 deletions 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 @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ struct RainbowColorMapper {
return CHSV(255 * index / leds.length, 255, 255u * velocity / 127u);
}
};

using namespace MIDI_Notes;
NoteRangeFastLED<leds.length, RainbowColorMapper> midiled = {leds, note(C, 4)};

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

void setup() {
// See FastLED examples and documentation for more information.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
8 changes: 3 additions & 5 deletions examples/2. MIDI Input/1. LEDs/3.NoteLEDBar/3.NoteLEDBar.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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.
Expand All @@ -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),
* };
*/
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,15 @@
// 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)
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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<leds.length> midiled = {leds, note(C, 4)};
NoteRangeFastLED<leds.length> midiled = {leds, MIDI_Notes::C(4)};

void setup() {
// See FastLED examples and documentation for more information.
Expand Down
8 changes: 4 additions & 4 deletions examples/3. MIDI Interfaces/AppleMIDI/AppleMIDI.ino
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,14 @@ FortySevenEffectsMIDI_Interface<decltype(MIDI) &> 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 -------------------------- //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 1 addition & 2 deletions examples/3. MIDI Interfaces/MIDI-Output/MIDI-Output.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,25 @@ auto &serial = Serial;
SerialMIDI_Interface<decltype(serial)> 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() {
Expand Down
10 changes: 4 additions & 6 deletions examples/5.Banks/Transposer/Transposer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -54,10 +52,10 @@ IncrementDecrementSelector<transposer.getNumberOfBanks()> 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}

Expand All @@ -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();
Expand Down Expand Up @@ -142,21 +142,19 @@ 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 = {
bank, // Bank to manage
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
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand All @@ -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() {
Expand Down
Loading

0 comments on commit b727931

Please sign in to comment.