wip value input
This commit is contained in:
+45
-15
@@ -10,8 +10,8 @@
|
||||
|
||||
StateConfig state_parse_config(ConfigFile config) {
|
||||
unsigned int i, j, offset, total;
|
||||
// TODO rename total var
|
||||
StateConfig state_config;
|
||||
UintArray tmp_counts;
|
||||
char name[256];
|
||||
|
||||
state_config.select_page_codes.length =
|
||||
@@ -44,22 +44,24 @@ StateConfig state_parse_config(ConfigFile config) {
|
||||
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
||||
}
|
||||
|
||||
state_config.src_count = tmp_counts.length =
|
||||
state_config.src_active_counts.length = state_config.src_counts.length =
|
||||
state_config.src_active_offsets.length = state_config.src_offsets.length =
|
||||
config_file_get_int(config, "SRC_COUNT", 0);
|
||||
state_config.values_offsets.length =
|
||||
config_file_get_int(config, "SRC_COUNT", 0);
|
||||
|
||||
total = 0;
|
||||
for (i = 0; i < tmp_counts.length; i++) {
|
||||
for (i = 0; i < state_config.src_active_counts.length; i++) {
|
||||
sprintf(name, "SRC_%d_ACTIVE_COUNT", i + 1);
|
||||
tmp_counts.values[i] = config_file_get_int(config, name, 0);
|
||||
state_config.src_active_counts.values[i] =
|
||||
config_file_get_int(config, name, 1);
|
||||
state_config.src_active_offsets.values[i] = total;
|
||||
total += tmp_counts.values[i];
|
||||
total += state_config.src_active_counts.values[i];
|
||||
}
|
||||
|
||||
state_config.src_active_codes.length = total;
|
||||
|
||||
for (i = 0; i < tmp_counts.length; i++) {
|
||||
for (j = 0; j < tmp_counts.values[i]; j++) {
|
||||
for (i = 0; i < state_config.src_active_counts.length; i++) {
|
||||
for (j = 0; j < state_config.src_active_counts.values[i]; j++) {
|
||||
sprintf(name, "SRC_%d_ACTIVE_%d", i + 1, j + 1);
|
||||
state_config.src_active_codes
|
||||
.values[state_config.src_active_offsets.values[i] + j] =
|
||||
@@ -68,18 +70,22 @@ StateConfig state_parse_config(ConfigFile config) {
|
||||
}
|
||||
|
||||
total = 0;
|
||||
for (i = 0; i < tmp_counts.length; i++) {
|
||||
offset = 0;
|
||||
for (i = 0; i < state_config.src_counts.length; i++) {
|
||||
sprintf(name, "SRC_%d_COUNT", i + 1);
|
||||
tmp_counts.values[i] = config_file_get_int(config, name, 0);
|
||||
state_config.src_counts.values[i] = config_file_get_int(config, name, 0);
|
||||
state_config.src_offsets.values[i] = total;
|
||||
total += tmp_counts.values[i];
|
||||
state_config.values_offsets.values[i] = offset;
|
||||
offset += state_config.src_counts.values[i] *
|
||||
state_config.src_active_counts.values[i];
|
||||
total += state_config.src_counts.values[i];
|
||||
}
|
||||
|
||||
state_config.src_codes.length = total * 3;
|
||||
|
||||
for (i = 0; i < tmp_counts.length; i++) {
|
||||
for (i = 0; i < state_config.src_counts.length; i++) {
|
||||
offset = state_config.src_offsets.values[i];
|
||||
for (j = 0; j < tmp_counts.values[i]; j++) {
|
||||
for (j = 0; j < state_config.src_counts.values[i]; j++) {
|
||||
sprintf(name, "SRC_%d_%d_X", i + 1, j + 1);
|
||||
state_config.src_codes.values[(offset + j) * 3] =
|
||||
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
||||
@@ -157,7 +163,7 @@ static void update_selected(SharedContext *context, StateConfig state_config,
|
||||
void state_apply_event(SharedContext *context, StateConfig state_config,
|
||||
MidiDevice midi, unsigned char code,
|
||||
unsigned char value) {
|
||||
unsigned int index, part;
|
||||
unsigned int index, sub_index, src_index, part;
|
||||
bool found;
|
||||
|
||||
found = false;
|
||||
@@ -201,7 +207,30 @@ void state_apply_event(SharedContext *context, StateConfig state_config,
|
||||
if (value > 0) {
|
||||
part = arr_uint_remap_index(state_config.src_active_offsets, &index);
|
||||
context->active[part] = index;
|
||||
// TODO things
|
||||
// TODO update values
|
||||
}
|
||||
}
|
||||
|
||||
// VALUE CHANGE
|
||||
index = arr_uint_index_of(state_config.src_codes, code);
|
||||
if (index != 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;
|
||||
|
||||
if (arr_uint_index_of(state_config.fader_codes, code) != ARRAY_NOT_FOUND) {
|
||||
context->values[src_index][index % 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;
|
||||
midi_write(midi, code, 0);
|
||||
} else {
|
||||
context->values[src_index][index % 3] = 1;
|
||||
midi_write(midi, code, MIDI_MAX);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,6 +259,7 @@ bool state_background_midi_write(SharedContext *context,
|
||||
|
||||
update_page(context, state_config, midi);
|
||||
update_selected(context, state_config, midi);
|
||||
// TODO init values
|
||||
|
||||
while (!context->stop) {
|
||||
// TODO tap tempo and more
|
||||
|
||||
Reference in New Issue
Block a user