Skip to content

Commit

Permalink
Use direct initialization in examples
Browse files Browse the repository at this point in the history
Results in better error messages when used incorrectly
  • Loading branch information
tttapa committed Jun 24, 2021
1 parent f6b6ec5 commit c75e43f
Show file tree
Hide file tree
Showing 57 changed files with 181 additions and 180 deletions.
4 changes: 2 additions & 2 deletions examples/0. Getting-Started/1.First-Output/1.First-Output.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
USBMIDI_Interface midi;

// Instantiate an analog multiplexer
CD74HC4051 mux = {
CD74HC4051 mux {
A0, // Analog input pin
{3, 4, 5} // Address pins S0, S1, S2
};
Expand All @@ -24,7 +24,7 @@ CD74HC4051 mux = {
// MIDI Control Change messages when you turn the
// potentiometers connected to the eight input pins of
// the multiplexer
CCPotentiometer volumePotentiometers[] = {
CCPotentiometer volumePotentiometers[] {
{mux.pin(0), {MIDI_CC::Channel_Volume, CHANNEL_1}},
{mux.pin(1), {MIDI_CC::Channel_Volume, CHANNEL_2}},
{mux.pin(2), {MIDI_CC::Channel_Volume, CHANNEL_3}},
Expand Down
20 changes: 10 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 @@ -22,23 +22,23 @@
USBMIDI_Interface midi;

// Instantiate a shift register as output for the LEDs
SPIShiftRegisterOut<8> sreg = {
SPIShiftRegisterOut<8> sreg {
SPI, // SPI interface to use
10, // Latch pin (ST_CP)
MSBFIRST, // Byte order
};

// 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)}, //
{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)}, //
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)}, //
};

// Initialize the Control Surface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ USBMIDI_Interface midi;
// Create a new instance of the class `CCPotentiometer`, called `potentiometer`,
// on pin A0, that sends MIDI messages with controller 7 (channel volume)
// on channel 1.
CCPotentiometer potentiometer = {
CCPotentiometer potentiometer {
A0, {MIDI_CC::Channel_Volume, CHANNEL_1}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
USBMIDI_Interface midi;

// Instantiate a CCPotentiometer object
CCPotentiometer potentiometer = {
CCPotentiometer potentiometer {
A0, // Analog pin connected to potentiometer
{MIDI_CC::Channel_Volume, CHANNEL_1}, // Channel volume of channel 1
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
USBMIDI_Interface midi;

// Instantiate an array of CCPotentiometer objects
CCPotentiometer potentiometers[] = {
CCPotentiometer potentiometers[] {
{A0, // Analog pin connected to potentiometer 1
0x10}, // Controller number of the first potentiometer
{A1, // Analog pin connected to potentiometer 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
USBMIDI_Interface midi;

// Instantiate a PBPotentiometer object
PBPotentiometer potentiometer = {
PBPotentiometer potentiometer {
A0, // Analog pin connected to potentiometer
CHANNEL_1, // MIDI Channel 1
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
USBMIDI_Interface midi;

// Instantiate a CCButton object
CCButton button = {
CCButton button {
// Push button on pin 5:
5,
// General Purpose Controller #1 on MIDI channel 1:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
USBMIDI_Interface midi;

// Instantiate a NoteButton object
NoteButton button = {
NoteButton button {
5, // Push button on pin 5
{MIDI_Notes::C(4), CHANNEL_1}, // Note C4 on MIDI channel 1
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
USBMIDI_Interface midi;

// The note numbers corresponding to the buttons in the matrix
const AddressMatrix<4, 3> addresses = {{
const AddressMatrix<4, 3> addresses {{
{1, 2, 3},
{4, 5, 6},
{7, 8, 9},
{10, 11, 12},
}};

NoteButtonMatrix<4, 3> buttonmatrix = {
NoteButtonMatrix<4, 3> buttonmatrix {
{2, 3, 4, 5}, // row pins
{6, 7, 8}, // column pins
addresses, // address matrix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
USBMIDI_Interface midi;

// Instantiate a CCIncrementDecrementButtons object
CCIncrementDecrementButtons buttons = {
CCIncrementDecrementButtons buttons {
{5, 6}, // Button pins: 5 increments, 6 decrements
MCU::V_POT_1, // Increment/Decrement CC address
1, // Multiplier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@
USBMIDI_Interface midi;

// Instantiate a CCAbsoluteEncoder object
CCAbsoluteEncoder enc = {
CCAbsoluteEncoder enc {
{2, 3}, // pins
MIDI_CC::Pan, // MIDI address (CC number + optional channel)
1, // optional multiplier if the control isn't fast enough
};

// Similarly, for Pitch Bend
// PBAbsoluteEncoder enc = {
// PBAbsoluteEncoder enc {
// {2, 3}, // pins
// CHANNEL_1, // MIDI channel
// 127, // large multiplier because Pitch Bend has high resolution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ USBDebugMIDI_Interface midi;
const uint8_t interrupt_pin = 12;

// Create an object that manages the 8 encoders connected to the MCP23017.
MCPEncoderType enc = {Wire, 0x0, interrupt_pin};
MCPEncoderType enc {Wire, 0x0, interrupt_pin};
// │ │ └─ Interrupt pin
// │ └────── Address offset
// └──────────── I²C interface

// Instantiate 8 MIDI rotary encoders.
CCMCPEncoder ccencoders[] = {
CCMCPEncoder ccencoders[] {
{
enc[0], // The encoder to use
MCU::V_POT_1, // The MIDI address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ struct CCMCPEncoder : GenericMIDIRotaryEncoder<MCPEncoderType::MCP23017Encoder,
USBDebugMIDI_Interface midi;

// Create an object that manages the 8 encoders connected to the MCP23017.
MCPEncoderType enc = {Wire, 0x0, 12};
MCPEncoderType enc {Wire, 0x0, 12};
// │ │ └─ Interrupt pin
// │ └────── Address offset
// └──────────── I²C interface

// Instantiate 8 MIDI rotary encoders.
CCMCPEncoder ccencoders[] = {
CCMCPEncoder ccencoders[] {
{
enc[0], // The encoder to use
MCU::V_POT_1, // The MIDI address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
USBMIDI_Interface midi;

// Instantiate a CCRotaryEncoder object
CCRotaryEncoder enc = {
CCRotaryEncoder enc {
{2, 3}, // pins
MCU::V_POT_1, // MIDI address (CC number + optional channel)
1, // optional multiplier if the control isn't fast enough
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
USBMIDI_Interface midi;

Bank<3> bank(4);
IncrementDecrementSelector<3> bankSelector = {bank, {A0, A1}, Wrap::Clamp};
IncrementDecrementSelector<3> bankSelector {bank, {A0, A1}, Wrap::Clamp};

using namespace MIDI_PC;

Bankable::ManyAddresses::PCButton<3> pcbuttons[] = {
Bankable::ManyAddresses::PCButton<3> pcbuttons[] {
{bank,
2, // pin
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ USBMIDI_Interface midi;

// Instantiate a PCButton that reads the input from a push button and sends out
// a MIDI Program Change message when it's pressed.
PCButton pcBtn = {
PCButton pcBtn {
2, // pin
{MIDI_PC::Steel_Drums, CHANNEL_1}, // address
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
USBMIDI_Interface midi;

// Instantiate a program changer with 3 programs
ProgramChanger<3> programChanger = {
ProgramChanger<3> programChanger {
{
MIDI_PC::Acoustic_Grand_Piano, // list of programs
MIDI_PC::Rock_Organ,
Expand All @@ -43,7 +43,7 @@ ProgramChanger<3> programChanger = {

// Instantiate a selector that reads three buttons and controls the program
// changer
ManyButtonsSelector<3> programSelector = {
ManyButtonsSelector<3> programSelector {
programChanger,
{{2, 3, 4}},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,42 +46,42 @@ const int speedMultiplier = 1;

Bank<2> bank(4); // A bank with four channels, and 2 bank settings

Bankable::CCPotentiometer faders[] = {
Bankable::CCPotentiometer faders[] {
{{bank, BankType::CHANGE_CHANNEL}, A0, {MIDI_CC::Channel_Volume, CHANNEL_1}},
{{bank, BankType::CHANGE_CHANNEL}, A1, {MIDI_CC::Channel_Volume, CHANNEL_2}},
{{bank, BankType::CHANGE_CHANNEL}, A2, {MIDI_CC::Channel_Volume, CHANNEL_3}},
{{bank, BankType::CHANGE_CHANNEL}, A3, {MIDI_CC::Channel_Volume, CHANNEL_4}},
};

CCPotentiometer knobsTop[] = {
CCPotentiometer knobsTop[] {
{A4, MIDI_CC::General_Purpose_Controller_1},
{A5, MIDI_CC::General_Purpose_Controller_2},
{A6, MIDI_CC::General_Purpose_Controller_3},
{A7, MIDI_CC::General_Purpose_Controller_4},
};

Bankable::CCPotentiometer knobsSide[] = {
Bankable::CCPotentiometer knobsSide[] {
{{bank, BankType::CHANGE_CHANNEL}, A8, {MIDI_CC::Pan, CHANNEL_1}},
{{bank, BankType::CHANGE_CHANNEL}, A9, {MIDI_CC::Pan, CHANNEL_2}},
{{bank, BankType::CHANGE_CHANNEL}, A10, {MIDI_CC::Pan, CHANNEL_3}},
{{bank, BankType::CHANGE_CHANNEL}, A11, {MIDI_CC::Pan, CHANNEL_4}},
};

Bankable::NoteButtonLatching switches[] = {
Bankable::NoteButtonLatching switches[] {
{{bank, BankType::CHANGE_ADDRESS}, 2, MCU::MUTE_1},
{{bank, BankType::CHANGE_ADDRESS}, 3, MCU::MUTE_2},
{{bank, BankType::CHANGE_ADDRESS}, 5, MCU::MUTE_3},
{{bank, BankType::CHANGE_ADDRESS}, 7, MCU::MUTE_4},
};

CCRotaryEncoder enc = {
CCRotaryEncoder enc {
{1, 0}, // pins
MIDI_CC::General_Purpose_Controller_5, // address
speedMultiplier, // multiplier
4, // pulses per click
};

SwitchSelector selector = {bank, 11};
SwitchSelector selector {bank, 11};

void setup() {
Control_Surface.begin();
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 @@ -33,7 +33,7 @@
USBMIDI_Interface midi;

// Instantiate the LED that will light up when middle C is playing
NoteLED led = {
NoteLED led {
LED_BUILTIN, // Pin of built-in LED
{MIDI_Notes::C(4), CHANNEL_1}, // Note C4 on MIDI channel 1
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include <Control_Surface.h>

// Define the array of leds.
Array<CRGB, 8> leds = {};
Array<CRGB, 8> leds {};
// The data pin with the strip connected.
constexpr uint8_t ledpin = 2;

Expand All @@ -51,7 +51,7 @@ struct RainbowColorMapper {
}
};

NoteRangeFastLED<leds.length, RainbowColorMapper> midiled = {
NoteRangeFastLED<leds.length, RainbowColorMapper> midiled {
leds,
MIDI_Notes::C(4),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@
USBMIDI_Interface midi;

// Instantiate a shift register as output for the LEDs
SPIShiftRegisterOut<8> sreg = {
SPIShiftRegisterOut<8> sreg {
SPI, // SPI interface to use
10, // Latch pin (ST_CP)
MSBFIRST, // Byte order
};

// 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
8 changes: 4 additions & 4 deletions examples/2. MIDI Input/1. LEDs/3.NoteLEDBar/3.NoteLEDBar.ino
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@
USBDebugMIDI_Interface midi;

// Instantiate a shift register as output for the LEDs
SPIShiftRegisterOut<8> sreg = {
SPIShiftRegisterOut<8> sreg {
SPI, // SPI interface to use
10, // Latch pin (ST_CP)
MSBFIRST, // Byte order
};

// 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 @@ -72,7 +72,7 @@ void loop() {
* 2. You can use any type of pins for the LEDs, and in any combination.
* For example, if you want to use the normal Arduino pins 2-9:
*
* NoteLEDBar<8> leds = {
* NoteLEDBar<8> leds {
* {{2, 3, 4, 5, 6, 7, 8, 9}},
* MIDI_Notes::C(4),
* };
Expand All @@ -81,7 +81,7 @@ void loop() {
*
* You can even mix and match pins of different types:
*
* NoteLEDBar<8> leds = {
* NoteLEDBar<8> leds {
* {{2, 3, 4, 5, 6, 7, sreg.pin(0), sreg.pin(1) }},
* MIDI_Notes::C(4),
* };
Expand Down
6 changes: 3 additions & 3 deletions examples/2. MIDI Input/1. LEDs/4.VULEDs/4.VULEDs.ino
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ USBMIDI_Interface midi;

// Instantiate two daisy-chained shift register with the SPI slave select pin as
// latch pin, most significant bit first, and a total of 16 outputs.
SPIShiftRegisterOut<16> sreg = {SPI, SS, MSBFIRST};
SPIShiftRegisterOut<16> sreg {SPI, SS, MSBFIRST};

// Instantiate a VULEDs object with 12 LEDs.
MCU::VULEDs<12> vu = {
MCU::VULEDs<12> vu {
sreg.pins().slice<0, 11>(), // first 12 pins of the shift registers
1, // track number [1, 8]
MCU::VUDecay::Default, // how long does it take for the meter to decay
Expand All @@ -54,7 +54,7 @@ MCU::VULEDs<12> vu = {
// If you don't want to use shift registers, you can just specify a list of pin
// numbers:
//
// MCU::VULEDs<12> vu = {
// MCU::VULEDs<12> vu {
// {{2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}}, // Arduino pin numbers
// 1, // track number [1, 8]
// MCU::VUDecay::Default, // how long does it take for the meter to decay
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ USBMIDI_Interface midi;
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 = {
NoteLEDPWM led {
ledPin, // Pin of the LED, must be PWM pin
{MIDI_Notes::C(4), CHANNEL_1}, // Note C4 on MIDI channel 1
};
Expand Down
Loading

0 comments on commit c75e43f

Please sign in to comment.