Fixing bank upload.

pull/32/head
Holger Wirtz 5 years ago
parent 1ff6ea3d5f
commit f29d26d7d6
  1. 129
      MicroDexed.ino
  2. 35
      UI.hpp
  3. 4
      config.h
  4. 32
      dexed_sd.cpp

@ -1151,76 +1151,105 @@ void handleSystemExclusive(byte * sysex, uint len)
LCDML.loop_menu(); LCDML.loop_menu();
} }
} }
else if (len == 4104 && strlen(receive_bank_filename) > 0 && LCDML.FUNC_getID() == LCDML.OTHER_getIDFromFunction(UI_func_sysex_receive_bank)) else if (len == 4104)
{ {
int32_t bulk_checksum_calc = 0; if (strlen(receive_bank_filename) > 0 && LCDML.FUNC_getID() == LCDML.OTHER_getIDFromFunction(UI_func_sysex_receive_bank))
int8_t bulk_checksum = sysex[4102]; {
int32_t bulk_checksum_calc = 0;
int8_t bulk_checksum = sysex[4102];
// 1 Bank bulk upload // 1 Bank bulk upload
if ((sysex[3] & 0x7f) != 9)
{
#ifdef DEBUG #ifdef DEBUG
Serial.println(F("Bank bulk upload")); Serial.println(F("E: Not a SysEx bank bulk upload."));
#endif #endif
lcd.setCursor(0, 1);
lcd.print(F("Error (TYPE) "));
delay(MESSAGE_WAIT_TIME);
LCDML.FUNC_goBackToMenu();
return;
}
if ((sysex[3] & 0x7f) != 9)
{
#ifdef DEBUG #ifdef DEBUG
Serial.println(F("E: Not a SysEx bank bulk upload.")); Serial.println(F("Bank bulk upload."));
#endif #endif
return;
}
if (((sysex[4] << 7) | sysex[5]) != 0x1000) if (((sysex[4] << 7) | sysex[5]) != 0x1000)
{ {
#ifdef DEBUG #ifdef DEBUG
Serial.println(F("E: Wrong length for SysEx bank bulk upload (not 4096).")); Serial.println(F("E: Wrong length for SysEx bank bulk upload (not 4096)."));
#endif #endif
return; lcd.setCursor(0, 1);
} lcd.print(F("Error (SIZE) "));
delay(MESSAGE_WAIT_TIME);
LCDML.FUNC_goBackToMenu();
return;
}
// checksum calculation #ifdef DEBUG
for (uint8_t i = 0; i < 4096 ; i++) Serial.println(F("Bank type ok"));
{ #endif
bulk_checksum_calc -= sysex[i + 6];
}
bulk_checksum_calc &= 0x7f;
if (bulk_checksum_calc != bulk_checksum) // checksum calculation
{ for (uint16_t i = 0; i < 4096 ; i++)
{
bulk_checksum_calc -= sysex[i + 6];
}
bulk_checksum_calc &= 0x7f;
if (bulk_checksum_calc != bulk_checksum)
{
#ifdef DEBUG #ifdef DEBUG
Serial.print(F("E: Checksum error for bank [0x")); Serial.print(F("E: Checksum error for bank [0x"));
Serial.print(bulk_checksum, HEX); Serial.print(bulk_checksum, HEX);
Serial.print(F("/0x")); Serial.print(F("/0x"));
Serial.print(bulk_checksum_calc, HEX); Serial.print(bulk_checksum_calc, HEX);
Serial.println(F("]")); Serial.println(F("]"));
#endif
lcd.setCursor(0, 1);
lcd.print(F("Error (CHECKSUM)"));
delay(MESSAGE_WAIT_TIME);
LCDML.FUNC_goBackToMenu();
return;
}
#ifdef DEBUG
Serial.println(F("Bank checksum ok"));
#endif #endif
return;
}
if (save_sd_bank(receive_bank_filename, sysex)) if (save_sd_bank(receive_bank_filename, sysex))
{ {
#ifdef DEBUG #ifdef DEBUG
Serial.print(F("Bank saved as [")); Serial.print(F("Bank saved as ["));
Serial.print(receive_bank_filename); Serial.print(receive_bank_filename);
Serial.println(F("]")); Serial.println(F("]"));
#endif #endif
lcd.setCursor(0, 1); lcd.setCursor(0, 1);
lcd.print(F("Done. ")); lcd.print(F("Done. "));
delay(MESSAGE_WAIT_TIME); delay(MESSAGE_WAIT_TIME);
LCDML.FUNC_goBackToMenu(); LCDML.FUNC_goBackToMenu();
} //if (!get_bank_name(bank_number, bank_name, sizeof(bank_name)))
else // strncpy(bank_name, "*ERROR*", 7);
{ }
else
{
#ifdef DEBUG #ifdef DEBUG
Serial.println(F("Error during saving bank as [")); Serial.println(F("Error during saving bank as ["));
Serial.print(receive_bank_filename); Serial.print(receive_bank_filename);
Serial.println(F("]")); Serial.println(F("]"));
#endif #endif
lcd.setCursor(0, 1); lcd.setCursor(0, 1);
lcd.print(F("Error. ")); lcd.print(F("Error. "));
delay(MESSAGE_WAIT_TIME); delay(MESSAGE_WAIT_TIME);
LCDML.FUNC_goBackToMenu(); LCDML.FUNC_goBackToMenu();
}
memset(receive_bank_filename, 0, FILENAME_LEN);
} }
memset(receive_bank_filename, 0, FILENAME_LEN); #ifdef DEBUG
else
Serial.println(F("E: Not in MIDI receive bank mode."));
#endif
} }
#ifdef DEBUG #ifdef DEBUG
else else

