|
|
@ -32,135 +32,236 @@ |
|
|
|
#include "config.h" |
|
|
|
#include "config.h" |
|
|
|
#include "UI.h" |
|
|
|
#include "UI.h" |
|
|
|
|
|
|
|
|
|
|
|
bool get_bank_voice_name(uint8_t b, uint8_t v) |
|
|
|
void create_sysex_filename(uint8_t b, char* sysex_file_name) |
|
|
|
{ |
|
|
|
{ |
|
|
|
File root; |
|
|
|
// init and set name for actual bank
|
|
|
|
|
|
|
|
memset(sysex_file_name, 0, 4 + VOICE_NAME_LEN); |
|
|
|
|
|
|
|
sysex_file_name[0] = '/'; |
|
|
|
|
|
|
|
itoa(b, &sysex_file_name[1], 10); |
|
|
|
|
|
|
|
strcat(sysex_file_name, "/"); |
|
|
|
|
|
|
|
strcat(sysex_file_name, bank_names[b]); |
|
|
|
|
|
|
|
#ifdef DEBUG |
|
|
|
|
|
|
|
Serial.print(F("Created sysex_filename from bank ")); |
|
|
|
|
|
|
|
Serial.print(b, DEC); |
|
|
|
|
|
|
|
Serial.print(F(" and name ")); |
|
|
|
|
|
|
|
Serial.print(bank_names[b]); |
|
|
|
|
|
|
|
Serial.print(F(": [")); |
|
|
|
|
|
|
|
Serial.print(sysex_file_name); |
|
|
|
|
|
|
|
Serial.println(F("]")); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void strip_extension(char* s, char* target) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
char tmp[BANK_NAME_LEN]; |
|
|
|
|
|
|
|
char* token; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
strcpy(tmp,s); |
|
|
|
|
|
|
|
token = strtok(tmp, "."); |
|
|
|
|
|
|
|
if (token == NULL) |
|
|
|
|
|
|
|
strcpy(target, "*ERROR*"); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
strcpy(target, token); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool get_voice_names_from_bank(uint8_t b) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
File sysex; |
|
|
|
|
|
|
|
uint8_t voice_counter = 0; |
|
|
|
|
|
|
|
int32_t bulk_checksum_calc = 0; |
|
|
|
|
|
|
|
int8_t bulk_checksum; |
|
|
|
|
|
|
|
|
|
|
|
b %= MAX_BANKS; |
|
|
|
b %= MAX_BANKS; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// erase all data for voice names
|
|
|
|
|
|
|
|
memset(voice_names, 0, MAX_VOICES * VOICE_NAME_LEN); |
|
|
|
|
|
|
|
|
|
|
|
if (sd_card_available) |
|
|
|
if (sd_card_available) |
|
|
|
{ |
|
|
|
{ |
|
|
|
char bankdir[4]; |
|
|
|
char sysex_file_name[4 + VOICE_NAME_LEN]; |
|
|
|
|
|
|
|
|
|
|
|
memset(bankdir, 0, sizeof(bankdir)); |
|
|
|
// init and set name for actual bank
|
|
|
|
bankdir[0] = '/'; |
|
|
|
create_sysex_filename(b, sysex_file_name); |
|
|
|
itoa(b, &bankdir[1], 10); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
root = SD.open(bankdir); |
|
|
|
#ifdef DEBUG |
|
|
|
if (!root) |
|
|
|
Serial.print(F("Reading voice names for bank [")); |
|
|
|
|
|
|
|
Serial.print(sysex_file_name); |
|
|
|
|
|
|
|
Serial.println(F("]")); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// try to open bank directory
|
|
|
|
|
|
|
|
sysex = SD.open(sysex_file_name); |
|
|
|
|
|
|
|
if (!sysex) |
|
|
|
|
|
|
|
return (false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (sysex.size() != 4104) // check sysex size
|
|
|
|
{ |
|
|
|
{ |
|
|
|
#ifdef DEBUG |
|
|
|
#ifdef DEBUG |
|
|
|
Serial.println(F("E: Cannot open main dir from SD.")); |
|
|
|
Serial.println(F("E : SysEx file size wrong.")); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
return (false); |
|
|
|
return (false); |
|
|
|
} |
|
|
|
} |
|
|
|
while (42 == 42) |
|
|
|
if (sysex.read() != 0xf0) // check sysex start-byte
|
|
|
|
{ |
|
|
|
{ |
|
|
|
File entry = root.openNextFile(); |
|
|
|
#ifdef DEBUG |
|
|
|
if (!entry) |
|
|
|
Serial.println(F("E : SysEx start byte not found.")); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
return (false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (sysex.read() != 0x43) // check sysex vendor is Yamaha
|
|
|
|
{ |
|
|
|
{ |
|
|
|
// No more files
|
|
|
|
#ifdef DEBUG |
|
|
|
break; |
|
|
|
Serial.println(F("E : SysEx vendor not Yamaha.")); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
return (false); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
sysex.seek(4103); |
|
|
|
|
|
|
|
if (sysex.read() != 0xf7) // check sysex end-byte
|
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!entry.isDirectory()) |
|
|
|
#ifdef DEBUG |
|
|
|
|
|
|
|
Serial.println(F("E : SysEx end byte not found.")); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
return (false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
sysex.seek(3); |
|
|
|
|
|
|
|
if (sysex.read() != 0x09) // check for sysex type (0x09=32 voices)
|
|
|
|
{ |
|
|
|
{ |
|
|
|
char *token; |
|
|
|
#ifdef DEBUG |
|
|
|
uint8_t data[128]; |
|
|
|
Serial.println(F("E : SysEx type not 32 voices.")); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
return (false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
sysex.seek(4102); // Bulk checksum
|
|
|
|
|
|
|
|
bulk_checksum = sysex.read(); |
|
|
|
|
|
|
|
|
|
|
|
if (get_sysex_voice(bankdir, entry, v, data)) |
|
|
|
sysex.seek(6); // start of bulk data
|
|
|
|
strncpy(voice_name, (char*)&data[118], 10); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
strcpy(voice_name, "*ERROR*"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
token = strtok(entry.name(), "."); |
|
|
|
for (uint16_t n = 0; n < 4096; n++) |
|
|
|
if (token == NULL) |
|
|
|
{ |
|
|
|
strcpy(bank_name, "*ERROR*"); |
|
|
|
uint8_t d = sysex.read(); |
|
|
|
else |
|
|
|
|
|
|
|
strcpy(bank_name, token); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (true); |
|
|
|
if ((n % 128) >= 118 && (n % 128) < 128) // found the start of the voicename
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
voice_names[voice_counter][(n % 128) - 118] = d; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (n % 128 == 127) |
|
|
|
|
|
|
|
voice_counter++; |
|
|
|
|
|
|
|
bulk_checksum_calc -= d; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
bulk_checksum_calc &= 0x7f; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG |
|
|
|
|
|
|
|
Serial.print(F("Bulk checksum : 0x")); |
|
|
|
|
|
|
|
Serial.print(bulk_checksum_calc, HEX); |
|
|
|
|
|
|
|
Serial.print(F(" [0x")); |
|
|
|
|
|
|
|
Serial.print(bulk_checksum, HEX); |
|
|
|
|
|
|
|
Serial.println(F("]")); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (bulk_checksum_calc != bulk_checksum) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
#ifdef DEBUG |
|
|
|
|
|
|
|
Serial.print(F("E : Bulk checksum mismatch : 0x")); |
|
|
|
|
|
|
|
Serial.print(bulk_checksum_calc, HEX); |
|
|
|
|
|
|
|
Serial.print(F(" != 0x")); |
|
|
|
|
|
|
|
Serial.println(bulk_checksum, HEX); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
return (false); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
return (false); |
|
|
|
return (false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool load_sysex(uint8_t b, uint8_t v) |
|
|
|
uint8_t get_bank_names(void) |
|
|
|
{ |
|
|
|
{ |
|
|
|
File root; |
|
|
|
File root; |
|
|
|
bool found = false; |
|
|
|
uint8_t bank_counter = 0; |
|
|
|
|
|
|
|
|
|
|
|
v %= MAX_VOICES; |
|
|
|
// erase all data for bank names
|
|
|
|
b %= MAX_BANKS; |
|
|
|
memset(bank_names, 0, MAX_BANKS * BANK_NAME_LEN); |
|
|
|
|
|
|
|
|
|
|
|
if (sd_card_available) |
|
|
|
if (sd_card_available) |
|
|
|
{ |
|
|
|
{ |
|
|
|
char bankdir[4]; |
|
|
|
char bankdir[4]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
do |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// init and set name for actual bank directory
|
|
|
|
memset(bankdir, 0, sizeof(bankdir)); |
|
|
|
memset(bankdir, 0, sizeof(bankdir)); |
|
|
|
bankdir[0] = '/'; |
|
|
|
bankdir[0] = '/'; |
|
|
|
itoa(b, &bankdir[1], 10); |
|
|
|
itoa(bank_counter, &bankdir[1], 10); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// try to open directory
|
|
|
|
root = SD.open(bankdir); |
|
|
|
root = SD.open(bankdir); |
|
|
|
if (!root) |
|
|
|
if (!root) |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// read filenames
|
|
|
|
|
|
|
|
File entry = root.openNextFile(); |
|
|
|
|
|
|
|
if (!entry.isDirectory()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
strcpy(bank_names[bank_counter], entry.name()); |
|
|
|
#ifdef DEBUG |
|
|
|
#ifdef DEBUG |
|
|
|
Serial.println(F("E: Cannot open main dir from SD.")); |
|
|
|
Serial.print(F("Found bank [")); |
|
|
|
|
|
|
|
Serial.print(bank_names[bank_counter]); |
|
|
|
|
|
|
|
Serial.println(F("]")); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
return (false); |
|
|
|
bank_counter++; |
|
|
|
} |
|
|
|
} |
|
|
|
while (42 == 42) |
|
|
|
} while (root); |
|
|
|
{ |
|
|
|
|
|
|
|
File entry = root.openNextFile(); |
|
|
|
return (bank_counter); |
|
|
|
if (!entry) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// No more files
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
|
|
|
|
return (bank_counter); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool load_sysex(uint8_t b, uint8_t v) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!entry.isDirectory()) |
|
|
|
bool found = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v %= MAX_VOICES; |
|
|
|
|
|
|
|
b %= MAX_BANKS; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (sd_card_available) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
File sysex; |
|
|
|
|
|
|
|
char sysex_file_name[4 + VOICE_NAME_LEN]; |
|
|
|
uint8_t data[128]; |
|
|
|
uint8_t data[128]; |
|
|
|
found = true; |
|
|
|
|
|
|
|
if (get_sysex_voice(bankdir, entry, v, data)) |
|
|
|
create_sysex_filename(b, sysex_file_name); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sysex = SD.open(sysex_file_name); |
|
|
|
|
|
|
|
if (!sysex) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
#ifdef DEBUG |
|
|
|
|
|
|
|
Serial.print(F("E : Cannot open ")); |
|
|
|
|
|
|
|
Serial.print(sysex_file_name); |
|
|
|
|
|
|
|
Serial.println(F("from SD.")); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
return (false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (get_sysex_voice(sysex, v, data)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
#ifdef DEBUG |
|
|
|
#ifdef DEBUG |
|
|
|
char n[11]; |
|
|
|
char n[11]; |
|
|
|
|
|
|
|
|
|
|
|
strncpy(n, (char*)&data[118], 10); |
|
|
|
strncpy(n, (char*)&data[118], 10); |
|
|
|
Serial.print("Loading sysex "); |
|
|
|
Serial.print("Loading sysex "); |
|
|
|
Serial.print(bankdir); |
|
|
|
Serial.print(sysex_file_name); |
|
|
|
Serial.print("/"); |
|
|
|
|
|
|
|
Serial.print(entry.name()); |
|
|
|
|
|
|
|
Serial.print(F(" [")); |
|
|
|
Serial.print(F(" [")); |
|
|
|
Serial.print(n); |
|
|
|
Serial.print(voice_names[v]); |
|
|
|
Serial.println(F("]")); |
|
|
|
Serial.println(F(" [")); |
|
|
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
#endif |
|
|
|
char *token; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
token = strtok(entry.name(), "."); |
|
|
|
|
|
|
|
if (token != NULL) |
|
|
|
|
|
|
|
strcpy(bank_name, token); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
strcpy(bank_name, "*ERROR*"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (dexed->loadSysexVoice(data)); |
|
|
|
return (dexed->loadSysexVoice(data)); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
#ifdef DEBUG |
|
|
|
#ifdef DEBUG |
|
|
|
Serial.println(F("E : Cannot load voice data")); |
|
|
|
Serial.println(F("E : Cannot load voice data")); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
entry.close(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG |
|
|
|
#ifdef DEBUG |
|
|
|
if (found == false) |
|
|
|
if (found == false) |
|
|
|
Serial.println(F("E : File not found.")); |
|
|
|
Serial.println(F("E : File not found.")); |
|
|
@ -169,17 +270,11 @@ bool load_sysex(uint8_t b, uint8_t v) |
|
|
|
return (false); |
|
|
|
return (false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool get_sysex_voice(char* dir, File sysex, uint8_t voice_number, uint8_t* data) |
|
|
|
bool get_sysex_voice(File sysex, uint8_t voice_number, uint8_t* data) |
|
|
|
{ |
|
|
|
{ |
|
|
|
File file; |
|
|
|
|
|
|
|
uint16_t n; |
|
|
|
uint16_t n; |
|
|
|
int32_t bulk_checksum_calc = 0; |
|
|
|
int32_t bulk_checksum_calc = 0; |
|
|
|
int8_t bulk_checksum; |
|
|
|
int8_t bulk_checksum; |
|
|
|
char sysex_file[20]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
strcpy(sysex_file, dir); |
|
|
|
|
|
|
|
strcat(sysex_file, "/"); |
|
|
|
|
|
|
|
strcat(sysex_file, sysex.name()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (sysex.size() != 4104) // check sysex size
|
|
|
|
if (sysex.size() != 4104) // check sysex size
|
|
|
|
{ |
|
|
|
{ |
|
|
@ -188,45 +283,43 @@ bool get_sysex_voice(char* dir, File sysex, uint8_t voice_number, uint8_t* data) |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
return (false); |
|
|
|
return (false); |
|
|
|
} |
|
|
|
} |
|
|
|
if (file = SD.open(sysex_file)) |
|
|
|
if (sysex.read() != 0xf0) // check sysex start-byte
|
|
|
|
{ |
|
|
|
|
|
|
|
if (file.read() != 0xf0) // check sysex start-byte
|
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
#ifdef DEBUG |
|
|
|
#ifdef DEBUG |
|
|
|
Serial.println(F("E : SysEx start byte not found.")); |
|
|
|
Serial.println(F("E : SysEx start byte not found.")); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
return (false); |
|
|
|
return (false); |
|
|
|
} |
|
|
|
} |
|
|
|
if (file.read() != 0x43) // check sysex vendor is Yamaha
|
|
|
|
if (sysex.read() != 0x43) // check sysex vendor is Yamaha
|
|
|
|
{ |
|
|
|
{ |
|
|
|
#ifdef DEBUG |
|
|
|
#ifdef DEBUG |
|
|
|
Serial.println(F("E : SysEx vendor not Yamaha.")); |
|
|
|
Serial.println(F("E : SysEx vendor not Yamaha.")); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
return (false); |
|
|
|
return (false); |
|
|
|
} |
|
|
|
} |
|
|
|
file.seek(4103); |
|
|
|
sysex.seek(4103); |
|
|
|
if (file.read() != 0xf7) // check sysex end-byte
|
|
|
|
if (sysex.read() != 0xf7) // check sysex end-byte
|
|
|
|
{ |
|
|
|
{ |
|
|
|
#ifdef DEBUG |
|
|
|
#ifdef DEBUG |
|
|
|
Serial.println(F("E : SysEx end byte not found.")); |
|
|
|
Serial.println(F("E : SysEx end byte not found.")); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
return (false); |
|
|
|
return (false); |
|
|
|
} |
|
|
|
} |
|
|
|
file.seek(3); |
|
|
|
sysex.seek(3); |
|
|
|
if (file.read() != 0x09) // check for sysex type (0x09=32 voices)
|
|
|
|
if (sysex.read() != 0x09) // check for sysex type (0x09=32 voices)
|
|
|
|
{ |
|
|
|
{ |
|
|
|
#ifdef DEBUG |
|
|
|
#ifdef DEBUG |
|
|
|
Serial.println(F("E : SysEx type not 32 voices.")); |
|
|
|
Serial.println(F("E : SysEx type not 32 voices.")); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
return (false); |
|
|
|
return (false); |
|
|
|
} |
|
|
|
} |
|
|
|
file.seek(4102); // Bulk checksum
|
|
|
|
sysex.seek(4102); // Bulk checksum
|
|
|
|
bulk_checksum = file.read(); |
|
|
|
bulk_checksum = sysex.read(); |
|
|
|
|
|
|
|
|
|
|
|
file.seek(6); // start of bulk data
|
|
|
|
sysex.seek(6); // start of bulk data
|
|
|
|
for (n = 0; n < 4096; n++) |
|
|
|
for (n = 0; n < 4096; n++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
uint8_t d = file.read(); |
|
|
|
uint8_t d = sysex.read(); |
|
|
|
if (n >= voice_number * 128 && n < (voice_number + 1) * 128) |
|
|
|
if (n >= voice_number * 128 && n < (voice_number + 1) * 128) |
|
|
|
{ |
|
|
|
{ |
|
|
|
data[n - (voice_number * 128)] = d; |
|
|
|
data[n - (voice_number * 128)] = d; |
|
|
@ -253,14 +346,6 @@ bool get_sysex_voice(char* dir, File sysex, uint8_t voice_number, uint8_t* data) |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
return (false); |
|
|
|
return (false); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#ifdef DEBUG |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Serial.print(F("Cannot open ")); |
|
|
|
|
|
|
|
Serial.println(sysex.name()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
render_time_max = 0; |
|
|
|
render_time_max = 0; |
|
|
|
|
|
|
|
|
|
|
|