feat: auto random

This commit is contained in:
2025-11-08 13:09:12 +01:00
parent ae833b04ff
commit abe138ecf9
10 changed files with 50 additions and 12 deletions
+10 -1
View File
@@ -30,6 +30,7 @@ static void print_help(int status_code) {
"[-vs=SIZE] "
"[-t=TEMPO] "
"[-d] "
"[-ar / -nar] "
"[-w] "
"[-tm] "
"[-tf] "
@@ -59,7 +60,9 @@ static void print_help(int status_code) {
"internal texture height)\n"
" -t, --tempo base tempo (default: 60)\n"
" -d, --demo demonstration mode (assume --no-save-state "
"and --no-load-state)\n"
", --no-load-state, --auto-random)\n"
" -ar, --auto-random randomize state every 4 beats\n"
" -nar, --no-auto-random do not randomize state (default)\n"
" -w, --windowed not fullscreen\n"
" -tm, --trace-midi print midi code and values\n"
" -tf, --trace-fps print fps status of subsystems\n");
@@ -116,6 +119,7 @@ Parameters args_parse(int argc, char **argv) {
params.video_size = 0;
params.base_tempo = 60.0f;
params.demo = false;
params.auto_random = false;
params.windowed = false;
params.video_in.length = 0;
params.trace_midi = false;
@@ -175,6 +179,11 @@ Parameters args_parse(int argc, char **argv) {
params.demo = true;
params.load_state = false;
params.save_state = false;
params.auto_random = true;
} else if (is_arg(arg, "-ar") || is_arg(arg, "--auto-random")) {
params.auto_random = true;
} else if (is_arg(arg, "-nar") || is_arg(arg, "--no-auto-random")) {
params.auto_random = false;
} else if (is_arg(arg, "-w") || is_arg(arg, "--windowed")) {
params.windowed = true;
} else if (is_arg(arg, "-tm") || is_arg(arg, "--trace-midi")) {
+7 -2
View File
@@ -61,8 +61,8 @@ static void compute_fps(bool trace_fps) {
static void init_context(Parameters params, unsigned int in_count) {
unsigned int i;
state_init(context, state_config, params.demo, params.base_tempo,
params.state_file, params.load_state);
state_init(context, state_config, params.demo, params.auto_random,
params.base_tempo, params.state_file, params.load_state);
context->monitor = params.monitor;
@@ -199,6 +199,11 @@ static void key_callback(Window *window, int key,
// D: demo on/off
log_info((context->demo ? "[D] Demo OFF" : "[D] Demo ON"));
context->demo = !context->demo;
} else if (window_char_key(key, action, 65)) {
// A: auto random on/off
log_info(
(context->auto_random ? "[A] Auto Random OFF" : "[A] Auto Random ON"));
context->auto_random = !context->auto_random;
}
}
+5
View File
@@ -268,6 +268,9 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
program->idemo_locations[i] = glGetUniformLocation(
program->programs[i],
config_file_get_str(config, "UNIFORM_DEMO", "iDemo"));
program->iautorand_locations[i] = glGetUniformLocation(
program->programs[i],
config_file_get_str(config, "UNIFORM_AUTORAND", "iAutoRand"));
program->ipage_locations[i] = glGetUniformLocation(
program->programs[i],
config_file_get_str(config, "UNIFORM_PAGE", "iPage"));
@@ -515,6 +518,8 @@ static void use_program(ShaderProgram program, int i, bool output,
write_uniform_1f(program.ibeats_locations[i], context->tempo_total);
write_uniform_1i(program.ifps_locations[i], context->fps);
write_uniform_1i(program.idemo_locations[i], context->demo ? 1 : 0);
write_uniform_1i(program.iautorand_locations[i],
context->auto_random ? 1 : 0);
write_uniform_1i(program.ipage_locations[i], context->page);
write_uniform_1i(program.iselected_locations[i], context->selected + 1);
write_uniform_2f(program.ires_locations[i], &context->resolution);
+5 -3
View File
@@ -312,7 +312,7 @@ bool state_background_write(SharedContext *context, StateConfig state_config,
change = tempo_progress(context->tempo, 4.0) < 0.25;
if (context->demo && change && !last_change) {
if (context->auto_random && change && !last_change) {
state_randomize(context, state_config);
}
@@ -365,17 +365,19 @@ static void state_load(SharedContext *context, StateConfig state_config,
}
void state_init(SharedContext *context, StateConfig state_config, bool demo,
unsigned int base_tempo, char *state_file, bool load_state) {
bool auto_random, unsigned int base_tempo, char *state_file,
bool load_state) {
unsigned int i;
context->tempo = tempo_init();
tempo_set(&context->tempo, base_tempo);
context->demo = demo;
context->auto_random = auto_random;
context->state.length = state_config.select_frag_codes.length;
memset(context->state.values, 0, sizeof(context->state.values));
if (demo) {
if (auto_random) {
state_randomize(context, state_config);
}
+2 -1
View File
@@ -13,7 +13,8 @@ bool state_background_write(SharedContext *context, StateConfig state_config,
MidiDevice midi);
void state_init(SharedContext *context, StateConfig state_config, bool demo,
unsigned int base_tempo, char *state_file, bool load_state);
bool auto_random, unsigned int base_tempo, char *state_file,
bool load_state);
void state_randomize(SharedContext *context, StateConfig state_config);
+3
View File
@@ -44,6 +44,7 @@ typedef struct Parameters {
unsigned int video_size;
float base_tempo;
bool demo;
bool auto_random;
bool windowed;
StringArray video_in;
bool trace_midi;
@@ -96,6 +97,7 @@ typedef struct ShaderProgram {
GLuint iinfmt_locations[ARRAY_SIZE];
GLuint iinfps_locations[ARRAY_SIZE];
GLuint idemo_locations[ARRAY_SIZE];
GLuint iautorand_locations[ARRAY_SIZE];
GLuint iseed_locations[ARRAY_SIZE];
GLuint istate_locations[ARRAY_SIZE];
GLuint ipage_locations[ARRAY_SIZE];
@@ -165,6 +167,7 @@ typedef struct SharedContext {
unsigned int active[ARRAY_SIZE];
vec3 values[ARRAY_SIZE];
bool demo;
bool auto_random;
unsigned int seeds[MAX_FRAG];
bool monitor;