init-midi-default

copsmusic/midi-basic/init-midi-default

Init the midi Hardware configuration on the default UART of the Arduino. For example : Serial1 for Arduino DUE & Leonardo and Serial for Arduino UNO
init-midi-default
@/init-midi-default
Init the midi Hardware configuration on the default UART of the Arduino. For example : Serial1 for Arduino DUE & Leonardo and Serial for Arduino UNO
TRGpulse
Trigger the midi read
CH_INnumber
Channel to listen (1-16) 0 = ALL
init-midi-default
TRG
CH_IN
Done
CH
CHnumber
channel to listen
Donepulse
Triggered when the MIDI initialization is done
To use the node in your project you should have the copsmusic/midi-basic 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

#pragma XOD require "https://github.com/FortySevenEffects/arduino_midi_library"

{{#global}}

#include <MIDI.h>

namespace xod {
namespace copsmusic__midi {
  #ifndef MIDI_DEFAULT_INSTANCE
    // create one 'MIDI' object only once
    #define MIDI_DEFAULT_INSTANCE
    
    //init default hardware serial port and name it "MIDI"
    // Leonardo, Due and other USB boards use Serial1 by default.
    // UNO uses Serial by default
    MIDI_CREATE_DEFAULT_INSTANCE();
        
    bool MIDI_DefaultInited=0; // control setup once
    
    void midi_setup(int inChannelToListen) {

      if (!MIDI_DefaultInited) {
          
            MIDI.begin( inChannelToListen ); // set the channel to listen to. Rate is 31250 bauds for MIDI
            MIDI.turnThruOff(); // Disable midi thru
            
            MIDI_DefaultInited = 1;
      }
    }
  #endif     
}}

{{/global}}

struct State {
};

{{ GENERATED_CODE }}
    
void evaluate(Context ctx) {
    int channelToListen ;

    channelToListen = getValue<input_CH_IN>(ctx);
    xod::copsmusic__midi::midi_setup(channelToListen);

    if (isInputDirty<input_TRG>(ctx)) {
            emitValue<output_CH>(ctx,channelToListen);
            emitValue<output_Done>(ctx,1);
    }
}