From d53b2d52d2af121b061c431b0bff04893e9a4f90 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Fri, 1 Jun 2018 12:54:10 +0200 Subject: [PATCH] Added masterkey (C8) for ebaling switching the sounds. --- MicroDexed.ino | 86 ++++++++++++++++++++++++++++++++++++++----------- config.h | 3 +- dexed.cpp | 9 +++--- dexed_sysex.cpp | 30 ++++++++++++++--- dexed_sysex.h | 2 +- 5 files changed, 100 insertions(+), 30 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index cfc4dc5..03baaf5 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -27,10 +27,12 @@ #include #include #include -#include #include "dexed.h" #include "dexed_sysex.h" #include "config.h" +#ifdef USE_ONBOARD_USB_HOST +#include +#endif // GUItool: begin automatically generated code AudioPlayQueue queue1; //xy=84,294 @@ -49,6 +51,7 @@ MIDIDevice midi_usb(usb_host); #endif bool sd_card_available = false; +bool master_key_enabled = false; #ifdef TEST_MIDI IntervalTimer sched_note_on; IntervalTimer sched_note_off; @@ -59,7 +62,7 @@ void setup() { //while (!Serial) ; // wait for Arduino Serial Monitor Serial.begin(SERIAL_SPEED); - delay(50); + delay(200); Serial.println(F("MicroDexed based on https://github.com/asb2m10/dexed")); Serial.println(F("(c)2018 H. Wirtz")); Serial.println(F("setup start")); @@ -77,6 +80,7 @@ void setup() } else { + Serial.println(F("SD card found.")); sd_card_available = true; } @@ -89,22 +93,18 @@ void setup() sgtl5000_1.enable(); sgtl5000_1.volume(VOLUME); - // Initialize processor and memory measurements #ifdef SHOW_CPU_LOAD_MSEC + // Initialize processor and memory measurements AudioProcessorUsageMaxReset(); AudioMemoryUsageMaxReset(); #endif -#ifdef DEBUG - show_patch(); -#endif //dexed->activate(); //dexed->setMaxNotes(MAX_NOTES); //dexed->setEngineType(DEXED_ENGINE); -#ifdef SHOW_CPU_LOAD_MSEC - sched.begin(cpu_and_mem_usage, SHOW_CPU_LOAD_MSEC * 1000); -#endif + sched.begin(cleanup, SHOW_CPU_LOAD_MSEC * 1000); + Serial.print(F("AUDIO_BLOCK_SAMPLES=")); Serial.println(AUDIO_BLOCK_SAMPLES); @@ -118,12 +118,12 @@ void setup() cpu_and_mem_usage(); #ifdef TEST_MIDI - //dexed->data[139] = 99; // full pitch mod sense! - //dexed->data[143] = 99; // full pitch mod depth! - //dexed->data[158] = 7; // mod wheel assign all - //dexed->data[160] = 7; // foot ctrl assign all - //dexed->data[162] = 7; // breath ctrl assign all - //dexed->data[164] = 7; // at ctrl assign all + //dexed->data[DEXED_VOICE_OFFSET+DEXED_LFO_PITCH_MOD_DEP] = 99; // full pitch mod depth + //dexed->data[DEXED_VOICE_OFFSET+DEXED_LFO_PITCH_MOD_SENS] = 99; // full pitch mod sense + //dexed->data[DEXED_GLOBAL_PARAMETER_OFFSET+DEXED_MODWHEEL_ASSIGN] = 7; // mod wheel assign all + //dexed->data[DEXED_GLOBAL_PARAMETER_OFFSET+DEXED_FOOTCTRL_ASSIGN] = 7; // foot ctrl assign all + //dexed->data[DEXED_GLOBAL_PARAMETER_OFFSET+DEXED_BREATHCTRL_ASSIGN] = 7; // breath ctrl assign all + //dexed->data[DEXED_GLOBAL_PARAMETER_OFFSET+AT_ASSIGN] = 7; // at ctrl assign all //queue_midi_event(0xb0, 1, 99); // test mod wheel //queue_midi_event(0xb0, 2, 99); // test breath ctrl //queue_midi_event(0xb0, 4, 99); // test food switch @@ -151,7 +151,7 @@ void loop() #ifdef USE_ONBOARD_USB_HOST while (midi_usb.read()) { - break_for_calculation = dexed->processMidiMessage(midi_usb.getType(), midi_usb.getData1(), midi_usb.getData2()); + break_for_calculation = queue_midi_event(midi_usb.getType(), midi_usb.getData1(), midi_usb.getData2()); if (break_for_calculation == true) break; } @@ -160,7 +160,7 @@ void loop() #endif while (MIDI.read()) { - break_for_calculation = dexed->processMidiMessage(MIDI.getType(), MIDI.getData1(), MIDI.getData2()); + break_for_calculation = queue_midi_event(MIDI.getType(), MIDI.getData1(), MIDI.getData2()); if (break_for_calculation == true) break; } @@ -228,13 +228,61 @@ void note_off(void) queue_midi_event(0x80, TEST_NOTE + 52, 0); // 14 queue_midi_event(0x80, TEST_NOTE + 57, 0); // 15 queue_midi_event(0x80, TEST_NOTE + 60, 0); // 16 - load_sysex("ROM1A.SYX", ++_voice_counter % 32); + + //bool success=true; + //bool success = load_sysex("ROM1A.SYX", (++_voice_counter)-1); + //bool success=load_sysex("ROM1B.SYX", (++_voice_counter)-1); + //bool success=load_sysex("RITCH01-32.SYX", (++_voice_counter)-1); + //bool success=load_sysex("RITCH33-64.SYX", (++_voice_counter)-1); + bool success = load_sysex("RITCH0~1.SYX", (++_voice_counter) - 1); + if (success == false) + Serial.println(F("Cannot load SYSEX data")); + else + show_patch(); } #endif bool queue_midi_event(uint8_t type, uint8_t data1, uint8_t data2) { - return (dexed->processMidiMessage(type, data1, data2)); + if (master_key_enabled == true) + { + if (data1 >= 24 && data1 <= 56) + { + if (!load_sysex("RITCH0~1.SYX", data1 - 24)) + { + Serial.print("E: cannot load voice number "); + Serial.println(data1 - 24, DEC); + } + } + master_key_enabled = false; + Serial.println("Master key disabled"); + } + else + { + if (type == 0x80 && data1 == MASTER_KEY_MIDI) // ignore Master key up + return (false); + else if (type == 0x90 && data1 == MASTER_KEY_MIDI) // Master key pressed + { + master_key_enabled = true; + Serial.println("Master key enabled"); + } + else + return (dexed->processMidiMessage(type, data1, data2)); + } + return (false); +} + +void cleanup(void) +{ + if (master_key_enabled == true) + { + master_key_enabled = false; + Serial.println("Auto disabled master key"); + } + +#ifdef SHOW_CPU_LOAD_MSEC + cpu_and_mem_usage(); +#endif } #ifdef SHOW_CPU_LOAD_MSEC diff --git a/config.h b/config.h index fcf7f12..a435244 100644 --- a/config.h +++ b/config.h @@ -22,7 +22,7 @@ */ -#define TEST_MIDI 1 +//#define TEST_MIDI 1 #define TEST_NOTE 40 #define TEST_VEL_MIN 60 #define TEST_VEL_MAX 110 @@ -38,6 +38,7 @@ #define SHOW_CPU_LOAD_MSEC 5000 #define MAX_NOTES 16 #define AUDIO_MEM 2 +#define MASTER_KEY_MIDI 108 // Use these with the Teensy Audio Shield #define SDCARD_CS_PIN 10 diff --git a/dexed.cpp b/dexed.cpp index 791a458..186d1ae 100644 --- a/dexed.cpp +++ b/dexed.cpp @@ -490,7 +490,7 @@ bool Dexed::loadSysexVoice(uint8_t* new_data) uint8_t op; uint8_t tmp; - notesOff(); + //notesOff(); for (op = 0; op < 6; op++) { @@ -572,16 +572,17 @@ bool Dexed::loadSysexVoice(uint8_t* new_data) (*(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_OP5_ENABLE) << 1) | *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_OP6_ENABLE )); setMaxNotes(*(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_MAX_NOTES)); + //panic(); doRefreshVoice(); - activate(); + //activate(); #ifdef DEBUG char voicename[11]; memset(voicename, 0, sizeof(voicename)); strncpy(voicename, (char *)&data[145], sizeof(voicename) - 1); - Serial.print(F("[")); + Serial.print(F("Voice [")); Serial.print(voicename); - Serial.println(F("]")); + Serial.println(F("] loaded.")); #endif return (true); diff --git a/dexed_sysex.cpp b/dexed_sysex.cpp index fbb13b7..a579aea 100644 --- a/dexed_sysex.cpp +++ b/dexed_sysex.cpp @@ -30,31 +30,44 @@ #include "dexed_sysex.h" #include "config.h" -void load_sysex(char *name, uint8_t voice_number) +bool load_sysex(char *name, uint8_t voice_number) { File root; + bool found = false; + + voice_number %= 32; if (sd_card_available) { root = SD.open("/"); + if (!root) + { + Serial.println(F("E: Cannot open main dir from SD.")); + return (false); + } while (42 == 42) { File entry = root.openNextFile(); if (!entry) + { + // No more files break; + } else { if (!entry.isDirectory()) { + Serial.println(entry.name()); + if (strcmp(name, entry.name()) == 0) { uint8_t data[128]; - Serial.println(entry.name()); + found = true; if (get_sysex_voice(entry, voice_number, data)) - dexed->loadSysexVoice(data); + return (dexed->loadSysexVoice(data)); else - Serial.println(F("Cannot load voice data")); + Serial.println(F("E: Cannot load voice data")); entry.close(); break; } @@ -63,16 +76,23 @@ void load_sysex(char *name, uint8_t voice_number) } } } + if (found == false) + Serial.println(F("E: File not found.")); + + return (false); } bool get_sysex_voice(File sysex, uint8_t voice_number, uint8_t* data) { File file; - uint16_t i,n; + uint16_t i, n; uint32_t calc_checksum = 0; if (sysex.size() != 4104) // check sysex size + { + Serial.println(F("E: SysEx file size wrong.")); return (false); + } if (file = SD.open(sysex.name())) { if (file.read() != 0xf0) // check sysex start-byte diff --git a/dexed_sysex.h b/dexed_sysex.h index ae9a1f7..50ce75e 100644 --- a/dexed_sysex.h +++ b/dexed_sysex.h @@ -25,6 +25,6 @@ extern bool sd_card_available; extern Dexed* dexed; -void load_sysex(char *name, uint8_t voice_number); +bool load_sysex(char *name, uint8_t voice_number); bool get_sysex_voice(File sysex, uint8_t voice_number, uint8_t* data);