Skip to content

Commit

Permalink
Make Control_Surface a MIDI Sink/Source
Browse files Browse the repository at this point in the history
When disconnecting a MIDI Source, also disconnect the Pipe from the Sink
(and vice versa)
  • Loading branch information
tttapa committed Mar 3, 2020
1 parent f90479e commit 8a3b1b3
Show file tree
Hide file tree
Showing 31 changed files with 1,724 additions and 1,590 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
* This example demonstrates how to group together two or more MIDI interfaces,
* so you can send the MIDI output over both MIDI USB and 5-pin DIN MIDI, for
* example. MIDI input is received from all interfaces as well.
*
* Also have a look at the @ref MIDI_Pipes-Routing.ino example and the
* @ref MIDI_Pipe documentation for more information about MIDI routing.
* Control Surface can be used as both a MIDI sink and a MIDI source.
*
* When you call `Control_Surface.begin()`, it automatically connects itself to
* the default MIDI interface (@ref MIDI_Interface::getDefault()).
* If you want to route everything manually, you have to connect it before
* calling `Control_Surface.begin()`, or you have to disconnect the default
* pipes before connecting your own, using
* @ref Control_Surface_::disconnectMIDI_Interfaces().
*
* @boards AVR USB, Due, Teensy 3.x
*
Expand Down Expand Up @@ -35,20 +46,18 @@
USBMIDI_Interface usbmidi;
HardwareSerialMIDI_Interface serialmidi = {Serial1, MIDI_BAUD};

// And group them together
MultiMIDI_Interface<2> midi = {{&usbmidi, &serialmidi}};

// The MIDI interface that was instantiated last will be used as the
// default MIDI interface by Control_Surface.
// To override the default, you can use the following line in your setup:
// `midi.setAsDefault();`
// where `midi` is the MIDI interface you want to set as the default.
// Create a MIDI pipe factory to connect the MIDI interfaces to Control Surface
BidirectionalMIDI_PipeFactory<2> pipes;

// Add some MIDI elements to show that the MIDI interfaces actually work
CCPotentiometer pot = {A0, MIDI_CC::General_Purpose_Controller_1};
NoteValueLED led = {LED_BUILTIN, 0x3C};

void setup() {
// Manually connect the MIDI interfaces to Control Surface
Control_Surface | pipes | usbmidi;
Control_Surface | pipes | serialmidi;
// Initialize Control Surface _after_ connecting the interfaces
Control_Surface.begin();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ class MyNoteButton : public MIDIOutputElement {
void update() final override {
AH::Button::State state = button.update(); // Read the button
if (state == AH::Button::Falling) { // if pressed
Control_Surface.MIDI().sendNoteOn(address, velocity); // → note on
Control_Surface.sendNoteOn(address, velocity); // → note on
} else if (state == AH::Button::Rising) { // if released
Control_Surface.MIDI().sendNoteOff(address, velocity); // → note off
Control_Surface.sendNoteOff(address, velocity); // → note off
}
}

Expand Down
Loading

0 comments on commit 8a3b1b3

Please sign in to comment.