Add jump function to loop

This commit is contained in:
fillotassi 2018-09-10 08:11:18 +02:00
parent 2686fb98d1
commit ed6f3e1de2
2 changed files with 542 additions and 519 deletions

View file

@ -56,6 +56,7 @@ unsigned i;
void sequencer_main_loop(void) void sequencer_main_loop(void)
{ {
unsigned i; unsigned i;
line_time_t new_cursor;
// Restart main loop timer // Restart main loop timer
timer0_write(ESP.getCycleCount() + TIMESTEPS); timer0_write(ESP.getCycleCount() + TIMESTEPS);
@ -66,14 +67,24 @@ unsigned i;
switch(lines[i].next_event->type) { switch(lines[i].next_event->type) {
case EVENT_NOTEON: case EVENT_NOTEON:
digitalWrite(LINE_PIN_MAP[i], 1); digitalWrite(LINE_PIN_MAP[i], 1);
++lines[i].next_event;
break; break;
case EVENT_NOTEOFF: case EVENT_NOTEOFF:
digitalWrite(LINE_PIN_MAP[i], 0); digitalWrite(LINE_PIN_MAP[i], 0);
break;
// Todo: tone, jump, barrier, envelope
}
++lines[i].next_event; ++lines[i].next_event;
break;
case EVENT_JUMP:
new_cursor = lines[i].cursor = lines[i].next_event->new_cursor;
for(list<event_t>::iterator it = lines[i].events.begin(); it != lines[i].events.end(); ++it) {
if(it->time >= new_cursor) {
lines[i].next_event = it;
break;
}
}
break;
// Todo: tone, barrier, envelope
}
} }
if(lines[i].next_event != lines[i].events.end()) if(lines[i].next_event != lines[i].events.end())
@ -101,7 +112,9 @@ const char *p;
JsonArray &model_lines = model["lines"]; JsonArray &model_lines = model["lines"];
unsigned millis_per_slot = model["millis_per_slot"]; unsigned millis_per_slot = model["millis_per_slot"];
// // Critical section
noInterrupts();
for(lineno = 0; lineno < LINES_NUM; ++lineno) { for(lineno = 0; lineno < LINES_NUM; ++lineno) {
lines[lineno].cursor = 0; lines[lineno].cursor = 0;
lines[lineno].events.clear(); lines[lineno].events.clear();
@ -119,10 +132,17 @@ const char *p;
lines[lineno].events.push_back(event); lines[lineno].events.push_back(event);
} }
} }
event.type = EVENT_JUMP;
event.time = t * millis_per_slot;
event.new_cursor = 0;
lines[lineno].events.push_back(event);
} }
for(lineno = 0; lineno < LINES_NUM; ++lineno) for(lineno = 0; lineno < LINES_NUM; ++lineno)
lines[lineno].next_event = lines[lineno].events.begin(); lines[lineno].next_event = lines[lineno].events.begin();
interrupts();
} }
void setup() void setup()

File diff suppressed because it is too large Load diff