note

awgrover/x-midi/note

Start/stop a note.
note
@/note
Start/stop a note.
No.number
Note number
Chnumber
MIDI Channel
VelOnnumber
Velocity Level (on). often volume, depends on the instrument
VelOffnumber
some instruments respond to off-velocity, or have decay. Normally 0
playpulse
Send NoteOn when triggered
stoppulse
Send NoteOff when triggered
note
No.
Ch
VelOn
VelOff
play
stop
To use the node in your project you should have the awgrover/x-midi library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

{{#global}}
#include <MIDI.h>
namespace xod {
namespace awgrover__midi {
  #ifndef MIDI47_DEFAULT_INSTANCE
    // create one 'MIDI' object only once
    #define MIDI47_DEFAULT_INSTANCE
    bool MIDI_DefaultInited=0; // control setup once

    MIDI_CREATE_DEFAULT_INSTANCE(); // MIDI

    #define DEBUG_SendText(body) /* nothing, see the "debug" node */

    void midi_setup() {
      // this should be in setup
      // ( call as xod::awgrover__midi::midi_setup(); in evaluate)
      if (!MIDI_DefaultInited) {
        // this will reset the serial port to 31250 for the midi's serial port
        MIDI.begin(MIDI_CHANNEL_OMNI); // Enable Soft Thru, everything at the input is sent back
        MIDI_DefaultInited = 1;
        DEBUG_SendText( Serial.print(millis());Serial.print(F(" MIDI.begin()")); )
      }
    }
  #endif
}}
{{/global}}

struct State {
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
    xod::awgrover__midi::midi_setup(); 
    
    auto channel = getValue<input_channel>(ctx);
    auto note = getValue<input_note>(ctx);
    
    if (isInputDirty<input_play>(ctx)) {
        auto on_velocity = getValue<input_on_velocity>(ctx);
    	// note, velocity, channel
    	xod::awgrover__midi::MIDI.sendNoteOn(note, on_velocity, channel);
      // only if xod "Debugger" is on
      DEBUG_SERIAL.print(millis());DEBUG_SERIAL.print(F(" "));
      DEBUG_SERIAL.print(F("Sent midi-note "));DEBUG_SERIAL.print(note);
      DEBUG_SERIAL.print(F("Vel "));DEBUG_SERIAL.println(on_velocity);	
    }
    else if (isInputDirty<input_stop>(ctx)) {
        auto off_velocity = getValue<input_off_velocity>(ctx);
    	// note, velocity, channel
    	xod::awgrover__midi::MIDI.sendNoteOff(note, off_velocity, channel);
      // only if xod "Debugger" is on
      DEBUG_SERIAL.print(millis());DEBUG_SERIAL.print(F(" "));
      DEBUG_SERIAL.print(F("Sent midi-note "));DEBUG_SERIAL.print(note);
      DEBUG_SERIAL.print(F("Vel "));DEBUG_SERIAL.print(off_velocity);
      DEBUG_SERIAL.println(F(" off"));
    }

}