Added new MIDI dispatching - currently not ready for running.

pull/4/head
Holger Wirtz 6 years ago
parent 241e8931b0
commit 9edc7ddd4c
  1. 221
      MicroDexed.ino
  2. 1602
      midi_devices.hpp

@ -29,15 +29,10 @@
#include <SD.h> #include <SD.h>
#include <MIDI.h> #include <MIDI.h>
#include <EEPROM.h> #include <EEPROM.h>
#if defined(USBCON) #include "midi_devices.hpp"
#include <midi_UsbTransport.h>
#endif
#include <limits.h> #include <limits.h>
#include "dexed.h" #include "dexed.h"
#include "dexed_sysex.h" #include "dexed_sysex.h"
#ifdef USE_ONBOARD_USB_HOST
#include <USBHost_t36.h>
#endif
#ifdef I2C_DISPLAY // selecting sounds by encoder, button and display #ifdef I2C_DISPLAY // selecting sounds by encoder, button and display
#include "UI.h" #include "UI.h"
@ -129,20 +124,6 @@ bool master_key_enabled = false;
elapsedMillis cpu_mem_millis; elapsedMillis cpu_mem_millis;
#endif #endif
#ifdef MIDI_DEVICE
MIDI_CREATE_INSTANCE(HardwareSerial, MIDI_DEVICE, midi_serial);
#endif
#ifdef USE_ONBOARD_USB_HOST
USBHost usb_host;
MIDIDevice midi_usb(usb_host);
#endif
#if defined(USBCON)
static const unsigned sUsbTransportBufferSize = 16;
typedef midi::UsbTransport<sUsbTransportBufferSize> UsbTransport;
UsbTransport sUsbTransport;
MIDI_CREATE_INSTANCE(UsbTransport, sUsbTransport, midi_onboard_usb);
#endif
#ifdef TEST_NOTE #ifdef TEST_NOTE
IntervalTimer sched_note_on; IntervalTimer sched_note_on;
IntervalTimer sched_note_off; IntervalTimer sched_note_off;
@ -177,23 +158,7 @@ void setup()
Serial.println(F("<setup start>")); Serial.println(F("<setup start>"));
initial_values_from_eeprom(); initial_values_from_eeprom();
// start up USB host setup_midi_devices();
#ifdef USE_ONBOARD_USB_HOST
usb_host.begin();
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);
Serial.println(F("Serial MIDI enabled"));
#endif
// start audio card // start audio card
AudioMemory(AUDIO_MEM); AudioMemory(AUDIO_MEM);
@ -369,7 +334,7 @@ void loop()
} }
// MIDI input handling // MIDI input handling
handle_input(); check_midi_devices();
#ifdef I2C_DISPLAY #ifdef I2C_DISPLAY
// UI // UI
@ -390,106 +355,132 @@ void loop()
#endif #endif
} }
void handle_input(void) void handleNoteOn(byte inChannel, byte inNumber, byte inVelocity)
{ {
#if defined(USBCON) if (checkMidiChannel(inChannel))
while (midi_onboard_usb.read())
{ {
#ifdef DEBUG ;
Serial.println(F("[ONBOARD-MIDI-USB]")); }
#endif }
if (midi_onboard_usb.getType() >= 0xf0) // SysEX
void handleNoteOff(byte inChannel, byte inNumber, byte inVelocity)
{
if (checkMidiChannel(inChannel))
{ {
handle_sysex_parameter(midi_onboard_usb.getSysExArray(), midi_onboard_usb.getSysExArrayLength()); ;
} }
else }
void handleControlChange(byte inChannel, byte inData1, byte inData2)
{ {
queue_midi_event(midi_onboard_usb.getType(), midi_onboard_usb.getData1(), midi_onboard_usb.getData2()); if (checkMidiChannel(inChannel))
#ifdef MIDI_MERGE_THRU {
#ifdef USB_CON ;
midi_onboard_usb.send(midi_serial.getType(), midi_serial.getData1(), midi_serial.getData2(), midi_serial.getChannel());
#endif
#ifdef USE_ONBOARD_USB_HOST
midi_usb.send(midi_serial.getType(), midi_serial.getData1(), midi_serial.getData2(), midi_serial.getChannel());
#endif
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()) void handleAfterTouch(byte inChannel, byte inPressure)
{ {
#ifdef DEBUG ;
Serial.println(F("[MIDI-USB-HOST]")); }
#endif
if (midi_usb.getType() >= 0xf0) // SysEX void handlePitchBend(byte inChannel, int inPitch)
{ {
handle_sysex_parameter(midi_usb.getSysExArray(), midi_usb.getSysExArrayLength()); ;
} }
else
void handleProgramChange(byte inChannel, byte inProgram)
{ {
queue_midi_event(midi_usb.getType(), midi_usb.getData1(), midi_usb.getData2()); ;
#ifdef MIDI_MERGE_THRU
#ifdef USB_CON
midi_onboard_usb.send(midi_serial.getType(), midi_serial.getData1(), midi_serial.getData2(), midi_serial.getChannel());
#endif
#ifdef USE_ONBOARD_USB_HOST
midi_usb.send(midi_serial.getType(), midi_serial.getData1(), midi_serial.getData2(), midi_serial.getChannel());
#endif
midi_serial.send(midi_serial.getType(), midi_serial.getData1(), midi_serial.getData2(), midi_serial.getChannel());
#endif
} }
void handleSystemExclusive(byte *data, uint len)
{
handle_sysex_parameter(data, len);
} }
#endif
#ifdef MIDI_DEVICE void handleSystemExclusiveChunk(const byte *data, uint16_t len, bool last)
while (midi_serial.read())
{ {
#ifdef DEBUG ;
Serial.print(F("[MIDI-Serial] ")); }
#endif
if (midi_serial.getType() >= 0xf0) // SYSEX void handleTimeCodeQuarterFrame(byte data)
{ {
handle_sysex_parameter(midi_serial.getSysExArray(), midi_serial.getSysExArrayLength()); ;
} }
else
void handleAfterTouchPoly(byte inChannel, byte inNumber, byte inVelocity)
{ {
queue_midi_event(midi_serial.getType(), midi_serial.getData1(), midi_serial.getData2()); ;
#ifdef MIDI_MERGE_THRU
#ifdef USB_CON
midi_onboard_usb.send(midi_serial.getType(), midi_serial.getData1(), midi_serial.getData2(), midi_serial.getChannel());
#endif
midi_usb.send(midi_serial.getType(), midi_serial.getData1(), midi_serial.getData2(), midi_serial.getChannel());
midi_serial.send(midi_serial.getType(), midi_serial.getData1(), midi_serial.getData2(), midi_serial.getChannel());
#endif
} }
void handleSongSelect(byte inSong)
{
;
} }
#endif
void handleTuneRequest(void)
{
;
} }
#ifdef DEBUG void handleClock(void)
#ifdef SHOW_MIDI_EVENT {
void print_midi_event(uint8_t type, uint8_t data1, uint8_t data2) ;
}
void handleStart(void)
{
;
}
void handleContinue(void)
{
;
}
void handleStop(void)
{
;
}
void handleActiveSensing(void)
{
;
}
void handleSystemReset(void)
{ {
Serial.print(F("Listen MIDI-Channel: ")); ;
}
void handleRealTimeSystem(void)
{
;
}
bool checkMidiChannel(byte inChannel)
{
// check for MIDI channel
if (midi_channel == MIDI_CHANNEL_OMNI) if (midi_channel == MIDI_CHANNEL_OMNI)
Serial.print(F("OMNI")); {
else return (true);
Serial.print(midi_channel, DEC);
Serial.print(F(", MIDI event type: 0x"));
if (type < 16)
Serial.print(F("0"));
Serial.print(type, HEX);
Serial.print(F(", incoming MIDI channel: "));
Serial.print((type & 0x0f) + 1, DEC);
Serial.print(F(", data1: "));
Serial.print(data1, DEC);
Serial.print(F(", data2: "));
Serial.println(data2, DEC);
} }
else if (inChannel != midi_channel)
{
#ifdef DEBUG
Serial.print(F("Ignoring MIDI data on channel "));
Serial.print(inChannel);
Serial.print(F("(listening on "));
Serial.print(midi_channel);
Serial.println(F(")"));
#endif #endif
#endif return (false);
}
return (true);
}
#ifdef MASTER_KEY_MIDI #ifdef MASTER_KEY_MIDI
bool handle_master_key(uint8_t data) bool handle_master_key(uint8_t data)
@ -570,10 +561,6 @@ bool queue_midi_event(uint8_t type, uint8_t data1, uint8_t data2)
{ {
bool ret = false; bool ret = false;
#if defined(DEBUG) && defined(SHOW_MIDI_EVENT)
print_midi_event(type, data1, data2);
#endif
// check for MIDI channel // check for MIDI channel
if (midi_channel != MIDI_CHANNEL_OMNI) if (midi_channel != MIDI_CHANNEL_OMNI)
{ {

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save