Skip to content

Commit

Permalink
add UI to tune each channel to a constant offset (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
tehn authored Mar 5, 2020
1 parent f9b53f7 commit 5a71907
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 18 deletions.
20 changes: 15 additions & 5 deletions src/ansible_grid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 ++) {
Expand All @@ -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();
}
Expand Down Expand Up @@ -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();
}
}
Expand Down
39 changes: 27 additions & 12 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5a71907

Please sign in to comment.