diff --git a/MicroDexed.ino b/MicroDexed.ino index 6b388a7..a22143b 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -44,9 +44,10 @@ AudioControlSGTL5000 sgtl5000_1; //xy=507,403 MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI); Dexed* dexed = new Dexed(SAMPLE_RATE); -IntervalTimer sched_master_key_auto_disable; bool sd_card_available = false; +#ifdef MASTER_KEY_MIDI bool master_key_enabled = false; +#endif #ifdef SHOW_CPU_LOAD_MSEC IntervalTimer sched_show_cpu_usage; @@ -257,10 +258,28 @@ void note_off(void) } #endif +#ifdef SHOW_MIDI_EVENT +void print_midi_event(uint8_t type, uint8_t data1, uint8_t data2) +{ + Serial.print("MIDI event type: 0x"); + if (type < 16) + Serial.print(F("0")); + Serial.print(type, HEX); + Serial.print(" data1: "); + Serial.print(data1, DEC); + Serial.print(" data2: "); + Serial.println(data2, DEC); +} +#endif + +#ifdef MASTER_KEY_MIDI bool handle_master_key(uint8_t data) { int8_t num = num_key_base_c(data); + Serial.print(F("Key->Number: ")); + Serial.println(num); + if (num > 0) { // a white key! @@ -293,41 +312,39 @@ bool handle_master_key(uint8_t data) } return (false); } +#endif bool queue_midi_event(uint8_t type, uint8_t data1, uint8_t data2) { + bool ret = false; + #ifdef SHOW_MIDI_EVENT - Serial.print("MIDI event type: "); - Serial.print(type, DEC); - Serial.print(" data1: "); - Serial.print(data1, DEC); - Serial.print(" data2: "); - Serial.println(data2, DEC); + print_midi_event(type, data1, data2); #endif - if (master_key_enabled == true) +#ifdef MASTER_KEY_MIDI + if (master_key_enabled == true && type == 0x80) { master_key_enabled = handle_master_key(data1); - - if (master_key_enabled == false) - Serial.println("Master key disabled"); } - else + if (type == 0x80 && data1 == MASTER_KEY_MIDI) { - if (type == 0x80 && data1 == MASTER_KEY_MIDI) // ignore Master key up - return (false); - else if (type == 0x90 && data1 == MASTER_KEY_MIDI) // Master key pressed - { - sched_master_key_auto_disable.begin(master_key_auto_disable, MASTER_KEY_AUTO_DISABLE_MSEC * 1000); - master_key_enabled = true; - Serial.println("Master key enabled"); - } - else - return (dexed->processMidiMessage(type, data1, data2)); + master_key_enabled = false; + Serial.println("Master key disabled"); } - return (false); + else if (type == 0x90 && data1 == MASTER_KEY_MIDI) // Master key pressed + { + master_key_enabled = true; + Serial.println("Master key enabled"); + } + else +#endif + ret = dexed->processMidiMessage(type, data1, data2); + + return (ret); } +#ifdef MASTER_KEY_MIDI int8_t num_key_base_c(uint8_t midi_note) { switch (midi_note % 12) @@ -360,6 +377,7 @@ int8_t num_key_base_c(uint8_t midi_note) } return (0); } +#endif void handle_sysex_parameter(const uint8_t* sysex, uint8_t len) { @@ -415,16 +433,6 @@ void handle_sysex_parameter(const uint8_t* sysex, uint8_t len) Serial.println(F("E: SysEx parameter length wrong.")); } -void master_key_auto_disable(void) -{ - if (master_key_enabled == true) - { - master_key_enabled = false; - Serial.println("Auto disabling master key"); - } - sched_master_key_auto_disable.end(); -} - #ifdef SHOW_CPU_LOAD_MSEC void show_cpu_and_mem_usage(void) { diff --git a/config.h b/config.h index 249ad28..83b38f1 100644 --- a/config.h +++ b/config.h @@ -44,7 +44,6 @@ #define DEFAULT_SYSEXSOUND 0 #define MASTER_KEY_MIDI 84 // C6 -#define MASTER_KEY_AUTO_DISABLE_MSEC 5000 #define MASTER_NUM1 24 // C1 #define MASTER_BANK_SELECT 83 // B5 diff --git a/dexed.cpp b/dexed.cpp index a8e0eb2..529f43f 100644 --- a/dexed.cpp +++ b/dexed.cpp @@ -155,14 +155,6 @@ void Dexed::getSamples(uint16_t n_samples, int16_t* buffer) bool Dexed::processMidiMessage(uint8_t type, uint8_t data1, uint8_t data2) { -#ifdef SHOW_MIDI_EVENT - Serial.print("MIDI event type: "); - Serial.print(type, DEC); - Serial.print(" data1: "); - Serial.print(data1, DEC); - Serial.print(" data2: "); - Serial.println(data2, DEC); -#endif switch (type & 0xf0) { case 0x80 : keyup(data1); diff --git a/dexed_sysex.cpp b/dexed_sysex.cpp index a579aea..8c02dcb 100644 --- a/dexed_sysex.cpp +++ b/dexed_sysex.cpp @@ -57,8 +57,6 @@ bool load_sysex(char *name, uint8_t voice_number) { if (!entry.isDirectory()) { - Serial.println(entry.name()); - if (strcmp(name, entry.name()) == 0) { uint8_t data[128];