From 1bbfed551e2b994b8065f5a50cf62d37e1962859 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Thu, 28 May 2020 08:55:53 +0200 Subject: [PATCH] Added sending of banks via sysex. --- MicroDexed.ino | 1 - UI.hpp | 73 ++++++++++++++++++++++++++++++++++++++++++++---- config.h | 4 +-- dexed.cpp | 4 +-- midi_devices.hpp | 7 +++++ 5 files changed, 78 insertions(+), 11 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index fab3b2d..4a98851 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -2,7 +2,6 @@ MicroDexed MicroDexed is a port of the Dexed sound engine - (https://github.com/asb2m10/dexed) for the Teensy-3.5/3.6/4.x/4.x with audio shield. Dexed ist heavily based on https://github.com/google/music-synthesizer-for-android (c)2018-2020 H. Wirtz diff --git a/UI.hpp b/UI.hpp index 92fb315..5fb5858 100644 --- a/UI.hpp +++ b/UI.hpp @@ -4850,14 +4850,21 @@ void UI_func_sysex_receive_bank(uint8_t param) void UI_func_sysex_send_bank(uint8_t param) { + char bank_name[BANK_NAME_LEN]; + static uint8_t bank_number; + if (LCDML.FUNC_setup()) // ****** SETUP ********* { encoderDir[ENC_R].reset(); - + bank_number = configuration.performance.bank[selected_instance_id]; lcd.setCursor(0, 0); lcd.print(F("MIDI Send Bank")); - lcd.setCursor(0, 1); - lcd.print(F("Not implemented.")); + if (!get_bank_name(configuration.performance.bank[selected_instance_id], bank_name, sizeof(bank_name))) + strncpy(bank_name, "*ERROR*", sizeof(bank_name)); + lcd.show(1, 0, 1, "["); + lcd.show(1, 3, 1, "]"); + lcd.show(1, 1, 2, configuration.performance.bank[selected_instance_id]); + lcd.show(1, 5, 10, bank_name); } if (LCDML.FUNC_loop()) // ****** LOOP ********* @@ -4866,18 +4873,74 @@ void UI_func_sysex_send_bank(uint8_t param) { if (LCDML.BT_checkDown()) { - ; + bank_number = constrain(bank_number + ENCODER[ENC_R].speed(), 0, MAX_BANKS - 1); + } else if (LCDML.BT_checkUp()) { - ; + bank_number = constrain(bank_number - ENCODER[ENC_R].speed(), 0, MAX_BANKS - 1); } + if (!get_bank_name(bank_number, bank_name, sizeof(bank_name))) + strcpy(bank_name, "*ERROR*"); + lcd.show(1, 1, 2, bank_number); + lcd.show(1, 5, 10, bank_name); + } + else if (LCDML.BT_checkEnter() && encoderDir[ENC_R].ButtonShort()) + { + File sysex; + char filename[FILENAME_LEN]; + + if (get_bank_name(bank_number, bank_name, sizeof(bank_name))) + { + sprintf(filename, "/%d/%s.syx", bank_number, bank_name); +#ifdef DEBUG + Serial.print(F("Send bank ")); + Serial.print(filename); + Serial.println(F(" from SD.")); +#endif + sysex = SD.open(filename); + if (!sysex) + { +#ifdef DEBUG + Serial.println(F("Connot read from SD.")); +#endif + lcd.show(1, 0, 16, "Read error."); + bank_number = 0xff; + } + else + { + uint8_t bank_data[4104]; + + sysex.read(bank_data, 4104); + sysex.close(); + + lcd.show(1, 0, 16, "Sending..."); + send_sysex_bank(configuration.dexed[selected_instance_id].midi_channel, bank_data); + lcd.show(1, 0, 16, "Done."); + bank_number = 0xff; + } + } + else + { + lcd.show(1, 0, 16, "No bank."); + bank_number = 0xff; + } + + delay(MESSAGE_WAIT_TIME); + LCDML.FUNC_goBackToMenu(); } } if (LCDML.FUNC_close()) // ****** STABLE END ********* { encoderDir[ENC_R].reset(); + + if (bank_number != 0xff) + { + lcd.setCursor(0, 1); + lcd.print(F("Canceled. ")); + delay(MESSAGE_WAIT_TIME); + } } } diff --git a/config.h b/config.h index ac260c2..50018fb 100644 --- a/config.h +++ b/config.h @@ -54,9 +54,9 @@ // For SYSEX Bank upload via USB: // sed -i.orig 's/SYSEX_MAX_LEN = 290/SYSEX_MAX_LEN = 4104/' /usr/local/arduino-teensy-1.8.12/hardware/teensy/avr/libraries/USBHost_t36/USBHost_t36.h // sed -i.orig 's/^#define USB_MIDI_SYSEX_MAX 290/#define USB_MIDI_SYSEX_MAX 4104/' /usr/local/arduino-teensy-1.8.12/hardware/teensy/avr/cores/teensy3/usb_midi.h -#define USB_MIDI_SYSEX_MAX 4104 +//#define USB_MIDI_SYSEX_MAX 4104 -#define VERSION "0.9.9k" +#define VERSION "0.9.9l" //************************************************************************************************* //* DEVICE SETTINGS diff --git a/dexed.cpp b/dexed.cpp index a59c7c6..b4f8056 100644 --- a/dexed.cpp +++ b/dexed.cpp @@ -640,9 +640,7 @@ bool Dexed::encodeVoice(uint8_t* encoded_data) bool Dexed::getVoiceData(uint8_t* data_copy) { - for (uint8_t i = 0; i < sizeof(data); i++) - data_copy[i] = data[i]; - + memcpy(data_copy, data, sizeof(data)); return (true); } diff --git a/midi_devices.hpp b/midi_devices.hpp index 351f631..184f496 100644 --- a/midi_devices.hpp +++ b/midi_devices.hpp @@ -1697,4 +1697,11 @@ void send_sysex_voice(uint8_t midi_channel, uint8_t* data) usbMIDI.sendSysEx(161, voice_data); // Send to USB-HOST MIDI } +void send_sysex_bank(uint8_t midi_channel, uint8_t* bank_data) +{ + midi_serial.sendSysEx(4104, bank_data); // Send to DIN MIDI + midi_usb.sendSysEx(4104, bank_data); // Send to USB MIDI + usbMIDI.sendSysEx(4104, bank_data); // Send to USB-HOST MIDI +} + #endif // MIDI_DEVICES_H