From d58ad40ba6f74e621e4abc16122fdc7c304eb07a Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Fri, 1 Jun 2018 07:57:55 +0200 Subject: [PATCH] Isolated loading sysex from SD and moving sysex data into engine. --- .dexed_sysex.cpp.swp | Bin 16384 -> 0 bytes .swp | Bin 12288 -> 0 bytes MicroDexed.ino | 6 +- config.h | 33 +++++++--- dexed.cpp | 153 ++++++++++++++++++++++++++++++++++++------- dexed.h | 3 +- dexed_sysex.cpp | 138 ++++++-------------------------------- dexed_sysex.h | 48 +++++++------- 8 files changed, 202 insertions(+), 179 deletions(-) delete mode 100644 .dexed_sysex.cpp.swp delete mode 100644 .swp diff --git a/.dexed_sysex.cpp.swp b/.dexed_sysex.cpp.swp deleted file mode 100644 index f4db4db0e61b6aaefb4d506ffab5f79e55cc3041..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16384 zcmeI2+ixRR9mfwX3oX4t3q0`j+f+h!*6V9Fm(3={o7fw(PVCywF58tD#^d97$auz` z87Fa9ERWnJDj}hL*q2sCT&f~eAq46R5&|Ldzzap<4*;r_C`jCjDDXXJ#u?j*v+BMe z#2M-1%bef&&F_5AZ_a3bGtKms(k3k?(+u1D8TH5!!{dd`R z`(1ru;VwpKz9}81@@}hd+D>ZIG+bw$AMjSHB|bH8;PHc`(d*sam9kI@CQa~x76i^B%1(X6x0i}RaKq>IQtAO9TpM4hL-xm(S3%}nr z@%`^`tA+dhiT3-${~r#&e>%|~{#9Q}0i}RaKq;UUPzopolmbctrGQdEDWDWk3j7xo z&|8c>g5&;0-0$b)~u(QDuaxC}lH zPJtgi%vc}z;91ZE*Fgy^f*AM^_~%26{T}=dd>_0Dz5!kWUk0BC4tNGMKmvROJOmi{ z`}-Js9sB~^2G4^Xa0z@6y!9YszXiVmKL$Sl-v!?SFM$`q3*ghB1FnN-z&yx;#{dIw zJ^)?7>)==5W$;z-MWBNv@B#3~dvP3a3p@)-;52yaJ&gSld>z~b=fNLOG4^ZlJSc-4 zxbtqtz6m;@0v-TAN1^2_;B(+pUknNdSRMcb zVjkBEjqS0?ADhXAMHyr6o?@)8m9^TXjfS?iUAr!_&YXz{ zZQ_FEalRXy7bp9kV;Wqu``spYu^MKwi*cMo(o()tcy`rxeC}yZyDhG8vH>q2`iq(` zu7JUbGTdQ~{hg(7DP5t^mAD=X6A`7^rkGfu5M_Nm>GZfA3tnHe^)8Ra<8g7UqA(Cv z%j^bgI*vt_qlfP~YBKbgG?6_MG>l_(Q1BzJ3&FKvc!d~#5BHPYxb3@xq+vN80tki@ zG(_g&e-oGc-O*;EsXggvz|uBBV=<0_sccl^{QaanwU*JHEsgKE3Z2LIgm3(cooqHG&%%;zBolNlLq%7&cP-PV zy6%_9 zXUEmMST5Rx^FBfQuIY2~9W-+siF2wuZGT^P@z3eoIH65=7p|^3eeya^-)d1u-{XW- z;pQH1kxquw8<5kMJ}zx-(N+j6JqQMG#IxzlB5foIneRVG7vyX1AM5F^?wP*l_gkiu zY;oj1!jE-)zvrD#rFJmfeluw}-IVS%v)xQOcndx*Ger!p!I4*kv$^ECR4zFmq`5Af zAyG|kwS>Fq9eOc$I`tgaAL_9#UaH5CAQzU)9n%hSH0r`qvrOFo--mnjJs|G?htKbS zhI{<)f$xA@pa#m|3Gg=V_5TK51z!VC0|I}7k2~Op;6-p7+yY+!2S6O757edttZgR=F3S2!SlfO-h(OO(q7bx`j(fky`ndGVZW wDJ~1)QgnHjFYCU6yO?NSIdm9Q3Z)BK>>fTWx#yTUiU4B#GVZph2?R0!2N_lKWB>pF diff --git a/.swp b/.swp deleted file mode 100644 index 2ff57aada4b620b8586e8c243334275cc75938d2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI1&2H0B5QT5MLxL8;j@3Y=DsH3J*G_Rzl}aUXXjSJ2$M%xeB|(Zxr6>foV#6Ns z9J~Z?z#FjUC0H{4t8b$?$_gdYxzh2?B%U)f-*pyIF7@EFMb$lB@Om6wlGV5n;$}FW ze97LJvtNC_4lQfW4fqHIKwt?7Jn&6J#$WZV7tiVG6MqSMLJJ@O0w4eaAOHd&00JNY z0{@G^WV9x}auj4Fo^{1V8`;KmY_l00ck)1V8`;Kwt$4gnc2}4~6)_ zivIu4e*b^x7oS+WtUnt<{9=7$wOI$OzmJ6Y$+}^^V?AU2&U{vo16l?F5C8!X009sH z0T2KI5LgxhABGy6*%)B zj?OIdaqQ-OpBatjM}GH|D-U@3guAj#uE8={l`=UTI~+S4J5g*0alzN_8FjsKUc6y< My^|!4hl*qI4_-#rvH$=8 diff --git a/MicroDexed.ino b/MicroDexed.ino index 6d1f70d..42aa70a 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -46,6 +46,7 @@ bool sd_card_available = false; #ifdef TEST_MIDI IntervalTimer sched_note_on; IntervalTimer sched_note_off; +uint8_t _voice_counter=0; #endif void setup() @@ -83,7 +84,6 @@ void setup() AudioMemoryUsageMaxReset(); #endif - load_sysex("ROM1A.SYX", 10); #ifdef DEBUG show_patch(); #endif @@ -113,7 +113,6 @@ void setup() //dexed->data[160] = 7; // foot ctrl assign all //dexed->data[162] = 7; // breath ctrl assign all //dexed->data[164] = 7; // at ctrl assign all - //queue_midi_event(0xb0, 1, 99); // test mod wheel //queue_midi_event(0xb0, 2, 99); // test breath ctrl //queue_midi_event(0xb0, 4, 99); // test food switch @@ -211,6 +210,7 @@ void note_off(void) queue_midi_event(0x80, TEST_NOTE + 52, 0); // 14 queue_midi_event(0x80, TEST_NOTE + 57, 0); // 15 queue_midi_event(0x80, TEST_NOTE + 60, 0); // 16 + load_sysex("ROM1A.SYX", ++_voice_counter%32); } #endif @@ -327,7 +327,7 @@ void show_patch(void) Serial.print(F("[")); Serial.print(voicename); Serial.println(F("]")); - for (i = DEXED_VOICE_OFFSET + DEXED_NAME; i < DEXED_VOICE_OFFSET + DEXED_NAME + 10 ; i++) + for (i = DEXED_GLOBAL_PARAMETER_OFFSET; i <= DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_MAX_NOTES; i++) { Serial.print(i, DEC); Serial.print(F(": ")); diff --git a/config.h b/config.h index 58c9d8c..0f16b0f 100644 --- a/config.h +++ b/config.h @@ -1,11 +1,28 @@ -// -// MicroDexed -// -// A port of the Dexed sound engine (https://github.com/asb2m10/dexed) for the Teensy-3.5/3.6 with audio shield -// (c)2018 H. Wirtz -// - -//#define TEST_MIDI 1 +/* + MicroDexed + + MicroDexed is a port of the Dexed sound engine + (https://github.com/asb2m10/dexed) for the Teensy-3.5/3.6 with audio shield + + (c)2018 H. Wirtz + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#define TEST_MIDI 1 #define TEST_NOTE 40 #define TEST_VEL_MIN 60 #define TEST_VEL_MAX 110 diff --git a/dexed.cpp b/dexed.cpp index 5bdb471..791a458 100644 --- a/dexed.cpp +++ b/dexed.cpp @@ -1,26 +1,26 @@ /* - * MicroDexed - * - * MicroDexed is a port of the Dexed sound engine - * (https://github.com/asb2m10/dexed) for the Teensy-3.5/3.6 with audio shield - * - * (c)2018 H. Wirtz - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ + MicroDexed + + MicroDexed is a port of the Dexed sound engine + (https://github.com/asb2m10/dexed) for the Teensy-3.5/3.6 with audio shield + + (c)2018 H. Wirtz + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +*/ #include "synth.h" #include "dexed.h" @@ -197,7 +197,7 @@ bool Dexed::processMidiMessage(uint8_t type, uint8_t data1, uint8_t data2) return (true); break; case 123: - notes_off(); + notesOff(); return (true); break; } @@ -466,7 +466,7 @@ void Dexed::panic(void) { } } -void Dexed::notes_off(void) { +void Dexed::notesOff(void) { for (uint8_t i = 0; i < MAX_ACTIVE_NOTES; i++) { if (voices[i].live == true && voices[i].keydown == true) { voices[i].keydown = false; @@ -477,9 +477,112 @@ void Dexed::notes_off(void) { void Dexed::setMaxNotes(uint8_t n) { if (n <= MAX_ACTIVE_NOTES) { - notes_off(); + notesOff(); max_notes = n; panic(); controllers.refresh(); } } + +bool Dexed::loadSysexVoice(uint8_t* new_data) +{ + uint8_t* p_data = data; + uint8_t op; + uint8_t tmp; + + notesOff(); + + for (op = 0; op < 6; op++) + { + // DEXED_OP_EG_R1, // 0 + // DEXED_OP_EG_R2, // 1 + // DEXED_OP_EG_R3, // 2 + // DEXED_OP_EG_R4, // 3 + // DEXED_OP_EG_L1, // 4 + // DEXED_OP_EG_L2, // 5 + // DEXED_OP_EG_L3, // 6 + // DEXED_OP_EG_L4, // 7 + // 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]; + *(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]; + *(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]; + *(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_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]; + } + // DEXED_PITCH_EG_R1, // 0 + // DEXED_PITCH_EG_R2, // 1 + // DEXED_PITCH_EG_R3, // 2 + // DEXED_PITCH_EG_R4, // 3 + // DEXED_PITCH_EG_L1, // 4 + // 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]; + *(p_data + DEXED_VOICE_OFFSET + DEXED_ALGORITHM) = (tmp & 0x1f); + tmp = new_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]; + *(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) = 0; + *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_MODWHEEL_RANGE) = 99; + *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_MODWHEEL_ASSIGN) = 0; + *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_FOOTCTRL_RANGE) = 99; + *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_FOOTCTRL_ASSIGN) = 0; + *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_BREATHCTRL_RANGE) = 99; + *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_BREATHCTRL_ASSIGN) = 0; + *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_AT_RANGE) = 99; + *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_AT_ASSIGN) = 0; + *(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; + + setOPs((*(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_OP1_ENABLE) << 5) | + (*(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_OP2_ENABLE) << 4) | + (*(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_OP3_ENABLE) << 3) | + (*(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_OP4_ENABLE) << 2) | + (*(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)); + doRefreshVoice(); + activate(); + +#ifdef DEBUG + char voicename[11]; + memset(voicename, 0, sizeof(voicename)); + strncpy(voicename, (char *)&data[145], sizeof(voicename) - 1); + Serial.print(F("[")); + Serial.print(voicename); + Serial.println(F("]")); +#endif + + return (true); +} diff --git a/dexed.h b/dexed.h index c69e2e2..2e87b36 100644 --- a/dexed.h +++ b/dexed.h @@ -137,10 +137,11 @@ class Dexed void getSamples(uint16_t n_samples, int16_t* buffer); bool processMidiMessage(uint8_t type, uint8_t data1, uint8_t data2); void panic(void); - void notes_off(void); + void notesOff(void); void setMaxNotes(uint8_t n); void doRefreshVoice(void); void setOPs(uint8_t ops); + bool loadSysexVoice(uint8_t* data); Controllers controllers; diff --git a/dexed_sysex.cpp b/dexed_sysex.cpp index bb2de2c..fbb13b7 100644 --- a/dexed_sysex.cpp +++ b/dexed_sysex.cpp @@ -48,9 +48,13 @@ void load_sysex(char *name, uint8_t voice_number) { if (strcmp(name, entry.name()) == 0) { + uint8_t data[128]; + Serial.println(entry.name()); - check_sysex(entry); - load_sysex_voice(entry, voice_number); + if (get_sysex_voice(entry, voice_number, data)) + dexed->loadSysexVoice(data); + else + Serial.println(F("Cannot load voice data")); entry.close(); break; } @@ -61,121 +65,10 @@ void load_sysex(char *name, uint8_t voice_number) } } -bool load_sysex_voice(File sysex, uint8_t voice_number) +bool get_sysex_voice(File sysex, uint8_t voice_number, uint8_t* data) { File file; - - if (file = SD.open(sysex.name())) - { - uint8_t* p_data = dexed->data; - uint8_t op; - uint8_t tmp; - - dexed->notes_off(); - - file.seek(6 + (voice_number * 128)); - for (op = 0; op < 6; op++) - { - // DEXED_OP_EG_R1, // 0 - // DEXED_OP_EG_R2, // 1 - // DEXED_OP_EG_R3, // 2 - // DEXED_OP_EG_R4, // 3 - // DEXED_OP_EG_L1, // 4 - // DEXED_OP_EG_L2, // 5 - // DEXED_OP_EG_L3, // 6 - // DEXED_OP_EG_L4, // 7 - // DEXED_OP_LEV_SCL_BRK_PT, // 8 - // DEXED_OP_SCL_LEFT_DEPTH, // 9 - // DEXED_OP_SCL_RGHT_DEPTH, // 10 - file.read(p_data + (op * 21) + DEXED_OP_EG_R1, 11); - tmp = file.read(); - *(p_data + DEXED_OP_SCL_LEFT_CURVE + (op * 21)) = (tmp & 0x3); - *(p_data + DEXED_OP_SCL_RGHT_CURVE + (op * 21)) = (tmp & 0x0c) >> 2; - tmp = file.read(); - *(p_data + DEXED_OP_OSC_DETUNE + (op * 21)) = (tmp & 0x78) >> 3; - *(p_data + DEXED_OP_OSC_RATE_SCALE + (op * 21)) = (tmp & 0x07); - tmp = file.read(); - *(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)) = file.read(); - tmp = file.read(); - *(p_data + DEXED_OP_FREQ_COARSE + (op * 21)) = (tmp & 0x3e) >> 1; - *(p_data + DEXED_OP_OSC_MODE + (op * 21)) = (tmp & 0x01); - file.read(p_data + DEXED_OP_FREQ_FINE + (op * 21), 1); - } - // DEXED_PITCH_EG_R1, // 0 - // DEXED_PITCH_EG_R2, // 1 - // DEXED_PITCH_EG_R3, // 2 - // DEXED_PITCH_EG_R4, // 3 - // DEXED_PITCH_EG_L1, // 4 - // DEXED_PITCH_EG_L2, // 5 - // DEXED_PITCH_EG_L3, // 6 - // DEXED_PITCH_EG_L4, // 7 - file.read(p_data + DEXED_VOICE_OFFSET + DEXED_PITCH_EG_R1, 8); - tmp = file.read(); - *(p_data + DEXED_VOICE_OFFSET + DEXED_ALGORITHM) = (tmp & 0x1f); - tmp = file.read(); - *(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 - file.read(p_data + DEXED_VOICE_OFFSET + DEXED_LFO_SPEED, 4); - tmp = file.read(); - *(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); - file.read(p_data + DEXED_VOICE_OFFSET + DEXED_TRANSPOSE, 1); - file.read(p_data + DEXED_VOICE_OFFSET + DEXED_NAME, 10); - *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_PITCHBEND_RANGE) = 1; - *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_PITCHBEND_STEP) = 0; - *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_MODWHEEL_RANGE) = 99; - *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_MODWHEEL_ASSIGN) = 0; - *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_FOOTCTRL_RANGE) = 99; - *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_FOOTCTRL_ASSIGN) = 0; - *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_BREATHCTRL_RANGE) = 99; - *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_BREATHCTRL_ASSIGN) = 0; - *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_AT_RANGE) = 99; - *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_AT_ASSIGN) = 0; - *(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; - - dexed->setOPs((*(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_OP1_ENABLE) << 5) | - (*(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_OP2_ENABLE) << 4) | - (*(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_OP3_ENABLE) << 3) | - (*(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_OP4_ENABLE) << 2) | - (*(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_OP5_ENABLE) << 1) | - *(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_OP6_ENABLE )); - dexed->setMaxNotes(*(p_data + DEXED_GLOBAL_PARAMETER_OFFSET + DEXED_MAX_NOTES)); - dexed->doRefreshVoice(); - dexed->activate(); - -#ifdef DEBUG - char voicename[11]; - memset(voicename, 0, sizeof(voicename)); - strncpy(voicename, (char *)&dexed->data[145], sizeof(voicename) - 1); - Serial.print(F("[")); - Serial.print(voicename); - Serial.println(F("]")); -#endif - - return (true); - } - else - return (false); -} - -bool check_sysex(File sysex) -{ - File file; - uint16_t i; + uint16_t i,n; uint32_t calc_checksum = 0; if (sysex.size() != 4104) // check sysex size @@ -205,8 +98,18 @@ bool check_sysex(File sysex) return (false); } file.seek(6); // start of 32*128 (=4096) bytes data - for (i = 0; i < 4096; i++) - calc_checksum += (file.read() & 0x7F); // calculate checksum + for (i = 0; i < 32; i++) + { + for (n = 0; n < 128; n++) + { + uint8_t d = file.read(); + if (i == voice_number) + { + data[n] = d; + } + calc_checksum += (d & 0x7F); // calculate checksum + } + } calc_checksum = uint8_t(~calc_checksum + 1); if (calc_checksum != uint8_t(file.read())) { @@ -214,6 +117,5 @@ bool check_sysex(File sysex) return (false); } } - file.close(); return (true); } diff --git a/dexed_sysex.h b/dexed_sysex.h index d22694e..ae9a1f7 100644 --- a/dexed_sysex.h +++ b/dexed_sysex.h @@ -1,30 +1,30 @@ /* - * MicroDexed - * - * MicroDexed is a port of the Dexed sound engine - * (https://github.com/asb2m10/dexed) for the Teensy-3.5/3.6 with audio shield - * - * (c)2018 H. Wirtz - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ + MicroDexed + + MicroDexed is a port of the Dexed sound engine + (https://github.com/asb2m10/dexed) for the Teensy-3.5/3.6 with audio shield + + (c)2018 H. Wirtz + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +*/ extern bool sd_card_available; extern Dexed* dexed; void load_sysex(char *name, uint8_t voice_number); -bool load_sysex_voice(File sysex, uint8_t voice_number); -bool check_sysex(File sysex); +bool get_sysex_voice(File sysex, uint8_t voice_number, uint8_t* data); +