From ff6e5cd6cb8634fa4256c4c5cea89cd489ea97d7 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Wed, 27 May 2020 16:43:49 +0200 Subject: [PATCH] Sending voice data via MIDI (DIN and USB) when changing a voice. --- MicroDexed.ino | 2 -- UI.hpp | 1 - dexed.cpp | 8 ++++++++ dexed.h | 1 + dexed_sd.cpp | 6 ++++++ dexed_sd.h | 2 ++ midi_devices.hpp | 27 +++++++++++++++++++++++++++ 7 files changed, 44 insertions(+), 3 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index 8e9f1c2..fab3b2d 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -1229,8 +1229,6 @@ void handleSystemExclusive(byte * sysex, uint len) lcd.print(F("Done. ")); delay(MESSAGE_WAIT_TIME); LCDML.FUNC_goBackToMenu(); - //if (!get_bank_name(bank_number, bank_name, sizeof(bank_name))) - // strncpy(bank_name, "*ERROR*", 7); } else { diff --git a/UI.hpp b/UI.hpp index 0c9c143..92fb315 100644 --- a/UI.hpp +++ b/UI.hpp @@ -5186,7 +5186,6 @@ bool UI_select_name(uint8_t y, uint8_t x, char* edit_string, uint8_t len, bool i { edit_pos = 0; edit_mode = false; - //string_trim(edit_string); return (true); } diff --git a/dexed.cpp b/dexed.cpp index 2653b16..a59c7c6 100644 --- a/dexed.cpp +++ b/dexed.cpp @@ -638,6 +638,14 @@ bool Dexed::encodeVoice(uint8_t* encoded_data) return (true); } +bool Dexed::getVoiceData(uint8_t* data_copy) +{ + for (uint8_t i = 0; i < sizeof(data); i++) + data_copy[i] = data[i]; + + return (true); +} + bool Dexed::loadVoiceParameters(uint8_t* new_data) { char dexed_voice_name[11]; diff --git a/dexed.h b/dexed.h index f9be082..439f4cc 100644 --- a/dexed.h +++ b/dexed.h @@ -160,6 +160,7 @@ class Dexed void setOPs(uint8_t ops); bool decodeVoice(uint8_t* encoded_data); bool encodeVoice(uint8_t* encoded_data); + bool getVoiceData(uint8_t* data_copy); bool loadVoiceParameters(uint8_t* data); bool loadGlobalParameters(uint8_t* data); bool initGlobalParameters(void); diff --git a/dexed_sd.cpp b/dexed_sd.cpp index e709954..309cde8 100644 --- a/dexed_sd.cpp +++ b/dexed_sd.cpp @@ -75,9 +75,15 @@ bool load_sd_voice(uint8_t b, uint8_t v, uint8_t instance_id) #ifdef DEBUG show_patch(instance_id); #endif + configuration.dexed[instance_id].transpose = MicroDexed[instance_id]->data[DEXED_VOICE_OFFSET + DEXED_TRANSPOSE]; + sysex.close(); + uint8_t data_copy[155]; + MicroDexed[instance_id]->getVoiceData(data_copy); + send_sysex_voice(configuration.dexed[instance_id].midi_channel, data_copy); + return (ret); } #ifdef DEBUG diff --git a/dexed_sd.h b/dexed_sd.h index 075f2e2..05613ea 100644 --- a/dexed_sd.h +++ b/dexed_sd.h @@ -34,6 +34,8 @@ extern Dexed* dexed; extern AudioSourceMicroDexed * MicroDexed[NUM_DEXED]; extern void show_patch(uint8_t instance_id); +extern void send_sysex_voice(uint8_t midi_channel, uint8_t* data); + extern uint8_t bank; extern uint8_t voice; extern uint8_t ui_state; diff --git a/midi_devices.hpp b/midi_devices.hpp index 4051f95..351f631 100644 --- a/midi_devices.hpp +++ b/midi_devices.hpp @@ -1670,4 +1670,31 @@ void check_midi_devices(void) midi_usb.read(); #endif } + +void send_sysex_voice(uint8_t midi_channel, uint8_t* data) +{ + uint8_t checksum = 0; + uint8_t voice_data[161]; + + // Send SYSEX data also via MIDI + //voice_data[0] = 0xF0; // SysEx start + voice_data[0] = 0x43; // ID=Yamaha + voice_data[1] = midi_channel; // Sub-status and MIDI channel + voice_data[2] = 0x00; // Format number (0=1 voice) + voice_data[3] = 0x01; // Byte count MSB + voice_data[4] = 0x1B; // Byte count LSB + for (uint8_t n = 0; n < 155; n++) + { + checksum -= data[n]; + voice_data[5 + n] = data[n]; + } + checksum &= 0x7f; + voice_data[160] = checksum; // Checksum + //voice_data[162] = 0xF7; // SysEx end + + midi_serial.sendSysEx(161, voice_data); // Send to DIN MIDI + midi_usb.sendSysEx(161, voice_data); // Send to USB MIDI + usbMIDI.sendSysEx(161, voice_data); // Send to USB-HOST MIDI +} + #endif // MIDI_DEVICES_H