diff --git a/MicroDexed.ino b/MicroDexed.ino index 8f8ae99..61772e0 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -721,7 +721,7 @@ void handleSystemExclusive(byte * sysex, uint len) Serial.print(voice_name); Serial.print(F("] loaded.")); - dexed->loadSysexVoice(tmp_data); + dexed->loadVoiceParameters(tmp_data); } #ifdef DEBUG else diff --git a/dexed.cpp b/dexed.cpp index 16a830d..b637fc7 100644 --- a/dexed.cpp +++ b/dexed.cpp @@ -425,7 +425,7 @@ uint8_t Dexed::getNumNotesPlaying(void) return (count_playing_voices); } -bool Dexed::loadSysexVoice(uint8_t* new_data) +bool Dexed::loadVoiceParameters(uint8_t* data) { uint8_t* p_data = data; uint8_t op; @@ -446,21 +446,21 @@ bool Dexed::loadSysexVoice(uint8_t* new_data) // DEXED_OP_LEV_SCL_BRK_PT, // 8 // DEXED_OP_SCL_LEFT_DEPTH, // 9 // DEXED_OP_SCL_RGHT_DEPTH, // 10 - memcpy(&data[op * 21], &new_data[op * 17], 11); - tmp = new_data[(op * 17) + 11]; + memcpy(&data[op * 21], &data[op * 17], 11); + tmp = data[(op * 17) + 11]; *(p_data + DEXED_OP_SCL_LEFT_CURVE + (op * 21)) = (tmp & 0x3); *(p_data + DEXED_OP_SCL_RGHT_CURVE + (op * 21)) = (tmp & 0x0c) >> 2; - tmp = new_data[(op * 17) + 12]; + tmp = data[(op * 17) + 12]; *(p_data + DEXED_OP_OSC_DETUNE + (op * 21)) = (tmp & 0x78) >> 3; *(p_data + DEXED_OP_OSC_RATE_SCALE + (op * 21)) = (tmp & 0x07); - tmp = new_data[(op * 17) + 13]; + tmp = data[(op * 17) + 13]; *(p_data + DEXED_OP_KEY_VEL_SENS + (op * 21)) = (tmp & 0x1c) >> 2; *(p_data + DEXED_OP_AMP_MOD_SENS + (op * 21)) = (tmp & 0x03); - *(p_data + DEXED_OP_OUTPUT_LEV + (op * 21)) = new_data[(op * 17) + 14]; - tmp = new_data[(op * 17) + 15]; + *(p_data + DEXED_OP_OUTPUT_LEV + (op * 21)) = data[(op * 17) + 14]; + tmp = data[(op * 17) + 15]; *(p_data + DEXED_OP_FREQ_COARSE + (op * 21)) = (tmp & 0x3e) >> 1; *(p_data + DEXED_OP_OSC_MODE + (op * 21)) = (tmp & 0x01); - *(p_data + DEXED_OP_FREQ_FINE + (op * 21)) = new_data[(op * 17) + 16]; + *(p_data + DEXED_OP_FREQ_FINE + (op * 21)) = data[(op * 17) + 16]; } // DEXED_PITCH_EG_R1, // 0 // DEXED_PITCH_EG_R2, // 1 @@ -470,41 +470,42 @@ bool Dexed::loadSysexVoice(uint8_t* new_data) // DEXED_PITCH_EG_L2, // 5 // DEXED_PITCH_EG_L3, // 6 // DEXED_PITCH_EG_L4, // 7 - memcpy(&data[DEXED_VOICE_OFFSET], &new_data[102], 8); - tmp = new_data[110]; + memcpy(&data[DEXED_VOICE_OFFSET], &data[102], 8); + tmp = data[110]; *(p_data + DEXED_VOICE_OFFSET + DEXED_ALGORITHM) = (tmp & 0x1f); - tmp = new_data[111]; + tmp = data[111]; *(p_data + DEXED_VOICE_OFFSET + DEXED_OSC_KEY_SYNC) = (tmp & 0x08) >> 3; *(p_data + DEXED_VOICE_OFFSET + DEXED_FEEDBACK) = (tmp & 0x07); // DEXED_LFO_SPEED, // 11 // DEXED_LFO_DELAY, // 12 // DEXED_LFO_PITCH_MOD_DEP, // 13 // DEXED_LFO_AMP_MOD_DEP, // 14 - memcpy(&data[DEXED_VOICE_OFFSET + DEXED_LFO_SPEED], &new_data[112], 4); - tmp = new_data[116]; + memcpy(&data[DEXED_VOICE_OFFSET + DEXED_LFO_SPEED], &data[112], 4); + tmp = data[116]; *(p_data + DEXED_VOICE_OFFSET + DEXED_LFO_PITCH_MOD_SENS) = (tmp & 0x30) >> 4; *(p_data + DEXED_VOICE_OFFSET + DEXED_LFO_WAVE) = (tmp & 0x0e) >> 1; *(p_data + DEXED_VOICE_OFFSET + DEXED_LFO_SYNC) = (tmp & 0x01); - *(p_data + DEXED_VOICE_OFFSET + DEXED_TRANSPOSE) = new_data[117]; - memcpy(&data[DEXED_VOICE_OFFSET + DEXED_NAME], &new_data[118], 10); - *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_PITCHBEND_RANGE) = 1; - *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_PITCHBEND_STEP) = 1; - *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_MODWHEEL_RANGE) = 99; - *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_MODWHEEL_ASSIGN) = 7; - *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_FOOTCTRL_RANGE) = 99; - *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_FOOTCTRL_ASSIGN) = 7; - *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_BREATHCTRL_RANGE) = 99; - *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_BREATHCTRL_ASSIGN) = 7; - *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_AT_RANGE) = 99; - *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_AT_ASSIGN) = 7; - *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_MASTER_TUNE) = 0; - *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_OP1_ENABLE) = 1; - *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_OP2_ENABLE) = 1; - *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_OP3_ENABLE) = 1; - *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_OP4_ENABLE) = 1; - *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_OP5_ENABLE) = 1; - *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_OP6_ENABLE) = 1; - *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_MAX_NOTES) = MAX_NOTES; + *(p_data + DEXED_VOICE_OFFSET + DEXED_TRANSPOSE) = data[117]; + memcpy(&data[DEXED_VOICE_OFFSET + DEXED_NAME], &data[118], 10); + + //panic(); + doRefreshVoice(); + //activate(); + + strncpy(voice_name, (char *)&data[145], sizeof(voice_name) - 1); + +#ifdef DEBUG + Serial.print(F("Voice [")); + Serial.print(voice_name); + Serial.println(F("] loaded.")); +#endif + + return (true); +} + +bool Dexed::loadGlobalParameters(uint8_t* data) +{ + uint8_t* p_data = data; controllers.values_[kControllerPitchRange] = data[DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_PITCHBEND_RANGE]; controllers.values_[kControllerPitchStep] = data[DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_PITCHBEND_STEP]; @@ -526,22 +527,46 @@ bool Dexed::loadSysexVoice(uint8_t* new_data) (*(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_OP5_ENABLE) << 1) | *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_OP6_ENABLE )); setMaxNotes(*(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_MAX_NOTES)); + + setMaxNotes(*(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_MAX_NOTES)); //panic(); doRefreshVoice(); //activate(); - strncpy(voice_name, (char *)&data[145], sizeof(voice_name) - 1); #ifdef DEBUG - //char voicename[11]; - //memset(voicename, 0, sizeof(voicename)); - //strncpy(voicename, (char *)&data[145], sizeof(voicename) - 1); + Serial.println(F("Global parameters loaded.")); +#endif + return (true); +} - Serial.print(F("Voice [")); - //Serial.print(voicename); - Serial.print(voice_name); - Serial.println(F("] loaded.")); +bool Dexed::initGlobalParameters(void) +{ + uint8_t init_data[18]; + +#ifdef DEBUG + Serial.println(F("Initializing global parameters")); #endif + init_data[DEXED_PITCHBEND_RANGE] = 1; + init_data[DEXED_PITCHBEND_STEP] = 1; + init_data[DEXED_MODWHEEL_RANGE] = 99; + init_data[DEXED_MODWHEEL_ASSIGN] = 7; + init_data[DEXED_FOOTCTRL_RANGE] = 99; + init_data[DEXED_FOOTCTRL_ASSIGN] = 7; + init_data[DEXED_BREATHCTRL_RANGE] = 99; + init_data[DEXED_BREATHCTRL_ASSIGN] = 7; + init_data[DEXED_AT_RANGE] = 99; + init_data[DEXED_AT_ASSIGN] = 7; + init_data[DEXED_MASTER_TUNE] = 0; + init_data[DEXED_OP1_ENABLE] = 1; + init_data[DEXED_OP2_ENABLE] = 1; + init_data[DEXED_OP3_ENABLE] = 1; + init_data[DEXED_OP4_ENABLE] = 1; + init_data[DEXED_OP5_ENABLE] = 1; + init_data[DEXED_OP6_ENABLE] = 1; + init_data[DEXED_MAX_NOTES] = MAX_NOTES; + + loadGlobalParameters(init_data); return (true); } diff --git a/dexed.h b/dexed.h index 6188f1e..ee90bfa 100644 --- a/dexed.h +++ b/dexed.h @@ -156,7 +156,9 @@ class Dexed uint8_t getMaxNotes(void); void doRefreshVoice(void); void setOPs(uint8_t ops); - bool loadSysexVoice(uint8_t* data); + bool loadVoiceParameters(uint8_t* data); + bool loadGlobalParameters(uint8_t* data); + bool initGlobalParameters(void); void keyup(uint8_t pitch); void keydown(uint8_t pitch, uint8_t velo); void setSustain(bool sustain); diff --git a/dexed_sysex.cpp b/dexed_sysex.cpp index e1ec493..e80044b 100644 --- a/dexed_sysex.cpp +++ b/dexed_sysex.cpp @@ -256,7 +256,7 @@ bool load_sysex(uint8_t b, uint8_t v) Serial.print(voice_names[v]); Serial.println(F("]")); #endif - return (dexed->loadSysexVoice(data)); + return (dexed->loadVoiceParameters(data)); } #ifdef DEBUG else