Mix or merge MIDI IN signals with internal MIDI messages / midi library

I'm using the midi library 3.2 for a midi controller and it is working very well. It is for changing CC values of a synth, but i want to play it on a keyboard, too. So I'm curious about mixing the Keyboard signals with the arduino MIDI messages somehow...
Well, I could go and buy an hardware merger, or maybe there is a way to listen to the incoming MIDI messages and send them inside my loop along with the internal MIDI messages?

This simplified part is working, I couldn't find any proper "AllTheIncomingMidiMessage" function in the library:

void loop() {
  // Work with the input
  sensorValue = analogRead(sensorPin) / 8;
  
  // Send MIDI cc74 example on channel 1
  if(sensorValue != sensorValue_old) {                   // only if value has changed
    MIDI.send(ControlChange,74,sensorValue,1);
    sensorValue_old = sensorValue;                        // compare and change if not the same
  }
  
  //Read and send all incoming MIDI messages
  //MIDI.send(AllTheIncomingMidiMessageSomehow,1);

It would be great to get a hint!

Hi,
Yes, it's possible.
Just add the MIDI listener in your loop :

if (MIDI.read()) { ...}

Then you get the MIDI messages types : MIDI.getType()
and the values (depending on the types) : MIDI.getData1() and MIDI.getData2()

So you can choose what you will send. For exemple, if the MIDI type is "NoteOn", MIDI.getData1() will be the value of the note, and MIDI.getData2() the volume.

Gaétan

And if you want to send everything, just add :

if (MIDI.read()) MIDI.send(MIDI.getType(), MIDI.getData1(), MIDI.getData2(), MIDI.getChannel());

Great! Can't wait to check this out 8)

We'll, almost after a year I decided to move away from the arduino in this case.
The overall timing was too bad, and I think the best way would be to write the code from scratch.
Merging two large libraries wasn't the best idea :smiley:

For my case ( shruthi-1 control ) I found a solution that was dedicated for the shruthi with its own pcb.