From 17c0282f94674c1ba6d014e73c2b71b00aec80c2 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Sun, 4 Sep 2022 18:17:16 +0200 Subject: [PATCH] Exchanged midi_devices.hpp (from MicroDexed-touch) for better MIDI handling. --- config.h | 2 +- midi_devices.hpp | 1676 ++++++++++++++-------------------------------- 2 files changed, 488 insertions(+), 1190 deletions(-) diff --git a/config.h b/config.h index 84cc929..a202609 100644 --- a/config.h +++ b/config.h @@ -54,7 +54,7 @@ // sed -i.orig 's/^#define USB_MIDI_SYSEX_MAX 290/#define USB_MIDI_SYSEX_MAX 4104/' /usr/local/arduino-teensy/hardware/teensy/avr/cores/teensy4/usb_midi.h //#define USB_MIDI_SYSEX_MAX 4104 -#define VERSION "1.2.2" +#define VERSION "1.2.3" //************************************************************************************************* //* DEVICE SETTINGS diff --git a/midi_devices.hpp b/midi_devices.hpp index 3a97cf3..90544d0 100644 --- a/midi_devices.hpp +++ b/midi_devices.hpp @@ -21,7 +21,8 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#pragma once +#ifndef MIDI_DEVICES_H +#define MIDI_DEVICES_H #include "config.h" @@ -51,10 +52,10 @@ void handleControlChange(byte inChannel, byte inData1, byte inData2); void handleAfterTouch(byte inChannel, byte inPressure); void handlePitchBend(byte inChannel, int inPitch); void handleProgramChange(byte inChannel, byte inProgram); +void handleAfterTouchPoly(byte inChannel, byte inNumber, byte inVelocity); void handleSystemExclusive(byte *data, uint len); //void handleSystemExclusiveChunk(const byte *data, uint len, bool last); void handleTimeCodeQuarterFrame(byte data); -void handleAfterTouchPoly(byte inChannel, byte inNumber, byte inVelocity); void handleSongSelect(byte inSong); void handleTuneRequest(void); void handleClock(void); @@ -66,190 +67,464 @@ void handleSystemReset(void); //void handleRealTimeSystem(void); void MD_sendControlChange(uint8_t channel, uint8_t cc, uint8_t value); -/***************************************** - MIDI_DEVICE_DIN - *****************************************/ -#ifdef MIDI_DEVICE_DIN -void handleNoteOn_MIDI_DEVICE_DIN(byte inChannel, byte inNumber, byte inVelocity) +#define MIDI_BY_DIN "MIDI_DIN" +#define MIDI_BY_USB_HOST "MIDI_USB_HOST" +#define MIDI_BY_USB "USB_MIDI" + +void handle_generic(byte inChannel, byte inData1, byte inData2, const char *midi_device, midi::MidiType event) { - handleNoteOn(inChannel, inNumber, inVelocity); - #ifdef DEBUG - Serial.print(F("[MIDI_DIN] NoteOn")); + char text[10]; + + switch(event) { + case midi::NoteOn: + handleNoteOn(inChannel, inData1, inData2); + strcpy(text, "NoteOn"); + break; + case midi::NoteOff: + handleNoteOff(inChannel, inData1, inData2); + strcpy(text, "NoteOff"); + break; + case midi::ControlChange: + handleControlChange(inChannel, inData1, inData2); + strcpy(text, "CC"); + break; + case midi::AfterTouchChannel: + handleAfterTouch(inChannel, inData1); + strcpy(text, "Mono AT"); + break; + case midi::PitchBend: + handlePitchBend(inChannel, inData1); + strcpy(text, "PB"); + break; + case midi::ProgramChange: + handleProgramChange(inChannel, inData1); + strcpy(text, "PC"); + break; + case midi::AfterTouchPoly: + handleAfterTouchPoly(inChannel, inData1, inData2); + strcpy(text, "Poly AT"); + break; + default: + break; + } +#ifdef DEBUG + Serial.printf("[%s] %s", midi_device, text); #endif + + // MIDI THRU if (configuration.sys.soft_midi_thru == 1) { -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendNoteOn(inNumber, inVelocity, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif #ifdef MIDI_DEVICE_USB - usbMIDI.sendNoteOn(inNumber, inVelocity, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); + if(strcmp(MIDI_BY_USB, midi_device)) { + switch(event) { + case midi::NoteOn: + usbMIDI.sendNoteOn(inData1, inData2, inChannel); + break; + case midi::NoteOff: + usbMIDI.sendNoteOff(inData1, inData2, inChannel); + break; + case midi::ControlChange: + usbMIDI.sendControlChange(inData1, inData2, inChannel); + break; + case midi::AfterTouchChannel: + usbMIDI.sendAfterTouch(inData1, inChannel); + break; + case midi::PitchBend: + usbMIDI.sendPitchBend(inData1, inChannel); + break; + case midi::ProgramChange: + usbMIDI.sendProgramChange(inData1, inChannel); + break; + case midi::AfterTouchPoly: + usbMIDI.sendAfterTouch(inData1, inData2, inChannel); + break; + default: + break; + } + #ifdef DEBUG + Serial.print(F(" THRU->MIDI_USB")); + #endif + } +#endif + +#ifdef MIDI_DEVICE_DIN + if(strcmp(MIDI_BY_DIN, midi_device)) { + switch(event) { + case midi::NoteOn: + midi_serial.sendNoteOn(inData1, inData2, inChannel); + break; + case midi::NoteOff: + midi_serial.sendNoteOff(inData1, inData2, inChannel); + break; + case midi::ControlChange: + midi_serial.sendControlChange(inData1, inData2, inChannel); + break; + case midi::AfterTouchChannel: + midi_serial.sendAfterTouch(inData1, inChannel); + break; + case midi::PitchBend: + midi_serial.sendPitchBend(inData1, inChannel); + break; + case midi::ProgramChange: + midi_serial.sendProgramChange(inData1, inChannel); + break; + case midi::AfterTouchPoly: + midi_serial.sendAfterTouch(inData1, inData2, inChannel); + break; + default: + break; + } + #ifdef DEBUG + Serial.print(F(" THRU->MIDI_DIN")); + #endif + } #endif + +#ifdef MIDI_DEVICE_USB_HOST + if(strcmp(MIDI_BY_USB_HOST, midi_device)) { + switch(event) { + case midi::NoteOn: + midi_usb.sendNoteOn(inData1, inData2, inChannel); + break; + case midi::NoteOff: + midi_usb.sendNoteOff(inData1, inData2, inChannel); + break; + case midi::ControlChange: + midi_usb.sendControlChange(inData1, inData2, inChannel); + break; + case midi::AfterTouchChannel: + midi_usb.sendAfterTouch(inData1, inChannel); + break; + case midi::PitchBend: + midi_usb.sendPitchBend(inData1, inChannel); + break; + case midi::ProgramChange: + midi_usb.sendProgramChange(inData1, inChannel); + break; + case midi::AfterTouchPoly: + midi_usb.sendAfterTouch(inData1, inData2, inChannel); + break; + default: + break; + } + #ifdef DEBUG + Serial.print(F(" THRU->MIDI_USB_HOST")); + #endif + } #endif } + #ifdef DEBUG Serial.println(); #endif } -void handleNoteOff_MIDI_DEVICE_DIN(byte inChannel, byte inNumber, byte inVelocity) -{ - handleNoteOff(inChannel, inNumber, inVelocity); +void handleSystemExclusive_generic(byte *data, uint len, const char *midi_device) { + handleSystemExclusive(data, len); #ifdef DEBUG - Serial.print(F("[MIDI_DIN] NoteOff")); + Serial.printf("[%s] SysEx", midi_device); #endif + + // MIDI THRU if (configuration.sys.soft_midi_thru == 1) { -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendNoteOff(inNumber, inVelocity, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif #ifdef MIDI_DEVICE_USB - usbMIDI.sendNoteOff(inNumber, inVelocity, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); + if(strcmp(MIDI_BY_USB, midi_device)) { + usbMIDI.sendSysEx(len, data); + #ifdef DEBUG + Serial.print(F(" THRU->MIDI_USB")); + #endif + } +#endif + +#ifdef MIDI_DEVICE_DIN + if(strcmp(MIDI_BY_DIN, midi_device)) { + midi_serial.sendSysEx(len, data); + #ifdef DEBUG + Serial.print(F(" THRU->MIDI_DIN")); + #endif + } #endif + +#ifdef MIDI_DEVICE_USB_HOST + if(strcmp(MIDI_BY_USB_HOST, midi_device)) { + midi_usb.sendSysEx(len, data); + #ifdef DEBUG + Serial.print(F(" THRU->MIDI_USB_HOST")); + #endif + } #endif } + #ifdef DEBUG Serial.println(); #endif } -void handleControlChange_MIDI_DEVICE_DIN(byte inChannel, byte inData1, byte inData2) +void handleSystemCommon_generic(byte inData1, const char *midi_device, midi::MidiType event) { - handleControlChange(inChannel, inData1, inData2); + char text[10]; + + switch(event) { + case midi::TimeCodeQuarterFrame: + handleTimeCodeQuarterFrame(inData1); + strcpy(text, "TimeCodeQuarterFrame"); + break; + case midi::SongSelect: + handleSongSelect(inData1); + strcpy(text, "SongSelect"); + break; + case midi::TuneRequest: + handleTuneRequest(); + strcpy(text, "TuneRequest"); + break; + default: + break; + } #ifdef DEBUG - Serial.print(F("[MIDI_DIN] CC")); + Serial.printf("[%s] %s", midi_device, text); #endif + + // MIDI THRU if (configuration.sys.soft_midi_thru == 1) { -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendControlChange(inData1, inData2, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif #ifdef MIDI_DEVICE_USB - usbMIDI.sendControlChange(inData1, inData2, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); + if(strcmp(MIDI_BY_USB, midi_device)) { + switch(event) { + case midi::TimeCodeQuarterFrame: + usbMIDI.sendTimeCodeQuarterFrame(0xF1, inData1); + break; + case midi::SongSelect: + usbMIDI.sendSongSelect(inData1); + break; + case midi::TuneRequest: + usbMIDI.sendTuneRequest(); + break; + default: + break; + } + #ifdef DEBUG + Serial.print(F(" THRU->MIDI_USB")); + #endif + } +#endif + +#ifdef MIDI_DEVICE_DIN + if(strcmp(MIDI_BY_DIN, midi_device)) { + switch(event) { + case midi::TimeCodeQuarterFrame: + midi_serial.sendTimeCodeQuarterFrame(inData1); + break; + case midi::SongSelect: + midi_serial.sendSongSelect(inData1); + break; + case midi::TuneRequest: + midi_serial.sendTuneRequest(); + break; + default: + break; + } + #ifdef DEBUG + Serial.print(F(" THRU->MIDI_DIN")); + #endif + } #endif + +#ifdef MIDI_DEVICE_USB_HOST + if(strcmp(MIDI_BY_USB_HOST, midi_device)) { + switch(event) { + case midi::TimeCodeQuarterFrame: + midi_usb.sendTimeCodeQuarterFrame(0xF1, inData1); + break; + case midi::SongSelect: + midi_usb.sendSongSelect(inData1); + break; + case midi::TuneRequest: + midi_usb.sendTuneRequest(); + break; + default: + break; + } + #ifdef DEBUG + Serial.print(F(" THRU->MIDI_USB_HOST")); + #endif + } #endif } + #ifdef DEBUG Serial.println(); #endif } -void handleAfterTouch_MIDI_DEVICE_DIN(byte inChannel, byte inPressure) +void handleRealtime_generic(const char *midi_device, midi::MidiType event) { - handleAfterTouch(inChannel, inPressure); + char text[10]; + + switch(event) { + case midi::Clock: + handleClock(); + strcpy(text, "Clock"); + break; + case midi::Start: + handleStart(); + strcpy(text, "Start"); + break; + case midi::Continue: + handleContinue(); + strcpy(text, "Continue"); + break; + case midi::Stop: + handleStop(); + strcpy(text, "Stop"); + break; + case midi::ActiveSensing: + handleActiveSensing(); + strcpy(text, "ActiveSensing"); + break; + case midi::SystemReset: + handleSystemReset(); + strcpy(text, "SystemReset"); + break; + default: + break; + } #ifdef DEBUG - Serial.print(F("[MIDI_DIN] AT")); + Serial.printf("[%s] %s", midi_device, text); #endif + + // MIDI THRU if (configuration.sys.soft_midi_thru == 1) { -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendAfterTouch(inPressure, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif #ifdef MIDI_DEVICE_USB - usbMIDI.sendAfterTouch(inPressure, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); + if(strcmp(MIDI_BY_USB, midi_device)) { + usbMIDI.sendRealTime(event); + #ifdef DEBUG + Serial.print(F(" THRU->MIDI_USB")); + #endif + } +#endif + +#ifdef MIDI_DEVICE_DIN + if(strcmp(MIDI_BY_DIN, midi_device)) { + midi_serial.sendRealTime(event); + #ifdef DEBUG + Serial.print(F(" THRU->MIDI_DIN")); + #endif + } #endif + +#ifdef MIDI_DEVICE_USB_HOST + if(strcmp(MIDI_BY_USB_HOST, midi_device)) { + midi_usb.sendRealTime(event); + #ifdef DEBUG + Serial.print(F(" THRU->MIDI_USB_HOST")); + #endif + } #endif } + #ifdef DEBUG Serial.println(); #endif } +///* void handleSystemExclusiveChunk_MIDI_DEVICE_DIN(byte *data, uint len, bool last) + +// void handlRealTimeSystem_generic(byte inRealTime, byte midi_device) { +// handleRealTimeSystem(); +// #ifdef DEBUG +// switch(midi_device) { +// case MIDI_DIN: +// Serial.print(F("[MIDI_DIN] RealTimeSystem")); +// break; +// case MIDI_USB_HOST: +// Serial.print(F("[MIDI_USB_HOST] RealTimeSystem")); +// break; +// case USB_MIDI: +// Serial.print(F("[USB_MIDI] RealTimeSystem")); +// break; +// } +// #endif +// if (configuration.sys.soft_midi_thru == 1) +// { +// #ifdef MIDI_DEVICE_USB +// if(midi_device != USB_MIDI) { +// usbMIDI.sendRealTime(inRealTime); +// #ifdef DEBUG +// Serial.print(F(" THRU->MIDI_USB")); +// #endif +// } +// #endif + +// #ifdef MIDI_DEVICE_DIN +// if(midi_device != MIDI_DIN) { +// midi_serial.sendRealTime((midi::MidiType)inRealTime); +// #ifdef DEBUG +// Serial.print(F(" THRU->MIDI_DIN")); +// #endif +// } +// #endif + +// #ifdef MIDI_DEVICE_USB_HOST +// if(midi_device != MIDI_USB_HOST) { +// midi_usb.sendRealTime(inRealTime); +// #ifdef DEBUG +// Serial.print(F(" THRU->MIDI_USB_HOST")); +// #endif +// } +// #endif +// } + +// #ifdef DEBUG +// Serial.println(); +// #endif +// } + + +/***************************************** + MIDI_DEVICE_DIN + *****************************************/ +#ifdef MIDI_DEVICE_DIN + +void handleNoteOn_MIDI_DEVICE_DIN(byte inChannel, byte inNoteNumber, byte inVelocity) +{ + handle_generic(inChannel, inNoteNumber, inVelocity, MIDI_BY_DIN, midi::NoteOn); +} + +void handleNoteOff_MIDI_DEVICE_DIN(byte inChannel, byte inNoteNumber, byte inVelocity) +{ + handle_generic(inChannel, inNoteNumber, inVelocity, MIDI_BY_DIN, midi::NoteOff); +} + +void handleControlChange_MIDI_DEVICE_DIN(byte inChannel, byte inData1, byte inData2) +{ + handle_generic(inChannel, inData1, inData2, MIDI_BY_DIN, midi::ControlChange); +} + +void handleAfterTouch_MIDI_DEVICE_DIN(byte inChannel, byte inPressure) +{ + handle_generic(inChannel, inPressure, '\0', MIDI_BY_DIN, midi::AfterTouchChannel); +} + void handlePitchBend_MIDI_DEVICE_DIN(byte inChannel, int inPitch) { - handlePitchBend(inChannel, inPitch); -#ifdef DEBUG - Serial.print(F("[MIDI_DIN] PB")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendPitchBend(inPitch, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif -#ifdef MIDI_DEVICE_USB - usbMIDI.sendPitchBend(inPitch, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handle_generic(inChannel, inPitch, '\0', MIDI_BY_DIN, midi::PitchBend); } void handleProgramChange_MIDI_DEVICE_DIN(byte inChannel, byte inProgram) { - handleProgramChange(inChannel, inProgram); -#ifdef DEBUG - Serial.print(F("[MIDI_DIN] PC")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendProgramChange(inProgram, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif -#ifdef MIDI_DEVICE_USB - usbMIDI.sendProgramChange(inProgram, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handle_generic(inChannel, inProgram, '\0', MIDI_BY_DIN, midi::ProgramChange); +} + +void handleAfterTouchPoly_MIDI_DEVICE_DIN(byte inChannel, byte inNoteNumber, byte inVelocity) +{ + handle_generic(inChannel, inNoteNumber, inVelocity, MIDI_BY_DIN, midi::AfterTouchPoly); } void handleSystemExclusive_MIDI_DEVICE_DIN(byte * data, uint len) { - handleSystemExclusive(data, len); -#ifdef DEBUG - Serial.print(F("[MIDI_DIN] SysEx")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendSysEx(len, data); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif -#ifdef MIDI_DEVICE_USB - usbMIDI.sendSysEx(len, data); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handleSystemExclusive_generic(data, len, MIDI_BY_DIN); } /* void handleSystemExclusiveChunk_MIDI_DEVICE_DIN(byte *data, uint len, bool last) @@ -280,288 +555,52 @@ void handleSystemExclusive_MIDI_DEVICE_DIN(byte * data, uint len) void handleTimeCodeQuarterFrame_MIDI_DEVICE_DIN(byte data) { - handleTimeCodeQuarterFrame(data); -#ifdef DEBUG - Serial.print(F("[MIDI_DIN] TimeCodeQuarterFrame")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendTimeCodeQuarterFrame(0xF1, data); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif -#ifdef MIDI_DEVICE_USB - usbMIDI.sendTimeCodeQuarterFrame(0xF1, data); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif -} - -void handleAfterTouchPoly_MIDI_DEVICE_DIN(byte inChannel, byte inNumber, byte inVelocity) -{ - handleAfterTouchPoly(inChannel, inNumber, inVelocity); -#ifdef DEBUG - Serial.print(F("[MIDI_DIN] AT-Poly")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendAfterTouch(inNumber, inVelocity, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif -#ifdef MIDI_DEVICE_USB - usbMIDI.sendAfterTouch(inNumber, inVelocity, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handleSystemCommon_generic(data, MIDI_BY_DIN, midi::TimeCodeQuarterFrame); } void handleSongSelect_MIDI_DEVICE_DIN(byte inSong) { - handleSongSelect(inSong); -#ifdef DEBUG - Serial.print(F("[MIDI_DIN] SongSelect")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendSongSelect(inSong); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif -#ifdef MIDI_DEVICE_USB - usbMIDI.sendSongSelect(inSong); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handleSystemCommon_generic(inSong, MIDI_BY_DIN, midi::SongSelect); } void handleTuneRequest_MIDI_DEVICE_DIN(void) { - handleTuneRequest(); -#ifdef DEBUG - Serial.print(F("[MIDI_DIN] TuneRequest")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendTuneRequest(); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif -#ifdef MIDI_DEVICE_USB - usbMIDI.sendTuneRequest(); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handleSystemCommon_generic('\0', MIDI_BY_DIN, midi::TuneRequest); } void handleClock_MIDI_DEVICE_DIN(void) { - handleClock(); -#ifdef DEBUG - Serial.print(F("[MIDI_DIN] Clock")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendRealTime(midi::Clock); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif -#ifdef MIDI_DEVICE_USB - usbMIDI.sendRealTime(midi::Clock); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handleRealtime_generic(MIDI_BY_DIN, midi::Clock); } void handleStart_MIDI_DEVICE_DIN(void) { - handleStart(); -#ifdef DEBUG - Serial.print(F("[MIDI_DIN] Start")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendRealTime(midi::Start); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif -#ifdef MIDI_DEVICE_USB - usbMIDI.sendRealTime(midi::Start); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handleRealtime_generic(MIDI_BY_DIN, midi::Start); } void handleContinue_MIDI_DEVICE_DIN(void) { - handleContinue(); -#ifdef DEBUG - Serial.print(F("[MIDI_DIN] Continue")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendRealTime(midi::Continue); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif -#ifdef MIDI_DEVICE_USB - usbMIDI.sendRealTime(midi::Continue); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handleRealtime_generic(MIDI_BY_DIN, midi::Continue); } void handleStop_MIDI_DEVICE_DIN(void) { - handleStop(); -#ifdef DEBUG - Serial.print(F("[MIDI_DIN] Stop")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendRealTime(midi::Stop); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif -#ifdef MIDI_DEVICE_USB - usbMIDI.sendRealTime(midi::Stop); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handleRealtime_generic(MIDI_BY_DIN, midi::Stop); } void handleActiveSensing_MIDI_DEVICE_DIN(void) { - handleActiveSensing(); -#ifdef DEBUG - Serial.print(F("[MIDI_DIN] ActiveSensing")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendRealTime(midi::ActiveSensing); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif -#ifdef MIDI_DEVICE_USB - usbMIDI.sendRealTime(midi::ActiveSensing); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handleRealtime_generic(MIDI_BY_DIN, midi::ActiveSensing); } void handleSystemReset_MIDI_DEVICE_DIN(void) { - handleSystemReset(); -#ifdef DEBUG - Serial.print(F("[MIDI_DIN] SystemReset")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendRealTime(midi::SystemReset); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif -#ifdef MIDI_DEVICE_USB - usbMIDI.sendRealTime(midi::SystemReset); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handleRealtime_generic(MIDI_BY_DIN, midi::SystemReset); } /* void handlRealTimeSysteme_MIDI_DEVICE_DIN(byte inRealTime) { - handleRealTimeSystem(); - #ifdef DEBUG - Serial.print(F("[MIDI_DIN] RealTimeSystem")); - #endif - if (configuration.sys.soft_midi_thru == 1) - { - #ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendRealTime(inRealTime); - #ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); - #endif - #endif - #ifdef MIDI_DEVICE_USB - //usbMIDI.sendRealTime(inRealTIme); - #ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB[NOTSUPPORTED]")); - #endif - #endif - } - #ifdef DEBUG - Serial.println(); - #endif + handleRealTimeSystem_generic(MIDI_DIN); } */ #endif // MIDI_DEVICE_DIN @@ -569,186 +608,44 @@ void handleSystemReset_MIDI_DEVICE_DIN(void) MIDI_DEVICE_USB_HOST *****************************************/ #ifdef MIDI_DEVICE_USB_HOST -void handleNoteOn_MIDI_DEVICE_USB_HOST(byte inChannel, byte inNumber, byte inVelocity) +void handleNoteOn_MIDI_DEVICE_USB_HOST(byte inChannel, byte inNoteNumber, byte inVelocity) { - handleNoteOn(inChannel, inNumber, inVelocity); -#ifdef DEBUG - Serial.print(F("[MIDI_USB_HOST] NoteOn")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendNoteOn(inNumber, inVelocity, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB - usbMIDI.sendNoteOn(inNumber, inVelocity, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handle_generic(inChannel, inNoteNumber, inVelocity, MIDI_BY_USB_HOST, midi::NoteOn); } -void handleNoteOff_MIDI_DEVICE_USB_HOST(byte inChannel, byte inNumber, byte inVelocity) +void handleNoteOff_MIDI_DEVICE_USB_HOST(byte inChannel, byte inNoteNumber, byte inVelocity) { - handleNoteOff(inChannel, inNumber, inVelocity); -#ifdef DEBUG - Serial.print(F("[MIDI_USB_HOST] NoteOff")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendNoteOff(inNumber, inVelocity, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB - usbMIDI.sendNoteOff(inNumber, inVelocity, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handle_generic(inChannel, inNoteNumber, inVelocity, MIDI_BY_USB_HOST, midi::NoteOff); } void handleControlChange_MIDI_DEVICE_USB_HOST(byte inChannel, byte inData1, byte inData2) { - handleControlChange(inChannel, inData1, inData2); -#ifdef DEBUG - Serial.print(F("[MIDI_USB_HOST] CC")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendControlChange(inData1, inData2, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB - usbMIDI.sendControlChange(inData1, inData2, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handle_generic(inChannel, inData1, inData2, MIDI_BY_USB_HOST, midi::ControlChange); } void handleAfterTouch_MIDI_DEVICE_USB_HOST(byte inChannel, byte inPressure) { - handleAfterTouch(inChannel, inPressure); -#ifdef DEBUG - Serial.print(F("[MIDI_USB_HOST] AT")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendAfterTouch(inPressure, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB - usbMIDI.sendAfterTouch(inPressure, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handle_generic(inChannel, inPressure, '\0', MIDI_BY_USB_HOST, midi::AfterTouchChannel); } void handlePitchBend_MIDI_DEVICE_USB_HOST(byte inChannel, int inPitch) { - handlePitchBend(inChannel, inPitch); -#ifdef DEBUG - Serial.print(F("[MIDI_USB_HOST] PB")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendPitchBend(inPitch, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB - usbMIDI.sendPitchBend(inPitch, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handle_generic(inChannel, inPitch, '\0', MIDI_BY_USB_HOST, midi::PitchBend); } -void handleProgramChange_MIDI_DEVICE_USB_HOST(byte inChannel, byte inProgram) +void handleProgramChange_MIDI_DEVICE_USB_HOST(byte inChannel, byte inPitch) { - handleProgramChange(inChannel, inProgram); -#ifdef DEBUG - Serial.print(F("[MIDI_USB_HOST] PC")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendProgramChange(inProgram, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB - usbMIDI.sendProgramChange(inProgram, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handle_generic(inChannel, inPitch, '\0', MIDI_BY_USB_HOST, midi::ProgramChange); +} + +void handleAfterTouchPoly_MIDI_DEVICE_USB_HOST(byte inChannel, byte inNoteNumber, byte inVelocity) +{ + handle_generic(inChannel, inNoteNumber, inVelocity, MIDI_BY_USB_HOST, midi::AfterTouchPoly); } void handleSystemExclusive_MIDI_DEVICE_USB_HOST(byte * data, uint len) { - handleSystemExclusive(data, len); -#ifdef DEBUG - Serial.print(F("[MIDI_USB_HOST] SysEx")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendSysEx(len, data); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB - usbMIDI.sendSysEx(len, data); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handleSystemExclusive_generic(data, len, MIDI_BY_USB_HOST); } /* void handleSystemExclusiveChunk_MIDI_DEVICE_USB_HOST(byte *data, uint len, bool last) @@ -779,288 +676,52 @@ void handleSystemExclusive_MIDI_DEVICE_USB_HOST(byte * data, uint len) void handleTimeCodeQuarterFrame_MIDI_DEVICE_USB_HOST(midi::DataByte data) { - handleTimeCodeQuarterFrame(data); -#ifdef DEBUG - Serial.print(F("[MIDI_USB_HOST] TimeCodeQuarterFrame")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendTimeCodeQuarterFrame(data); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB - usbMIDI.sendTimeCodeQuarterFrame(0xF1, data); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif -} - -void handleAfterTouchPoly_MIDI_DEVICE_USB_HOST(byte inChannel, byte inNumber, byte inVelocity) -{ - handleAfterTouchPoly(inChannel, inNumber, inVelocity); -#ifdef DEBUG - Serial.print(F("[MIDI_USB_HOST] AT-Poly")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendAfterTouch(inNumber, inVelocity, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB - usbMIDI.sendAfterTouch(inNumber, inVelocity, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handleSystemCommon_generic(data, MIDI_BY_USB_HOST, midi::TimeCodeQuarterFrame); } void handleSongSelect_MIDI_DEVICE_USB_HOST(byte inSong) { - handleSongSelect(inSong); -#ifdef DEBUG - Serial.print(F("[MIDI_USB_HOST] SongSelect")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendSongSelect(inSong); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB - usbMIDI.sendSongSelect(inSong); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handleSystemCommon_generic(inSong, MIDI_BY_USB_HOST, midi::SongSelect); } void handleTuneRequest_MIDI_DEVICE_USB_HOST(void) { - handleTuneRequest(); -#ifdef DEBUG - Serial.print(F("[MIDI_USB_HOST] TuneRequest")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendTuneRequest(); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB - usbMIDI.sendTuneRequest(); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handleSystemCommon_generic('\0', MIDI_BY_USB_HOST, midi::TuneRequest); } void handleClock_MIDI_DEVICE_USB_HOST(void) { - handleClock(); -#ifdef DEBUG - Serial.print(F("[MIDI_USB_HOST] Clock")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendRealTime(midi::Clock); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB - usbMIDI.sendRealTime(midi::Clock); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handleRealtime_generic(MIDI_BY_USB_HOST, midi::Clock); } void handleStart_MIDI_DEVICE_USB_HOST(void) { - handleStart(); -#ifdef DEBUG - Serial.print(F("[MIDI_USB_HOST] Start")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendRealTime(midi::Start); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB - usbMIDI.sendRealTime(midi::Start); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handleRealtime_generic(MIDI_BY_USB_HOST, midi::Start); } void handleContinue_MIDI_DEVICE_USB_HOST(void) { - handleContinue(); -#ifdef DEBUG - Serial.print(F("[MIDI_USB_HOST] Continue")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendRealTime(midi::Continue); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB - usbMIDI.sendRealTime(midi::Continue); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handleRealtime_generic(MIDI_BY_USB_HOST, midi::Continue); } void handleStop_MIDI_DEVICE_USB_HOST(void) { - handleStop(); -#ifdef DEBUG - Serial.print(F("[MIDI_USB_HOST] Stop")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendRealTime(midi::Stop); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB - usbMIDI.sendRealTime(midi::Stop); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handleRealtime_generic(MIDI_BY_USB_HOST, midi::Stop); } void handleActiveSensing_MIDI_DEVICE_USB_HOST(void) { - handleActiveSensing(); -#ifdef DEBUG - Serial.print(F("[MIDI_USB_HOST] ActiveSensing")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendRealTime(midi::ActiveSensing); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB - usbMIDI.sendRealTime(midi::ActiveSensing); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handleRealtime_generic(MIDI_BY_USB_HOST, midi::ActiveSensing); } void handleSystemReset_MIDI_DEVICE_USB_HOST(void) { - handleSystemReset(); -#ifdef DEBUG - Serial.print(F("[MIDI_USB_HOST] SystemReset")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendRealTime(midi::SystemReset); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB - usbMIDI.sendRealTime(midi::SystemReset); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handleRealtime_generic(MIDI_BY_USB_HOST, midi::SystemReset); } -/* void handlRealTimeSysteme_MIDI_DEVICE_USB_HOST(midi::MidiType inRealTime) +/* void handlRealTimeSystem_MIDI_DEVICE_USB_HOST(midi::MidiType inRealTime) { - handleRealTimeSystem(); - #ifdef DEBUG - Serial.print(F("[MIDI_USB_HOST] RealTimeSystem")); - #endif - if (configuration.sys.soft_midi_thru == 1) - { - #ifdef MIDI_DEVICE_DIN - midi_serial.sendRealTime(inRealTime); - #ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); - #endif - #endif - #ifdef MIDI_DEVICE_USB - usbMIDI.sendRealTime(inRealTime); - #ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); - #endif - #endif - } - #ifdef DEBUG - Serial.println(); - #endif + handleRealTimeSystem_generic(inRealTime, MIDI_USB_HOST); } */ #endif // MIDI_DEVICE_USB_HOST @@ -1068,189 +729,47 @@ void handleSystemReset_MIDI_DEVICE_USB_HOST(void) MIDI_DEVICE_USB *****************************************/ #ifdef MIDI_DEVICE_USB -void handleNoteOn_MIDI_DEVICE_USB(byte inChannel, byte inNumber, byte inVelocity) +void handleNoteOn_MIDI_DEVICE_USB(byte inChannel, byte inNoteNumber, byte inVelocity) { - handleNoteOn(inChannel, inNumber, inVelocity); -#ifdef DEBUG - Serial.print(F("[MIDI_USB] NoteOn")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendNoteOn(inNumber, inVelocity, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendNoteOn(inNumber, inVelocity, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handle_generic(inChannel, inNoteNumber, inVelocity, MIDI_BY_USB, midi::NoteOn); } -void handleNoteOff_MIDI_DEVICE_USB(byte inChannel, byte inNumber, byte inVelocity) +void handleNoteOff_MIDI_DEVICE_USB(byte inChannel, byte inNoteNumber, byte inVelocity) { - handleNoteOff(inChannel, inNumber, inVelocity); -#ifdef DEBUG - Serial.print(F("[MIDI_USB] NoteOff")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendNoteOff(inNumber, inVelocity, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendNoteOff(inNumber, inVelocity, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handle_generic(inChannel, inNoteNumber, inVelocity, MIDI_BY_USB, midi::NoteOff); } void handleControlChange_MIDI_DEVICE_USB(byte inChannel, byte inData1, byte inData2) -{ - handleControlChange(inChannel, inData1, inData2); -#ifdef DEBUG - Serial.print(F("[MIDI_USB] CC")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendControlChange(inData1, inData2, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendControlChange(inData1, inData2, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif +{ + handle_generic(inChannel, inData1, inData2, MIDI_BY_USB, midi::ControlChange); } void handleAfterTouch_MIDI_DEVICE_USB(byte inChannel, byte inPressure) { - handleAfterTouch(inChannel, inPressure); -#ifdef DEBUG - Serial.print(F("[MIDI_USB] AT")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendAfterTouch(inPressure, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendAfterTouch(inPressure, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handle_generic(inChannel, inPressure, '\0', MIDI_BY_USB, midi::AfterTouchChannel); } void handlePitchBend_MIDI_DEVICE_USB(byte inChannel, int inPitch) { - handlePitchBend(inChannel, inPitch); -#ifdef DEBUG - Serial.print(F("[MIDI_USB] PB")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendPitchBend(inPitch, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendPitchBend(inPitch, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handle_generic(inChannel, inPitch, '\0', MIDI_BY_USB, midi::PitchBend); } void handleProgramChange_MIDI_DEVICE_USB(byte inChannel, byte inProgram) { - handleProgramChange(inChannel, inProgram); -#ifdef DEBUG - Serial.print(F("[MIDI_USB] PC")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendProgramChange(inProgram, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendProgramChange(inProgram, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handle_generic(inChannel, inProgram, '\0', MIDI_BY_USB, midi::ProgramChange); +} + +void handleAfterTouchPoly_MIDI_DEVICE_USB(byte inChannel, byte inNoteNumber, byte inVelocity) +{ + handle_generic(inChannel, inNoteNumber, inVelocity, MIDI_BY_USB, midi::AfterTouchPoly); } void handleSystemExclusive_MIDI_DEVICE_USB(byte * data, uint len) { - handleSystemExclusive(data, len); -#ifdef DEBUG - Serial.print(F("[MIDI_USB] SysEx")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendSysEx(len, data); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendSysEx(len, data); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handleSystemExclusive_generic(data, len, MIDI_BY_USB); } -/* void handleSystemExclusiveChunk_MIDI_DEVICE_USB(byte *data, uint len, bool last) +/* FLASHMEM void handleSystemExclusiveChunk_MIDI_DEVICE_USB(byte *data, uint len, bool last) { handleSystemExclusiveChunk(data, len, last); #ifdef DEBUG @@ -1278,290 +797,56 @@ void handleSystemExclusive_MIDI_DEVICE_USB(byte * data, uint len) void handleTimeCodeQuarterFrame_MIDI_DEVICE_USB(midi::DataByte data) { - handleTimeCodeQuarterFrame(data); -#ifdef DEBUG - Serial.print(F("[MIDI_USB] TimeCodeQuarterFrame")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendTimeCodeQuarterFrame(data); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendTimeCodeQuarterFrame(0xF1, data); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif -} - -void handleAfterTouchPoly_MIDI_DEVICE_USB(byte inChannel, byte inNumber, byte inVelocity) -{ - handleAfterTouchPoly(inChannel, inNumber, inVelocity); -#ifdef DEBUG - Serial.print(F("[MIDI_USB] AT-Poly")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendAfterTouch(inNumber, inVelocity, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendAfterTouch(inNumber, inVelocity, inChannel); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handleSystemCommon_generic(data, MIDI_BY_USB, midi::TimeCodeQuarterFrame); } void handleSongSelect_MIDI_DEVICE_USB(byte inSong) { - handleSongSelect(inSong); -#ifdef DEBUG - Serial.print(F("[MIDI_USB] SongSelect")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendSongSelect(inSong); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendSongSelect(inSong); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handleSystemCommon_generic(inSong, MIDI_BY_USB, midi::SongSelect); } void handleTuneRequest_MIDI_DEVICE_USB(void) { - handleTuneRequest(); -#ifdef DEBUG - Serial.print(F("[MIDI_USB] TuneRequest")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendTuneRequest(); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendTuneRequest(); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handleSystemCommon_generic('\0', MIDI_BY_USB, midi::TuneRequest); } void handleClock_MIDI_DEVICE_USB(void) { - handleClock(); -#ifdef DEBUG - Serial.print(F("[MIDI_USB] Clock")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendRealTime(midi::Clock); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendRealTime(midi::Clock); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handleRealtime_generic(MIDI_BY_USB, midi::Clock); } void handleStart_MIDI_DEVICE_USB(void) { - handleStart(); -#ifdef DEBUG - Serial.print(F("[MIDI_USB] Start")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendRealTime(midi::Start); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendRealTime(midi::Start); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handleRealtime_generic(MIDI_BY_USB, midi::Start); } void handleContinue_MIDI_DEVICE_USB(void) { - handleContinue(); -#ifdef DEBUG - Serial.print(F("[MIDI_USB] Continue")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendRealTime(midi::Continue); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendRealTime(midi::Continue); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handleRealtime_generic(MIDI_BY_USB, midi::Continue); } void handleStop_MIDI_DEVICE_USB(void) { - handleStop(); -#ifdef DEBUG - Serial.print(F("[MIDI_USB] Stop")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendRealTime(midi::Stop); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendRealTime(midi::Stop); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handleRealtime_generic(MIDI_BY_USB, midi::Stop); } void handleActiveSensing_MIDI_DEVICE_USB(void) { - handleActiveSensing(); -#ifdef DEBUG - Serial.print(F("[MIDI_USB] ActiveSensing")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendRealTime(midi::ActiveSensing); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendRealTime(midi::ActiveSensing); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handleRealtime_generic(MIDI_BY_USB, midi::ActiveSensing); } void handleSystemReset_MIDI_DEVICE_USB(void) { - handleSystemReset(); -#ifdef DEBUG - Serial.print(F("[MIDI_USB] SystemReset")); -#endif - if (configuration.sys.soft_midi_thru == 1) - { -#ifdef MIDI_DEVICE_DIN - midi_serial.sendRealTime(midi::SystemReset); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); -#endif -#endif -#ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendRealTime(midi::SystemReset); -#ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); -#endif -#endif - } -#ifdef DEBUG - Serial.println(); -#endif + handleRealtime_generic(MIDI_BY_USB, midi::SystemReset); } -/* void handleRealTimeSystem_MIDI_DEVICE_USB(byte inRealTime) +/* FLASHMEM void handleRealTimeSystem_MIDI_DEVICE_USB(byte inRealTime) { - handleRealTimeSystem(); - #ifdef DEBUG - Serial.print(F("[MIDI_USB] RealTimeSystem")); - #endif - #ifdef MIDI_DEVICE_DIN - midi_serial.sendRealTime((midi::MidiType)inRealTime); - #ifdef DEBUG - Serial.print(F(" THRU->MIDI_DIN")); - #endif - #endif - #ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendRealTime(inRealTime); - #ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); - #endif - #endif - } - #ifdef DEBUG - Serial.println(); - #endif + handleRealTimeSystem_generic(inRealTime, USB_MIDI); } */ #endif // MIDI_DEVICE_USB -void MD_sendControlChange(uint8_t channel, uint8_t cc, uint8_t value) +FLASHMEM void MD_sendControlChange(uint8_t channel, uint8_t cc, uint8_t value) { #ifdef DEBUG Serial.print(F("[MD] SendControlChange CH:")); @@ -1595,9 +880,9 @@ void MD_sendControlChange(uint8_t channel, uint8_t cc, uint8_t value) } /***************************************** - HELPER FUCNTIONS + HELPER FUNCTIONS *****************************************/ -void setup_midi_devices(void) +FLASHMEM void setup_midi_devices(void) { #ifdef MIDI_DEVICE_DIN // Start serial MIDI @@ -1681,7 +966,7 @@ void setup_midi_devices(void) #endif } -void check_midi_devices(void) +FLASHMEM void check_midi_devices(void) { #ifdef MIDI_DEVICE_DIN midi_serial.read(); @@ -1695,7 +980,7 @@ void check_midi_devices(void) #endif } -void send_sysex_voice(uint8_t midi_channel, uint8_t* data) +FLASHMEM void send_sysex_voice(uint8_t midi_channel, uint8_t* data) { uint8_t checksum = 0; uint8_t vd[161]; @@ -1715,25 +1000,36 @@ void send_sysex_voice(uint8_t midi_channel, uint8_t* data) vd[160] = checksum & 0x7f; // Checksum //vd[162] = 0xF7; // SysEx end +#ifdef MIDI_DEVICE_DIN midi_serial.sendSysEx(161, vd); // Send to DIN MIDI - midi_usb.sendSysEx(161, vd); // Send to USB MIDI - usbMIDI.sendSysEx(161, vd); // Send to USB-HOST MIDI +#endif +#ifdef MIDI_DEVICE_USB + usbMIDI.sendSysEx(161, vd); // Send to USB MIDI +#endif +#ifdef MIDI_DEVICE_USB_HOST + midi_usb.sendSysEx(161, vd); // Send to USB-HOST MIDI +#endif } -void send_sysex_bank(uint8_t midi_channel, uint8_t* bank_data) +FLASHMEM void send_sysex_bank(uint8_t midi_channel, uint8_t* bank_data) { #ifdef MIDI_DEVICE_DIN midi_serial.sendSysEx(4104, bank_data); // Send to DIN MIDI #endif #ifdef MIDI_DEVICE_USB - midi_usb.sendSysEx(4104, bank_data); // Send to USB MIDI + // Sysex bank dump is splitted due to Windows USB driver limitations + usbMIDI.sendSysEx(2048, bank_data, true); // Send to USB MIDI + delay(50); + usbMIDI.sendSysEx(2048, bank_data+2048, true); + delay(50); + usbMIDI.sendSysEx(8, bank_data+4096, true); #endif #ifdef MIDI_DEVICE_USB_HOST - usbMIDI.sendSysEx(4104, bank_data); // Send to USB-HOST MIDI + midi_usb.sendSysEx(4104, bank_data); // Send to USB-HOST MIDI #endif } -void send_sysex_param(uint8_t midi_channel, uint8_t var, uint8_t val, uint8_t param_group) +FLASHMEM void send_sysex_param(uint8_t midi_channel, uint8_t var, uint8_t val, uint8_t param_group) { uint8_t s[5]; @@ -1755,9 +1051,11 @@ void send_sysex_param(uint8_t midi_channel, uint8_t var, uint8_t val, uint8_t pa midi_serial.sendSysEx(5, s); // Send to DIN MIDI #endif #ifdef MIDI_DEVICE_USB - midi_usb.sendSysEx(5, s); // Send to USB MIDI + usbMIDI.sendSysEx(5, s); // Send to USB MIDI #endif #ifdef MIDI_DEVICE_USB_HOST - usbMIDI.sendSysEx(5, s); // Send to USB-HOST MIDI + midi_usb.sendSysEx(5, s); // Send to USB-HOST MIDI #endif -} \ No newline at end of file +} + +#endif // MIDI_DEVICES_H