so close rn
This commit is contained in:
+17
-7
@@ -326,17 +326,26 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
|
||||
glGetUniformLocation(program->programs[i], name);
|
||||
}
|
||||
|
||||
if (program->src_lengths.length == 0) {
|
||||
index1 = 0;
|
||||
for (j = 0; j < state_config.src_active_counts.length; j++) {
|
||||
for (k = 0; k < state_config.src_active_counts.values[j]; k++) {
|
||||
program->src_lengths.values[index1++] =
|
||||
state_config.src_counts.values[j];
|
||||
}
|
||||
}
|
||||
program->src_lengths.length = index1;
|
||||
}
|
||||
|
||||
prefix = config_file_get_str(config, "UNIFORM_SRC_PREFIX", "src");
|
||||
index1 = index2 = 0;
|
||||
index2 = 0;
|
||||
for (j = 0; j < state_config.src_active_counts.length; j++) {
|
||||
for (k = 0; k < state_config.src_active_counts.values[j]; k++) {
|
||||
program->src_lengths.values[index1++] = state_config.src_counts.values[j];
|
||||
sprintf(name, "%s%d_%d", prefix, j + 1, k + 1);
|
||||
program->isrc_locations[index2++] =
|
||||
program->isrc_locations[i * program->src_lengths.length + index2++] =
|
||||
glGetUniformLocation(program->programs[i], name);
|
||||
}
|
||||
}
|
||||
program->src_lengths.length = index1;
|
||||
|
||||
// create texX uniforms pointer
|
||||
prefix = config_file_get_str(config, "UNIFORM_TEX_PREFIX", "tex");
|
||||
@@ -381,6 +390,7 @@ ShaderProgram shaders_init(FileArray fragment_shaders, ConfigFile config,
|
||||
program.in_count = config_file_get_int(config, "IN_COUNT", 0);
|
||||
program.sub_variant_count = state_config.state_max;
|
||||
program.active_count = state_config.src_active_counts.length;
|
||||
program.src_lengths.length = 0;
|
||||
|
||||
if (program.frag_count > MAX_FRAG) {
|
||||
log_error("FRAG_COUNT over %d", MAX_FRAG);
|
||||
@@ -542,9 +552,9 @@ static void use_program(ShaderProgram program, int i, bool output,
|
||||
|
||||
offset = 0;
|
||||
for (j = 0; j < program.src_lengths.length; j++) {
|
||||
write_uniform_multi_3f(program.isrc_locations[j],
|
||||
program.src_lengths.values[j],
|
||||
context->values + offset);
|
||||
write_uniform_multi_3f(
|
||||
program.isrc_locations[i * program.src_lengths.length + j],
|
||||
program.src_lengths.values[j], context->values + offset);
|
||||
offset += program.src_lengths.values[j];
|
||||
}
|
||||
|
||||
|
||||
+51
-36
@@ -150,91 +150,106 @@ static void update_page(SharedContext *context, StateConfig state_config,
|
||||
}
|
||||
}
|
||||
|
||||
static void update_selected(SharedContext *context, StateConfig state_config,
|
||||
MidiDevice midi) {
|
||||
unsigned int i;
|
||||
static void update_active(SharedContext *context, StateConfig state_config,
|
||||
MidiDevice midi) {
|
||||
unsigned int i, j, k;
|
||||
|
||||
for (i = 0; i < state_config.select_frag_codes.length; i++) {
|
||||
safe_midi_write(midi, state_config.select_frag_codes.values[i],
|
||||
i == context->selected ? MIDI_MAX : 0);
|
||||
for (i = 0; i < state_config.src_active_counts.length; i++) {
|
||||
for (j = 0; j < state_config.src_active_counts.values[i]; j++) {
|
||||
k = state_config.src_active_offsets.values[i] + j;
|
||||
safe_midi_write(midi, state_config.src_active_codes.values[k],
|
||||
context->active[i] == j ? MIDI_MAX : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void update_values(SharedContext *context, StateConfig state_config,
|
||||
MidiDevice midi) {
|
||||
unsigned int i, j, k, part;
|
||||
|
||||
for (i = 0; i < state_config.src_codes.length; i++) {
|
||||
j = i / 3;
|
||||
part = arr_uint_remap_index(state_config.src_offsets, &j);
|
||||
k = state_config.values_offsets.values[part] +
|
||||
context->active[part] * state_config.src_counts.values[part] + j;
|
||||
safe_midi_write(midi, state_config.src_codes.values[i],
|
||||
context->values[k][i % 3] * MIDI_MAX);
|
||||
}
|
||||
}
|
||||
|
||||
void state_apply_event(SharedContext *context, StateConfig state_config,
|
||||
MidiDevice midi, unsigned char code,
|
||||
unsigned char value) {
|
||||
unsigned int index, sub_index, src_index, part;
|
||||
unsigned int i, j, k, part;
|
||||
bool found;
|
||||
|
||||
found = false;
|
||||
|
||||
// PAGE CHANGE
|
||||
index = arr_uint_index_of(state_config.select_page_codes, code);
|
||||
if (index != ARRAY_NOT_FOUND) {
|
||||
i = arr_uint_index_of(state_config.select_page_codes, code);
|
||||
if (i != ARRAY_NOT_FOUND) {
|
||||
found = true;
|
||||
if (value > 0) {
|
||||
context->page = index;
|
||||
context->page = i;
|
||||
update_page(context, state_config, midi);
|
||||
}
|
||||
}
|
||||
|
||||
// TARGET CHANGE
|
||||
index = arr_uint_index_of(state_config.select_frag_codes, code);
|
||||
if (index != ARRAY_NOT_FOUND) {
|
||||
i = arr_uint_index_of(state_config.select_frag_codes, code);
|
||||
if (i != ARRAY_NOT_FOUND) {
|
||||
found = true;
|
||||
if (value > 0) {
|
||||
context->selected = index;
|
||||
context->selected = i;
|
||||
update_page(context, state_config, midi);
|
||||
update_selected(context, state_config, midi);
|
||||
}
|
||||
}
|
||||
|
||||
// ITEM CHANGE
|
||||
index = arr_uint_index_of(state_config.select_item_codes, code);
|
||||
if (index != ARRAY_NOT_FOUND) {
|
||||
i = arr_uint_index_of(state_config.select_item_codes, code);
|
||||
if (i != ARRAY_NOT_FOUND) {
|
||||
found = true;
|
||||
if (value > 0) {
|
||||
context->state[context->selected] =
|
||||
context->page * state_config.select_item_codes.length + index;
|
||||
context->page * state_config.select_item_codes.length + i;
|
||||
update_page(context, state_config, midi);
|
||||
}
|
||||
}
|
||||
|
||||
// ACTIVE CHANGE
|
||||
index = arr_uint_index_of(state_config.src_active_codes, code);
|
||||
if (index != ARRAY_NOT_FOUND) {
|
||||
i = arr_uint_index_of(state_config.src_active_codes, code);
|
||||
if (i != ARRAY_NOT_FOUND) {
|
||||
found = true;
|
||||
if (value > 0) {
|
||||
part = arr_uint_remap_index(state_config.src_active_offsets, &index);
|
||||
context->active[part] = index;
|
||||
// TODO update values
|
||||
part = arr_uint_remap_index(state_config.src_active_offsets, &i);
|
||||
context->active[part] = i;
|
||||
update_active(context, state_config, midi);
|
||||
update_values(context, state_config, midi);
|
||||
}
|
||||
}
|
||||
|
||||
// VALUE CHANGE
|
||||
index = arr_uint_index_of(state_config.src_codes, code);
|
||||
if (index != ARRAY_NOT_FOUND) {
|
||||
i = arr_uint_index_of(state_config.src_codes, code);
|
||||
if (i != ARRAY_NOT_FOUND) {
|
||||
found = true;
|
||||
sub_index = index / 3;
|
||||
part = arr_uint_remap_index(state_config.src_offsets, &sub_index);
|
||||
src_index = state_config.values_offsets.values[part] +
|
||||
context->active[part] * state_config.src_counts.values[part] +
|
||||
sub_index;
|
||||
j = i / 3;
|
||||
part = arr_uint_remap_index(state_config.src_offsets, &j);
|
||||
k = state_config.values_offsets.values[part] +
|
||||
context->active[part] * state_config.src_counts.values[part] + j;
|
||||
|
||||
if (arr_uint_index_of(state_config.fader_codes, code) != ARRAY_NOT_FOUND) {
|
||||
context->values[src_index][index % 3] = (float)value / MIDI_MAX;
|
||||
context->values[k][i % 3] = (float)value / MIDI_MAX;
|
||||
} else if (value > 0) {
|
||||
if (context->values[src_index][index % 3] > 0.5) {
|
||||
context->values[src_index][index % 3] = 0;
|
||||
if (context->values[k][i % 3] > 0.5) {
|
||||
context->values[k][i % 3] = 0;
|
||||
midi_write(midi, code, 0);
|
||||
} else {
|
||||
context->values[src_index][index % 3] = 1;
|
||||
context->values[k][i % 3] = 1;
|
||||
midi_write(midi, code, MIDI_MAX);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO values
|
||||
if (!found) {
|
||||
log_trace("unknown midi: %d %d", code, value);
|
||||
midi_write(midi, code, value);
|
||||
@@ -258,8 +273,8 @@ bool state_background_midi_write(SharedContext *context,
|
||||
log_info("(state) background writing started (pid: %d)", pid);
|
||||
|
||||
update_page(context, state_config, midi);
|
||||
update_selected(context, state_config, midi);
|
||||
// TODO init values
|
||||
update_active(context, state_config, midi);
|
||||
update_values(context, state_config, midi);
|
||||
|
||||
while (!context->stop) {
|
||||
// TODO tap tempo and more
|
||||
|
||||
Reference in New Issue
Block a user