wip value input

This commit is contained in:
2025-10-02 21:12:08 +02:00
parent 0119ed2fec
commit a2ba37df16
14 changed files with 256 additions and 176 deletions
+1 -1
View File
@@ -23,4 +23,4 @@ unsigned int arr_uint_remap_index(UintArray offsets, unsigned int *index) {
}
return 0;
}
}
+2
View File
@@ -4,6 +4,7 @@
#include <stdlib.h>
#include <sys/wait.h>
#include "arr.h"
#include "config.h"
#include "config_file.h"
#include "file.h"
@@ -68,6 +69,7 @@ static void init_context(Parameters params, unsigned int in_count,
}
memset(context->active, 0, sizeof(context->active));
memset(context->values, 0, sizeof(context->values));
context->page = 0;
context->selected = 0;
+41 -17
View File
@@ -3,6 +3,7 @@
#include <stddef.h>
#include <stdio.h>
#include "arr.h"
#include "config.h"
#include "config_file.h"
#include "constants.h"
@@ -234,8 +235,8 @@ static void init_shaders(ShaderProgram *program, FileArray fragment_shaders) {
}
static void init_single_program(ShaderProgram *program, unsigned int i,
ConfigFile config) {
unsigned int j, k;
ConfigFile config, StateConfig state_config) {
unsigned int j, k, index1, index2;
char name[256];
char *prefix;
program->programs[i] = glCreateProgram();
@@ -325,6 +326,18 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
glGetUniformLocation(program->programs[i], name);
}
prefix = config_file_get_str(config, "UNIFORM_SRC_PREFIX", "src");
index1 = 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++] =
glGetUniformLocation(program->programs[i], name);
}
}
program->src_lengths.length = index1;
// create texX uniforms pointer
prefix = config_file_get_str(config, "UNIFORM_TEX_PREFIX", "tex");
for (j = 0; j < program->tex_count; j++) {
@@ -340,11 +353,12 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
log_info("Program %d initialized", i + 1);
}
static void init_programs(ShaderProgram *program, ConfigFile config) {
static void init_programs(ShaderProgram *program, ConfigFile config,
StateConfig state_config) {
unsigned int i;
for (i = 0; i < program->frag_count; i++) {
init_single_program(program, i, config);
init_single_program(program, i, config, state_config);
}
}
@@ -366,7 +380,7 @@ ShaderProgram shaders_init(FileArray fragment_shaders, ConfigFile config,
program.sub_type_count = config_file_get_int(config, "SUB_TYPE_COUNT", 0);
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_count;
program.active_count = state_config.src_active_counts.length;
if (program.frag_count > MAX_FRAG) {
log_error("FRAG_COUNT over %d", MAX_FRAG);
@@ -388,7 +402,7 @@ ShaderProgram shaders_init(FileArray fragment_shaders, ConfigFile config,
init_framebuffers(&program, config);
init_programs(&program, config);
init_programs(&program, config, state_config);
init_vertices(&program);
@@ -451,16 +465,18 @@ static void write_uniform_2f(GLuint location, vec2 *value) {
}
}
// static void write_uniform_3f(GLuint location, vec3 *value) {
// if (location != unused_uniform) {
// glUniform3fv(location, 1, (const GLfloat *)value);
// }
// }
static void write_uniform_multi_3f(GLuint location, unsigned int count,
vec3 *value) {
if (location != unused_uniform) {
glUniform3fv(location, count, (const GLfloat *)value);
}
}
static void use_program(ShaderProgram program, int i, bool output,
SharedContext *context) {
unsigned int j, k;
unsigned int j, k, offset;
GLuint subroutines[ARRAY_SIZE];
// TODO direct vec2 in context
vec2 resolution, tex_resolution, in_resolution;
resolution[0] = (float)context->width;
@@ -519,6 +535,19 @@ static void use_program(ShaderProgram program, int i, bool output,
context->seeds[j]);
}
for (j = 0; j < program.frag_count; j++) {
write_uniform_1i(program.istate_locations[i * program.frag_count + j],
context->state[j]);
}
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);
offset += program.src_lengths.values[j];
}
// set subroutines for fragment and update state uniforms
k = context->state[i];
for (j = 0; j < program.sub_type_count; j++) {
@@ -527,11 +556,6 @@ static void use_program(ShaderProgram program, int i, bool output,
j * program.sub_variant_count + k];
}
for (j = 0; j < program.frag_count; j++) {
write_uniform_1i(program.istate_locations[i * program.frag_count + j],
context->state[j]);
}
glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, program.sub_type_count,
subroutines);
+45 -15
View File
@@ -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
+27 -13
View File
@@ -14,10 +14,16 @@
#ifndef TYPES_H
#define TYPES_H
typedef struct UintArray {
unsigned int values[ARRAY_SIZE];
unsigned int length;
} UintArray;
#define ARRAY(X, Y) \
struct X { \
Y values[ARRAY_SIZE]; \
unsigned int length; \
} X
typedef ARRAY(UintArray, unsigned int);
typedef ARRAY(StringArray, char *);
typedef ARRAY(Vec3Array, vec3);
typedef ARRAY(GLuintArray, GLuint);
typedef struct Parameters {
bool hot_reload;
@@ -32,6 +38,7 @@ typedef struct Parameters {
float base_tempo;
bool demo;
bool windowed;
// TODO use array
char *video_in[MAX_VIDEO];
unsigned int video_in_count;
} Parameters;
@@ -47,10 +54,7 @@ typedef struct File {
time_t last_write;
} File;
typedef struct FileArray {
File values[ARRAY_SIZE];
unsigned int length;
} FileArray;
typedef ARRAY(FileArray, File);
typedef struct ShaderProgram {
bool error;
@@ -71,11 +75,14 @@ typedef struct ShaderProgram {
unsigned int frag_output_index;
unsigned int frag_monitor_index;
// TODO use array
GLuint programs[ARRAY_SIZE];
// TODO use array
GLuint frame_buffers[ARRAY_SIZE];
GLuint fragment_shaders[ARRAY_SIZE];
// TODO use array
GLuint itime_locations[ARRAY_SIZE];
GLuint itempo_locations[ARRAY_SIZE];
GLuint ifps_locations[ARRAY_SIZE];
@@ -91,8 +98,13 @@ typedef struct ShaderProgram {
GLuint iselected_locations[ARRAY_SIZE];
GLuint iactive_locations[ARRAY_SIZE];
// TODO rename inputs_xxx
UintArray src_lengths;
GLuint isrc_locations[ARRAY_SIZE];
GLuint vpos_locations[ARRAY_SIZE];
// TODO use array
GLuint textures_locations[ARRAY_SIZE];
unsigned int sub_type_count;
@@ -119,10 +131,7 @@ typedef struct VideoCapture {
EGLImageKHR dma_image;
} VideoCapture;
typedef struct VideoCaptureArray {
VideoCapture values[ARRAY_SIZE];
unsigned int length;
} VideoCaptureArray;
typedef ARRAY(VideoCaptureArray, VideoCapture);
typedef GLFWwindow Window;
@@ -137,10 +146,12 @@ typedef struct SharedContext {
double time;
unsigned int fps;
float tempo;
// TODO use array
unsigned int state[MAX_FRAG];
unsigned int page;
unsigned int selected;
unsigned int active[ARRAY_SIZE];
vec3 values[ARRAY_SIZE];
bool demo;
unsigned int seeds[MAX_FRAG];
bool monitor;
@@ -153,16 +164,19 @@ 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 rename input_xxx
UintArray src_active_counts;
UintArray src_active_offsets;
UintArray src_active_codes;
UintArray src_counts;
UintArray src_offsets;
UintArray src_codes;
UintArray fader_codes;
UintArray values_offsets;
unsigned int tap_tempo_code;
} StateConfig;