|
|
@ -29,11 +29,15 @@ |
|
|
|
#include <ArduinoJson.h> |
|
|
|
#include <ArduinoJson.h> |
|
|
|
#include <Audio.h> |
|
|
|
#include <Audio.h> |
|
|
|
#include "config.h" |
|
|
|
#include "config.h" |
|
|
|
|
|
|
|
#include "drums.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extern uint8_t num_drums; |
|
|
|
|
|
|
|
extern drum_config_t drum_config[DRUM_MAX_INSTRUMENTS]; |
|
|
|
|
|
|
|
|
|
|
|
void read_drum_config(void) |
|
|
|
void read_drum_config(void) |
|
|
|
{ |
|
|
|
{ |
|
|
|
File json; |
|
|
|
File json; |
|
|
|
|
|
|
|
DynamicJsonDocument drums_json(4096); |
|
|
|
|
|
|
|
|
|
|
|
AudioNoInterrupts(); |
|
|
|
AudioNoInterrupts(); |
|
|
|
if (SD.exists("/DRM/CFGDrums.json")) |
|
|
|
if (SD.exists("/DRM/CFGDrums.json")) |
|
|
@ -44,18 +48,210 @@ void read_drum_config(void) |
|
|
|
json = SD.open("/DRM/CFGDrums.json"); |
|
|
|
json = SD.open("/DRM/CFGDrums.json"); |
|
|
|
if (json) |
|
|
|
if (json) |
|
|
|
{ |
|
|
|
{ |
|
|
|
DynamicJsonDocument drums_json(5000); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
deserializeJson(drums_json, json); |
|
|
|
deserializeJson(drums_json, json); |
|
|
|
|
|
|
|
json.close(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
num_drums = drums_json.size(); |
|
|
|
#ifdef DEBUG |
|
|
|
#ifdef DEBUG |
|
|
|
Serial.println("Drums:"); |
|
|
|
|
|
|
|
serializeJsonPretty(drums_json, Serial); |
|
|
|
|
|
|
|
Serial.println(); |
|
|
|
|
|
|
|
Serial.print(F("Drum Objects: ")); |
|
|
|
Serial.print(F("Drum Objects: ")); |
|
|
|
Serial.println(drums_json["drums"].size()); |
|
|
|
Serial.println(num_drums); |
|
|
|
|
|
|
|
if (num_drums > DRUM_MAX_INSTRUMENTS) |
|
|
|
|
|
|
|
Serial.println(F("*** Maximum number of drum samples exceeded! ***")); |
|
|
|
|
|
|
|
//Serial.println(F("Drum Configuration:"));
|
|
|
|
|
|
|
|
//serializeJsonPretty(drums_json, Serial);
|
|
|
|
|
|
|
|
//Serial.println();
|
|
|
|
#endif |
|
|
|
#endif |
|
|
|
json.close(); |
|
|
|
num_drums = constrain(num_drums, 0, DRUM_MAX_INSTRUMENTS); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
AudioInterrupts(); |
|
|
|
AudioInterrupts(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t drum = 0; |
|
|
|
|
|
|
|
JsonObject root = drums_json["drums"].as<JsonObject>(); |
|
|
|
|
|
|
|
for (JsonPair kv : root) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
sprintf(drum_config[drum].filename, "/drm/%s.wav", kv.key().c_str()); |
|
|
|
|
|
|
|
if (!SD.exists(drum_config[drum].filename)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
#ifdef DEBUG |
|
|
|
|
|
|
|
Serial.print(F("Cannot find WAV file [")); |
|
|
|
|
|
|
|
Serial.print(drum_config[drum].filename); |
|
|
|
|
|
|
|
Serial.println(F("]")); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
JsonObject drum_root = drums_json["drums"][kv.key().c_str()].as<JsonObject>(); |
|
|
|
|
|
|
|
for (JsonPair drum_kv : drum_root) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (strcmp(drum_kv.key().c_str(), "drum_class") == 0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (drum_kv.value().is<const char*>()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (strcmp(drum_kv.value().as<const char*>(), "DRUM_NONE") == 0) |
|
|
|
|
|
|
|
drum_config[drum].drum_class = DRUM_NONE; |
|
|
|
|
|
|
|
else if (strcmp(drum_kv.value().as<const char*>(), "DRUM_BASS") == 0) |
|
|
|
|
|
|
|
drum_config[drum].drum_class = DRUM_BASS; |
|
|
|
|
|
|
|
else if (strcmp(drum_kv.value().as<const char*>(), "DRUM_SNARE") == 0) |
|
|
|
|
|
|
|
drum_config[drum].drum_class = DRUM_SNARE; |
|
|
|
|
|
|
|
else if (strcmp(drum_kv.value().as<const char*>(), "DRUM_HIHAT") == 0) |
|
|
|
|
|
|
|
drum_config[drum].drum_class = DRUM_HIHAT; |
|
|
|
|
|
|
|
else if (strcmp(drum_kv.value().as<const char*>(), "DRUM_HANDCLAP") == 0) |
|
|
|
|
|
|
|
drum_config[drum].drum_class = DRUM_HANDCLAP; |
|
|
|
|
|
|
|
else if (strcmp(drum_kv.value().as<const char*>(), "DRUM_RIDE") == 0) |
|
|
|
|
|
|
|
drum_config[drum].drum_class = DRUM_RIDE; |
|
|
|
|
|
|
|
else if (strcmp(drum_kv.value().as<const char*>(), "DRUM_CHRASH") == 0) |
|
|
|
|
|
|
|
drum_config[drum].drum_class = DRUM_CHRASH; |
|
|
|
|
|
|
|
else if (strcmp(drum_kv.value().as<const char*>(), "DRUM_LOWTOM") == 0) |
|
|
|
|
|
|
|
drum_config[drum].drum_class = DRUM_LOWTOM; |
|
|
|
|
|
|
|
else if (strcmp(drum_kv.value().as<const char*>(), "DRUM_MIDTOM") == 0) |
|
|
|
|
|
|
|
drum_config[drum].drum_class = DRUM_MIDTOM; |
|
|
|
|
|
|
|
else if (strcmp(drum_kv.value().as<const char*>(), "DRUM_HIGHTOM") == 0) |
|
|
|
|
|
|
|
drum_config[drum].drum_class = DRUM_HIGHTOM; |
|
|
|
|
|
|
|
else if (strcmp(drum_kv.value().as<const char*>(), "DRUM_PERCUSSION") == 0) |
|
|
|
|
|
|
|
drum_config[drum].drum_class = DRUM_PERCUSSION; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (strcmp(drum_kv.key().c_str(), "midinote") == 0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (drum_kv.value().is<const char*>()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
uint8_t note_number = 0; |
|
|
|
|
|
|
|
uint8_t oct = 0; |
|
|
|
|
|
|
|
char midi_note[4]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
strcpy(midi_note, drum_kv.value().as<const char*>()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (midi_note[0]) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
case 'A': |
|
|
|
|
|
|
|
if (midi_note[1] == '#') |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
note_number = 1; |
|
|
|
|
|
|
|
oct = midi_note[2] - 48; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
note_number = 0; |
|
|
|
|
|
|
|
oct = midi_note[1] - 48; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 'B': |
|
|
|
|
|
|
|
note_number = 2; |
|
|
|
|
|
|
|
oct = midi_note[1] - 48; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 'C': |
|
|
|
|
|
|
|
if (midi_note[1] == '#') |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
note_number = 4; |
|
|
|
|
|
|
|
oct = midi_note[2] - 48; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
note_number = 3; |
|
|
|
|
|
|
|
oct = midi_note[1] - 48; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 'D': |
|
|
|
|
|
|
|
if (midi_note[1] == '#') |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
note_number = 6; |
|
|
|
|
|
|
|
oct = midi_note[2] - 48; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
note_number = 5; |
|
|
|
|
|
|
|
oct = midi_note[1] - 48; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 'E': |
|
|
|
|
|
|
|
note_number = 7; |
|
|
|
|
|
|
|
oct = midi_note[1] - 48; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 'F': |
|
|
|
|
|
|
|
if (midi_note[1] == '#') |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
note_number = 9; |
|
|
|
|
|
|
|
oct = midi_note[2] - 48; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
note_number = 8; |
|
|
|
|
|
|
|
oct = midi_note[1] - 48; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 'G': |
|
|
|
|
|
|
|
if (midi_note[1] == '#') |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
note_number = 11; |
|
|
|
|
|
|
|
oct = midi_note[2] - 48; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
note_number = 10; |
|
|
|
|
|
|
|
oct = midi_note[1] - 48; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
drum_config[drum].midinote = note_number + 9 + (oct * 12); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (strcmp(drum_kv.key().c_str(), "shortname") == 0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
memset(drum_config[drum].shortname, 0, 2); |
|
|
|
|
|
|
|
if (drum_kv.value().is<const char*>()) |
|
|
|
|
|
|
|
drum_config[drum].shortname[0] = drum_kv.value().as<const char*>()[0]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (strcmp(drum_kv.key().c_str(), "pan") == 0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (drum_kv.value().is<float>()) |
|
|
|
|
|
|
|
drum_config[drum].pan = drum_kv.value().as<float>(); |
|
|
|
|
|
|
|
if (drum_kv.value().is<int>()) |
|
|
|
|
|
|
|
drum_config[drum].pan = float(drum_kv.value().as<int>()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (strcmp(drum_kv.key().c_str(), "vol_max") == 0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (drum_kv.value().is<float>()) |
|
|
|
|
|
|
|
drum_config[drum].vol_max = drum_kv.value().as<float>(); |
|
|
|
|
|
|
|
if (drum_kv.value().is<int>()) |
|
|
|
|
|
|
|
drum_config[drum].vol_max = float(drum_kv.value().as<int>()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (strcmp(drum_kv.key().c_str(), "vol_min") == 0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (drum_kv.value().is<float>()) |
|
|
|
|
|
|
|
drum_config[drum].vol_min = drum_kv.value().as<float>(); |
|
|
|
|
|
|
|
if (drum_kv.value().is<int>()) |
|
|
|
|
|
|
|
drum_config[drum].vol_min = float(drum_kv.value().as<int>()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (strcmp(drum_kv.key().c_str(), "reverb_send") == 0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (drum_kv.value().is<float>()) |
|
|
|
|
|
|
|
drum_config[drum].reverb_send = drum_kv.value().as<float>(); |
|
|
|
|
|
|
|
if (drum_kv.value().is<int>()) |
|
|
|
|
|
|
|
drum_config[drum].reverb_send = float(drum_kv.value().as<int>()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG |
|
|
|
|
|
|
|
Serial.print(F("[Drum ")); |
|
|
|
|
|
|
|
Serial.print(drum, DEC); |
|
|
|
|
|
|
|
Serial.println(F("]")); |
|
|
|
|
|
|
|
Serial.print(F("drum_class=")); |
|
|
|
|
|
|
|
Serial.println(drum_config[drum].drum_class, DEC); |
|
|
|
|
|
|
|
Serial.print(F("midinote=")); |
|
|
|
|
|
|
|
Serial.println(drum_config[drum].midinote, DEC); |
|
|
|
|
|
|
|
Serial.print(F("filename=")); |
|
|
|
|
|
|
|
Serial.println(drum_config[drum].filename); |
|
|
|
|
|
|
|
Serial.print(F("shortname=")); |
|
|
|
|
|
|
|
Serial.println(drum_config[drum].shortname); |
|
|
|
|
|
|
|
Serial.print(F("pan=")); |
|
|
|
|
|
|
|
Serial.println(drum_config[drum].pan); |
|
|
|
|
|
|
|
Serial.print(F("vol_max=")); |
|
|
|
|
|
|
|
Serial.println(drum_config[drum].vol_max); |
|
|
|
|
|
|
|
Serial.print(F("vol_min=")); |
|
|
|
|
|
|
|
Serial.println(drum_config[drum].vol_min); |
|
|
|
|
|
|
|
Serial.print(F("reverb_send=")); |
|
|
|
|
|
|
|
Serial.println(drum_config[drum].reverb_send); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
drum++; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|