From 3cacbe6460a2749004f6f3bcc70ae7e265a23747 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Tue, 19 Jul 2022 12:43:48 +0200 Subject: [PATCH] Last fixes. Now the seqeuncer should be removed. --- midi_devices.hpp | 1756 +++++++++++++++++++++++++++++++++------------- 1 file changed, 1279 insertions(+), 477 deletions(-) diff --git a/midi_devices.hpp b/midi_devices.hpp index 12ac916..962d95b 100644 --- a/midi_devices.hpp +++ b/midi_devices.hpp @@ -1,12 +1,10 @@ /* MicroDexed - MicroDexed is a port of the Dexed sound engine - (https://github.com/asb2m10/dexed) for the Teensy-3.5/3.6/4.x with audio shield. - Dexed ist heavily based on https://github.com/google/music-synthesizer-for-android + MicroMDAEPiano is a port of the MDA-EPiano sound engine + (https://sourceforge.net/projects/mda-vst/) for the Teensy-3.5/3.6/4.x with audio shield. - (c)2018-2022 H. Wirtz - (c)2021-2022 H. Wirtz , M. Koslowski + (c)2019-2021 H. Wirtz This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,21 +19,25 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ #ifndef MIDI_DEVICES_H #define MIDI_DEVICES_H + #include "config.h" + extern config_t configuration; + #ifdef MIDI_DEVICE_USB_HOST #include #endif + // override default sysex size settings struct MicroDexedSettings : public midi::DefaultSettings { static const unsigned SysExMaxSize = 4104; // Accept SysEx messages up to 1024 bytes long. }; + #ifdef MIDI_DEVICE_DIN MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, MIDI_DEVICE_DIN, midi_serial, MicroDexedSettings); #endif @@ -43,22 +45,17 @@ MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, MIDI_DEVICE_DIN, midi_serial, MicroD USBHost usb_host; MIDIDevice midi_usb(usb_host); #endif -/* #ifdef MIDI_DEVICE_USB - static const unsigned sUsbTransportBufferSize = 16; - typedef midi::UsbTransport UsbTransport; - UsbTransport sUsbTransport; - MIDI_CREATE_INSTANCE(UsbTransport, sUsbTransport, midi_onboard_usb); - #endif */ -void handleNoteOn(byte inChannel, byte inNumber, byte inVelocity, byte device); -void handleNoteOff(byte inChannel, byte inNumber, byte inVelocity, byte device); + +void handleNoteOn(byte inChannel, byte inNumber, byte inVelocity); +void handleNoteOff(byte inChannel, byte inNumber, byte inVelocity); 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); @@ -69,427 +66,193 @@ void handleActiveSensing(void); void handleSystemReset(void); //void handleRealTimeSystem(void); void MD_sendControlChange(uint8_t channel, uint8_t cc, uint8_t value); -#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) -{ - char text[10]; - switch(event) { - case midi::NoteOn: - handleNoteOn(inChannel, inData1, inData2, 0); - strcpy(text, "NoteOn"); - break; - case midi::NoteOff: - handleNoteOff(inChannel, inData1, inData2, 0); - 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 - 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; - } + +/***************************************** + MIDI_DEVICE_DIN + *****************************************/ +#ifdef MIDI_DEVICE_DIN +void handleNoteOn_MIDI_DEVICE_DIN(byte inChannel, byte inNumber, byte inVelocity) +{ + handleNoteOn(inChannel, inNumber, inVelocity); #ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB_HOST")); - #endif - } + Serial.print(F("[MIDI_DIN] NoteOn")); +#endif + 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")); +#endif #endif } #ifdef DEBUG Serial.println(); #endif } -void handleSystemExclusive_generic(byte *data, uint len, const char *midi_device) { - handleSystemExclusive(data, len); + +void handleNoteOff_MIDI_DEVICE_DIN(byte inChannel, byte inNumber, byte inVelocity) +{ + handleNoteOff(inChannel, inNumber, inVelocity); #ifdef DEBUG - Serial.printf("[%s] SysEx", midi_device); + Serial.print(F("[MIDI_DIN] NoteOff")); #endif - // MIDI THRU if (configuration.sys.soft_midi_thru == 1) { -#ifdef MIDI_DEVICE_USB - if(strcmp(MIDI_BY_USB, midi_device)) { - usbMIDI.sendSysEx(len, data); - #ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); - #endif - } +#ifdef MIDI_DEVICE_USB_HOST + midi_usb.sendNoteOff(inNumber, inVelocity, inChannel); +#ifdef DEBUG + Serial.print(F(" THRU->MIDI_USB_HOST")); #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 - } +#ifdef MIDI_DEVICE_USB + usbMIDI.sendNoteOff(inNumber, inVelocity, inChannel); +#ifdef DEBUG + Serial.print(F(" THRU->MIDI_USB")); +#endif #endif } #ifdef DEBUG Serial.println(); #endif } -void handleSystemCommon_generic(byte inData1, const char *midi_device, midi::MidiType event) + +void handleControlChange_MIDI_DEVICE_DIN(byte inChannel, byte inData1, byte 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; - } + handleControlChange(inChannel, inData1, inData2); #ifdef DEBUG - Serial.printf("[%s] %s", midi_device, text); + Serial.print(F("[MIDI_DIN] CC")); #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 - 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 - } + usbMIDI.sendControlChange(inData1, inData2, inChannel); +#ifdef DEBUG + Serial.print(F(" THRU->MIDI_USB")); +#endif #endif } #ifdef DEBUG Serial.println(); #endif } -void handleRealtime_generic(const char *midi_device, midi::MidiType event) + +void handleAfterTouch_MIDI_DEVICE_DIN(byte inChannel, byte 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; - } + handleAfterTouch(inChannel, inPressure); #ifdef DEBUG - Serial.printf("[%s] %s", midi_device, text); + Serial.print(F("[MIDI_DIN] AT")); #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 - if(strcmp(MIDI_BY_USB, midi_device)) { - usbMIDI.sendRealTime(event); - #ifdef DEBUG - Serial.print(F(" THRU->MIDI_USB")); - #endif - } + usbMIDI.sendAfterTouch(inPressure, inChannel); +#ifdef DEBUG + Serial.print(F(" THRU->MIDI_USB")); #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); + } +#ifdef DEBUG + Serial.println(); +#endif } + void handlePitchBend_MIDI_DEVICE_DIN(byte inChannel, int inPitch) { - handle_generic(inChannel, inPitch, '\0', MIDI_BY_DIN, midi::PitchBend); + 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 } + void handleProgramChange_MIDI_DEVICE_DIN(byte inChannel, byte inProgram) { - 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); + 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 } + void handleSystemExclusive_MIDI_DEVICE_DIN(byte * data, uint len) { - handleSystemExclusive_generic(data, len, MIDI_BY_DIN); + 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 } + /* void handleSystemExclusiveChunk_MIDI_DEVICE_DIN(byte *data, uint len, bool last) { handleSystemExclusiveChunk(data, len, last); @@ -515,83 +278,480 @@ void handleSystemExclusive_MIDI_DEVICE_DIN(byte * data, uint len) Serial.println(); #endif } */ + void handleTimeCodeQuarterFrame_MIDI_DEVICE_DIN(byte data) { - handleSystemCommon_generic(data, MIDI_BY_DIN, midi::TimeCodeQuarterFrame); + 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 } + void handleSongSelect_MIDI_DEVICE_DIN(byte inSong) { - handleSystemCommon_generic(inSong, MIDI_BY_DIN, midi::SongSelect); + 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 } + void handleTuneRequest_MIDI_DEVICE_DIN(void) { - handleSystemCommon_generic('\0', MIDI_BY_DIN, midi::TuneRequest); + 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 } + void handleClock_MIDI_DEVICE_DIN(void) { - handleRealtime_generic(MIDI_BY_DIN, midi::Clock); + 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 } + void handleStart_MIDI_DEVICE_DIN(void) { - handleRealtime_generic(MIDI_BY_DIN, midi::Start); + 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 } + void handleContinue_MIDI_DEVICE_DIN(void) { - handleRealtime_generic(MIDI_BY_DIN, midi::Continue); -} -void handleStop_MIDI_DEVICE_DIN(void) -{ - handleRealtime_generic(MIDI_BY_DIN, midi::Stop); -} -void handleActiveSensing_MIDI_DEVICE_DIN(void) -{ - handleRealtime_generic(MIDI_BY_DIN, midi::ActiveSensing); + 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 +} + +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 +} + +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 } + void handleSystemReset_MIDI_DEVICE_DIN(void) { - handleRealtime_generic(MIDI_BY_DIN, midi::SystemReset); + 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 } + /* void handlRealTimeSysteme_MIDI_DEVICE_DIN(byte inRealTime) { - handleRealTimeSystem_generic(MIDI_DIN); + 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 } */ #endif // MIDI_DEVICE_DIN + /***************************************** MIDI_DEVICE_USB_HOST *****************************************/ #ifdef MIDI_DEVICE_USB_HOST -void handleNoteOn_MIDI_DEVICE_USB_HOST(byte inChannel, byte inNoteNumber, byte inVelocity) +void handleNoteOn_MIDI_DEVICE_USB_HOST(byte inChannel, byte inNumber, byte inVelocity) { - handle_generic(inChannel, inNoteNumber, inVelocity, MIDI_BY_USB_HOST, midi::NoteOn); + 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 } -void handleNoteOff_MIDI_DEVICE_USB_HOST(byte inChannel, byte inNoteNumber, byte inVelocity) + +void handleNoteOff_MIDI_DEVICE_USB_HOST(byte inChannel, byte inNumber, byte inVelocity) { - handle_generic(inChannel, inNoteNumber, inVelocity, MIDI_BY_USB_HOST, midi::NoteOff); + 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 } + void handleControlChange_MIDI_DEVICE_USB_HOST(byte inChannel, byte inData1, byte inData2) { - handle_generic(inChannel, inData1, inData2, MIDI_BY_USB_HOST, midi::ControlChange); + 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 } + void handleAfterTouch_MIDI_DEVICE_USB_HOST(byte inChannel, byte inPressure) { - handle_generic(inChannel, inPressure, '\0', MIDI_BY_USB_HOST, midi::AfterTouchChannel); + 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 } + void handlePitchBend_MIDI_DEVICE_USB_HOST(byte inChannel, int inPitch) { - handle_generic(inChannel, inPitch, '\0', MIDI_BY_USB_HOST, midi::PitchBend); -} -void handleProgramChange_MIDI_DEVICE_USB_HOST(byte inChannel, byte inPitch) -{ - handle_generic(inChannel, inPitch, '\0', MIDI_BY_USB_HOST, midi::ProgramChange); + 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 } -void handleAfterTouchPoly_MIDI_DEVICE_USB_HOST(byte inChannel, byte inNoteNumber, byte inVelocity) + +void handleProgramChange_MIDI_DEVICE_USB_HOST(byte inChannel, byte inProgram) { - handle_generic(inChannel, inNoteNumber, inVelocity, MIDI_BY_USB_HOST, midi::AfterTouchPoly); + 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 } + void handleSystemExclusive_MIDI_DEVICE_USB_HOST(byte * data, uint len) { - handleSystemExclusive_generic(data, len, MIDI_BY_USB_HOST); + 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 } + /* void handleSystemExclusiveChunk_MIDI_DEVICE_USB_HOST(byte *data, uint len, bool last) { handleSystemExclusiveChunk(data, len, last); @@ -617,84 +777,481 @@ void handleSystemExclusive_MIDI_DEVICE_USB_HOST(byte * data, uint len) Serial.println(); #endif } */ + void handleTimeCodeQuarterFrame_MIDI_DEVICE_USB_HOST(midi::DataByte data) { - handleSystemCommon_generic(data, MIDI_BY_USB_HOST, midi::TimeCodeQuarterFrame); + 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 +} + void handleSongSelect_MIDI_DEVICE_USB_HOST(byte inSong) { - handleSystemCommon_generic(inSong, MIDI_BY_USB_HOST, midi::SongSelect); + 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 } + void handleTuneRequest_MIDI_DEVICE_USB_HOST(void) { - handleSystemCommon_generic('\0', MIDI_BY_USB_HOST, midi::TuneRequest); + 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 } + void handleClock_MIDI_DEVICE_USB_HOST(void) { - handleRealtime_generic(MIDI_BY_USB_HOST, midi::Clock); + 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 } + void handleStart_MIDI_DEVICE_USB_HOST(void) { - handleRealtime_generic(MIDI_BY_USB_HOST, midi::Start); + 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 } + void handleContinue_MIDI_DEVICE_USB_HOST(void) { - handleRealtime_generic(MIDI_BY_USB_HOST, midi::Continue); + 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 } + void handleStop_MIDI_DEVICE_USB_HOST(void) { - handleRealtime_generic(MIDI_BY_USB_HOST, midi::Stop); + 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 } + void handleActiveSensing_MIDI_DEVICE_USB_HOST(void) { - handleRealtime_generic(MIDI_BY_USB_HOST, midi::ActiveSensing); + 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 } + void handleSystemReset_MIDI_DEVICE_USB_HOST(void) { - handleRealtime_generic(MIDI_BY_USB_HOST, midi::SystemReset); + 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 } -/* void handlRealTimeSystem_MIDI_DEVICE_USB_HOST(midi::MidiType inRealTime) + +/* void handlRealTimeSysteme_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) { - handleRealTimeSystem_generic(inRealTime, MIDI_USB_HOST); + #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 } */ #endif // MIDI_DEVICE_USB_HOST + /***************************************** MIDI_DEVICE_USB *****************************************/ #ifdef MIDI_DEVICE_USB -void handleNoteOn_MIDI_DEVICE_USB(byte inChannel, byte inNoteNumber, byte inVelocity) +void handleNoteOn_MIDI_DEVICE_USB(byte inChannel, byte inNumber, byte inVelocity) { - handle_generic(inChannel, inNoteNumber, inVelocity, MIDI_BY_USB, midi::NoteOn); + 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 } -void handleNoteOff_MIDI_DEVICE_USB(byte inChannel, byte inNoteNumber, byte inVelocity) + +void handleNoteOff_MIDI_DEVICE_USB(byte inChannel, byte inNumber, byte inVelocity) { - handle_generic(inChannel, inNoteNumber, inVelocity, MIDI_BY_USB, midi::NoteOff); + 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 } + void handleControlChange_MIDI_DEVICE_USB(byte inChannel, byte inData1, byte inData2) { - handle_generic(inChannel, inData1, inData2, MIDI_BY_USB, midi::ControlChange); + 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 } + void handleAfterTouch_MIDI_DEVICE_USB(byte inChannel, byte inPressure) { - handle_generic(inChannel, inPressure, '\0', MIDI_BY_USB, midi::AfterTouchChannel); + 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 } + void handlePitchBend_MIDI_DEVICE_USB(byte inChannel, int inPitch) { - handle_generic(inChannel, inPitch, '\0', MIDI_BY_USB, midi::PitchBend); + 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 } + void handleProgramChange_MIDI_DEVICE_USB(byte inChannel, byte inProgram) { - 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); + 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 } + void handleSystemExclusive_MIDI_DEVICE_USB(byte * data, uint len) { - handleSystemExclusive_generic(data, len, MIDI_BY_USB); + 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 } -/* FLASHMEM void handleSystemExclusiveChunk_MIDI_DEVICE_USB(byte *data, uint len, bool last) + +/* void handleSystemExclusiveChunk_MIDI_DEVICE_USB(byte *data, uint len, bool last) { handleSystemExclusiveChunk(data, len, last); #ifdef DEBUG @@ -719,48 +1276,293 @@ void handleSystemExclusive_MIDI_DEVICE_USB(byte * data, uint len) Serial.println(); #endif } */ + void handleTimeCodeQuarterFrame_MIDI_DEVICE_USB(midi::DataByte data) { - handleSystemCommon_generic(data, MIDI_BY_USB, midi::TimeCodeQuarterFrame); + 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 } + void handleSongSelect_MIDI_DEVICE_USB(byte inSong) { - handleSystemCommon_generic(inSong, MIDI_BY_USB, midi::SongSelect); + 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 } + void handleTuneRequest_MIDI_DEVICE_USB(void) { - handleSystemCommon_generic('\0', MIDI_BY_USB, midi::TuneRequest); + 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 } + void handleClock_MIDI_DEVICE_USB(void) { - handleRealtime_generic(MIDI_BY_USB, midi::Clock); + 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 } + void handleStart_MIDI_DEVICE_USB(void) { - handleRealtime_generic(MIDI_BY_USB, midi::Start); + 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 } + void handleContinue_MIDI_DEVICE_USB(void) { - handleRealtime_generic(MIDI_BY_USB, midi::Continue); + 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 } + void handleStop_MIDI_DEVICE_USB(void) { - handleRealtime_generic(MIDI_BY_USB, midi::Stop); + 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 } + void handleActiveSensing_MIDI_DEVICE_USB(void) { - handleRealtime_generic(MIDI_BY_USB, midi::ActiveSensing); + 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 } + void handleSystemReset_MIDI_DEVICE_USB(void) { - handleRealtime_generic(MIDI_BY_USB, midi::SystemReset); + 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 } -/* FLASHMEM void handleRealTimeSystem_MIDI_DEVICE_USB(byte inRealTime) + +/* void handleRealTimeSystem_MIDI_DEVICE_USB(byte inRealTime) { - handleRealTimeSystem_generic(inRealTime, USB_MIDI); + 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 } */ #endif // MIDI_DEVICE_USB -FLASHMEM void MD_sendControlChange(uint8_t channel, uint8_t cc, uint8_t value) + +void MD_sendControlChange(uint8_t channel, uint8_t cc, uint8_t value) { #ifdef DEBUG Serial.print(F("[MD] SendControlChange CH:")); @@ -792,10 +1594,11 @@ FLASHMEM void MD_sendControlChange(uint8_t channel, uint8_t cc, uint8_t value) Serial.println(); #endif } + /***************************************** - HELPER FUNCTIONS + HELPER FUCNTIONS *****************************************/ -FLASHMEM void setup_midi_devices(void) +void setup_midi_devices(void) { #ifdef MIDI_DEVICE_DIN // Start serial MIDI @@ -823,6 +1626,7 @@ FLASHMEM void setup_midi_devices(void) Serial.println(F("MIDI_DEVICE_DIN enabled")); #endif #endif + // start up USB host #ifdef MIDI_DEVICE_USB_HOST usb_host.begin(); @@ -849,6 +1653,7 @@ FLASHMEM void setup_midi_devices(void) Serial.println(F("MIDI_DEVICE_USB_HOST enabled.")); #endif #endif + // check for onboard USB-MIDI #ifdef MIDI_DEVICE_USB usbMIDI.begin(); @@ -876,7 +1681,8 @@ FLASHMEM void setup_midi_devices(void) #endif #endif } -FLASHMEM void check_midi_devices(void) + +void check_midi_devices(void) { #ifdef MIDI_DEVICE_DIN midi_serial.read(); @@ -889,10 +1695,12 @@ FLASHMEM void check_midi_devices(void) midi_usb.read(); #endif } -FLASHMEM void send_sysex_voice(uint8_t midi_channel, uint8_t* data) + +void send_sysex_voice(uint8_t midi_channel, uint8_t* data) { uint8_t checksum = 0; uint8_t vd[161]; + // Send SYSEX data also via MIDI //vd[0] = 0xF0; // SysEx start vd[0] = 0x43; // ID=Yamaha @@ -907,36 +1715,29 @@ FLASHMEM 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 -#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 + midi_usb.sendSysEx(161, vd); // Send to USB MIDI + usbMIDI.sendSysEx(161, vd); // Send to USB-HOST MIDI } -FLASHMEM void send_sysex_bank(uint8_t midi_channel, uint8_t* bank_data) + +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 - // 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); + midi_usb.sendSysEx(4104, bank_data); // Send to USB MIDI #endif #ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendSysEx(4104, bank_data); // Send to USB-HOST MIDI + usbMIDI.sendSysEx(4104, bank_data); // Send to USB-HOST MIDI #endif } -FLASHMEM void send_sysex_param(uint8_t midi_channel, uint8_t var, uint8_t val, uint8_t param_group) + +void send_sysex_param(uint8_t midi_channel, uint8_t var, uint8_t val, uint8_t param_group) { uint8_t s[5]; + s[0] = 0x43; // ID=Yamaha s[1] = midi_channel; // Sub-status and MIDI channel s[2] = (param_group & 5) << 2; // Format number (0=1 voice) @@ -950,14 +1751,15 @@ FLASHMEM void send_sysex_param(uint8_t midi_channel, uint8_t var, uint8_t val, u s[3] = var & 0x7f; } s[4] = val & 0x7f; + #ifdef MIDI_DEVICE_DIN midi_serial.sendSysEx(5, s); // Send to DIN MIDI #endif #ifdef MIDI_DEVICE_USB - usbMIDI.sendSysEx(5, s); // Send to USB MIDI + midi_usb.sendSysEx(5, s); // Send to USB MIDI #endif #ifdef MIDI_DEVICE_USB_HOST - midi_usb.sendSysEx(5, s); // Send to USB-HOST MIDI + usbMIDI.sendSysEx(5, s); // Send to USB-HOST MIDI #endif }