@ -266,6 +266,7 @@ void lcd_active_instance_number(uint8_t instance_id);
void lcd_OP_active_instance_number(uint8_t instance_id, uint8_t op); void lcd_OP_active_instance_number(uint8_t instance_id, uint8_t op);
void lcd_special_chars(uint8_t mode); void lcd_special_chars(uint8_t mode);
void eeprom_update_var(uint16_t pos, uint8_t val, const char* val_string); void eeprom_update_var(uint16_t pos, uint8_t val, const char* val_string);
void string_trim(char *s);
// normal menu // normal menu
LCDMenuLib2_menu LCDML_0(255, 0, 0, NULL, NULL); // normal root menu element (do not change) LCDMenuLib2_menu LCDML_0(255, 0, 0, NULL, NULL); // normal root menu element (do not change)
@ -4693,13 +4694,14 @@ void UI_func_sysex_receive_bank(uint8_t param)
yesno = false; yesno = false;
mode = 0; mode = 0;
bank_number = configuration.performance.bank[selected_instance_id]; bank_number = configuration.performance.bank[selected_instance_id];
memset(receive_bank_filename, 0, sizeof(receive_bank_filename));
lcd.setCursor(0, 0); lcd.setCursor(0, 0);
lcd.print(F("MIDI Recv Bank")); lcd.print(F("MIDI Recv Bank"));
lcd.setCursor(0, 1); lcd.setCursor(0, 1);
lcd.print(F("[ ]")); lcd.print(F("[ ]"));
if (!get_bank_name(configuration.performance.bank[selected_instance_id], receive_bank_filename, sizeof(receive_bank_filename))) if (!get_bank_name(configuration.performance.bank[selected_instance_id], receive_bank_filename, sizeof(receive_bank_filename)))
strncpy(receive_bank_filename, "*ERROR*", sizeof(receive_bank_filename)); strncpy(receive_bank_filename, "*ERROR*", 7);
lcd.show(1, 1, 2, bank_number); lcd.show(1, 1, 2, bank_number);
lcd.show(1, 5, 10, receive_bank_filename); lcd.show(1, 5, 10, receive_bank_filename);
} }
@ -4715,7 +4717,7 @@ void UI_func_sysex_receive_bank(uint8_t param)
case 0: case 0:
bank_number = constrain(bank_number + ENCODER[ENC_R].speed(), 0, MAX_BANKS - 1); bank_number = constrain(bank_number + ENCODER[ENC_R].speed(), 0, MAX_BANKS - 1);
if (!get_bank_name(bank_number, receive_bank_filename, sizeof(receive_bank_filename))) if (!get_bank_name(bank_number, receive_bank_filename, sizeof(receive_bank_filename)))
strncpy(receive_bank_filename, "*ERROR*", sizeof(receive_bank_filename)); strncpy(receive_bank_filename, "*ERROR*", 7);
lcd.show(1, 1, 2, bank_number); lcd.show(1, 1, 2, bank_number);
lcd.show(1, 5, 10, receive_bank_filename); lcd.show(1, 5, 10, receive_bank_filename);
break; break;
@ -4762,7 +4764,7 @@ void UI_func_sysex_receive_bank(uint8_t param)
if (!strncmp(receive_bank_filename, "*ERROR*", sizeof(receive_bank_filename))) if (!strncmp(receive_bank_filename, "*ERROR*", sizeof(receive_bank_filename)))
{ {
yesno = true; yesno = true;
strncpy(receive_bank_filename, "EMPTY", BANK_NAME_LEN); strncpy(receive_bank_filename, "NONAME", 6);
mode += 2; mode += 2;
lcd.blink(); lcd.blink();
} }
@ -4788,8 +4790,22 @@ void UI_func_sysex_receive_bank(uint8_t param)
{ {
if (yesno == true) if (yesno == true)
{ {
#ifdef DEBUG
Serial.print(F("Bank name: ["));
Serial.print(receive_bank_filename);
Serial.println(F("]"));
#endif
char tmp[FILENAME_LEN];
strncpy(tmp, receive_bank_filename, strlen(receive_bank_filename));
sprintf(receive_bank_filename, "/%d/%s.syx", bank_number, tmp);
#ifdef DEBUG
Serial.print(F("Receiving into bank "));
Serial.print(bank_number);
Serial.print(F(" as filename "));
Serial.print(receive_bank_filename);
Serial.println(F("."));
#endif
mode = 0xff; mode = 0xff;
lcd.noBlink(); lcd.noBlink();
lcd.setCursor(0, 1); lcd.setCursor(0, 1);
lcd.print(F("Waiting... ")); lcd.print(F("Waiting... "));
@ -5133,6 +5149,8 @@ bool UI_select_name(uint8_t y, uint8_t x, char* edit_string, uint8_t len, bool i
{ {
edit_pos = 0; edit_pos = 0;
edit_mode = false; edit_mode = false;
string_trim(edit_string);
return (true); return (true);
} }
else else
@ -5467,5 +5485,14 @@ void eeprom_update_var(uint16_t pos, uint8_t val, const char* val_string)
EEPROM.update(EEPROM_START_ADDRESS + pos, val); EEPROM.update(EEPROM_START_ADDRESS + pos, val);
} }
void string_trim(char *s)
{
int i;
while (isspace (*s)) s++; // skip left side white spaces
for (i = strlen (s) - 1; (isspace (s[i])); i--) ; // skip right side white spaces
s[i + 1] = '\0';
}
#endif #endif
#endif #endif

@ -45,7 +45,8 @@
// //
// e.g.: // e.g.:
// * sendmidi dev "MicroDexed MIDI" on 80 127 && sleep 1.0 && sendmidi dev "MicroDexed MIDI" off 80 0 // * sendmidi dev "MicroDexed MIDI" on 80 127 && sleep 1.0 && sendmidi dev "MicroDexed MIDI" off 80 0
// * sendmidi dev "MicroDexed MIDI" syx syf addon/SD/90/RitCh1.syx // * sendmidi dev "MicroDexed MIDI" syf addon/SD/90/RitCh1.syx
// * amidi -p hw:2,0,0 -s addon/SD/90/RitCh1.syx
// //
// Receiving and storing MIDI SYSEX with Linux: // Receiving and storing MIDI SYSEX with Linux:
// amidi -p hw:2,0,0 -d -r /tmp/bkup1.syx // amidi -p hw:2,0,0 -d -r /tmp/bkup1.syx
@ -53,6 +54,7 @@
// For SYSEX Bank upload via USB: // For SYSEX Bank upload via USB:
// sed -i.orig 's/SYSEX_MAX_LEN = 290/SYSEX_MAX_LEN = 4104/' /usr/local/arduino-teensy-1.8.12/hardware/teensy/avr/libraries/USBHost_t36/USBHost_t36.h // sed -i.orig 's/SYSEX_MAX_LEN = 290/SYSEX_MAX_LEN = 4104/' /usr/local/arduino-teensy-1.8.12/hardware/teensy/avr/libraries/USBHost_t36/USBHost_t36.h
// sed -i.orig 's/^#define USB_MIDI_SYSEX_MAX 290/#define USB_MIDI_SYSEX_MAX 4104/' /usr/local/arduino-teensy-1.8.12/hardware/teensy/avr/cores/teensy3/usb_midi.h // sed -i.orig 's/^#define USB_MIDI_SYSEX_MAX 290/#define USB_MIDI_SYSEX_MAX 4104/' /usr/local/arduino-teensy-1.8.12/hardware/teensy/avr/cores/teensy3/usb_midi.h
#define USB_MIDI_SYSEX_MAX 4104
#define VERSION "0.9.9k" #define VERSION "0.9.9k"

@ -292,11 +292,18 @@ bool put_sd_voice(File sysex, uint8_t voice_number, uint8_t* data)
bool save_sd_bank(const char* bank_filename, uint8_t* data) bool save_sd_bank(const char* bank_filename, uint8_t* data)
{ {
char tmp[FILENAME_LEN]; char tmp[FILENAME_LEN];
char tmp2[FILENAME_LEN];
int bank_number; int bank_number;
File root, entry; File root, entry;
if (sd_card > 0) if (sd_card > 0)
{ {
#ifdef DEBUG
Serial.print(F("Trying so store "));
Serial.print(bank_filename);
Serial.println(F("."));
#endif
// first remove old bank // first remove old bank
sscanf(bank_filename, "/%d/%s", &bank_number, tmp); sscanf(bank_filename, "/%d/%s", &bank_number, tmp);
sprintf(tmp, "/%d", bank_number); sprintf(tmp, "/%d", bank_number);
@ -314,8 +321,20 @@ bool save_sd_bank(const char* bank_filename, uint8_t* data)
Serial.print(F("/")); Serial.print(F("/"));
Serial.println(entry.name()); Serial.println(entry.name());
#endif #endif
SD.remove(entry.name()); sprintf(tmp2, "%s/%s", tmp, entry.name());
entry.close(); entry.close();
#ifndef DEBUG
SD.remove(tmp2);
#else
bool r = SD.remove(tmp2);
if (r == false)
{
Serial.print(F("E: cannot remove "));
Serial.print(tmp2);
Serial.println(F("."));
}
#endif
break;
} }
} }
else else
@ -326,13 +345,16 @@ bool save_sd_bank(const char* bank_filename, uint8_t* data)
root.close(); root.close();
// store new bank at /<b>/<bank_name>.syx // store new bank at /<b>/<bank_name>.syx
root = SD.open(bank_filename);
root.write(data, 4104);
root.close();
#ifdef DEBUG #ifdef DEBUG
Serial.print(F("Storing bank as ")); Serial.print(F("Storing bank as "));
Serial.print(bank_filename); Serial.print(bank_filename);
Serial.println(F(".")); Serial.print(F("..."));
#endif
root = SD.open(bank_filename, FILE_WRITE);
root.write(data, 4104);
root.close();
#ifdef DEBUG
Serial.println(F(" done."));
#endif #endif
} }
else else

Loading…
Cancel
Save