diff --git a/src/ansible_grid.c b/src/ansible_grid.c index 3aac5c3..7f9ec7b 100644 --- a/src/ansible_grid.c +++ b/src/ansible_grid.c @@ -289,7 +289,8 @@ void refresh_grid_tuning(void) { memset(monomeLedBuffer + R5, L0, 10); monomeLedBuffer[R5 + tuning_octave] = L1; - monomeLedBuffer[R5 + 12] = L1; // reload / longpress to restore factory default + monomeLedBuffer[R5 + 11] = L1; // reload / longpress to restore factory default + monomeLedBuffer[R5 + 13] = L1; // save offsets key monomeLedBuffer[R5 + 14] = L1; // save interpolated key monomeLedBuffer[R5 + 15] = L1; // save as-is key @@ -389,7 +390,7 @@ void grid_keytimer(void) { if (view_tuning) { if (y == 5) { - if (x == 12) { + if (x == 11) { // reload factory default, don't immediately save it for (uint8_t i = 0; i < 4; i++) { for (uint8_t j = 0; j < 120; j ++) { @@ -398,9 +399,15 @@ void grid_keytimer(void) { } restore_grid_tuning(); } + if (x == 13) { + // apply fixed offset and save + fit_tuning(0); + flashc_memcpy((void*)f.tuning_table, tuning_table, sizeof(tuning_table), true); + restore_grid_tuning(); + } if (x == 14) { // interpolate octaves and save - fit_tuning(); + fit_tuning(1); flashc_memcpy((void*)f.tuning_table, tuning_table, sizeof(tuning_table), true); restore_grid_tuning(); } @@ -1634,11 +1641,14 @@ void handler_KriaGridKey(s32 data) { } else if(view_tuning) { if (y == 5) { - if (x == 12) { + if (x == 11) { init_tuning(); restore_grid_tuning(); + } else if (x == 13) { + fit_tuning(0); + restore_grid_tuning(); } else if (x == 14) { - fit_tuning(); + fit_tuning(1); restore_grid_tuning(); } } diff --git a/src/main.c b/src/main.c index 64ff314..126f291 100644 --- a/src/main.c +++ b/src/main.c @@ -466,21 +466,36 @@ void init_tuning(void) { memcpy((void *)&tuning_table, &f.tuning_table, sizeof(tuning_table)); } -void fit_tuning(void) { - for (uint8_t i = 0; i < 4; i++) { - fix16_t step = 0; - for (uint8_t j = 0; j < 10; j++) { - fix16_t acc = fix16_from_int(tuning_table[i][j*12]); - if (j < 9) { - step = fix16_div( - fix16_from_int(tuning_table[i][(j+1)*12] - tuning_table[i][j*12]), - fix16_from_int(12)); +void fit_tuning(int mode) { + switch (mode) { + case 0: { // fixed offset per channel + for (uint8_t i = 0; i < 4; i++) { + uint16_t offset = tuning_table[i][0]; + for (uint8_t j = 0; j < 120; j++) { + tuning_table[i][j] = (ET[j] << 2) + offset; + } } - for (uint8_t k = j*12; k < (j+1)*12; k++) { - tuning_table[i][k] = fix16_to_int(acc); - acc = fix16_add(acc, step); + break; + } + case 1: { // linear fit between octaves + for (uint8_t i = 0; i < 4; i++) { + fix16_t step = 0; + for (uint8_t j = 0; j < 10; j++) { + fix16_t acc = fix16_from_int(tuning_table[i][j*12]); + if (j < 9) { + step = fix16_div( + fix16_from_int(tuning_table[i][(j+1)*12] - tuning_table[i][j*12]), + fix16_from_int(12)); + } + for (uint8_t k = j*12; k < (j+1)*12; k++) { + tuning_table[i][k] = fix16_to_int(acc); + acc = fix16_add(acc, step); + } + } } + break; } + default: break; } } diff --git a/src/main.h b/src/main.h index a1a86f1..d2ddc7e 100644 --- a/src/main.h +++ b/src/main.h @@ -77,7 +77,7 @@ extern uint16_t tuning_table[4][120]; void (*clock)(u8 phase); void init_tuning(void); void default_tuning(void); -void fit_tuning(void); +void fit_tuning(int mode); extern void handler_None(s32 data); extern void clock_null(u8 phase);