|
|
@ -44,9 +44,10 @@ AudioControlSGTL5000 sgtl5000_1; //xy=507,403 |
|
|
|
|
|
|
|
|
|
|
|
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI); |
|
|
|
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI); |
|
|
|
Dexed* dexed = new Dexed(SAMPLE_RATE); |
|
|
|
Dexed* dexed = new Dexed(SAMPLE_RATE); |
|
|
|
IntervalTimer sched_master_key_auto_disable; |
|
|
|
|
|
|
|
bool sd_card_available = false; |
|
|
|
bool sd_card_available = false; |
|
|
|
|
|
|
|
#ifdef MASTER_KEY_MIDI |
|
|
|
bool master_key_enabled = false; |
|
|
|
bool master_key_enabled = false; |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#ifdef SHOW_CPU_LOAD_MSEC |
|
|
|
#ifdef SHOW_CPU_LOAD_MSEC |
|
|
|
IntervalTimer sched_show_cpu_usage; |
|
|
|
IntervalTimer sched_show_cpu_usage; |
|
|
@ -257,10 +258,28 @@ void note_off(void) |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
#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) |
|
|
|
bool handle_master_key(uint8_t data) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int8_t num = num_key_base_c(data); |
|
|
|
int8_t num = num_key_base_c(data); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Serial.print(F("Key->Number: ")); |
|
|
|
|
|
|
|
Serial.println(num); |
|
|
|
|
|
|
|
|
|
|
|
if (num > 0) |
|
|
|
if (num > 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// a white key!
|
|
|
|
// a white key!
|
|
|
@ -293,41 +312,39 @@ bool handle_master_key(uint8_t data) |
|
|
|
} |
|
|
|
} |
|
|
|
return (false); |
|
|
|
return (false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
bool queue_midi_event(uint8_t type, uint8_t data1, uint8_t data2) |
|
|
|
bool queue_midi_event(uint8_t type, uint8_t data1, uint8_t data2) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
bool ret = false; |
|
|
|
|
|
|
|
|
|
|
|
#ifdef SHOW_MIDI_EVENT |
|
|
|
#ifdef SHOW_MIDI_EVENT |
|
|
|
Serial.print("MIDI event type: "); |
|
|
|
print_midi_event(type, data1, data2); |
|
|
|
Serial.print(type, DEC); |
|
|
|
|
|
|
|
Serial.print(" data1: "); |
|
|
|
|
|
|
|
Serial.print(data1, DEC); |
|
|
|
|
|
|
|
Serial.print(" data2: "); |
|
|
|
|
|
|
|
Serial.println(data2, DEC); |
|
|
|
|
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
if (master_key_enabled == true) |
|
|
|
#ifdef MASTER_KEY_MIDI |
|
|
|
|
|
|
|
if (master_key_enabled == true && type == 0x80) |
|
|
|
{ |
|
|
|
{ |
|
|
|
master_key_enabled = handle_master_key(data1); |
|
|
|
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
|
|
|
|
master_key_enabled = false; |
|
|
|
return (false); |
|
|
|
Serial.println("Master key disabled"); |
|
|
|
|
|
|
|
} |
|
|
|
else if (type == 0x90 && data1 == MASTER_KEY_MIDI) // Master key pressed
|
|
|
|
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; |
|
|
|
master_key_enabled = true; |
|
|
|
Serial.println("Master key enabled"); |
|
|
|
Serial.println("Master key enabled"); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
return (dexed->processMidiMessage(type, data1, data2)); |
|
|
|
#endif |
|
|
|
} |
|
|
|
ret = dexed->processMidiMessage(type, data1, data2); |
|
|
|
return (false); |
|
|
|
|
|
|
|
|
|
|
|
return (ret); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef MASTER_KEY_MIDI |
|
|
|
int8_t num_key_base_c(uint8_t midi_note) |
|
|
|
int8_t num_key_base_c(uint8_t midi_note) |
|
|
|
{ |
|
|
|
{ |
|
|
|
switch (midi_note % 12) |
|
|
|
switch (midi_note % 12) |
|
|
@ -360,6 +377,7 @@ int8_t num_key_base_c(uint8_t midi_note) |
|
|
|
} |
|
|
|
} |
|
|
|
return (0); |
|
|
|
return (0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
void handle_sysex_parameter(const uint8_t* sysex, uint8_t len) |
|
|
|
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.")); |
|
|
|
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 |
|
|
|
#ifdef SHOW_CPU_LOAD_MSEC |
|
|
|
void show_cpu_and_mem_usage(void) |
|
|
|
void show_cpu_and_mem_usage(void) |
|
|
|
{ |
|
|
|
{ |
|
|
|