summaryrefslogtreecommitdiff
path: root/source/saw
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2024-02-11 18:17:33 +0100
committerMitya Selivanov <automainint@guattari.tech>2024-02-11 18:17:33 +0100
commitdf00df5a7a5bcd9076d4423128ea014ab3535626 (patch)
tree337e62f8ca39b19b250b155a3fbeb495384e356b /source/saw
parent80da54bb97c279aa60fb77a9bbad9baa0f2e4477 (diff)
downloadsaw-df00df5a7a5bcd9076d4423128ea014ab3535626.zip
Update kit
Diffstat (limited to 'source/saw')
-rw-r--r--source/saw/main.c74
1 files changed, 39 insertions, 35 deletions
diff --git a/source/saw/main.c b/source/saw/main.c
index eba5c00..c793517 100644
--- a/source/saw/main.c
+++ b/source/saw/main.c
@@ -67,7 +67,7 @@ enum {
};
typedef struct {
- i8 enabled;
+ b8 enabled;
i64 time;
f64 duration;
f64 frequency;
@@ -77,16 +77,16 @@ typedef struct {
} saw_voice_t;
typedef struct {
- i8 enabled;
+ b8 enabled;
i64 time;
i64 duration;
i64 pitch;
} saw_roll_note_t;
typedef struct {
- i8 enabled;
+ b8 enabled;
i64 track;
- i8 pitch_turned_off[PITCH_COUNT];
+ b8 pitch_turned_off[PITCH_COUNT];
i64 rate;
saw_roll_note_t notes[SHEET_SIZE];
i64 time;
@@ -98,12 +98,12 @@ typedef struct {
// dynamic properties
//
i32 last_index;
- i8 grid_input;
+ b8 grid_input;
i32 grid_note;
i32 grid_time;
- i8 offset_x_input;
- i8 offset_y_input;
- i8 loop_input;
+ b8 offset_x_input;
+ b8 offset_y_input;
+ b8 loop_input;
} saw_roll_t;
typedef struct {
@@ -134,13 +134,13 @@ typedef struct {
// dynamic properties
//
- i8 grid_input;
+ b8 grid_input;
i32 grid_roll;
i32 grid_cell;
- i8 offset_input;
+ b8 offset_input;
i64 offset_x;
i64 offset_y;
- i8 duplicate_input;
+ b8 duplicate_input;
} saw_compose_t;
static struct NVGcontext *saw_nvg;
@@ -154,14 +154,14 @@ static mt64_state_t saw_mt64;
static i32 saw_mouse_x = 0;
static i32 saw_mouse_y = 0;
-static i8 saw_lbutton_click = 0;
-static i8 saw_lbutton_down = 0;
-static i8 saw_rbutton_click = 0;
-static i8 saw_rbutton_down = 0;
-static i8 saw_mbutton_click = 0;
-static i8 saw_mbutton_down = 0;
-
-static i8 saw_playback_on = 0;
+static b8 saw_lbutton_click = 0;
+static b8 saw_lbutton_down = 0;
+static b8 saw_rbutton_click = 0;
+static b8 saw_rbutton_down = 0;
+static b8 saw_mbutton_click = 0;
+static b8 saw_mbutton_down = 0;
+
+static b8 saw_playback_on = 0;
static i64 saw_playback_frame = 0;
static i64 saw_current_track = 0;
static i64 saw_current_roll = 0;
@@ -386,7 +386,7 @@ static void saw_ui_compose(i64 x0, i64 y0, i64 width, i64 height) {
// Tracks
//
- i8 hover_any = 0;
+ b8 hover_any = 0;
for (i64 i = 0; i < ROLL_COUNT; i++) {
if (saw_compose.rolls[i] == -1)
@@ -420,13 +420,13 @@ static void saw_ui_compose(i64 x0, i64 y0, i64 width, i64 height) {
i64 y = u;
i64 h = d - u;
- i8 is_choosen = (saw_current_roll == i);
+ b8 is_choosen = (saw_current_roll == i);
- i8 is_playing = saw_playback_on &&
+ b8 is_playing = saw_playback_on &&
saw_playback_frame >= roll->time &&
saw_playback_frame < roll->time + roll->duration;
- i8 has_cursor = (saw_compose.grid_input &&
+ b8 has_cursor = (saw_compose.grid_input &&
saw_compose.grid_roll == i) ||
(saw_mouse_x >= x && saw_mouse_x < x + w &&
saw_mouse_y >= y && saw_mouse_y < y + h);
@@ -580,7 +580,7 @@ static void saw_ui_compose(i64 x0, i64 y0, i64 width, i64 height) {
saw_roll_t *roll = saw_rolls + saw_current_roll;
- i8 collision = 0;
+ b8 collision = 0;
for (i64 i = 0; i < ROLL_COUNT; i++) {
saw_roll_t *p = saw_rolls + i;
@@ -1047,7 +1047,7 @@ static void saw_ui_roll(saw_roll_t *roll, i64 x0, i64 y0, i64 width,
// Piano roll
//
- i8 hover_any = 0;
+ b8 hover_any = 0;
for (i32 pitch = 0; pitch < PITCH_COUNT; pitch++) {
i32 x = x0 + border;
@@ -1064,7 +1064,7 @@ static void saw_ui_roll(saw_roll_t *roll, i64 x0, i64 y0, i64 width,
nvgBeginPath(saw_nvg);
nvgRect(saw_nvg, x, y, w, h);
- i8 has_cursor = saw_mouse_x >= x && saw_mouse_x < x + w &&
+ b8 has_cursor = saw_mouse_x >= x && saw_mouse_x < x + w &&
saw_mouse_y >= y && saw_mouse_y < y + h;
nvgFillColor(saw_nvg, roll->pitch_turned_off[pitch]
@@ -1167,12 +1167,12 @@ static void saw_ui_roll(saw_roll_t *roll, i64 x0, i64 y0, i64 width,
nvgRect(saw_nvg, x + border, y + border, w - border * 2,
h - border * 2);
- i8 turned_off = roll->pitch_turned_off[pitch] ||
+ b8 turned_off = roll->pitch_turned_off[pitch] ||
(roll->loop_duration > 0 &&
t >= (roll->loop_duration * roll->rate) /
SAMPLE_RATE);
- i8 has_cursor = !roll->grid_input && saw_mouse_x >= x &&
+ b8 has_cursor = !roll->grid_input && saw_mouse_x >= x &&
saw_mouse_x < x + w && saw_mouse_y >= y &&
saw_mouse_y < y + h;
@@ -1230,7 +1230,7 @@ static void saw_ui_roll(saw_roll_t *roll, i64 x0, i64 y0, i64 width,
SAMPLE_RATE;
i32 h = pianokey_height;
- i8 has_cursor = (roll->grid_input && roll->grid_note == n) ||
+ b8 has_cursor = (roll->grid_input && roll->grid_note == n) ||
(saw_mouse_x >= x && saw_mouse_x < x + w &&
saw_mouse_y >= y && saw_mouse_y < y + h);
@@ -1249,7 +1249,7 @@ static void saw_ui_roll(saw_roll_t *roll, i64 x0, i64 y0, i64 width,
frame -= ((frame - roll->time) / roll->loop_duration) *
roll->loop_duration;
- i8 is_playing = saw_playback_on &&
+ b8 is_playing = saw_playback_on &&
frame >= roll->time + note->time &&
frame < roll->time + note->time + note->duration;
@@ -1492,7 +1492,7 @@ static void saw_init(void) {
str_builder_t cache = path_join(WRAP_STR(path_cache(&arena)),
SZ("saw"), &arena);
- kit_status_t s = folder_create_recursive(WRAP_STR(cache));
+ s32 s = folder_create_recursive(WRAP_STR(cache));
if (s != KIT_OK)
printf("Failed to create cache folder: %s\n (code %d)",
@@ -1635,10 +1635,10 @@ static void saw_frame(void) {
glViewport(0, 0, frame_width, frame_height);
glClearColor(.15f, .12f, .10f, 1.f);
-#if defined(__EMSCRIPTEN__)
- glClearDepthf(1.f);
-#else
+#ifdef SOKOL_GLCORE33
glClearDepth(1.);
+#else
+ glClearDepthf(1.f);
#endif
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT |
GL_STENCIL_BUFFER_BIT);
@@ -1788,6 +1788,10 @@ static void saw_cleanup(void) {
}
static void saw_event(sapp_event const *event) {
+ // FIXME
+ // Do input processing in frame update procedure.
+ //
+
switch (event->type) {
case SAPP_EVENTTYPE_MOUSE_MOVE:
saw_mouse_x = event->mouse_x;
@@ -1993,7 +1997,7 @@ static void log_(const char *tag, uint32_t log_level,
}
sapp_desc sokol_main(i32 argc, char **argv) {
- i8 print_version = 0;
+ b8 print_version = 0;
for (i32 i = 0; i < argc; i++)
if (strcmp(argv[i], "--version") == 0)