From 8c91e5d45d31a5c7c836032112f83d3235f738a8 Mon Sep 17 00:00:00 2001 From: Mitya Selivanov Date: Sun, 1 Oct 2023 18:28:03 +0200 Subject: Sheet rate fixes --- TODO | 3 +-- source/saw/main.c | 32 ++++++++++++++++++++------------ 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/TODO b/TODO index 7f840ed..bd872f3 100644 --- a/TODO +++ b/TODO @@ -1,9 +1,8 @@ To-Do list - Grid size changing -- UI: Playback controls +- Playback: BPM, Volume - UI: Effects stack -- UI: Volume control - Sound: Simple tonal synth - Sound: Kick, snare, cymbal - UI: Catalog diff --git a/source/saw/main.c b/source/saw/main.c index d67efd1..0cb30d3 100644 --- a/source/saw/main.c +++ b/source/saw/main.c @@ -39,6 +39,7 @@ enum { UNISON_COUNT = 100, SHEET_SIZE = 200, + ROLL_DEFAULT_RATE = 8, ROLL_DEFAULT_OFFSET_Y = 710, INSTRUMENT_SINE = 0, @@ -526,13 +527,14 @@ static void saw_ui_compose(i64 x0, i64 y0, i64 width, i64 height) { .enabled = 1, .track = track, .pitch_turned_off = { 0 }, - .rate = 6, + .rate = ROLL_DEFAULT_RATE, .notes = { 0 }, .time = frame, - .duration = (6 * SAW_SAMPLE_RATE) / grid_rate, - .loop_duration = 0, - .offset_x = 0, - .offset_y = ROLL_DEFAULT_OFFSET_Y, + .duration = (ROLL_DEFAULT_RATE * SAW_SAMPLE_RATE) / + grid_rate, + .loop_duration = 0, + .offset_x = 0, + .offset_y = ROLL_DEFAULT_OFFSET_Y, .last_index = -1, .grid_input = 0, @@ -953,7 +955,8 @@ static void saw_ui_roll(saw_roll_t *roll, i64 x0, i64 y0, i64 width, if (t <= 0) roll->loop_duration = 0; else - roll->loop_duration = (t * SAW_SAMPLE_RATE) / roll->rate; + roll->loop_duration = (t * SAW_SAMPLE_RATE + roll->rate / 2) / + roll->rate; } } @@ -1058,8 +1061,10 @@ static void saw_ui_roll(saw_roll_t *roll, i64 x0, i64 y0, i64 width, for (i32 n = 0; n < SHEET_SIZE; n++) { saw_roll_note_t *p = roll->notes + n; if (p->enabled && p->pitch == pitch && - t >= (p->time * roll->rate) / SAW_SAMPLE_RATE && - t < ((p->time + p->duration) * roll->rate) / + t >= (p->time * roll->rate + SAW_SAMPLE_RATE / 2) / + SAW_SAMPLE_RATE && + t < ((p->time + p->duration) * roll->rate + + SAW_SAMPLE_RATE / 2) / SAW_SAMPLE_RATE) { note = n; break; @@ -1134,8 +1139,11 @@ static void saw_ui_roll(saw_roll_t *roll, i64 x0, i64 y0, i64 width, continue; i64 x = x0 + pianokey_width + sheet_offset + roll->offset_x + - (note->time * roll->rate * sheet_scale) / SAW_SAMPLE_RATE; - i64 w = (note->duration * roll->rate * sheet_scale) / + (note->time * roll->rate * sheet_scale + + SAW_SAMPLE_RATE / 2) / + SAW_SAMPLE_RATE; + i64 w = (note->duration * roll->rate * sheet_scale + + SAW_SAMPLE_RATE / 2) / SAW_SAMPLE_RATE; i32 h = pianokey_height; @@ -1340,10 +1348,10 @@ static void saw_init(void) { .track = 0, .last_index = -1, .pitch_turned_off = { 0 }, - .rate = 6, + .rate = ROLL_DEFAULT_RATE, .notes = { 0 }, .time = 0, - .duration = (48 * SAW_SAMPLE_RATE) / 6, + .duration = (48 * SAW_SAMPLE_RATE) / ROLL_DEFAULT_RATE, .loop_duration = 0, .offset_x = 0, .offset_y = ROLL_DEFAULT_OFFSET_Y, -- cgit v1.2.3