Skip to content
Permalink
Browse files

Merge branch 'feature/tuning-table' into csboling-dev

  • Loading branch information
csboling committed Jun 21, 2019
2 parents 3d58437 + 69da2cc commit afb85ecfdb32d99c1aa427baad8a6e907b28c915
Showing with 269 additions and 45 deletions.
  1. +11 −31 src/ansible_arc.c
  2. +197 −14 src/ansible_grid.c
  3. +1 −0 src/ansible_grid.h
  4. +19 −0 src/ansible_preset_docdef.c
  5. +36 −0 src/main.c
  6. +5 −0 src/main.h
@@ -1997,36 +1997,16 @@ static void generate_scales(uint8_t n) {
}

static void levels_dac_refresh(void) {
if(l.mode[0]) {
if(l.scale[0])
dac_set_value(0, ET[ levels_scales[0][ l.note[0][play] ] + l.octave[0]*12] << 2);
else
dac_set_value(0, ET[ l.note[0][play] + l.octave[0]*12] << 2);
}
else
dac_set_value(0, (l.pattern[0][play] + l.offset[0]) << (2 + l.range[0]));
if(l.mode[1]) {
if(l.scale[1])
dac_set_value(1, ET[ levels_scales[1][ l.note[1][play] ] + l.octave[1]*12] << 2);
else
dac_set_value(1, ET[ l.note[1][play] + l.octave[1]*12] << 2);
}
else
dac_set_value(1, (l.pattern[1][play] + l.offset[1]) << (2 + l.range[1]));
if(l.mode[2]) {
if(l.scale[2])
dac_set_value(2, ET[ levels_scales[2][ l.note[2][play] ] + l.octave[2]*12] << 2);
else
dac_set_value(2, ET[ l.note[2][play] + l.octave[2]*12] << 2);
}
else
dac_set_value(2, (l.pattern[2][play] + l.offset[2]) << (2 + l.range[2]));
if(l.mode[3]) {
if(l.scale[3])
dac_set_value(3, ET[ levels_scales[3][ l.note[3][play] ] + l.octave[3]*12] << 2);
else
dac_set_value(3, ET[ l.note[3][play] + l.octave[3]*12] << 2);
for (uint8_t i = 0; i < 4; i++) {
if (l.mode[i]) {
if (l.scale[i]) {
dac_set_value(i, tuning_table[i][ levels_scales[i][ l.note[i][play] ] + l.octave[i]*12 ] << 2);
} else {
dac_set_value(i, tuning_table[i][ l.note[i][play] + l.octave[i]*12 ] << 2);
}
break;
} else {
dac_set_value(i, (l.pattern[i][play] + l.offset[i]) << (2 + l.range[i]));
}
}
else
dac_set_value(3, (l.pattern[3][play] + l.offset[3]) << (2 + l.range[3]));
}
@@ -39,6 +39,7 @@ u8 grid_varibrightness;
bool clock_external;
bool view_clock;
bool view_config;
bool view_tuning;
uint32_t clock_period;
uint8_t clock_count;
uint8_t clock_mul;
@@ -51,6 +52,11 @@ u32 clock_deltas[4];
uint8_t time_rough;
uint8_t time_fine;

uint8_t tuning_track;
uint8_t tuning_octave;
int16_t tuning_octave_offset[4];
bool tuning_note_on[4];

uint8_t cue_div;
uint8_t cue_steps;

@@ -265,13 +271,64 @@ void refresh_preset(void) {
monome_set_quadrant_flag(1);
}

void refresh_grid_tuning(void) {
memset(monomeLedBuffer,0,128);

for (uint8_t i = 0; i < 4; i++) {
if (tuning_track == i) {
memset(monomeLedBuffer + i*16 + 2, L0 + 2, 12);
} else {
memset(monomeLedBuffer + i*16 + 2, L0, 12);
}
if (tuning_note_on[i]) {
monomeLedBuffer[(int)i*16 + tuning_octave_offset[i] + 2] += 4;
}
}

memset(monomeLedBuffer + R5, L0, 5);
monomeLedBuffer[R5 + tuning_octave] = L1;
monomeLedBuffer[R5 + 12] = L1; // reload / longpress to restore factory default
monomeLedBuffer[R5 + 14] = L1; // save interpolated key
monomeLedBuffer[R5 + 15] = L1; // save as-is key

// lit key indicating position
int tuning_slot = (int)(tuning_octave * 12) + tuning_octave_offset[tuning_track];
float dac_range_percent = (float)tuning_table[tuning_track][tuning_slot] / (float)(DAC_10V >> 2);
int dac_step = (int)(256.0 * dac_range_percent);
monomeLedBuffer[R6 + dac_step / 16] = dac_step % 16;

// tuning steps either direction
for (uint8_t i = 0; i < 8; i++) {
monomeLedBuffer[R7 + 8 + i] = 2*i + 1;
monomeLedBuffer[R7 + 7 - i] = 2*i + 1;
}
}

static void restore_grid_tuning(void) {
tuning_octave = 0;
tuning_track = 0;
for (uint8_t i = 0; i < 4; i++) {
tuning_note_on[i] = true;
tuning_octave_offset[i] = 0;
dac_set_value_noslew(
i,
tuning_table[i][
(int)(tuning_octave * 12) +
tuning_octave_offset[i]
] << 2);
set_tr(TR1 + i);
}
}

void grid_keytimer(void) {
for(uint8_t i1=0;i1<key_count;i1++) {
if(key_times[held_keys[i1]])
if(--key_times[held_keys[i1]]==0) {
uint8_t x = held_keys[i1] % 16;
uint8_t y = held_keys[i1] / 16;
if(preset_mode == 1) {
if(held_keys[i1] % 16 == 0) {
preset = held_keys[i1] / 16;
if(x == 0) {
preset = y;

// WRITE PRESET

@@ -324,6 +381,33 @@ void grid_keytimer(void) {
grid_keytimer_kria(held_keys[i1]);
}

if (view_tuning) {
if (y == 5) {
if (x == 12) {
// reload factory default
for (uint8_t i = 0; i < 4; i++) {
memcpy((void *)&tuning_table[i], ET, sizeof(ET));
}
restore_grid_tuning();
}
if (x == 14) {
// interpolate octaves and save
fit_tuning();
for (uint8_t i = 0; i < 4; i++) {
flashc_memcpy((void *)&f.tuning_table[i], tuning_table[i], sizeof(tuning_table[0]), true);
}
restore_grid_tuning();
}
if (x == 15) {
// save all tuning entries as-is
for (uint8_t i = 0; i < 4; i++) {
flashc_memcpy((void *)&f.tuning_table[i], tuning_table[i], sizeof(tuning_table[0]), true);
}
restore_grid_tuning();
}
}
}

// print_dbg("\rlong press: ");
// print_dbg_ulong(held_keys[i1]);
}
@@ -788,8 +872,8 @@ void clock_kria(uint8_t phase) {
}
}

static inline int8_t sum_clip_octave(int8_t l, int8_t r) {
return min(5, max(0, l + r));
static inline int sum_clip(int l, int r, int clip) {
return min(clip, max(0, l + r));
}

void clock_kria_note(kria_track* track, uint8_t trackNum) {
@@ -799,7 +883,7 @@ void clock_kria_note(kria_track* track, uint8_t trackNum) {
dur[trackNum] = (u16)(unscaled * clock_scale);
}
if(kria_next_step(trackNum, mOct)) {
oct[trackNum] = sum_clip_octave(track->octshift, track->oct[pos[trackNum][mOct]]);
oct[trackNum] = sum_clip(track->octshift, track->oct[pos[trackNum][mOct]], 5);
}
if(kria_next_step(trackNum, mNote)) {
note[trackNum] = track->note[pos[trackNum][mNote]];
@@ -815,7 +899,13 @@ void clock_kria_note(kria_track* track, uint8_t trackNum) {
static void kria_set_note(uint8_t trackNum) {
u8 noteInScale = (note[trackNum] + alt_note[trackNum]) % 7; // combine both note params
u8 octaveBump = (note[trackNum] + alt_note[trackNum]) / 7; // if it wrapped around the octave, bump it
dac_set_value(trackNum, ET[(int)cur_scale[noteInScale] + scale_adj[noteInScale] + (int)((oct[trackNum]+octaveBump) * 12)] << 2);
dac_set_value(
trackNum,
tuning_table[trackNum][
(int)cur_scale[noteInScale] +
scale_adj[noteInScale] +
(int)((oct[trackNum]+octaveBump) * 12)
] << 2);
}

void clock_kria_track( uint8_t trackNum ) {
@@ -1525,6 +1615,17 @@ void handler_KriaGridKey(s32 data) {
}
}
}
else if(view_tuning) {
if (y == 5) {
if (x == 12) {
init_tuning();
restore_grid_tuning();
} else if (x == 14) {
fit_tuning();
restore_grid_tuning();
}
}
}
}
}

@@ -1648,9 +1749,82 @@ void handler_KriaGridKey(s32 data) {

flashc_memset8((void*)&(f.kria_state.loop_sync), loop_sync, 1, true);
}
else if (y == 7 && x == 14) {
view_config = false;
view_clock = false;
view_tuning = true;

grid_refresh = &refresh_grid_tuning;
restore_grid_tuning();
}
monomeFrameDirty++;
}
}
else if(view_tuning) {
if(z) {
if (y <= 4) {
if (x >= 2 && x <= 13) {
if (tuning_track == y && tuning_note_on[y] && x == (tuning_octave_offset[y] + 2)) {
tuning_note_on[y] = false;
clr_tr(TR1 + y);
} else {
tuning_track = y;
tuning_note_on[y] = true;
tuning_octave_offset[y] = (int)x - 2;
dac_set_value_noslew(
y,
tuning_table[y][
(int)(tuning_octave * 12) +
tuning_octave_offset[y]
] << 2);
set_tr(TR1 + y);
}
}
}
else if (y == 5 && x <= 4) {
tuning_octave = x;
for (uint8_t i = 0; i < 4; i++) {
dac_set_value_noslew(
i,
tuning_table[i][
(int)(tuning_octave * 12) +
tuning_octave_offset[i]
] << 2);
}
}
else if (y == 6) {
int tuning_slot = (int)(tuning_octave * 12) + tuning_octave_offset[tuning_track];
tuning_table[tuning_track][tuning_slot] = x * ((DAC_10V >> 2) / 16);
dac_set_value_noslew(
tuning_track,
tuning_table[tuning_track][
(int)(tuning_octave * 12) +
tuning_octave_offset[tuning_track]
] << 2);
}
else if (y == 7) {
int tuning_slot = (int)(tuning_octave * 12) + tuning_octave_offset[tuning_track];

if (x >= 8) {
tuning_table[tuning_track][tuning_slot] = sum_clip(
tuning_table[tuning_track][tuning_slot],
1 << (x - 8),
DAC_10V >> 2);
} else {
tuning_table[tuning_track][tuning_slot] = sum_clip(
tuning_table[tuning_track][tuning_slot],
- (1 << (8 - x)),
DAC_10V >> 2);
}
dac_set_value_noslew(
tuning_track,
tuning_table[tuning_track][
(int)(tuning_octave * 12) +
tuning_octave_offset[tuning_track]
] << 2);
}
}
}
// NORMAL
else {
// bottom row
@@ -2440,10 +2614,17 @@ void handler_KriaKey(s32 data) {
view_config = false;
break;
case 2:
grid_refresh = &refresh_kria;
view_config = false;
if (!view_tuning) {
grid_refresh = &refresh_kria;
view_config = false;
}
break;
case 3:
if (view_tuning) {
view_tuning = false;
resume_kria();
break;
}
grid_refresh = &refresh_kria_config;
view_config = true;
view_clock = false;
@@ -2685,7 +2866,7 @@ void refresh_kria_oct(void) {

for(uint8_t i=0;i<16;i++) {
const uint8_t octshift = k.p[k.pattern].t[track].octshift;
const int8_t octsum = sum_clip_octave(k.p[k.pattern].t[track].oct[i], (int)octshift);
const int8_t octsum = sum_clip(k.p[k.pattern].t[track].oct[i], (int)octshift, 5);

for(uint8_t j=0;j<=5;j++) {
if (octsum >= octshift) {
@@ -2969,6 +3150,8 @@ void refresh_kria_config(void) {
monomeLedBuffer[R5 + 11] = i;
monomeLedBuffer[R5 + 12] = i;
monomeLedBuffer[R5 + 13] = i;

monomeLedBuffer[R7 + 14] = L0;
}


@@ -3335,7 +3518,7 @@ void mp_note_on(uint8_t n) {
if(mp_clock_count < 1) {
mp_clock_count++;
note_now[0] = n;
dac_set_value(0, ET[(int)cur_scale[7-n] + scale_adj[7-n]] << 2);
dac_set_value(0, tuning_table[0][(int)cur_scale[7-n] + scale_adj[7-n]] << 2);
set_tr(TR1);
}
break;
@@ -3344,7 +3527,7 @@ void mp_note_on(uint8_t n) {
mp_clock_count++;
w = get_note_slot(2);
note_now[w] = n;
dac_set_value(w, ET[(int)cur_scale[7-n] + scale_adj[7-n]] << 2);
dac_set_value(w, tuning_table[w][(int)cur_scale[7-n] + scale_adj[7-n]] << 2);
set_tr(TR1 + w);
}
break;
@@ -3353,7 +3536,7 @@ void mp_note_on(uint8_t n) {
mp_clock_count++;
w = get_note_slot(4);
note_now[w] = n;
dac_set_value(w, ET[(int)cur_scale[7-n] + scale_adj[7-n]] << 2);
dac_set_value(w, tuning_table[w][(int)cur_scale[7-n] + scale_adj[7-n]] << 2);
set_tr(TR1 + w);
}
break;
@@ -4173,7 +4356,7 @@ static void es_note_on(s8 x, s8 y, u8 from_pattern, u16 timer, u8 voices) {
note_index = 0;
else if (note_index > 119)
note_index = 119;
dac_set_value_noslew(note, ET[note_index] << 2);
dac_set_value_noslew(note, tuning_table[note][note_index] << 2);
dac_update_now();
set_tr(TR1 + note);

@@ -4194,7 +4377,7 @@ static void es_update_pitches(void) {
note_index = 0;
else if (note_index > 119)
note_index = 119;
dac_set_value_noslew(i, ET[note_index] << 2);
dac_set_value_noslew(i, tuning_table[i][note_index] << 2);
dac_update_now();
}
}
@@ -202,6 +202,7 @@ void set_mode_grid(void);
void handler_GridFrontShort(s32 data);
void handler_GridFrontLong(s32 data);
void refresh_preset(void);
void refresh_grid_tuning(void);
void grid_keytimer(void);
void ii_grid(uint8_t* data, uint8_t len);

0 comments on commit afb85ec

Please sign in to comment.