summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2023-09-27 05:57:41 +0200
committerMitya Selivanov <automainint@guattari.tech>2023-09-27 05:57:41 +0200
commite537c6f078de479ea9c380529b4117f510286516 (patch)
tree69266a89d03bee6205f8a61181506eae7c1a37a7 /source
parentdbaa065f8df1896a319fc7510e98a5cdec0c0bb9 (diff)
downloadsaw-e537c6f078de479ea9c380529b4117f510286516.zip
two rolls
Diffstat (limited to 'source')
-rw-r--r--source/saw/main.c82
1 files changed, 44 insertions, 38 deletions
diff --git a/source/saw/main.c b/source/saw/main.c
index a4a7168..ea9fcb2 100644
--- a/source/saw/main.c
+++ b/source/saw/main.c
@@ -70,15 +70,7 @@ static f64 saw_voice_duration[VOICE_COUNT] = { 0 };
static i8 saw_playback_on = 0;
static i64 saw_playback_frame = 0;
-static saw_roll_t saw_rolls[ROLL_COUNT] = {
- { .last_index = -1,
- .turned_off = { 0 },
- .sheet = { .rate = 6, .notes = { 0 } },
- .grid_input = 0,
- .grid_note = 0,
- .grid_pitch = 0,
- .grid_time = 0 }
-};
+static saw_roll_t saw_rolls[ROLL_COUNT];
#ifdef __GNUC__
# pragma GCC diagnostic push
@@ -111,30 +103,32 @@ static void saw_playback(i32 frame_count) {
if (!saw_playback_on)
return;
- saw_roll_t *roll = saw_rolls;
-
- for (i32 i = 0; i < SHEET_SIZE; i++) {
- saw_sheet_note_t *p = roll->sheet.notes + i;
- if (!p->enabled)
- continue;
- i64 frame = (p->time * SAW_SAMPLE_RATE) / roll->sheet.rate;
- if (saw_playback_frame + frame_count <= frame ||
- saw_playback_frame > frame)
- continue;
- if (saw_voice_on[VOICE_COUNT - 1])
- continue;
+ for (i32 k = 0; k < ROLL_COUNT; k++) {
+ saw_roll_t *roll = saw_rolls + k;
+
+ for (i32 i = 0; i < SHEET_SIZE; i++) {
+ saw_sheet_note_t *p = roll->sheet.notes + i;
+ if (!p->enabled)
+ continue;
+ i64 frame = (p->time * SAW_SAMPLE_RATE) / roll->sheet.rate;
+ if (saw_playback_frame + frame_count <= frame ||
+ saw_playback_frame > frame)
+ continue;
+ if (saw_voice_on[VOICE_COUNT - 1])
+ continue;
+
+ for (i32 n = VOICE_COUNT - 1; n > 0; --n) {
+ saw_voice_on[n] = saw_voice_on[n - 1];
+ saw_voice_pitch[n] = saw_voice_pitch[n - 1];
+ saw_voice_time[n] = saw_voice_time[n - 1];
+ saw_voice_duration[n] = saw_voice_duration[n - 1];
+ }
- for (i32 n = VOICE_COUNT - 1; n > 0; --n) {
- saw_voice_on[n] = saw_voice_on[n - 1];
- saw_voice_pitch[n] = saw_voice_pitch[n - 1];
- saw_voice_time[n] = saw_voice_time[n - 1];
- saw_voice_duration[n] = saw_voice_duration[n - 1];
+ saw_voice_on[0] = 1;
+ saw_voice_pitch[0] = p->pitch;
+ saw_voice_time[0] = 0;
+ saw_voice_duration[0] = ((f64) p->duration) / roll->sheet.rate;
}
-
- saw_voice_on[0] = 1;
- saw_voice_pitch[0] = p->pitch;
- saw_voice_time[0] = 0;
- saw_voice_duration[0] = ((f64) p->duration) / roll->sheet.rate;
}
saw_playback_frame += frame_count;
@@ -211,9 +205,9 @@ static void saw_ui_roll(saw_roll_t *roll, i64 x0, i64 y0, i64 width,
i32 w = pianokey_width - roll_border * 2;
i32 h = pianokey_height - roll_border * 2;
- if (y > y0 + height)
+ if (y > frame_height - y0)
continue;
- if (y < y0)
+ if (y < frame_height - y0 - height)
break;
nvgBeginPath(saw_nvg);
@@ -267,9 +261,9 @@ static void saw_ui_roll(saw_roll_t *roll, i64 x0, i64 y0, i64 width,
for (i32 pitch = 0; pitch < ROLL_SIZE; pitch++) {
i32 y = frame_height - y0 - (pitch + 1) * pianokey_height;
- if (y > y0 + height - pianokey_height)
+ if (y > frame_height - y0)
continue;
- if (y < y0)
+ if (y < frame_height - y0 - height)
break;
i32 h = pianokey_height;
@@ -413,8 +407,8 @@ static void saw_ui_roll(saw_roll_t *roll, i64 x0, i64 y0, i64 width,
i32 w = roll_border * 4;
nvgBeginPath(saw_nvg);
- nvgRect(saw_nvg, x, y0, w, height);
- nvgFillColor(saw_nvg, nvgRGBA(240, 240, 80, 220));
+ nvgRect(saw_nvg, x, frame_height - y0 - height, w, height);
+ nvgFillColor(saw_nvg, nvgRGBA(240, 240, 80, 180));
nvgFill(saw_nvg);
}
@@ -442,6 +436,16 @@ static void saw_init(void) {
}
ma_device_start(&saw_ma);
+
+ for (i32 i = 0; i < ROLL_COUNT; i++)
+ saw_rolls[i] = (saw_roll_t) { .last_index = -1,
+ .turned_off = { 0 },
+ .sheet = { .rate = 6,
+ .notes = { 0 } },
+ .grid_input = 0,
+ .grid_note = 0,
+ .grid_pitch = 0,
+ .grid_time = 0 };
}
static void saw_frame(void) {
@@ -456,7 +460,9 @@ static void saw_frame(void) {
nvgBeginFrame(saw_nvg, frame_width, frame_height, sapp_dpi_scale());
- saw_ui_roll(saw_rolls, 0, 0, frame_width, frame_height);
+ saw_ui_roll(saw_rolls, 0, 10, frame_width, frame_height / 2 - 20);
+ saw_ui_roll(saw_rolls + 1, 0, frame_height / 2 + 10, frame_width,
+ frame_height / 2 - 20);
nvgEndFrame(saw_nvg);