Skip to content

Commit

Permalink
Abort draw if event_count changes due to live record
Browse files Browse the repository at this point in the history
  • Loading branch information
jmamma committed Jul 23, 2023
1 parent d85ba28 commit 061793e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
23 changes: 18 additions & 5 deletions avr/cores/megacommand/MCL/SeqExtStepPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void SeqExtStepPage::draw_thick_line(uint8_t x1, uint8_t y1, uint8_t x2,
oled_display.drawLine(x1, y1 + 1, x2, y2 + 1, color);
}

void SeqExtStepPage::draw_lockeditor() {
bool SeqExtStepPage::draw_lockeditor() {
auto &active_track = mcl_seq.ext_tracks[last_ext_track];
uint8_t timing_mid = active_track.get_timing_mid();

Expand All @@ -195,6 +195,8 @@ void SeqExtStepPage::draw_lockeditor() {
uint16_t ev_idx = 0, ev_end = 0, ev_j_end;
uint8_t j = 0;

uint16_t event_count = active_track.event_count;

for (uint8_t i = 0; i < active_track.length; i++) {
// Update bucket index range
/* if (j > i) {
Expand All @@ -206,6 +208,7 @@ void SeqExtStepPage::draw_lockeditor() {
}*/
ev_end += active_track.timing_buckets.get(i);
for (; ev_idx != ev_end; ++ev_idx) {
if (active_track.event_count != event_count) { return false; }
auto &ev = active_track.events[ev_idx];

if (!ev.is_lock || (ev.lock_idx != pianoroll_mode - 1)) {
Expand Down Expand Up @@ -330,14 +333,15 @@ void SeqExtStepPage::draw_lockeditor() {
oled_display.drawPixel(draw_x + fov_cur_x + 1, draw_y + fov_cur_y - 2, WHITE);
oled_display.drawPixel(draw_x + fov_cur_x, draw_y + fov_cur_y - 1 - 2, WHITE);
oled_display.drawPixel(draw_x + fov_cur_x, draw_y + fov_cur_y + 1 - 2, WHITE);
return true;
}

void SeqExtStepPage::draw_note(uint8_t x, uint8_t y, uint8_t w) {
oled_display.drawRect(x, y, w, fov_h / fov_notes, WHITE);
oled_display.fillRect(x + 1, y + 1, w - 2, fov_h / fov_notes - 2, BLACK);
}

void SeqExtStepPage::draw_pianoroll() {
bool SeqExtStepPage::draw_pianoroll() {
auto &active_track = mcl_seq.ext_tracks[last_ext_track];
uint8_t timing_mid = active_track.get_timing_mid();

Expand All @@ -353,11 +357,16 @@ void SeqExtStepPage::draw_pianoroll() {

uint16_t ev_idx = 0, ev_end = 0;
uint8_t h = fov_h / fov_notes;

uint16_t event_count = active_track.event_count;
// MidiUartParent::handle_midi_lock = 1;
for (int i = 0; i < active_track.length; i++) {
// Update bucket index range
ev_end += active_track.timing_buckets.get(i);
uint8_t buckets = active_track.timing_buckets.get(i);
ev_end += buckets;

for (; ev_idx != ev_end; ++ev_idx) {
if (active_track.event_count != event_count) { return false; }
auto &ev = active_track.events[ev_idx];
int note_val = ev.event_value;
// Check if note is note_on and is visible within fov vertical
Expand Down Expand Up @@ -452,6 +461,8 @@ void SeqExtStepPage::draw_pianoroll() {
}
}
}

// MidiUartParent::handle_midi_lock = 0;
// Draw interactive cursor
uint8_t fov_cur_y = fov_h - ((cur_y - fov_y) * ((fov_h) / fov_notes));
int16_t fov_cur_x = (float)(cur_x - fov_offset) * fov_pixels_per_tick;
Expand All @@ -466,6 +477,7 @@ void SeqExtStepPage::draw_pianoroll() {
oled_display.fillRect(draw_x + fov_cur_x, draw_y + fov_cur_y, fov_cur_w,
(fov_h / fov_notes), WHITE);
}
return true;
}

void SeqExtStepPage::draw_viewport_minimap() {
Expand Down Expand Up @@ -745,6 +757,7 @@ void SeqExtStepPage::loop() {

void SeqExtStepPage::display() {
#ifdef EXT_TRACKS
again:
oled_display.clearDisplay();
auto &active_track = mcl_seq.ext_tracks[last_ext_track];
uint8_t timing_mid = active_track.get_timing_mid();
Expand All @@ -763,12 +776,12 @@ void SeqExtStepPage::display() {
str[4] = 0;
strcat(info1, str);
strcpy(info2, "NOTE");
draw_pianoroll();
if (!draw_pianoroll()) { goto again; }
} else {
strcpy(info2, "LOCK ");
mcl_gui.put_value_at(pianoroll_mode, info2 + 5);
mcl_gui.put_value_at(lock_cur_y, info1);
draw_lockeditor();
if (!draw_lockeditor()) { goto again; }
}
draw_seq_pos();

Expand Down
4 changes: 2 additions & 2 deletions avr/cores/megacommand/MCL/SeqExtStepPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class SeqExtStepPage : public SeqPage {
void draw_thick_line(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2,
uint8_t color = WHITE);
void draw_note(uint8_t x, uint8_t y, uint8_t w);
void draw_pianoroll();
void draw_lockeditor();
bool draw_pianoroll();
bool draw_lockeditor();
void draw_viewport_minimap();
void draw_seq_pos();
void draw_grid();
Expand Down

0 comments on commit 061793e

Please sign in to comment.