From 3c5a4ecc3114b256de25aec2b0c298606babad38 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Tue, 30 Oct 2018 08:58:56 +0100 Subject: [PATCH] Added usage of onboard USB connector as MIDI device (you have to enable the USB-Type as "Serial + MIDI" inside IDE before compiling!) - UNTESTED YET Added compile time option MIDI_MERGE_THRU for sending all incoming MIDI to the serial MIDI-OUT as MIDI-THRU simulation. --- MicroDexed.ino | 52 ++++++++++++++++++++++++++++++++++++++++++++++---- config.h | 1 + 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index 5ee47ec..c93a5fb 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -28,6 +28,9 @@ #include #include #include +#if defined(USBCON) +#include +#endif #include #include "dexed.h" #include "dexed_sysex.h" @@ -131,6 +134,12 @@ MIDI_CREATE_INSTANCE(HardwareSerial, MIDI_DEVICE, midi_serial); USBHost usb_host; MIDIDevice midi_usb(usb_host); #endif +#if defined(USBCON) +static const unsigned sUsbTransportBufferSize = 16; +typedef midi::UsbTransport UsbTransport; +UsbTransport sUsbTransport; +MIDI_CREATE_INSTANCE(UsbTransport, sUsbTransport, midi_onboard_usb); +#endif #ifdef TEST_NOTE IntervalTimer sched_note_on; @@ -171,6 +180,12 @@ void setup() Serial.println(F("USB-MIDI enabled.")); #endif + // check for onboard USB-MIDI +#if defined(USBCON) + midi_onboard_usb.begin(); + Serial.println(F("Onboard USB-MIDI enabled.")); +#endif + #ifdef MIDI_DEVICE // Start serial MIDI midi_serial.begin(DEFAULT_MIDI_CHANNEL); @@ -370,6 +385,25 @@ void loop() void handle_input(void) { +#if defined(USBCON) + while (midi_onboard_usb.read()) + { +#ifdef DEBUG + Serial.println(F("[ONBOARD-MIDI-USB]")); +#endif + if (midi_onboard_usb.getType() >= 0xf0) // SysEX + { + handle_sysex_parameter(midi_onboard_usb.getSysExArray(), midi_onboard_usb.getSysExArrayLength()); + } + else + { + queue_midi_event(midi_onboard_usb.getType(), midi_onboard_usb.getData1(), midi_onboard_usb.getData2()) +#ifdef MIDI_MERGE_THRU + midi_serial.send(midi_serial.getType(), midi_serial.getData1(), midi_serial.getData2(), midi_serial.getChannel()); +#endif + } + } +#endif #ifdef USE_ONBOARD_USB_HOST usb_host.Task(); while (midi_usb.read()) @@ -381,8 +415,13 @@ void handle_input(void) { handle_sysex_parameter(midi_usb.getSysExArray(), midi_usb.getSysExArrayLength()); } - else if (queue_midi_event(midi_usb.getType(), midi_usb.getData1(), midi_usb.getData2())) - return; + else + { + queue_midi_event(midi_usb.getType(), midi_usb.getData1(), midi_usb.getData2()); +#ifdef MIDI_MERGE_THRU + midi_serial.send(midi_serial.getType(), midi_serial.getData1(), midi_serial.getData2(), midi_serial.getChannel()); +#endif + } } #endif #ifdef MIDI_DEVICE @@ -395,8 +434,13 @@ void handle_input(void) { handle_sysex_parameter(midi_serial.getSysExArray(), midi_serial.getSysExArrayLength()); } - else if (queue_midi_event(midi_serial.getType(), midi_serial.getData1(), midi_serial.getData2())) - return; + else + { + queue_midi_event(midi_serial.getType(), midi_serial.getData1(), midi_serial.getData2()); +#ifdef MIDI_MERGE_THRU + midi_serial.send(midi_serial.getType(), midi_serial.getData1(), midi_serial.getData2(), midi_serial.getChannel()); +#endif + } } #endif } diff --git a/config.h b/config.h index dce899c..02650d2 100644 --- a/config.h +++ b/config.h @@ -35,6 +35,7 @@ #define VERSION 1.0.0 #define MIDI_DEVICE Serial1 #define USE_ONBOARD_USB_HOST 1 +#define MIDI_MERGE_THRU 1 #define TEENSY_AUDIO_BOARD 1 #define VOLUME 0.6 #define DEFAULT_MIDI_CHANNEL MIDI_CHANNEL_OMNI