Ok so since i have some new parts in my studio i modified my midi keyboard to have an extra Midi output port and created a dual-merger to create an extra input port. It all worked using the simplest of sketches
#include <MIDI.h>
#include <SoftwareSerial.h>
SoftwareSerial softSerial(2, 3);
MIDI_CREATE_INSTANCE(HardwareSerial, Serial, midiA);
MIDI_CREATE_INSTANCE(SoftwareSerial, softSerial, midiB);
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
midiA.begin(MIDI_CHANNEL_OMNI);
midiB.begin(MIDI_CHANNEL_OMNI);
midiB.turnThruOff();
midiA.turnThruOff();
}
void loop() {
static uint32_t lastmsg = millis();
if (midiB.read()) {
midiA.send(midiB.getType(), midiB.getData1(), midiB.getData2(), midiB.getChannel());
lastmsg = millis();
}
if (midiA.read()) {
midiA.send(midiA.getType(), midiA.getData1(), midiA.getData2(), midiA.getChannel());
lastmsg = millis();
}
}
if (millis() - lastmsg < 1000) digitalWrite(LED_BUILTIN, HIGH);
else digitalWrite(LED_BUILTIN, LOW);
}
But now i am working on getting my midi-pedal board connected and one of it's features should be sending midi-clock messages. I had a snippet somewhere that does that for me, and it works straight into my soundcard's midi input. But through the merger it doesn't. Then i remembered that for sending realtime messages you need to use
midiA.sendRealTime(midi::Clock);
and so i ended up doing this
if (midiB.read()) {
if (midiB.getType() == midi::Clock) {
midiA.sendRealTime(midi::Clock);
}
else if (midiB.getType() == midi::Start) {
midiA.sendRealTime(midi::Start);
}
else if (midiB.getType() == midi::Stop) {
midiA.sendRealTime(midi::Stop);
}
else if (midiB.getType() == midi::Continue) {
midiA.sendRealTime(midi::Continue);
}
else {
midiA.send(midiB.getType(), midiB.getData1(), midiB.getData2(), midiB.getChannel());
lastmsg = millis();
}
}
and that works, but is not very elegant.
so i looked at the midi namespace and the HEX values for the realtime messages are
Clock = 0xF8, ///< System Real Time - Timing Clock
Start = 0xFA, ///< System Real Time - Start
Continue = 0xFB, ///< System Real Time - Continue
Stop = 0xFC, ///< System Real Time - Stop
ActiveSensing = 0xFE, ///< System Real Time - Active Sensing
SystemReset = 0xFF, ///< System Real Time - System Reset
So i figured that
if (midiB.getType() & 0xF8 == 0xF8) {
midiA.sendRealTime(midiB.getType());
should also work, but that somehow doesn't. Anybody have any idea ?