diff options
author | Mitya Selivanov <automainint@guattari.tech> | 2023-10-01 21:35:23 +0200 |
---|---|---|
committer | Mitya Selivanov <automainint@guattari.tech> | 2023-10-01 21:35:23 +0200 |
commit | 09e6882619596bceed7083098ed9b5c239480f31 (patch) | |
tree | 4d8f4f95fdb504b6b9e6db6da59a6af8c0f04d24 | |
parent | 8c91e5d45d31a5c7c836032112f83d3235f738a8 (diff) | |
download | saw-09e6882619596bceed7083098ed9b5c239480f31.zip |
UI: duplicate improvement; Note placing sound
-rw-r--r-- | source/saw/main.c | 120 |
1 files changed, 72 insertions, 48 deletions
diff --git a/source/saw/main.c b/source/saw/main.c index 0cb30d3..81ed0ee 100644 --- a/source/saw/main.c +++ b/source/saw/main.c @@ -138,6 +138,7 @@ typedef struct { i8 offset_input; i64 offset_x; i64 offset_y; + i8 duplicate_input; } saw_compose_t; static struct NVGcontext *saw_nvg; @@ -167,13 +168,14 @@ static saw_roll_t saw_rolls[ROLL_COUNT]; static saw_track_t saw_tracks[TRACK_COUNT]; static saw_compose_t saw_compose = { - .rolls = { -1 }, - .grid_input = 0, - .grid_roll = 0, - .grid_cell = 0, - .offset_input = 0, - .offset_x = 0, - .offset_y = 0, + .rolls = { -1 }, + .grid_input = 0, + .grid_roll = 0, + .grid_cell = 0, + .offset_input = 0, + .offset_x = 0, + .offset_y = 0, + .duplicate_input = 0, }; #ifdef __GNUC__ @@ -551,6 +553,66 @@ static void saw_ui_compose(i64 x0, i64 y0, i64 width, i64 height) { } } + // Duplicate selected sheet + // + + if (saw_compose.duplicate_input) { + saw_compose.duplicate_input = 0; + + do { + if (saw_current_roll == -1) + break; + + i64 track = (saw_mouse_y - saw_compose.offset_y - frame_height + + y0 + height) / + track_height - + 1; + i64 cell = ((saw_mouse_x - saw_compose.offset_x) * grid_rate) / + grid_scale; + i64 frame = (cell * SAW_SAMPLE_RATE) / grid_rate; + + i64 n = -1; + + saw_roll_t *roll = saw_rolls + saw_current_roll; + + i8 collision = 0; + + for (i64 i = 0; i < ROLL_COUNT; i++) { + saw_roll_t *p = saw_rolls + i; + + if (p->enabled && p->track == track && + ((p->time >= frame && p->time < frame + roll->duration) || + (frame >= p->time && + frame < p->time + p->time + p->duration))) { + collision = 1; + break; + } + } + + if (collision) + break; + + for (i64 i = 0; i < ROLL_COUNT; i++) + if (!saw_rolls[i].enabled) { + n = i; + break; + } + + if (n == -1) + break; + + for (i64 i = 0; i < ROLL_COUNT; i++) + if (saw_compose.rolls[i] == -1) { + saw_compose.rolls[i] = n; + break; + } + + saw_rolls[n] = *roll; + saw_rolls[n].track = track; + saw_rolls[n].time = frame; + } while (0); + } + // Panning input // @@ -1117,6 +1179,8 @@ static void saw_ui_roll(saw_roll_t *roll, i64 x0, i64 y0, i64 width, roll->grid_input = 1; roll->grid_note = n; roll->grid_time = t; + saw_play_voice(saw_tracks + roll->track, roll, pitch, + SAW_SAMPLE_RATE / roll->rate); break; } } @@ -1863,47 +1927,7 @@ static void saw_event(sapp_event const *event) { break; - case SAPP_KEYCODE_D: - if (saw_current_roll != -1) { - i64 n = -1; - - saw_roll_t *roll = saw_rolls + saw_current_roll; - - i8 collision = 0; - - for (i64 i = 0; i < ROLL_COUNT; i++) - if (saw_rolls[i].enabled && - saw_rolls[i].track == roll->track && - saw_rolls[i].time >= - roll->time + roll->duration && - saw_rolls[i].time < - roll->time + roll->duration * 2) { - collision = 1; - break; - } - - if (collision) - break; - - for (i64 i = 0; i < ROLL_COUNT; i++) - if (!saw_rolls[i].enabled) { - n = i; - break; - } - - if (n == -1) - break; - - for (i64 i = 0; i < ROLL_COUNT; i++) - if (saw_compose.rolls[i] == -1) { - saw_compose.rolls[i] = n; - break; - } - - saw_rolls[n] = *roll; - saw_rolls[n].time = roll->time + roll->duration; - } - break; + case SAPP_KEYCODE_D: saw_compose.duplicate_input = 1; break; default:; } |