aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2024-01-04 16:40:17 +0100
committerBad Diode <bd@badd10de.dev>2024-01-04 16:40:17 +0100
commitb83804d58aa7d5a04c9b336c523b1337bc2411d3 (patch)
treee20708b7c93aefc09b5f80de33114893636d19f0
parent024e372b9e271ea817353f7d07a810b99c62eb60 (diff)
downloadstepper-b83804d58aa7d5a04c9b336c523b1337bc2411d3.tar.gz
stepper-b83804d58aa7d5a04c9b336c523b1337bc2411d3.zip
Add basic MIDI 24bpq sync in
-rw-r--r--src/sequencer.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/sequencer.c b/src/sequencer.c
index 9dcaa89..b5cfd46 100644
--- a/src/sequencer.c
+++ b/src/sequencer.c
@@ -346,16 +346,16 @@ play_step(void) {
346 step_counter = (step_counter + 1) % 16; 346 step_counter = (step_counter + 1) % 16;
347} 347}
348 348
349static int nseq_ticks = 0;
350
349void 351void
350sequencer_tick(void) { 352sequencer_tick(void) {
351 static int nseq_ticks = 0; 353 if (nseq_ticks++ == 0) {
352 if (nseq_ticks++ < 24) { 354 play_step();
353 return; 355 return;
356 } else if (nseq_ticks == 24) {
357 nseq_ticks = 0;
354 } 358 }
355 nseq_ticks = 0;
356
357 // NOTE: ACK interrupt before play_step???
358 play_step();
359} 359}
360 360
361void 361void
@@ -523,6 +523,7 @@ stop_sound(void) {
523void 523void
524stop_playing(void) { 524stop_playing(void) {
525 step_counter = 0; 525 step_counter = 0;
526 nseq_ticks = 0;
526 chain.current = 15; 527 chain.current = 15;
527 chain.current = find_next_pattern(); 528 chain.current = find_next_pattern();
528 chain.playing = false; 529 chain.playing = false;
@@ -534,6 +535,7 @@ void
534toggle_playing(void) { 535toggle_playing(void) {
535 play_status ^= 1; 536 play_status ^= 1;
536 step_counter = 0; 537 step_counter = 0;
538 nseq_ticks = 0;
537 chain.current = 15; 539 chain.current = 15;
538 chain.current = find_next_pattern(); 540 chain.current = find_next_pattern();
539 chain.playing = false; 541 chain.playing = false;
@@ -1559,14 +1561,14 @@ reset_serial_in(void) {
1559void 1561void
1560serial_irq(void) { 1562serial_irq(void) {
1561 if (play_status) { 1563 if (play_status) {
1562 if (in_ticks++ == 0) { 1564 sequencer_tick();
1563 // TODO: Instead of play_step use the nseq_ticks instead! 1565 sequencer_tick();
1564 play_step(); 1566 sequencer_tick();
1565 // MIDI: 24 / 8 = 3 1567 sequencer_tick();
1566 // set to 6 for half tempo 1568 sequencer_tick();
1567 } else if (in_ticks == 3) { 1569 sequencer_tick();
1568 in_ticks = 0; 1570 sequencer_tick();
1569 } 1571 sequencer_tick();
1570 } 1572 }
1571} 1573}
1572 1574