From 7dbce6218289b848f36d809acdb14c7f55bef106 Mon Sep 17 00:00:00 2001 From: klemek Date: Thu, 21 May 2026 00:32:03 +0200 Subject: [PATCH] feat: ignore some values in auto random --- default/forge_project.cfg | 20 +++++++++++++ default/frag8.glsl | 6 +--- default/frag9.glsl | 17 +++++------ src/arr.c | 10 +++++++ src/arr.h | 2 ++ src/state.c | 62 +++++++++++++++++++++++++++++++++++---- src/types.h | 1 + 7 files changed, 99 insertions(+), 19 deletions(-) diff --git a/default/forge_project.cfg b/default/forge_project.cfg index c0e1c70..3b71415 100644 --- a/default/forge_project.cfg +++ b/default/forge_project.cfg @@ -272,6 +272,26 @@ GROUP_3_2_X=0 GROUP_3_2_Y=16 GROUP_3_2_Z=11089 +# Auto-Random Ignore (ARI) prefixes +ARI_COUNT=17 +ARI_1=GROUP_3_1_Y +ARI_2=GROUP_3_2_Z +ARI_3=GROUP_2_1_X_4 +ARI_4=GROUP_2_1_Y_4 +ARI_5=GROUP_2_1_Z_4 +ARI_6=GROUP_2_2_X_4 +ARI_7=GROUP_2_2_Y_4 +ARI_8=GROUP_2_2_Z_4 +ARI_9=GROUP_2_4_X_4 +ARI_10=GROUP_2_4_Y_4 +ARI_11=GROUP_2_4_Z_4 +ARI_12=GROUP_2_6_X_4 +ARI_13=GROUP_2_6_Y_4 +ARI_14=GROUP_2_6_Z_4 +ARI_15=GROUP_2_7_X_4 +ARI_16=GROUP_2_7_Y_4 +ARI_17=GROUP_2_7_Z_4 + # ===== # OTHER # ===== diff --git a/default/frag8.glsl b/default/frag8.glsl index b83b50e..8a05179 100644 --- a/default/frag8.glsl +++ b/default/frag8.glsl @@ -16,15 +16,11 @@ uniform sampler2D iTex0; uniform int iSeed8; uniform vec3 iGroup2_3[7]; uniform vec3 iGroup3_1[2]; -uniform int iDemo; -uniform int iAutoRand; void main() { vec4 color = fx_stage(vUV, iTex9, iTex0, iSeed8, iGroup2_3[0], iGroup2_3[1].xy, iGroup2_3[2], iGroup2_3[3].xy, iGroup2_3[4], iGroup2_3[5].xy, iGroup2_3[6]); - if (iDemo < 1 && iAutoRand < 1) { - color = mix(color, vec4(0), iGroup3_1[0].y); - } + color = mix(color, vec4(0), iGroup3_1[0].y); fragColor = color; } diff --git a/default/frag9.glsl b/default/frag9.glsl index 08cb4f3..cab3b91 100644 --- a/default/frag9.glsl +++ b/default/frag9.glsl @@ -9,21 +9,20 @@ out vec4 fragColor; #include inc_map.glsl uniform sampler2D iTex0; -uniform int iAutoRand; uniform vec3 iGroup2_4[7]; void main() { - bool visible = iAutoRand < 1 && iGroup2_4[0].x > 0; - bool invert = iAutoRand < 1 && iGroup2_4[0].y > 0; - bool rect = iAutoRand < 1 && iGroup2_4[0].z > 0; + bool visible = iGroup2_4[0].x > 0; + bool invert = iGroup2_4[0].y > 0; + float rect = iGroup2_4[0].z; vec2 uv2 = vUV; if (visible) { - vec2 p1 = iAutoRand < 1 ? vec2(iGroup2_4[6].xy) : vec2(0); - vec2 p2 = iAutoRand < 1 ? vec2(iGroup2_4[1].xy) : vec2(0); - vec2 p3 = iAutoRand < 1 ? vec2(iGroup2_4[3].xy) : vec2(0); - vec2 p4 = iAutoRand < 1 ? vec2(iGroup2_4[5].xy) : vec2(0); + vec2 p1 = vec2(iGroup2_4[6].xy); + vec2 p2 = vec2(iGroup2_4[1].xy); + vec2 p3 = vec2(iGroup2_4[3].xy); + vec2 p4 = vec2(iGroup2_4[5].xy); p2.x = 1 - p2.x; p3.y = 1 - p3.y; @@ -38,7 +37,7 @@ void main() { if (visible) { float mask = step(0, uv2.x) * step(-1, -uv2.x) * step(0, uv2.y) * step(-1, -uv2.y); color *= mix(mask, 1 - mask, invert ? 1 : 0); - color = mix(color, mix(color, color + mask * vec4(1), step(uv2.x, 0.01) + step(uv2.y, 0.01) + step(1 - uv2.y, 0.01) + step(1 - uv2.x, 0.01)), rect ? 1 : 0); + color = mix(color, color + mask * vec4(1), rect * (step(uv2.x, 0.01) + step(uv2.y, 0.01) + step(1 - uv2.y, 0.01) + step(1 - uv2.x, 0.01))); } fragColor = color; diff --git a/src/arr.c b/src/arr.c index 8d47356..045a9e5 100644 --- a/src/arr.c +++ b/src/arr.c @@ -12,6 +12,16 @@ unsigned int arr_uint_index_of(UintArray array, unsigned int value) { return ARRAY_NOT_FOUND; } +bool arr_string_match(StringArray array, const char *needle) { + for (unsigned int i = 0; i < array.length; i++) { + if (strncmp(array.values[i], needle, strlen(array.values[i])) == 0) { + return true; + } + } + + return false; +} + unsigned int arr_uint_remap_index(UintArray offsets, unsigned int *index) { if (offsets.length == 0) { return 0; diff --git a/src/arr.h b/src/arr.h index b27b1eb..e9ccd47 100644 --- a/src/arr.h +++ b/src/arr.h @@ -7,4 +7,6 @@ unsigned int arr_uint_index_of(UintArray array, unsigned int value); unsigned int arr_uint_remap_index(UintArray offsets, unsigned int *index); +bool arr_string_match(StringArray array, const char *needle); + #endif /* ARR_H */ diff --git a/src/state.c b/src/state.c index 9d33b52..eb13fe1 100644 --- a/src/state.c +++ b/src/state.c @@ -98,11 +98,15 @@ static void randomize(Context *context, StateConfig state_config) { l = state_config.values_offsets.values[part] + k * state_config.group_counts.values[part] + j; - if (arr_uint_index_of(state_config.fader_codes, - 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; + if (arr_uint_index_of(state_config.random_ignored, (l * 3) + (i % 3)) == + ARRAY_NOT_FOUND) { + if (arr_uint_index_of(state_config.fader_codes, + 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; + } } } } @@ -271,6 +275,8 @@ void state_parse_config(StateConfig *state_config, const ConfigFile *config) { unsigned int offset; unsigned int count; unsigned int length; + unsigned int value_offset; + StringArray ignored_codes; char name[STR_LEN]; length = config_file_get_int(config, "SELECT_PAGE_COUNT", 0); @@ -312,6 +318,18 @@ void state_parse_config(StateConfig *state_config, const ConfigFile *config) { config_file_get_int(config, name, UNSET_MIDI_CODE); } + length = config_file_get_int(config, "ARI_COUNT", 0); + if (length > ARRAY_SIZE) { + length = ARRAY_SIZE; + } + ignored_codes.length = length; + + for (unsigned int i = 0; i < ignored_codes.length; i++) { + snprintf(name, STR_LEN, "ARI_%d", i + 1); + strlcpy(ignored_codes.values[i], + config_file_get_str(config, name, "unkown"), STR_LEN); + } + length = config_file_get_int(config, "GROUP_COUNT", 0); if (length > ARRAY_SIZE) { length = ARRAY_SIZE; @@ -361,26 +379,60 @@ void state_parse_config(StateConfig *state_config, const ConfigFile *config) { length = ARRAY_SIZE; } state_config->codes.length = count * 3; + state_config->random_ignored.length = 0; for (unsigned int i = 0; i < state_config->group_counts.length; i++) { offset = state_config->group_offsets.values[i]; + value_offset = state_config->values_offsets.values[i]; for (unsigned int j = 0; j < state_config->group_counts.values[i]; j++) { if ((offset + j) * 3 < ARRAY_SIZE) { 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); + for (unsigned int k = 0; + k < state_config->group_active_counts.values[i]; k++) { + snprintf(name, STR_LEN, "GROUP_%d_%d_X_%d", i + 1, j + 1, k + 1); + if (arr_string_match(ignored_codes, name)) { + state_config->random_ignored + .values[state_config->random_ignored.length++] = + (value_offset + k * state_config->group_counts.values[i] + j) * + 3; + } + } } if ((offset + j) * 3 + 1 < ARRAY_SIZE) { 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); + for (unsigned int k = 0; + k < state_config->group_active_counts.values[i]; k++) { + snprintf(name, STR_LEN, "GROUP_%d_%d_Y_%d", i + 1, j + 1, k + 1); + if (arr_string_match(ignored_codes, name)) { + state_config->random_ignored + .values[state_config->random_ignored.length++] = + (value_offset + k * state_config->group_counts.values[i] + j) * + 3 + + 1; + } + } } if ((offset + j) * 3 + 2 < ARRAY_SIZE) { 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); + for (unsigned int k = 0; + k < state_config->group_active_counts.values[i]; k++) { + snprintf(name, STR_LEN, "GROUP_%d_%d_Z_%d", i + 1, j + 1, k + 1); + if (arr_string_match(ignored_codes, name)) { + state_config->random_ignored + .values[state_config->random_ignored.length++] = + (value_offset + k * state_config->group_counts.values[i] + j) * + 3 + + 2; + } + } } } } diff --git a/src/types.h b/src/types.h index 45025ea..8afca99 100644 --- a/src/types.h +++ b/src/types.h @@ -251,6 +251,7 @@ typedef struct StateConfig { UintArray codes; UintArray fader_codes; UintArray values_offsets; + UintArray random_ignored; unsigned int value_count;