From 058d5ab589fda33f3d6b8ed841e2496d1fe06090 Mon Sep 17 00:00:00 2001 From: Nicola Pisanti Date: Thu, 25 Jul 2019 18:04:33 +0200 Subject: [PATCH] add --seed option --- README.md | 2 ++ tui_main.c | 21 ++++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d916611..413544f 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,8 @@ General options: Default: 57x25 --bpm Set the tempo (beats per minute). Default: 120 + --seed Set the seed for the random function. + Default: 1 -h or --help Print this message and exit. OSC/MIDI options: diff --git a/tui_main.c b/tui_main.c index a3f938b..d17211c 100644 --- a/tui_main.c +++ b/tui_main.c @@ -38,6 +38,8 @@ static void usage(void) { " Default: 57x25\n" " --bpm Set the tempo (beats per minute).\n" " Default: 120\n" +" --seed Set the seed for the random function.\n" +" Default: 1\n" " -h or --help Print this message and exit.\n" "\n" "OSC/MIDI options:\n" @@ -771,7 +773,7 @@ typedef struct { Usz random_seed; } Ged; -void ged_init(Ged* a, Usz undo_limit, Usz init_bpm) { +void ged_init(Ged* a, Usz undo_limit, Usz init_bpm, Usz init_seed) { field_init(&a->field); field_init(&a->scratch_field); field_init(&a->clipboard_field); @@ -808,7 +810,7 @@ void ged_init(Ged* a, Usz undo_limit, Usz init_bpm) { a->is_mouse_down = false; a->is_mouse_dragging = false; a->is_hud_visible = false; - a->random_seed = 1; + a->random_seed = init_seed; } void ged_deinit(Ged* a) { @@ -1846,6 +1848,7 @@ enum { Argopt_osc_midi_bidule, Argopt_strict_timing, Argopt_bpm, + Argopt_seed, #ifdef FEAT_PORTMIDI Argopt_portmidi_list_devices, Argopt_portmidi_output_device, @@ -1863,6 +1866,7 @@ int main(int argc, char** argv) { {"osc-midi-bidule", required_argument, 0, Argopt_osc_midi_bidule}, {"strict-timing", no_argument, 0, Argopt_strict_timing}, {"bpm", required_argument, 0, Argopt_bpm}, + {"seed", required_argument, 0, Argopt_seed}, #ifdef FEAT_PORTMIDI {"portmidi-list-devices", no_argument, 0, Argopt_portmidi_list_devices}, {"portmidi-output-device", required_argument, 0, @@ -1876,6 +1880,7 @@ int main(int argc, char** argv) { char const* osc_port = NULL; bool strict_timing = false; int init_bpm = 120; + long init_seed = 1; int init_grid_dim_y = 25; int init_grid_dim_x = 57; Midi_mode midi_mode; @@ -1924,6 +1929,16 @@ int main(int argc, char** argv) { exit(1); } } break; + case Argopt_seed: { + init_seed = atol(optarg); + if (init_bpm < 1) { + fprintf(stderr, + "Bad seed argument %s.\n" + "Must be positive integer.\n", + optarg); + exit(1); + } + } break; case Argopt_init_grid_size: { enum { Max_dim_arg_val_y = ORCA_Y_MAX, @@ -2008,7 +2023,7 @@ int main(int argc, char** argv) { qnav_init(); Ged ged_state; - ged_init(&ged_state, (Usz)undo_history_limit, (Usz)init_bpm); + ged_init(&ged_state, (Usz)undo_history_limit, (Usz)init_bpm, (Usz)init_seed); if (osc_hostname != NULL && osc_port == NULL) { fprintf(stderr,