From 48a22e0c42cb9755a78fa4e45202d19c904d9194 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Tue, 28 Nov 2023 11:40:08 +0100 Subject: [PATCH] Several fixes for USB-HOST-Serial handling. --- midi_devices.hpp | 115 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 94 insertions(+), 21 deletions(-) diff --git a/midi_devices.hpp b/midi_devices.hpp index 23b878d..70cd2c9 100644 --- a/midi_devices.hpp +++ b/midi_devices.hpp @@ -51,13 +51,13 @@ struct CustomBaudRateSettings : public MIDI_NAMESPACE::DefaultSerialSettings { MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, MIDI_DEVICE_DIN, midi_serial, MicroDexedSettings); #endif -#ifdef MIDI_DEVICE_USB_HOST +#if defined(MIDI_DEVICE_USB_HOST) || defined(MIDI_DEVICE_USB_HOST_SERIAL) USBHost usb_host; +#endif +#ifdef MIDI_DEVICE_USB_HOST MIDIDevice midi_usb(usb_host); #endif - #ifdef MIDI_DEVICE_USB_HOST_SERIAL -USBHost usb_host; USBHub hub1(usb_host); USBHub hub2(usb_host); USBHub hub3(usb_host); @@ -89,8 +89,9 @@ void handleSystemReset(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" +#define MIDI_BY_USB_HOST "MIDI_USB_HOST" +#define MIDI_BY_USB_HOST_SERIAL "MIDI_USB_HOST_SERIAL" void handle_generic(byte inChannel, byte inData1, byte inData2, const char *midi_device, midi::MidiType event) { char text[10]; @@ -231,6 +232,39 @@ void handle_generic(byte inChannel, byte inData1, byte inData2, const char *midi #endif } #endif + +#ifdef MIDI_DEVICE_USB_HOST_SERIAL + if (strcmp(MIDI_BY_USB_HOST_SERIAL, midi_device)) { + switch (event) { + case midi::NoteOn: + usbhost_midi_serial.sendNoteOn(inData1, inData2, inChannel); + break; + case midi::NoteOff: + usbhost_midi_serial.sendNoteOff(inData1, inData2, inChannel); + break; + case midi::ControlChange: + usbhost_midi_serial.sendControlChange(inData1, inData2, inChannel); + break; + case midi::AfterTouchChannel: + usbhost_midi_serial.sendAfterTouch(inData1, inChannel); + break; + case midi::PitchBend: + usbhost_midi_serial.sendPitchBend(inData1, inChannel); + break; + case midi::ProgramChange: + usbhost_midi_serial.sendProgramChange(inData1, inChannel); + break; + case midi::AfterTouchPoly: + usbhost_midi_serial.sendAfterTouch(inData1, inData2, inChannel); + break; + default: + break; + } +#ifdef DEBUG + Serial.print(F(" THRU->MIDI_USB_HOST_SERIAL")); +#endif + } +#endif } #ifdef DEBUG @@ -272,6 +306,15 @@ void handleSystemExclusive_generic(byte *data, uint len, const char *midi_device #endif } #endif + +#ifdef MIDI_DEVICE_USB_HOST_SERIAL + if (strcmp(MIDI_BY_USB_HOST_SERIAL, midi_device)) { + usbhost_midi_serial.sendSysEx(len, data); +#ifdef DEBUG + Serial.print(F(" THRU->MIDI_USB_HOST_SERIAL")); +#endif + } +#endif } #ifdef DEBUG @@ -366,6 +409,27 @@ void handleSystemCommon_generic(byte inData1, const char *midi_device, midi::Mid #endif } #endif + +#ifdef MIDI_DEVICE_USB_HOST_SERIAL + if (strcmp(MIDI_BY_USB_HOST_SERIAL, midi_device)) { + switch (event) { + case midi::TimeCodeQuarterFrame: + usbhost_midi_serial.sendTimeCodeQuarterFrame(0xF1, inData1); + break; + case midi::SongSelect: + usbhost_midi_serial.sendSongSelect(inData1); + break; + case midi::TuneRequest: + usbhost_midi_serial.sendTuneRequest(); + break; + default: + break; + } +#ifdef DEBUG + Serial.print(F(" THRU->MIDI_USB_HOST_SERIAL")); +#endif + } +#endif } #ifdef DEBUG @@ -436,6 +500,15 @@ void handleRealtime_generic(const char *midi_device, midi::MidiType event) { #endif } #endif + +#ifdef MIDI_DEVICE_USB_HOST_SERIAL + if (strcmp(MIDI_BY_USB_HOST_SERIAL, midi_device)) { + usbhost_midi_serial.sendRealTime(event); +#ifdef DEBUG + Serial.print(F(" THRU->MIDI_USB_HOST_SERIAL")); +#endif + } +#endif } #ifdef DEBUG @@ -708,35 +781,35 @@ void handleSystemReset_MIDI_DEVICE_USB_HOST(void) { #ifdef MIDI_DEVICE_USB_HOST_SERIAL void handleNoteOn_MIDI_DEVICE_USB_HOST_SERIAL(byte inChannel, byte inNoteNumber, byte inVelocity) { - handle_generic(inChannel, inNoteNumber, inVelocity, MIDI_BY_USB_HOST, midi::NoteOn); + handle_generic(inChannel, inNoteNumber, inVelocity, MIDI_BY_USB_HOST_SERIAL, midi::NoteOn); } void handleNoteOff_MIDI_DEVICE_USB_HOST_SERIAL(byte inChannel, byte inNoteNumber, byte inVelocity) { - handle_generic(inChannel, inNoteNumber, inVelocity, MIDI_BY_USB_HOST, midi::NoteOff); + handle_generic(inChannel, inNoteNumber, inVelocity, MIDI_BY_USB_HOST_SERIAL, midi::NoteOff); } void handleControlChange_MIDI_DEVICE_USB_HOST_SERIAL(byte inChannel, byte inData1, byte inData2) { - handle_generic(inChannel, inData1, inData2, MIDI_BY_USB_HOST, midi::ControlChange); + handle_generic(inChannel, inData1, inData2, MIDI_BY_USB_HOST_SERIAL, midi::ControlChange); } void handleAfterTouch_MIDI_DEVICE_USB_HOST_SERIAL(byte inChannel, byte inPressure) { - handle_generic(inChannel, inPressure, '\0', MIDI_BY_USB_HOST, midi::AfterTouchChannel); + handle_generic(inChannel, inPressure, '\0', MIDI_BY_USB_HOST_SERIAL, midi::AfterTouchChannel); } void handlePitchBend_MIDI_DEVICE_USB_HOST_SERIAL(byte inChannel, int inPitch) { - handle_generic(inChannel, inPitch, '\0', MIDI_BY_USB_HOST, midi::PitchBend); + handle_generic(inChannel, inPitch, '\0', MIDI_BY_USB_HOST_SERIAL, midi::PitchBend); } void handleProgramChange_MIDI_DEVICE_USB_HOST_SERIAL(byte inChannel, byte inProgram) { - handle_generic(inChannel, inProgram, '\0', MIDI_BY_USB_HOST, midi::ProgramChange); + handle_generic(inChannel, inProgram, '\0', MIDI_BY_USB_HOST_SERIAL, midi::ProgramChange); } void handleAfterTouchPoly_MIDI_DEVICE_USB_HOST_SERIAL(byte inChannel, byte inNoteNumber, byte inVelocity) { - handle_generic(inChannel, inNoteNumber, inVelocity, MIDI_BY_USB_HOST, midi::AfterTouchPoly); + handle_generic(inChannel, inNoteNumber, inVelocity, MIDI_BY_USB_HOST_SERIAL, midi::AfterTouchPoly); } void handleSystemExclusive_MIDI_DEVICE_USB_HOST_SERIAL(byte *data, uint len) { - handleSystemExclusive_generic(data, len, MIDI_BY_USB_HOST); + handleSystemExclusive_generic(data, len, MIDI_BY_USB_HOST_SERIAL); } /* void handleSystemExclusiveChunk_MIDI_DEVICE_USB_HOST_SERIAL(byte *data, uint len, bool last) @@ -766,39 +839,39 @@ void handleSystemExclusive_MIDI_DEVICE_USB_HOST_SERIAL(byte *data, uint len) { } */ void handleTimeCodeQuarterFrame_MIDI_DEVICE_USB_HOST_SERIAL(midi::DataByte data) { - handleSystemCommon_generic(data, MIDI_BY_USB_HOST, midi::TimeCodeQuarterFrame); + handleSystemCommon_generic(data, MIDI_BY_USB_HOST_SERIAL, midi::TimeCodeQuarterFrame); } void handleSongSelect_MIDI_DEVICE_USB_HOST_SERIAL(byte inSong) { - handleSystemCommon_generic(inSong, MIDI_BY_USB_HOST, midi::SongSelect); + handleSystemCommon_generic(inSong, MIDI_BY_USB_HOST_SERIAL, midi::SongSelect); } void handleTuneRequest_MIDI_DEVICE_USB_HOST_SERIAL(void) { - handleSystemCommon_generic('\0', MIDI_BY_USB_HOST, midi::TuneRequest); + handleSystemCommon_generic('\0', MIDI_BY_USB_HOST_SERIAL, midi::TuneRequest); } void handleClock_MIDI_DEVICE_USB_HOST_SERIAL(void) { - handleRealtime_generic(MIDI_BY_USB_HOST, midi::Clock); + handleRealtime_generic(MIDI_BY_USB_HOST_SERIAL, midi::Clock); } void handleStart_MIDI_DEVICE_USB_HOST_SERIAL(void) { - handleRealtime_generic(MIDI_BY_USB_HOST, midi::Start); + handleRealtime_generic(MIDI_BY_USB_HOST_SERIAL, midi::Start); } void handleContinue_MIDI_DEVICE_USB_HOST_SERIAL(void) { - handleRealtime_generic(MIDI_BY_USB_HOST, midi::Continue); + handleRealtime_generic(MIDI_BY_USB_HOST_SERIAL, midi::Continue); } void handleStop_MIDI_DEVICE_USB_HOST_SERIAL(void) { - handleRealtime_generic(MIDI_BY_USB_HOST, midi::Stop); + handleRealtime_generic(MIDI_BY_USB_HOST_SERIAL, midi::Stop); } void handleActiveSensing_MIDI_DEVICE_USB_HOST_SERIAL(void) { - handleRealtime_generic(MIDI_BY_USB_HOST, midi::ActiveSensing); + handleRealtime_generic(MIDI_BY_USB_HOST_SERIAL, midi::ActiveSensing); } void handleSystemReset_MIDI_DEVICE_USB_HOST_SERIAL(void) { - handleRealtime_generic(MIDI_BY_USB_HOST, midi::SystemReset); + handleRealtime_generic(MIDI_BY_USB_HOST_SERIAL, midi::SystemReset); } /* void handlRealTimeSystem_MIDI_DEVICE_USB_HOST_SERIAL(midi::MidiType inRealTime)