feat: arrow keys to control bpm/cycle

This commit is contained in:
2025-11-14 10:20:55 +01:00
parent 7739ac8254
commit f0c5ecab16
13 changed files with 77 additions and 23 deletions
+3 -3
View File
@@ -127,7 +127,7 @@ void args_parse(Parameters *params, int argc, char **argv) {
params->base_tempo = 60.0f;
params->demo = false;
params->auto_random = false;
params->auto_random_cycles = 4;
params->auto_random_cycle = 4;
params->video_in.length = 0;
params->video_size = 0;
params->internal_size = 720;
@@ -173,8 +173,8 @@ void args_parse(Parameters *params, int argc, char **argv) {
} else if (is_arg(arg, "-nar") || is_arg(arg, "--no-auto-random")) {
params->auto_random = false;
} else if (is_arg(arg, "-arc") || is_arg(arg, "--auto-random-cycle")) {
params->auto_random_cycles = parse_uint(arg, value);
if (params->auto_random_cycles == 0) {
params->auto_random_cycle = parse_uint(arg, value);
if (params->auto_random_cycle == 0) {
invalid_value(arg, value);
}
} else if (is_arg(arg, "-v") || is_arg(arg, "--video-in")) {
+1 -1
View File
@@ -59,7 +59,7 @@ static void compute_fps(bool trace_fps) {
static void init_context(const Parameters *params, unsigned int in_count) {
state_init(context, &project.state_config, params->demo, params->auto_random,
params->auto_random_cycles, params->base_tempo, params->state_file,
params->auto_random_cycle, params->base_tempo, params->state_file,
params->load_state);
context->monitor = params->monitor;
+5
View File
@@ -280,6 +280,9 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
program->iautorand_locations[i] = glGetUniformLocation(
program->programs[i],
config_file_get_str(config, "UNIFORM_AUTORAND", "iAutoRand"));
program->iautorandcycle_locations[i] = glGetUniformLocation(
program->programs[i],
config_file_get_str(config, "UNIFORM_AUTORANDCYCLE", "iAutoRandCycle"));
program->ipage_locations[i] = glGetUniformLocation(
program->programs[i],
config_file_get_str(config, "UNIFORM_PAGE", "iPage"));
@@ -545,6 +548,8 @@ static void use_program(const ShaderProgram *program, int i, bool output,
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->iautorandcycle_locations[i],
context->auto_random_cycle);
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);
+22 -2
View File
@@ -301,6 +301,26 @@ void state_key_event(SharedContext *context, const StateConfig *state_config,
log_info(
(context->auto_random ? "[A] Auto Random OFF" : "[A] Auto Random ON"));
context->auto_random = !context->auto_random;
} else if (code == 263) {
// LEFT ARROW
if (context->auto_random_cycle > 1) {
context->auto_random_cycle -= 1;
}
log_info("[LEFT] Auto Random Cycle: %d", context->auto_random_cycle);
} else if (code == 262) {
// RIGHT ARROW
context->auto_random_cycle += 1;
log_info("[RIGHT] Auto Random Cycle: %d", context->auto_random_cycle);
} else if (code == 265) {
// UP ARROW
tempo_set(&context->tempo, context->tempo.tempo + 1);
log_info("[UP] Tempo: %f", context->tempo);
} else if (code == 264) {
// DOWN ARROW
if (context->tempo.tempo > 0) {
tempo_set(&context->tempo, context->tempo.tempo - 1);
}
log_info("[DOWN] Tempo: %f", context->tempo);
} else {
log_info("[%d] No hotkey defined", code);
}
@@ -353,7 +373,7 @@ bool state_background_write(SharedContext *context,
last_active = beat_active;
change = tempo_progress(&context->tempo,
(double)context->auto_random_cycles) < 0.5;
(double)context->auto_random_cycle) < 0.5;
if (context->auto_random && change && !last_change) {
state_randomize(context, state_config);
@@ -416,7 +436,7 @@ void state_init(SharedContext *context, const StateConfig *state_config,
tempo_set(&context->tempo, base_tempo);
context->demo = demo;
context->auto_random = auto_random;
context->auto_random_cycles = auto_random_cycles;
context->auto_random_cycle = auto_random_cycles;
context->state.length = state_config->select_frag_codes.length;
memset(context->state.values, 0, sizeof(context->state.values));
+9
View File
@@ -99,8 +99,17 @@ static void add_tap_to_chain(Tempo *tempo, long t) {
}
void tempo_set(Tempo *tempo, float value) {
long t;
long progress;
t = now();
progress = (t - tempo->last_reset) % tempo->beat_length;
tempo->tempo = value;
tempo->beat_length = 60000.0 / value;
reset_tap_chain(tempo, t - progress);
}
void tempo_tap(Tempo *tempo) {
+3 -2
View File
@@ -43,7 +43,7 @@ typedef struct Parameters {
float base_tempo;
bool demo;
bool auto_random;
unsigned int auto_random_cycles;
unsigned int auto_random_cycle;
StringArray video_in;
unsigned int video_size;
unsigned int internal_size;
@@ -105,6 +105,7 @@ typedef struct ShaderProgram {
GLuint iinfps_locations[ARRAY_SIZE];
GLuint idemo_locations[ARRAY_SIZE];
GLuint iautorand_locations[ARRAY_SIZE];
GLuint iautorandcycle_locations[ARRAY_SIZE];
GLuint iseed_locations[ARRAY_SIZE];
GLuint istate_locations[ARRAY_SIZE];
GLuint ipage_locations[ARRAY_SIZE];
@@ -183,7 +184,7 @@ typedef struct SharedContext {
vec3 values[ARRAY_SIZE];
bool demo;
bool auto_random;
unsigned int auto_random_cycles;
unsigned int auto_random_cycle;
unsigned int seeds[MAX_FRAG];
bool monitor;