refactor: not overlaping keyboard and midi
Clang Lint CI / lint-no-video (push) Successful in 1m0s
Clang Build CI / run-no-video (push) Successful in 1m0s
Clang Build CI / run-video (push) Successful in 1m1s
Clang Build CI / build-release (push) Successful in 1m56s
Clang Lint CI / lint-video (push) Successful in 1m59s

This commit is contained in:
2026-05-14 22:27:39 +02:00
parent 28b87d316a
commit 6abf050bcc
16 changed files with 499 additions and 420 deletions
+11 -9
View File
@@ -565,23 +565,24 @@ static bool init_single_program(ShaderProgram *program, unsigned int i,
if (program->midi_lengths.length == 0) {
index1 = 0;
for (unsigned int j = 0; j < state_config->midi_active_counts.length; j++) {
for (unsigned int k = 0; k < state_config->midi_active_counts.values[j];
for (unsigned int j = 0; j < state_config->group_active_counts.length;
j++) {
for (unsigned int k = 0; k < state_config->group_active_counts.values[j];
k++) {
program->midi_lengths.values[index1++] =
state_config->midi_counts.values[j];
state_config->group_counts.values[j];
}
}
program->midi_lengths.length = index1;
}
prefix = config_file_get_str(config, "UNIFORM_MIDI_PREFIX", "iMidi");
prefix = config_file_get_str(config, "UNIFORM_GROUP_PREFIX", "iGroup");
index2 = 0;
for (unsigned int j = 0; j < state_config->midi_active_counts.length; j++) {
for (unsigned int k = 0; k < state_config->midi_active_counts.values[j];
for (unsigned int j = 0; j < state_config->group_active_counts.length; j++) {
for (unsigned int k = 0; k < state_config->group_active_counts.values[j];
k++) {
snprintf(name, STR_LEN, "%s%d_%d", prefix, j + 1, k + 1);
program->imidi_locations[i * program->midi_lengths.length + index2++] =
program->igroup_locations[i * program->midi_lengths.length + index2++] =
glGetUniformLocation(program->programs[i], name);
}
}
@@ -755,7 +756,7 @@ static void use_program(const ShaderProgram *program, int i, bool output,
offset = 0;
for (unsigned int j = 0; j < program->midi_lengths.length; j++) {
write_uniform_multi_3f(
program->imidi_locations[i * program->midi_lengths.length + j],
program->igroup_locations[i * program->midi_lengths.length + j],
program->midi_lengths.values[j], context->values + offset);
offset += program->midi_lengths.values[j];
}
@@ -780,6 +781,7 @@ static void use_program(const ShaderProgram *program, int i, bool output,
}
// set GL_TEXTURE(X) to uniform sampler2D texX
// TODO perform input swap here
for (unsigned int j = 0; j < program->tex_count; j++) {
write_uniform_1i(program->textures_locations[i * program->tex_count + j],
j);
@@ -805,7 +807,7 @@ void shaders_init(ShaderProgram *program, const Project *project,
config_file_get_int(&project->config, "SUB_TYPE_COUNT", 0);
program->in_count = config_file_get_int(&project->config, "IN_COUNT", 0);
program->sub_variant_count = project->state_config.state_max;
program->active_count = project->state_config.midi_active_counts.length;
program->active_count = project->state_config.group_active_counts.length;
program->midi_lengths.length = 0;
#ifdef VIDEO_IN
+111 -115
View File
@@ -15,7 +15,7 @@
static void safe_midi_write(MidiDevice midi, unsigned int code,
unsigned char value) {
if (code != UNSET_MIDI_CODE) {
if (code != UNSET_MIDI_CODE && code < 1000) {
midi_write(midi, code, value);
}
}
@@ -54,11 +54,11 @@ static void update_active(const Context *context, StateConfig state_config,
MidiDevice midi, bool beat_active) {
unsigned int k;
for (unsigned int i = 0; i < state_config.midi_active_counts.length; i++) {
for (unsigned int j = 0; j < state_config.midi_active_counts.values[i];
for (unsigned int i = 0; i < state_config.group_active_counts.length; i++) {
for (unsigned int j = 0; j < state_config.group_active_counts.values[i];
j++) {
k = state_config.midi_active_offsets.values[i] + j;
safe_midi_write(midi, state_config.midi_active_codes.values[k],
k = state_config.group_active_offsets.values[i] + j;
safe_midi_write(midi, state_config.group_active_codes.values[k],
context->active[i] == j && beat_active ? MIDI_MAX : 0);
}
}
@@ -70,12 +70,12 @@ static void update_values(const Context *context, StateConfig state_config,
unsigned int k;
unsigned int part;
for (unsigned int i = 0; i < state_config.midi_codes.length; i++) {
for (unsigned int i = 0; i < state_config.codes.length; i++) {
j = i / 3;
part = arr_uint_remap_index(state_config.midi_offsets, &j);
part = arr_uint_remap_index(state_config.group_offsets, &j);
k = state_config.values_offsets.values[part] +
context->active[part] * state_config.midi_counts.values[part] + j;
safe_midi_write(midi, state_config.midi_codes.values[i],
context->active[part] * state_config.group_counts.values[part] + j;
safe_midi_write(midi, state_config.codes.values[i],
context->values[k][i % 3] * MIDI_MAX);
}
}
@@ -90,17 +90,16 @@ static void randomize(Context *context, StateConfig state_config) {
unsigned int l;
unsigned int part;
for (unsigned int i = 0; i < state_config.midi_codes.length; i++) {
for (unsigned int i = 0; i < state_config.codes.length; i++) {
j = i / 3;
part = arr_uint_remap_index(state_config.midi_offsets, &j);
for (unsigned int k = 0; k < state_config.midi_active_counts.values[part];
part = arr_uint_remap_index(state_config.group_offsets, &j);
for (unsigned int k = 0; k < state_config.group_active_counts.values[part];
k++) {
l = state_config.values_offsets.values[part] +
k * state_config.midi_counts.values[part] + j;
k * state_config.group_counts.values[part] + j;
if (arr_uint_index_of(state_config.fader_codes,
state_config.midi_codes.values[i]) !=
ARRAY_NOT_FOUND) {
state_config.codes.values[i]) != ARRAY_NOT_FOUND) {
context->values[l][i % 3] = (float)rand_uint(MIDI_MAX + 1) / MIDI_MAX;
} else {
context->values[l][i % 3] = rand_uint(2) == 1 ? 1 : 0;
@@ -137,7 +136,7 @@ static void load_from_file(Context *context, StateConfig state_config,
context->state.values[i] = config_file_get_int(&saved_state, key, 0);
}
for (unsigned int i = 0; i < state_config.midi_active_counts.length; i++) {
for (unsigned int i = 0; i < state_config.group_active_counts.length; i++) {
snprintf(key, STR_LEN, "active_%d", i);
context->active[i] = config_file_get_int(&saved_state, key, 0);
}
@@ -196,7 +195,7 @@ static void save_to_file(const Context *context, StateConfig state_config,
context->state.values[i]);
}
for (unsigned int i = 0; i < state_config.midi_active_counts.length; i++) {
for (unsigned int i = 0; i < state_config.group_active_counts.length; i++) {
snprintf(lines.values[lines.length++], STR_LEN, "active_%d=%d", i,
context->active[i]);
}
@@ -267,62 +266,62 @@ void state_parse_config(StateConfig *state_config, const ConfigFile *config) {
config_file_get_int(config, name, UNSET_MIDI_CODE);
}
state_config->midi_active_counts.length = state_config->midi_counts.length =
state_config->midi_active_offsets.length =
state_config->midi_offsets.length =
state_config->group_active_counts.length = state_config->group_counts.length =
state_config->group_active_offsets.length =
state_config->group_offsets.length =
state_config->values_offsets.length =
config_file_get_int(config, "MIDI_COUNT", 0);
config_file_get_int(config, "GROUP_COUNT", 0);
count = 0;
for (unsigned int i = 0; i < state_config->midi_active_counts.length; i++) {
snprintf(name, STR_LEN, "MIDI_%d_ACTIVE_COUNT", i + 1);
state_config->midi_active_counts.values[i] =
for (unsigned int i = 0; i < state_config->group_active_counts.length; i++) {
snprintf(name, STR_LEN, "GROUP_%d_ACTIVE_COUNT", i + 1);
state_config->group_active_counts.values[i] =
config_file_get_int(config, name, 1);
state_config->midi_active_offsets.values[i] = count;
count += state_config->midi_active_counts.values[i];
state_config->group_active_offsets.values[i] = count;
count += state_config->group_active_counts.values[i];
}
state_config->midi_active_codes.length = count;
state_config->group_active_codes.length = count;
for (unsigned int i = 0; i < state_config->midi_active_counts.length; i++) {
for (unsigned int j = 0; j < state_config->midi_active_counts.values[i];
for (unsigned int i = 0; i < state_config->group_active_counts.length; i++) {
for (unsigned int j = 0; j < state_config->group_active_counts.values[i];
j++) {
snprintf(name, STR_LEN, "MIDI_%d_ACTIVE_%d", i + 1, j + 1);
state_config->midi_active_codes
.values[state_config->midi_active_offsets.values[i] + j] =
snprintf(name, STR_LEN, "GROUP_%d_ACTIVE_%d", i + 1, j + 1);
state_config->group_active_codes
.values[state_config->group_active_offsets.values[i] + j] =
config_file_get_int(config, name, UNSET_MIDI_CODE);
}
}
count = 0;
offset = 0;
for (unsigned int i = 0; i < state_config->midi_counts.length; i++) {
snprintf(name, STR_LEN, "MIDI_%d_COUNT", i + 1);
state_config->midi_counts.values[i] = config_file_get_int(config, name, 0);
state_config->midi_offsets.values[i] = count;
for (unsigned int i = 0; i < state_config->group_counts.length; i++) {
snprintf(name, STR_LEN, "GROUP_%d_COUNT", i + 1);
state_config->group_counts.values[i] = config_file_get_int(config, name, 0);
state_config->group_offsets.values[i] = count;
state_config->values_offsets.values[i] = offset;
offset += state_config->midi_counts.values[i] *
state_config->midi_active_counts.values[i];
count += state_config->midi_counts.values[i];
offset += state_config->group_counts.values[i] *
state_config->group_active_counts.values[i];
count += state_config->group_counts.values[i];
}
state_config->value_count = offset;
state_config->midi_codes.length = count * 3;
state_config->codes.length = count * 3;
for (unsigned int i = 0; i < state_config->midi_counts.length; i++) {
offset = state_config->midi_offsets.values[i];
for (unsigned int j = 0; j < state_config->midi_counts.values[i]; j++) {
snprintf(name, STR_LEN, "MIDI_%d_%d_X", i + 1, j + 1);
state_config->midi_codes.values[(offset + j) * 3] =
for (unsigned int i = 0; i < state_config->group_counts.length; i++) {
offset = state_config->group_offsets.values[i];
for (unsigned int j = 0; j < state_config->group_counts.values[i]; j++) {
snprintf(name, STR_LEN, "GROUP_%d_%d_X", i + 1, j + 1);
state_config->codes.values[(offset + j) * 3] =
config_file_get_int(config, name, UNSET_MIDI_CODE);
snprintf(name, STR_LEN, "MIDI_%d_%d_Y", i + 1, j + 1);
state_config->midi_codes.values[(offset + j) * 3 + 1] =
snprintf(name, STR_LEN, "GROUP_%d_%d_Y", i + 1, j + 1);
state_config->codes.values[(offset + j) * 3 + 1] =
config_file_get_int(config, name, UNSET_MIDI_CODE);
snprintf(name, STR_LEN, "MIDI_%d_%d_Z", i + 1, j + 1);
state_config->midi_codes.values[(offset + j) * 3 + 2] =
snprintf(name, STR_LEN, "GROUP_%d_%d_Z", i + 1, j + 1);
state_config->codes.values[(offset + j) * 3 + 2] =
config_file_get_int(config, name, UNSET_MIDI_CODE);
}
}
@@ -343,66 +342,63 @@ void state_parse_config(StateConfig *state_config, const ConfigFile *config) {
config_file_get_str(config, "SAVE_FILE_PREFIX", "forge_save"),
STR_LEN);
state_config->hotkey_randomize =
config_file_get_int(config, "HOTKEY_RANDOMIZE", 82);
state_config->hotkey_reset =
config_file_get_int(config, "HOTKEY_RESET", 1082);
state_config->hotkey_demo = config_file_get_int(config, "HOTKEY_DEMO", 68);
state_config->hotkey_autorand =
config_file_get_int(config, "HOTKEY_AUTORAND", 65);
state_config->hotkey_autorand_down =
config_file_get_int(config, "HOTKEY_AUTORAND_DOWN", 263);
state_config->hotkey_autorand_up =
config_file_get_int(config, "HOTKEY_AUTORAND_UP", 262);
state_config->hotkey_tempo_down =
config_file_get_int(config, "HOTKEY_TEMPO_DOWN", 264);
state_config->hotkey_tempo_up =
config_file_get_int(config, "HOTKEY_TEMPO_UP", 265);
state_config->key_randomize =
config_file_get_int(config, "KEY_RANDOMIZE", 1082);
state_config->key_reset = config_file_get_int(config, "KEY_RESET", 11082);
state_config->key_demo = config_file_get_int(config, "KEY_DEMO", 1068);
state_config->key_autorand =
config_file_get_int(config, "KEY_AUTORAND", 1065);
state_config->key_autorand_down =
config_file_get_int(config, "KEY_AUTORAND_DOWN", 1263);
state_config->key_autorand_up =
config_file_get_int(config, "KEY_AUTORAND_UP", 1262);
state_config->key_tempo_down =
config_file_get_int(config, "KEY_TEMPO_DOWN", 1264);
state_config->key_tempo_up =
config_file_get_int(config, "KEY_TEMPO_UP", 1265);
if (config_file_has(config, "HOTKEY_LOAD_COUNT")) {
state_config->hotkey_load.length =
config_file_get_int(config, "HOTKEY_LOAD_COUNT", 0);
if (config_file_has(config, "KEY_LOAD_COUNT")) {
state_config->key_load.length =
config_file_get_int(config, "KEY_LOAD_COUNT", 0);
for (unsigned int i = 0; i < state_config->hotkey_load.length; i++) {
snprintf(name, STR_LEN, "HOTKEY_LOAD_%d", i + 1);
state_config->hotkey_load.values[i] =
config_file_get_int(config, name, 0);
for (unsigned int i = 0; i < state_config->key_load.length; i++) {
snprintf(name, STR_LEN, "KEY_LOAD_%d", i + 1);
state_config->key_load.values[i] = config_file_get_int(config, name, 0);
}
} else {
state_config->hotkey_load.length = 10;
state_config->hotkey_load.values[0] = 49;
state_config->hotkey_load.values[1] = 50;
state_config->hotkey_load.values[2] = 51;
state_config->hotkey_load.values[3] = 52;
state_config->hotkey_load.values[4] = 53;
state_config->hotkey_load.values[5] = 54;
state_config->hotkey_load.values[6] = 55;
state_config->hotkey_load.values[7] = 56;
state_config->hotkey_load.values[8] = 57;
state_config->hotkey_load.values[9] = 48;
state_config->key_load.length = 10;
state_config->key_load.values[0] = 1049;
state_config->key_load.values[1] = 1050;
state_config->key_load.values[2] = 1051;
state_config->key_load.values[3] = 1052;
state_config->key_load.values[4] = 1053;
state_config->key_load.values[5] = 1054;
state_config->key_load.values[6] = 1055;
state_config->key_load.values[7] = 1056;
state_config->key_load.values[8] = 1057;
state_config->key_load.values[9] = 1048;
}
if (config_file_has(config, "HOTKEY_SAVE_COUNT")) {
state_config->hotkey_save.length =
config_file_get_int(config, "HOTKEY_SAVE_COUNT", 0);
if (config_file_has(config, "KEY_SAVE_COUNT")) {
state_config->key_save.length =
config_file_get_int(config, "KEY_SAVE_COUNT", 0);
for (unsigned int i = 0; i < state_config->hotkey_save.length; i++) {
snprintf(name, STR_LEN, "HOTKEY_SAVE_%d", i + 1);
state_config->hotkey_save.values[i] =
config_file_get_int(config, name, 0);
for (unsigned int i = 0; i < state_config->key_save.length; i++) {
snprintf(name, STR_LEN, "KEY_SAVE_%d", i + 1);
state_config->key_save.values[i] = config_file_get_int(config, name, 0);
}
} else {
state_config->hotkey_save.length = 10;
state_config->hotkey_save.values[0] = 1049;
state_config->hotkey_save.values[1] = 1050;
state_config->hotkey_save.values[2] = 1051;
state_config->hotkey_save.values[3] = 1052;
state_config->hotkey_save.values[4] = 1053;
state_config->hotkey_save.values[5] = 1054;
state_config->hotkey_save.values[6] = 1055;
state_config->hotkey_save.values[7] = 1056;
state_config->hotkey_save.values[8] = 1057;
state_config->hotkey_save.values[9] = 1048;
state_config->key_save.length = 10;
state_config->key_save.values[0] = 11049;
state_config->key_save.values[1] = 11050;
state_config->key_save.values[2] = 11051;
state_config->key_save.values[3] = 11052;
state_config->key_save.values[4] = 11053;
state_config->key_save.values[5] = 11054;
state_config->key_save.values[6] = 11055;
state_config->key_save.values[7] = 11056;
state_config->key_save.values[8] = 11057;
state_config->key_save.values[9] = 11048;
}
}
@@ -449,11 +445,11 @@ void state_midi_event(Context *context, StateConfig state_config,
}
// ACTIVE CHANGE
i = arr_uint_index_of(state_config.midi_active_codes, code);
i = arr_uint_index_of(state_config.group_active_codes, code);
if (i != ARRAY_NOT_FOUND) {
found = true;
if (value > 0) {
part = arr_uint_remap_index(state_config.midi_active_offsets, &i);
part = arr_uint_remap_index(state_config.group_active_offsets, &i);
context->active[part] = i;
update_active(context, state_config, midi, true);
update_values(context, state_config, midi);
@@ -461,13 +457,13 @@ void state_midi_event(Context *context, StateConfig state_config,
}
// VALUE CHANGE
i = arr_uint_index_of(state_config.midi_codes, code);
i = arr_uint_index_of(state_config.codes, code);
if (i != ARRAY_NOT_FOUND) {
found = true;
j = i / 3;
part = arr_uint_remap_index(state_config.midi_offsets, &j);
part = arr_uint_remap_index(state_config.group_offsets, &j);
k = state_config.values_offsets.values[part] +
context->active[part] * state_config.midi_counts.values[part] + j;
context->active[part] * state_config.group_counts.values[part] + j;
if (arr_uint_index_of(state_config.fader_codes, code) != ARRAY_NOT_FOUND) {
context->values[k][i % 3] = (float)value / MIDI_MAX;
@@ -504,40 +500,40 @@ void state_key_event(Context *context, StateConfig state_config,
unsigned int code, MidiDevice midi) {
unsigned int index;
if (code == state_config.hotkey_randomize) {
if (code == state_config.key_randomize) {
log_info("[%d] Randomized", code);
randomize(context, state_config);
update_values(context, state_config, midi);
} else if (code == state_config.hotkey_reset) {
} else if (code == state_config.key_reset) {
log_info("[%d] Reset", code);
reset(context);
update_values(context, state_config, midi);
} else if (code == state_config.hotkey_demo) {
} else if (code == state_config.key_demo) {
log_info((context->demo ? "[%d] Demo OFF" : "[%d] Demo ON"), code);
context->demo = !context->demo;
} else if (code == state_config.hotkey_autorand) {
} else if (code == state_config.key_autorand) {
log_info(
(context->auto_random ? "[%d] Auto Random OFF" : "[%d] Auto Random ON"),
code);
context->auto_random = !context->auto_random;
} else if (code == state_config.hotkey_autorand_down) {
} else if (code == state_config.key_autorand_down) {
if (context->auto_random_cycle > 1) {
context->auto_random_cycle -= 1;
}
log_info("[%d] Auto Random Cycle: %d", code, context->auto_random_cycle);
} else if (code == state_config.hotkey_autorand_up) {
} else if (code == state_config.key_autorand_up) {
context->auto_random_cycle += 1;
log_info("[%d] Auto Random Cycle: %d", code, context->auto_random_cycle);
} else if (code == state_config.hotkey_tempo_up) {
} else if (code == state_config.key_tempo_up) {
tempo_set(&context->tempo, context->tempo.tempo + 1);
log_info("[%d] Tempo: %f", code, context->tempo);
} else if (code == state_config.hotkey_tempo_down) {
} else if (code == state_config.key_tempo_down) {
if (context->tempo.tempo > 0) {
tempo_set(&context->tempo, context->tempo.tempo - 1);
}
log_info("[%d] Tempo: %f", code, context->tempo);
} else {
index = arr_uint_index_of(state_config.hotkey_load, code);
index = arr_uint_index_of(state_config.key_load, code);
if (index != ARRAY_NOT_FOUND) {
log_info("[%d] Loading state %d", code, index + 1);
@@ -545,7 +541,7 @@ void state_key_event(Context *context, StateConfig state_config,
return;
}
index = arr_uint_index_of(state_config.hotkey_save, code);
index = arr_uint_index_of(state_config.key_save, code);
if (index != ARRAY_NOT_FOUND) {
log_info("[%d] Saving state %d", code, index + 1);
+17 -17
View File
@@ -116,7 +116,7 @@ typedef struct ShaderProgram {
GLuint iactive_locations[ARRAY_SIZE];
UintArray midi_lengths;
GLuint imidi_locations[ARRAY_SIZE];
GLuint igroup_locations[ARRAY_SIZE];
GLuint vpos_locations[ARRAY_SIZE];
@@ -240,12 +240,12 @@ typedef struct StateConfig {
UintArray select_page_codes;
UintArray select_item_codes;
UintArray select_frag_codes;
UintArray midi_active_counts;
UintArray midi_active_offsets;
UintArray midi_active_codes;
UintArray midi_counts;
UintArray midi_offsets;
UintArray midi_codes;
UintArray group_active_counts;
UintArray group_active_offsets;
UintArray group_active_codes;
UintArray group_counts;
UintArray group_offsets;
UintArray codes;
UintArray fader_codes;
UintArray values_offsets;
@@ -255,17 +255,17 @@ typedef struct StateConfig {
char save_file_prefix[STR_LEN];
unsigned int hotkey_randomize;
unsigned int hotkey_reset;
unsigned int hotkey_demo;
unsigned int hotkey_autorand;
unsigned int hotkey_autorand_up;
unsigned int hotkey_autorand_down;
unsigned int hotkey_tempo_up;
unsigned int hotkey_tempo_down;
unsigned int key_randomize;
unsigned int key_reset;
unsigned int key_demo;
unsigned int key_autorand;
unsigned int key_autorand_up;
unsigned int key_autorand_down;
unsigned int key_tempo_up;
unsigned int key_tempo_down;
UintArray hotkey_load;
UintArray hotkey_save;
UintArray key_load;
UintArray key_save;
} StateConfig;
typedef struct StateBackgroundWriteArgs {
+1 -1
View File
@@ -199,7 +199,7 @@ static bool request_buffers(VideoCapture *video_capture) {
reqbuf.type = buf_type;
reqbuf.memory = V4L2_MEMORY_MMAP;
reqbuf.count = 2;
reqbuf.count = 2; // TODO buffer array with count from parameters
if (ioctl(video_capture->fd, VIDIOC_REQBUFS, &reqbuf) == -1) {
ioctl_error(video_capture, "VIDIOC_REQBUFS",
+5 -5
View File
@@ -157,15 +157,15 @@ unsigned int window_read_key(int key, int action, int mods) {
key == GLFW_KEY_RIGHT_ALT) {
return 0;
}
result = key;
result = 1000 + key;
if ((mods & GLFW_MOD_SHIFT) > 0) {
result += 1000;
}
if ((mods & GLFW_MOD_CONTROL) > 0) {
result += 10000;
}
if ((mods & GLFW_MOD_ALT) > 0) {
if ((mods & GLFW_MOD_CONTROL) > 0) {
result += 100000;
}
if ((mods & GLFW_MOD_ALT) > 0) {
result += 1000000;
}
return result;
}