summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2023-10-01 18:28:03 +0200
committerMitya Selivanov <automainint@guattari.tech>2023-10-01 18:28:03 +0200
commit8c91e5d45d31a5c7c836032112f83d3235f738a8 (patch)
treea41eccafd9766005c2a26769d92ce14fb55567df /source
parent8c67c8d891da66acf8692b178bec4b735be38caf (diff)
downloadsaw-8c91e5d45d31a5c7c836032112f83d3235f738a8.zip
Sheet rate fixes
Diffstat (limited to 'source')
-rw-r--r--source/saw/main.c32
1 files changed, 20 insertions, 12 deletions
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,