summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-06-10 14:34:51 +0200
committerBad Diode <bd@badd10de.dev>2021-06-10 14:34:51 +0200
commitab60d99e2ef778842726660d9016ab05c61cd005 (patch)
tree1bc3aee21510e1c057c0f5c25afccf61c054bdd8
parentc7f40ebf4ace263037e87a41ac331080aee2db36 (diff)
downloadgba-sequencer-ab60d99e2ef778842726660d9016ab05c61cd005.tar.gz
gba-sequencer-ab60d99e2ef778842726660d9016ab05c61cd005.zip
Add initial piano roll prototype
-rw-r--r--src/sequencer.c128
1 files changed, 123 insertions, 5 deletions
diff --git a/src/sequencer.c b/src/sequencer.c
index 3e34d68..205cb73 100644
--- a/src/sequencer.c
+++ b/src/sequencer.c
@@ -301,9 +301,9 @@ static ChannelWave ch3 = {
301 301
302#define TRIG_W 15 302#define TRIG_W 15
303#define TRIG_H 24 303#define TRIG_H 24
304#define TRIG_START_X 66 304#define TRIG_START_X 64
305#define TRIG_START_Y 90 305#define TRIG_START_Y 90
306#define TRIG_OFFSET_X (TRIG_W + 4) 306#define TRIG_OFFSET_X (TRIG_W + 3)
307#define TRIG_OFFSET_Y (TRIG_H + 7) 307#define TRIG_OFFSET_Y (TRIG_H + 7)
308 308
309void 309void
@@ -402,9 +402,9 @@ draw_channels(void) {
402 } 402 }
403 u8 clr = active ? COL_FG : COL_GREY; 403 u8 clr = active ? COL_FG : COL_GREY;
404 size_t y = CHAN_START_Y + i * CHAN_OFFSET_Y; 404 size_t y = CHAN_START_Y + i * CHAN_OFFSET_Y;
405 draw_tile(CHAN_START_X, y, channel_tiles + k++, clr, false); 405 draw_tile(CHAN_START_X, y, channel_tiles + k++, clr, true);
406 draw_tile(CHAN_START_X + 8, y, channel_tiles + k++, clr, false); 406 draw_tile(CHAN_START_X + 8, y, channel_tiles + k++, clr, true);
407 draw_tile(CHAN_START_X + 16, y, channel_tiles + k++, clr, false); 407 draw_tile(CHAN_START_X + 16, y, channel_tiles + k++, clr, true);
408 } 408 }
409} 409}
410 410
@@ -418,6 +418,123 @@ draw_channel_cursor(size_t i, u8 clr) {
418 draw_line(x0, y, x1, y, clr); 418 draw_line(x0, y, x1, y, clr);
419} 419}
420 420
421#define PIANO_W 170
422#define PIANO_H 20
423#define PIANO_START_X 35
424#define PIANO_START_Y 65
425#define PIANO_NOTE_W 2
426
427void
428draw_note(u8 note, u8 clr) {
429 size_t octave = note / 12;
430 size_t value = note % 12;
431
432 size_t x0;
433 size_t y0;
434 size_t x1;
435 size_t y1;
436 switch (value) {
437 // White notes.
438 case 0:{
439 x0 = PIANO_START_X + 2 + octave * 28;
440 x1 = x0 + 1;
441 y0 = PIANO_START_Y + 2;
442 y1 = PIANO_START_Y - 2 + PIANO_H;
443 draw_filled_rect(x0, y0, x1, y1, clr);
444 x0 = PIANO_START_X + 2 + octave * 28 + 2;
445 x1 = x0;
446 y0 = y0 + 9;
447 draw_filled_rect(x0, y0, x1, y1, clr);
448 } break;
449 case 2:{
450 x0 = PIANO_START_X + 2 + octave * 28 + 5;
451 x1 = x0;
452 y0 = PIANO_START_Y + 2;
453 y1 = PIANO_START_Y - 2 + 12;
454 draw_filled_rect(x0, y0, x1, y1, clr);
455 x0 = PIANO_START_X + 2 + octave * 28 + 4;
456 x1 = x0 + 2;
457 y0 = PIANO_START_Y - 2 + 13;
458 y1 = y0 + 7;
459 draw_filled_rect(x0, y0, x1, y1, clr);
460 } break;
461 case 4:{
462 x0 = PIANO_START_X + 2 + octave * 28 + 9;
463 x1 = x0 + 1;
464 y0 = PIANO_START_Y + 2;
465 y1 = PIANO_START_Y - 2 + 12;
466 draw_filled_rect(x0, y0, x1, y1, clr);
467 x0 = PIANO_START_X + 2 + octave * 28 + 8;
468 x1 = x0 + 2;
469 y0 = PIANO_START_Y - 2 + 13;
470 y1 = y0 + 7;
471 draw_filled_rect(x0, y0, x1, y1, clr);
472 } break;
473 case 5:{
474 x0 = PIANO_START_X + 2 + octave * 28 + 12;
475 x1 = x0 + 1;
476 y0 = PIANO_START_Y + 2;
477 y1 = PIANO_START_Y - 2 + PIANO_H;
478 draw_filled_rect(x0, y0, x1, y1, clr);
479 x0 = PIANO_START_X + 2 + octave * 28 + 14;
480 x1 = x0;
481 y0 = y0 + 9;
482 draw_filled_rect(x0, y0, x1, y1, clr);
483 } break;
484 case 7:{
485 x0 = PIANO_START_X + 2 + octave * 28 + 17;
486 x1 = x0;
487 y0 = PIANO_START_Y + 2;
488 y1 = PIANO_START_Y - 2 + 12;
489 draw_filled_rect(x0, y0, x1, y1, clr);
490 x0 = PIANO_START_X + 2 + octave * 28 + 16;
491 x1 = x0 + 2;
492 y0 = PIANO_START_Y - 2 + 13;
493 y1 = y0 + 7;
494 draw_filled_rect(x0, y0, x1, y1, clr);
495 } break;
496 case 9:{
497 x0 = PIANO_START_X + 2 + octave * 28 + 21;
498 x1 = x0;
499 y0 = PIANO_START_Y + 2;
500 y1 = PIANO_START_Y - 2 + 12;
501 draw_filled_rect(x0, y0, x1, y1, clr);
502 x0 = PIANO_START_X + 2 + octave * 28 + 20;
503 x1 = x0 + 2;
504 y0 = PIANO_START_Y - 2 + 13;
505 y1 = y0 + 7;
506 draw_filled_rect(x0, y0, x1, y1, clr);
507 } break;
508 case 11: {
509 x0 = PIANO_START_X + 2 + octave * 28 + 25;
510 x1 = x0 + 1;
511 y0 = PIANO_START_Y + 2;
512 y1 = PIANO_START_Y - 2 + 12;
513 draw_filled_rect(x0, y0, x1, y1, clr);
514 x0 = PIANO_START_X + 2 + octave * 28 + 24;
515 x1 = x0 + 2;
516 y0 = PIANO_START_Y - 2 + 13;
517 y1 = y0 + 7;
518 draw_filled_rect(x0, y0, x1, y1, clr);
519 } break;
520 default:
521 // TODO:
522 return;
523 }
524}
525
526void
527draw_piano(void) {
528 size_t x0 = PIANO_START_X;
529 size_t x1 = PIANO_START_X + PIANO_W;
530 size_t y0 = PIANO_START_Y;
531 size_t y1 = PIANO_START_Y + PIANO_H;
532 draw_rect(x0, y0, x1, y1, COL_FG);
533 for (size_t i = 0; i < 12 * 6; i++) {
534 draw_note(i, COL_FG);
535 }
536}
537
421void 538void
422irq_timer(void) { 539irq_timer(void) {
423 if (ch1.active) { 540 if (ch1.active) {
@@ -963,6 +1080,7 @@ sequencer_init(void) {
963 // Initialize background objects and sprites. 1080 // Initialize background objects and sprites.
964 draw_triggers(); 1081 draw_triggers();
965 draw_channels(); 1082 draw_channels();
1083 draw_piano();
966 1084
967 // Initialize input handler. 1085 // Initialize input handler.
968 channel_selection_loc = 2; // DEBUG: Starting on CH3 1086 channel_selection_loc = 2; // DEBUG: Starting on CH3