summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/saw/main.c72
1 files changed, 21 insertions, 51 deletions
diff --git a/source/saw/main.c b/source/saw/main.c
index 3301c06..425f210 100644
--- a/source/saw/main.c
+++ b/source/saw/main.c
@@ -221,8 +221,6 @@ typedef struct {
} saw_track_t;
typedef struct {
- i64 rolls[ROLL_COUNT];
-
// dynamic properties
//
b8 grid_input;
@@ -315,13 +313,9 @@ 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,
- .ui_offset_input = 0,
- .ui_offset_x = 0,
- .ui_offset_y = 0,
+ //.rolls = { -1 },
+ .grid_input = 0, .grid_roll = 0, .grid_cell = 0,
+ .ui_offset_input = 0, .ui_offset_x = 0, .ui_offset_y = 0,
.duplicate_input = 0,
};
@@ -1324,9 +1318,10 @@ static void saw_ui_compose(i64 x0, i64 y0, i64 width, i64 height) {
b8 hover_any = 0;
for (i64 i = 0; i < ROLL_COUNT; i++) {
- if (saw_compose.rolls[i] == -1)
+ saw_roll_t *roll = saw_rolls + i;
+
+ if (!roll->enabled)
continue;
- saw_roll_t *roll = saw_rolls + saw_compose.rolls[i];
i64 top = frame_height - y0 - height + track_height;
i64 bottom = frame_height - y0;
@@ -1378,13 +1373,12 @@ static void saw_ui_compose(i64 x0, i64 y0, i64 width, i64 height) {
if (has_cursor) {
if (saw_rbutton_down ||
(saw_edit_mode == EDIT_MODE_ERASE && saw_lbutton_down)) {
- if (saw_current_roll == saw_compose.rolls[i])
+ if (saw_current_roll == i)
saw_current_roll = -1;
- saw_compose.rolls[i] = -1;
- roll->enabled = 0;
+ roll->enabled = 0;
} else {
if (saw_edit_mode == EDIT_MODE_HAND && saw_lbutton_click) {
- if (saw_current_roll == saw_compose.rolls[i]) {
+ if (saw_current_roll == i) {
i64 cell = ((saw_mouse_x - saw_compose.ui_offset_x) *
grid_rate) /
grid_scale;
@@ -1402,7 +1396,7 @@ static void saw_ui_compose(i64 x0, i64 y0, i64 width, i64 height) {
grid_rate;
}
} else {
- saw_current_roll = saw_compose.rolls[i];
+ saw_current_roll = i;
saw_current_track = roll->track;
}
}
@@ -1456,14 +1450,9 @@ static void saw_ui_compose(i64 x0, i64 y0, i64 width, i64 height) {
n = -1;
if (n != -1) {
- for (i64 i = 0; i < ROLL_COUNT; i++)
- if (saw_compose.rolls[i] == -1) {
- saw_compose.rolls[i] = n;
- saw_compose.grid_input = 1;
- saw_compose.grid_roll = n;
- saw_compose.grid_cell = cell;
- break;
- }
+ saw_compose.grid_input = 1;
+ saw_compose.grid_roll = n;
+ saw_compose.grid_cell = cell;
saw_rolls[n] = (saw_roll_t) {
.enabled = 1,
@@ -1549,12 +1538,6 @@ static void saw_ui_compose(i64 x0, i64 y0, i64 width, i64 height) {
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;
@@ -2601,8 +2584,6 @@ static void saw_init(void) {
saw_tuning_equal_temperament(tuning);
for (i32 i = 0; i < ROLL_COUNT; i++) {
- saw_compose.rolls[i] = (i == 0 ? 0 : -1);
-
saw_rolls[i] = (saw_roll_t) {
.enabled = (i == 0),
.track = 0,
@@ -2682,6 +2663,8 @@ static void saw_init(void) {
// Load the project from a file
//
+ saw_current_roll = -1;
+
if (path_type(saw_project_file) == PATH_FILE) {
FILE *f = fopen(BS(saw_project_file), "rb");
@@ -2702,17 +2685,6 @@ static void saw_init(void) {
} while (0)
i32 total_rolls;
- SCAN_(" compose_rolls %d", 1, &total_rolls);
-
- if (total_rolls < 0 || total_rolls > ROLL_COUNT) {
- printf("Invalid roll count: %d\n", total_rolls);
- fflush(stdout);
- fclose(f);
- return;
- }
-
- for (i64 i = 0; i < total_rolls; i++)
- SCAN_(" %lld", 1, saw_compose.rolls + i);
SCAN_(" rolls %d", 1, &total_rolls);
@@ -2723,6 +2695,9 @@ static void saw_init(void) {
SCAN_(" enabled %d", 1, &enabled);
roll->enabled = enabled ? 1 : 0;
+ if (enabled && saw_current_roll == -1)
+ saw_current_roll = i;
+
SCAN_(" track %lld", 1, &roll->track);
i32 pitch_count;
@@ -2785,6 +2760,9 @@ static void saw_init(void) {
&roll->ui_offset_y);
}
+ for (i64 i = total_rolls; i < ROLL_COUNT; ++i)
+ saw_rolls[i].enabled = false;
+
i32 total_tracks;
SCAN_(" tracks %d", 1, &total_tracks);
@@ -3074,14 +3052,6 @@ static void saw_cleanup(void) {
return;
}
- // Save the compose
- //
-
- fprintf(f, "compose_rolls %d", ROLL_COUNT);
- for (i64 i = 0; i < ROLL_COUNT; i++)
- fprintf(f, " %lld", saw_compose.rolls[i]);
- fprintf(f, "\n\n");
-
// Save rolls
//