active selection

This commit is contained in:
2025-09-29 22:52:32 +02:00
parent 2138da7d4d
commit 8136896f59
6 changed files with 74 additions and 55 deletions
+13
View File
@@ -10,4 +10,17 @@ unsigned int arr_uint_index_of(UintArray array, unsigned int value) {
}
return ARRAY_NOT_FOUND;
}
unsigned int arr_uint_remap_index(UintArray offsets, unsigned int *index) {
unsigned int i;
for (i = offsets.length - 1; i > 0; i--) {
if (*index >= offsets.values[i]) {
*index -= offsets.values[i];
return i;
}
}
return 0;
}
+2
View File
@@ -5,4 +5,6 @@
unsigned int arr_uint_index_of(UintArray array, unsigned int value);
unsigned int arr_uint_remap_index(UintArray offsets, unsigned int *index);
#endif /* ARR_H */
+1 -3
View File
@@ -15,7 +15,7 @@ MidiDevice midi_open(char *name) {
device.error = device.input == NULL || device.output == NULL;
log_debug("(%s) MIDI open", name);
log_info("(%s) MIDI open", name);
return device;
}
@@ -51,8 +51,6 @@ bool midi_background_listen(MidiDevice device, SharedContext *context,
bytes_read = snd_rawmidi_read(device.input, buffer, 3);
if (bytes_read == 3) {
event_callback(buffer[1], (float)buffer[2] / 256.0);
log_debug("midi: %02x %d %.2f", buffer[0], buffer[1],
(float)buffer[2] / 256);
}
}
+1 -1
View File
@@ -499,7 +499,7 @@ static void use_program(ShaderProgram program, int i, bool output,
for (j = 0; j < program.active_count; j++) {
write_uniform_1i(program.iactive_locations[i * program.active_count + j],
context->active[i] + 1);
context->active[j] + 1);
}
for (j = 0; j < program.in_count; j++) {
+49 -38
View File
@@ -9,8 +9,9 @@
#include "types.h"
StateConfig state_parse_config(ConfigFile config) {
unsigned int i, j, offset, total, frag_count;
unsigned int i, j, offset, total;
StateConfig state_config;
UintArray tmp_counts;
char name[256];
state_config.select_page_codes.length =
@@ -43,55 +44,62 @@ StateConfig state_parse_config(ConfigFile config) {
config_file_get_int(config, name, UNSET_MIDI_CODE);
}
// TODO uint arrays
state_config.src_count = config_file_get_int(config, "SRC_COUNT", 0);
state_config.src_count = tmp_counts.length =
state_config.src_active_offsets.length = state_config.src_offsets.length =
config_file_get_int(config, "SRC_COUNT", 0);
total = 0;
for (i = 0; i < state_config.src_count; i++) {
for (i = 0; i < tmp_counts.length; i++) {
sprintf(name, "SRC_%d_ACTIVE_COUNT", i + 1);
state_config.src_active_counts[i] = config_file_get_int(config, name, 0);
state_config.src_active_offsets[i] = total;
total += state_config.src_active_counts[i];
tmp_counts.values[i] = config_file_get_int(config, name, 0);
state_config.src_active_offsets.values[i] = total;
total += tmp_counts.values[i];
}
for (i = 0; i < state_config.src_count; i++) {
for (j = 0; j < state_config.src_active_counts[i]; j++) {
state_config.src_active_codes.length = total;
for (i = 0; i < tmp_counts.length; i++) {
for (j = 0; j < tmp_counts.values[i]; j++) {
sprintf(name, "SRC_%d_ACTIVE_%d", i + 1, j + 1);
state_config.src_active_codes[state_config.src_active_offsets[i] + j] =
state_config.src_active_codes
.values[state_config.src_active_offsets.values[i] + j] =
config_file_get_int(config, name, UNSET_MIDI_CODE);
}
}
total = 0;
for (i = 0; i < state_config.src_count; i++) {
for (i = 0; i < tmp_counts.length; i++) {
sprintf(name, "SRC_%d_COUNT", i + 1);
state_config.src_subcounts[i] = config_file_get_int(config, name, 0);
state_config.src_offsets[i] = total;
total += state_config.src_subcounts[i];
tmp_counts.values[i] = config_file_get_int(config, name, 0);
state_config.src_offsets.values[i] = total;
total += tmp_counts.values[i];
}
for (i = 0; i < state_config.src_count; i++) {
offset = state_config.src_offsets[i];
for (j = 0; j < state_config.src_subcounts[i]; j++) {
state_config.src_codes.length = total * 3;
for (i = 0; i < tmp_counts.length; i++) {
offset = state_config.src_offsets.values[i];
for (j = 0; j < tmp_counts.values[i]; j++) {
sprintf(name, "SRC_%d_%d_X", i + 1, j + 1);
state_config.src_active_codes[(offset + j) * 3] =
state_config.src_codes.values[(offset + j) * 3] =
config_file_get_int(config, name, UNSET_MIDI_CODE);
sprintf(name, "SRC_%d_%d_Y", i + 1, j + 1);
state_config.src_active_codes[(offset + j) * 3 + 1] =
state_config.src_codes.values[(offset + j) * 3 + 1] =
config_file_get_int(config, name, UNSET_MIDI_CODE);
sprintf(name, "SRC_%d_%d_Z", i + 1, j + 1);
state_config.src_active_codes[(offset + j) * 3 + 2] =
state_config.src_codes.values[(offset + j) * 3 + 2] =
config_file_get_int(config, name, UNSET_MIDI_CODE);
}
}
state_config.fader_count = config_file_get_int(config, "FADER_COUNT", 0);
state_config.fader_codes.length =
config_file_get_int(config, "FADER_COUNT", 0);
for (i = 0; i < state_config.fader_count; i++) {
for (i = 0; i < state_config.fader_codes.length; i++) {
sprintf(name, "FADER_%d", i + 1);
state_config.fader_codes[i] =
state_config.fader_codes.values[i] =
config_file_get_int(config, name, UNSET_MIDI_CODE);
}
@@ -103,52 +111,55 @@ StateConfig state_parse_config(ConfigFile config) {
void state_apply_event(SharedContext *context, StateConfig state_config,
MidiDevice midi, unsigned char code, float value) {
unsigned int index;
unsigned int index, part;
bool found;
found = false;
if (value > 0) {
index =
arr_uint_index_of(state_config.select_page_codes, (unsigned int)code);
// PAGE CHANGE
index = arr_uint_index_of(state_config.select_page_codes, code);
if (index != ARRAY_NOT_FOUND) {
context->page = index;
found = true;
}
index = arr_uint_index_of(state_config.select_frag_codes, code);
// TARGET CHANGE
index = arr_uint_index_of(state_config.select_frag_codes, code);
if (index != ARRAY_NOT_FOUND) {
context->selected = index + 1;
found = true;
}
index = arr_uint_index_of(state_config.select_item_codes, code);
// ITEM CHANGE
index = arr_uint_index_of(state_config.select_item_codes, code);
if (index != ARRAY_NOT_FOUND) {
context->state[context->selected - 1] =
context->page * state_config.select_item_codes.length + index;
found = true;
}
}
if (!found) {
log_debug("unknown midi: %d %.2f", code, value);
// ACTIVE CHANGE
index = arr_uint_index_of(state_config.src_active_codes, code);
if (index != ARRAY_NOT_FOUND) {
part = arr_uint_remap_index(state_config.src_active_offsets, &index);
context->active[part] = index;
found = true;
}
if (!found) {
log_trace("unknown midi: %d %.2f", code, value);
}
}
midi_write(midi, code, value);
// TODO
}
bool state_background_midi_write(SharedContext *context,
StateConfig state_config, MidiDevice midi) {
bool state_background_midi_write(
SharedContext *context, __attribute__((unused)) StateConfig state_config,
__attribute__((unused)) MidiDevice midi) {
pid_t pid;
int bytes_read;
unsigned char buffer[3];
pid = fork();
if (pid < 0) {
+8 -13
View File
@@ -59,6 +59,7 @@ typedef struct ShaderProgram {
GLuint vertex_array[2];
unsigned int tex_count;
// TODO use arrays
GLuint textures[ARRAY_SIZE];
unsigned int frag_count;
@@ -118,6 +119,7 @@ typedef GLFWwindow Window;
typedef struct SharedContext {
int fd;
// TODO use arrays
int width;
int height;
unsigned int internal_width;
@@ -141,23 +143,16 @@ typedef struct SharedContext {
typedef struct StateConfig {
unsigned int state_max;
unsigned int src_count;
UintArray select_page_codes;
UintArray select_item_codes;
UintArray select_frag_codes;
// TODO Uint arrays
unsigned int src_count;
unsigned int src_active_counts[ARRAY_SIZE];
unsigned int src_active_offsets[ARRAY_SIZE];
unsigned int src_active_codes[ARRAY_SIZE];
unsigned int src_subcounts[ARRAY_SIZE];
unsigned int src_offsets[ARRAY_SIZE];
unsigned int src_codes[ARRAY_SIZE];
unsigned int fader_count;
unsigned int fader_codes[ARRAY_SIZE];
UintArray src_active_offsets;
UintArray src_active_codes;
UintArray src_offsets;
UintArray src_codes;
UintArray fader_codes;
unsigned int tap_tempo_code;
} StateConfig;