[SOLVED]Midi in and Midi out problem

i’m playing with midi and i have a weird issue that i can not solve.

ok my setup
pc with midiox and usb to midi (i also change the midi routing so it doesnt loop)
arduino DUE with midi in and out which seems to work great! after i changed the thru option off.

and the idea is to change notes to a differnt one an manipulate the velocity.

but for now i’m testing with the pc keyboeard to send midi massages to see what i get back.

i’m sending “h” = note 54(dec) and “g” = note 56(dec)
(PC) sends channel1 note 54 velocity 100 NOTE ON and channel1 note 54 velocity 64 NOTE OFF
(DUE) should sends back channel 1 note 36 velocity (pc) “100” NOTE ON

but weird enough sometimes i get the NOTE ON value 100 and other times i get the NOTE OFF value 64

#include <MIDI.h>

MIDI_CREATE_INSTANCE(HardwareSerial, Serial1,    midiA);

#define AMOUNT 6

uint32_t interval[] = {1000000, 1000000, 1000000, 1000000, 1000000, 1000000}; // delay time to trigger next trigger
uint32_t previousMicros[AMOUNT];
uint8_t noteOUT[] = {36, 38, 45, 41, 42, 50}; // note to send
uint8_t noteIN[] = {54, 56, 45, 41, 42, 50}; // note to send
// g = 54
// h = 56

void setup() {
  Serial.begin(9600);

  midiA.begin(0);
  midiA.turnThruOff();


}

void loop() {

  uint32_t currentTime = micros();

  if (midiA.read()) {

    Serial.println(midiA.getType());
    
    for (uint8_t y = 0; y < AMOUNT; y++) {
      
      if (currentTime - previousMicros[y] >= interval[y]) {
        
        if (noteIN[y] == midiA.getData1()) {
          
          midiA.sendNoteOn(noteOUT[y], midiA.getData2() , 1);
          
          previousMicros[y] = currentTime;
          
        }  
      }
    }
  }
}

oke never mind i allready found it :confused:

i need to check if its a NOTE ON command eith getType == 144 (NOTEON)

#include <MIDI.h>

MIDI_CREATE_INSTANCE(HardwareSerial, Serial1,    midiA);

#define AMOUNT 6

uint32_t interval[] = {1000000, 1000000, 1000000, 1000000, 1000000, 1000000}; // delay time to trigger next trigger
uint32_t previousMicros[AMOUNT];
uint8_t noteOUT[] = {36, 38, 45, 41, 42, 50}; // note to send
uint8_t noteIN[] = {54, 56, 45, 41, 42, 50}; // note to send
// g = 54
// h = 56

void setup() {
  Serial.begin(9600);

  midiA.begin(0);
  midiA.turnThruOff();


}

void loop() {

  uint32_t currentTime = micros();

  if (midiA.read()) {

    if (midiA.getType() == 144) {

      for (uint8_t y = 0; y < AMOUNT; y++) {

        if (currentTime - previousMicros[y] >= interval[y]) {

          if (noteIN[y] == midiA.getData1()) {

            midiA.sendNoteOn(noteOUT[y], midiA.getData2() , 1);

            previousMicros[y] = currentTime;

          }
        }
      }
    }
  }
}

Please edit the title of your post to include something like [Solved] to avoid people wasting time trying to help when help is unnecessary.

Keep in mind that 'Note-off' is actually also 'Note-on' velocity 0.