read-midi-msg

copsmusic/midi-basic/read-midi-msg

Read the input MIDI msg
read-midi-msg
@/read-midi-msg
Read the input MIDI msg
TRGpulse
Trigger the midi read continuously to catch all the input data. DO NOT CONNECT
CH_INnumber
Channel to listen 1-16 0 = ALL
read-midi-msg
MsgSent
CH
Type
Data1
Data2
TRG
CH_IN
Data2number
Second part of the midi msg data
Data1number
First part of the midi msg data
Typenumber
Type of the midi msg
CHnumber
Channel of the msg
MsgSentpulse
Triggered when valid midi msg is detected
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

struct State {
};

{{ GENERATED_CODE }}
    
void evaluate(Context ctx) {

    int channelToListen;    
    int channel;             //channel of the read msg
    int data1;
    int data2;
    int type;
    bool msg_received = 0;
    bool msg_stored = 0;
    
    channelToListen = getValue<input_CH_IN>(ctx);

    if (isInputDirty<input_TRG>(ctx)) {

        msg_received = xod::copsmusic__midi::MIDI.read(channelToListen); // Read the selected channel (0 = ALL)
        msg_stored = xod::copsmusic__midi::MIDI.check();
        
        if (msg_received and msg_stored) {

            type = xod::copsmusic__midi::MIDI.getType();
            channel = xod::copsmusic__midi::MIDI.getChannel();
            data1 = xod::copsmusic__midi::MIDI.getData1();
            data2 = xod::copsmusic__midi::MIDI.getData2();

            emitValue<output_CH>(ctx,channel);
            emitValue<output_Type>(ctx,type);
            emitValue<output_Data1>(ctx,data1);
            emitValue<output_Data2>(ctx,data2);
            emitValue<output_MsgSent>(ctx,1);
 /*                   
            Serial.print("Channel ="); Serial.println(channel);
            Serial.print("Type ="); Serial.println(type);
            Serial.print("data1 ="); Serial.println(data1);
            Serial.print("data2 ="); Serial.println(data2); 
 */         
       }
    }
}