tttapa / Control-Surface

Arduino library for creating MIDI controllers and other MIDI devices.
GNU General Public License v3.0
1.24k stars 139 forks source link

Trigger MIDI with a variable #333

Open AnnoyedSandwich opened 3 years ago

AnnoyedSandwich commented 3 years ago

Hey, is it possible to trigger a midi signal with a variable instead when a button is pressed?

For a little bit of context, I'm Working on a DMX to MIDI Converter. It listens for an incoming dmx signal on channel 1 and would then send a midi Note ON/OFF

I want to use this library for the MIDI part so my question is, is it possible to send a MIDI Signal when, for example, a boolean is true? So something like this

NoteButton example[] = { (DMX Channel 1 = true), {note(C, 2), CHANNEL_1} };

tttapa commented 3 years ago

Yes, you can send MIDI messages based on boolean values, but not using the NoteButton class, NoteButton is intended for buttons only.

To trigger the MIDI messages yourself, you can use the MIDI_Sender methods. Control_Surface implements these methods:

#include <Control_Surface.h> // Include the Control Surface library

// Instantiate a MIDI over USB interface.
USBMIDI_Interface midi;

using namespace MIDI_Notes;

void setup() {
  Control_Surface.begin(); // Initialize Control Surface
}

void loop() {
  Control_Surface.loop(); // Update the Control Surface

  if (/* DMX message received */) {
    uint8_t velocity = 127;
    Control_Surface.sendNoteOn({note(C, 2), CHANNEL_1}, velocity);
  } else if (/* other condition */) {
    uint8_t velocity = 127;
    Control_Surface.sendNoteOff({note(C, 2), CHANNEL_1}, velocity);
  }
}

If you don't need any of the MIDI controller-specific features of Control Surface, you can use the MIDI interface directly, instead of going through Control_Surface, see https://tttapa.github.io/Control-Surface-doc/Doxygen/d7/d8d/Send-MIDI-Notes_8ino-example.html and https://tttapa.github.io/Control-Surface-doc/Doxygen/d8/d9b/MIDI-Output_8ino-example.html.

AnnoyedSandwich commented 3 years ago

That's awesome. Is there a similar class for control change events ?

tttapa commented 3 years ago

Yes, if you go to the MIDI_Sender documentation page, you can see all methods, to send control change messages, you can use Control_Surface.sendCC({ccnumber, channel}, ccvalue).