style: better local variables
This commit is contained in:
+7
-3
@@ -91,18 +91,22 @@ static char *split_arg_value(char *arg) {
|
||||
}
|
||||
|
||||
static unsigned int parse_uint(char *arg, char *value) {
|
||||
unsigned long long tmp_value;
|
||||
|
||||
if (!string_is_number(value)) {
|
||||
invalid_value(arg, value);
|
||||
}
|
||||
unsigned long long tmp_value = (unsigned long long)atoll(value);
|
||||
|
||||
tmp_value = (unsigned long long)atoll(value);
|
||||
|
||||
if (tmp_value >= UINT_MAX) {
|
||||
invalid_value(arg, value);
|
||||
}
|
||||
|
||||
return (unsigned int)tmp_value;
|
||||
}
|
||||
|
||||
void args_parse(Parameters *params, int argc, char **argv) {
|
||||
int i;
|
||||
char *arg;
|
||||
char *value;
|
||||
|
||||
@@ -126,7 +130,7 @@ void args_parse(Parameters *params, int argc, char **argv) {
|
||||
params->trace_midi = false;
|
||||
params->trace_fps = false;
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
for (int i = 1; i < argc; i++) {
|
||||
arg = argv[i];
|
||||
value = split_arg_value(arg);
|
||||
if (is_arg(arg, "-h") || is_arg(arg, "--help")) {
|
||||
|
||||
@@ -3,9 +3,7 @@
|
||||
#include "arr.h"
|
||||
|
||||
unsigned int arr_uint_index_of(UintArray array, unsigned int value) {
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < array.length; i++) {
|
||||
for (unsigned int i = 0; i < array.length; i++) {
|
||||
if (array.values[i] == value) {
|
||||
return i;
|
||||
}
|
||||
@@ -15,9 +13,7 @@ unsigned int arr_uint_index_of(UintArray array, unsigned int value) {
|
||||
}
|
||||
|
||||
unsigned int arr_uint_remap_index(UintArray offsets, unsigned int *index) {
|
||||
unsigned int i;
|
||||
|
||||
for (i = offsets.length - 1; i > 0; i--) {
|
||||
for (unsigned int i = offsets.length - 1; i > 0; i--) {
|
||||
if (*index >= offsets.values[i]) {
|
||||
*index -= offsets.values[i];
|
||||
return i;
|
||||
|
||||
+3
-2
@@ -14,9 +14,11 @@
|
||||
|
||||
static time_t get_file_time(File *file) {
|
||||
struct stat attr;
|
||||
|
||||
if (stat(file->path, &attr) == 0) {
|
||||
return attr.st_mtim.tv_sec;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -97,7 +99,6 @@ void file_dump(char *path, char *content) {
|
||||
}
|
||||
|
||||
void file_write(char *path, StringArray *lines) {
|
||||
unsigned int i;
|
||||
FILE *file_pointer;
|
||||
|
||||
log_info("Writing %s...", path);
|
||||
@@ -110,7 +111,7 @@ void file_write(char *path, StringArray *lines) {
|
||||
}
|
||||
|
||||
// write file
|
||||
for (i = 0; i < lines->length; i++) {
|
||||
for (unsigned int i = 0; i < lines->length; i++) {
|
||||
fprintf(file_pointer, "%s\n", lines->values[i]);
|
||||
}
|
||||
|
||||
|
||||
+4
-12
@@ -58,8 +58,6 @@ static void compute_fps(bool trace_fps) {
|
||||
}
|
||||
|
||||
static void init_context(Parameters *params, unsigned int in_count) {
|
||||
unsigned int i;
|
||||
|
||||
state_init(context, &project.state_config, params->demo, params->auto_random,
|
||||
params->base_tempo, params->state_file, params->load_state);
|
||||
|
||||
@@ -69,7 +67,7 @@ static void init_context(Parameters *params, unsigned int in_count) {
|
||||
memset(context->input_formats, 0, sizeof(context->input_formats));
|
||||
memset(context->input_fps, 0, sizeof(context->input_fps));
|
||||
|
||||
for (i = 0; i < in_count; i++) {
|
||||
for (unsigned int i = 0; i < in_count; i++) {
|
||||
if (!inputs.values[i].error) {
|
||||
context->input_resolutions[i][0] = inputs.values[i].width;
|
||||
context->input_resolutions[i][1] = inputs.values[i].height;
|
||||
@@ -85,19 +83,15 @@ static void reload_shader(unsigned int i) {
|
||||
}
|
||||
|
||||
static void init_inputs(StringArray *video_in, unsigned int video_size) {
|
||||
unsigned int i;
|
||||
|
||||
inputs.length = video_in->length;
|
||||
|
||||
for (i = 0; i < video_in->length; i++) {
|
||||
for (unsigned int i = 0; i < video_in->length; i++) {
|
||||
video_init(&inputs.values[i], video_in->values[i], video_size);
|
||||
}
|
||||
}
|
||||
|
||||
static bool start_video_captures(unsigned int video_count, bool trace_fps) {
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < video_count; i++) {
|
||||
for (unsigned int i = 0; i < video_count; i++) {
|
||||
if (!inputs.values[i].error &&
|
||||
!video_background_read(&inputs.values[i], context, i, trace_fps)) {
|
||||
return false;
|
||||
@@ -108,9 +102,7 @@ static bool start_video_captures(unsigned int video_count, bool trace_fps) {
|
||||
}
|
||||
|
||||
static void free_video_captures(unsigned int video_count) {
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < video_count; i++) {
|
||||
for (unsigned int i = 0; i < video_count; i++) {
|
||||
shaders_free_input(&program, &inputs.values[i]);
|
||||
|
||||
video_free(&inputs.values[i]);
|
||||
|
||||
+2
-2
@@ -10,9 +10,9 @@
|
||||
#include "main.h"
|
||||
#include "rand.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
Parameters params;
|
||||
static Parameters params;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
args_parse(¶ms, argc, argv);
|
||||
|
||||
puts(PACKAGE " " VERSION);
|
||||
|
||||
+6
-9
@@ -14,7 +14,8 @@
|
||||
static bool parse_fragment_shader_file(Project *project, unsigned int i) {
|
||||
File tmp_file;
|
||||
char file_path[STR_LEN];
|
||||
char *include_pos, *include_end;
|
||||
char *include_pos;
|
||||
char *include_end;
|
||||
char included_file[STR_LEN];
|
||||
char *new_content;
|
||||
|
||||
@@ -78,7 +79,6 @@ static bool read_fragment_shader_file(Project *project, char *frag_prefix,
|
||||
void project_init(Project *project, char *project_path, char *config_file) {
|
||||
char config_path[STR_LEN];
|
||||
char *frag_prefix;
|
||||
unsigned int i;
|
||||
|
||||
strlcpy(project->path, project_path, STR_LEN);
|
||||
|
||||
@@ -102,7 +102,7 @@ void project_init(Project *project, char *project_path, char *config_file) {
|
||||
|
||||
project->sub_counts.length = project->frag_count;
|
||||
|
||||
for (i = 0; i < project->frag_count; i++) {
|
||||
for (unsigned int i = 0; i < project->frag_count; i++) {
|
||||
project->sub_counts.values[i] = 0;
|
||||
if (!read_fragment_shader_file(project, frag_prefix, i)) {
|
||||
project_free(project);
|
||||
@@ -113,13 +113,12 @@ void project_init(Project *project, char *project_path, char *config_file) {
|
||||
}
|
||||
|
||||
void project_reload(Project *project, void (*reload_callback)(unsigned int)) {
|
||||
unsigned int i, j;
|
||||
bool should_update;
|
||||
|
||||
for (i = 0; i < project->frag_count; i++) {
|
||||
for (unsigned int i = 0; i < project->frag_count; i++) {
|
||||
should_update = file_should_update(&project->fragment_shaders[i][0]);
|
||||
|
||||
for (j = 0; j < project->sub_counts.values[i]; j++) {
|
||||
for (unsigned int j = 0; j < project->sub_counts.values[i]; j++) {
|
||||
should_update = should_update ||
|
||||
file_should_update(&project->fragment_shaders[i][j + 1]);
|
||||
}
|
||||
@@ -136,9 +135,7 @@ void project_reload(Project *project, void (*reload_callback)(unsigned int)) {
|
||||
}
|
||||
|
||||
void project_free(Project *project) {
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < project->frag_count; i++) {
|
||||
for (unsigned int i = 0; i < project->frag_count; i++) {
|
||||
file_free(&project->fragment_shaders[i][0]);
|
||||
}
|
||||
|
||||
|
||||
+40
-51
@@ -36,11 +36,9 @@ static void init_gl(ShaderProgram *program) {
|
||||
}
|
||||
|
||||
static void init_textures(ShaderProgram *program, SharedContext *context) {
|
||||
unsigned int i;
|
||||
|
||||
glGenTextures(program->tex_count, program->textures);
|
||||
|
||||
for (i = 0; i < program->tex_count; i++) {
|
||||
for (unsigned int i = 0; i < program->tex_count; i++) {
|
||||
// selects which texture unit subsequent texture state calls will affect
|
||||
glActiveTexture(GL_TEXTURE0 + i);
|
||||
|
||||
@@ -64,8 +62,7 @@ static void init_textures(ShaderProgram *program, SharedContext *context) {
|
||||
}
|
||||
|
||||
static void rebind_textures(ShaderProgram *program) {
|
||||
unsigned int i;
|
||||
for (i = 0; i < program->tex_count; i++) {
|
||||
for (unsigned int i = 0; i < program->tex_count; i++) {
|
||||
glActiveTexture(GL_TEXTURE0 + i);
|
||||
glBindTexture(GL_TEXTURE_2D, program->textures[i]);
|
||||
}
|
||||
@@ -115,11 +112,10 @@ static void link_input_to_texture(ShaderProgram *program, VideoCapture *input,
|
||||
|
||||
static void init_input(ShaderProgram *program, ConfigFile *config,
|
||||
VideoCaptureArray *inputs) {
|
||||
unsigned int i;
|
||||
unsigned tex_i;
|
||||
unsigned int tex_i;
|
||||
char name[STR_LEN];
|
||||
|
||||
for (i = 0; i < program->in_count; i++) {
|
||||
for (unsigned int i = 0; i < program->in_count; i++) {
|
||||
if (i < inputs->length && !inputs->values[i].error) {
|
||||
snprintf(name, STR_LEN, "IN_%d_OUT", i + 1);
|
||||
tex_i = config_file_get_int(config, name, 0);
|
||||
@@ -131,13 +127,12 @@ static void init_input(ShaderProgram *program, ConfigFile *config,
|
||||
}
|
||||
|
||||
static void init_framebuffers(ShaderProgram *program, ConfigFile *config) {
|
||||
unsigned int i;
|
||||
unsigned tex_i;
|
||||
unsigned int tex_i;
|
||||
char name[STR_LEN];
|
||||
|
||||
glGenFramebuffers(program->frag_count, program->frame_buffers);
|
||||
|
||||
for (i = 0; i < program->frag_count; i++) {
|
||||
for (unsigned int i = 0; i < program->frag_count; i++) {
|
||||
if (i == program->frag_output_index || i == program->frag_monitor_index) {
|
||||
continue;
|
||||
}
|
||||
@@ -172,14 +167,12 @@ static void init_vertices(ShaderProgram *program) {
|
||||
}
|
||||
|
||||
static void bind_vertices(ShaderProgram *program, unsigned int index) {
|
||||
unsigned int i;
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, program->vertex_buffer);
|
||||
|
||||
glGenVertexArrays(1, &program->vertex_array[index]);
|
||||
glBindVertexArray(program->vertex_array[index]);
|
||||
|
||||
for (i = 0; i < program->frag_count; i++) {
|
||||
for (unsigned int i = 0; i < program->frag_count; i++) {
|
||||
// enable attribute pointer
|
||||
glEnableVertexAttribArray(program->vpos_locations[i]);
|
||||
// specify the location and data format of the array of generic vertex
|
||||
@@ -216,15 +209,13 @@ static bool compile_shader(GLuint shader_id, char *name, char *source_code) {
|
||||
}
|
||||
|
||||
static void init_shaders(ShaderProgram *program, Project *project) {
|
||||
unsigned int i;
|
||||
|
||||
// compile vertex shader
|
||||
program->vertex_shader = glCreateShader(GL_VERTEX_SHADER);
|
||||
program->error |= !compile_shader(
|
||||
program->vertex_shader, "internal vertex shader", vertex_shader_text);
|
||||
|
||||
// compile fragment shaders
|
||||
for (i = 0; i < program->frag_count; i++) {
|
||||
for (unsigned int i = 0; i < program->frag_count; i++) {
|
||||
program->fragment_shaders[i] = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
program->error |= !compile_shader(program->fragment_shaders[i],
|
||||
project->fragment_shaders[i][0].path,
|
||||
@@ -238,9 +229,11 @@ static void init_shaders(ShaderProgram *program, Project *project) {
|
||||
|
||||
static void init_single_program(ShaderProgram *program, unsigned int i,
|
||||
ConfigFile *config, StateConfig *state_config) {
|
||||
unsigned int j, k, index1, index2;
|
||||
unsigned int index1;
|
||||
unsigned int index2;
|
||||
char name[STR_LEN];
|
||||
char *prefix;
|
||||
|
||||
program->programs[i] = glCreateProgram();
|
||||
|
||||
glAttachShader(program->programs[i], program->vertex_shader);
|
||||
@@ -280,7 +273,7 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
|
||||
|
||||
prefix = config_file_get_str(config, "UNIFORM_IN_RESOLUTION_PREFIX",
|
||||
"iInputResolution");
|
||||
for (j = 0; j < program->in_count; j++) {
|
||||
for (unsigned int j = 0; j < program->in_count; j++) {
|
||||
snprintf(name, STR_LEN, "%s%d", prefix, j + 1);
|
||||
program->iinres_locations[i * program->in_count + j] =
|
||||
glGetUniformLocation(program->programs[i], name);
|
||||
@@ -288,37 +281,37 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
|
||||
|
||||
prefix =
|
||||
config_file_get_str(config, "UNIFORM_IN_FORMAT_PREFIX", "iInputFormat");
|
||||
for (j = 0; j < program->in_count; j++) {
|
||||
for (unsigned int j = 0; j < program->in_count; j++) {
|
||||
snprintf(name, STR_LEN, "%s%d", prefix, j + 1);
|
||||
program->iinfmt_locations[i * program->in_count + j] =
|
||||
glGetUniformLocation(program->programs[i], name);
|
||||
}
|
||||
|
||||
prefix = config_file_get_str(config, "UNIFORM_IN_FPS_PREFIX", "iInputFPS");
|
||||
for (j = 0; j < program->in_count; j++) {
|
||||
for (unsigned int j = 0; j < program->in_count; j++) {
|
||||
snprintf(name, STR_LEN, "%s%d", prefix, j + 1);
|
||||
program->iinfps_locations[i * program->in_count + j] =
|
||||
glGetUniformLocation(program->programs[i], name);
|
||||
}
|
||||
|
||||
prefix = config_file_get_str(config, "UNIFORM_SEED_PREFIX", "iSeed");
|
||||
for (j = 0; j < program->frag_count; j++) {
|
||||
for (unsigned int j = 0; j < program->frag_count; j++) {
|
||||
snprintf(name, STR_LEN, "%s%d", prefix, j + 1);
|
||||
program->iseed_locations[i * program->frag_count + j] =
|
||||
glGetUniformLocation(program->programs[i], name);
|
||||
}
|
||||
|
||||
prefix = config_file_get_str(config, "UNIFORM_STATE_PREFIX", "iState");
|
||||
for (j = 0; j < program->frag_count; j++) {
|
||||
for (unsigned int j = 0; j < program->frag_count; j++) {
|
||||
snprintf(name, STR_LEN, "%s%d", prefix, j + 1);
|
||||
program->istate_locations[i * program->frag_count + j] =
|
||||
glGetUniformLocation(program->programs[i], name);
|
||||
}
|
||||
|
||||
for (j = 0; j < program->sub_type_count; j++) {
|
||||
for (unsigned int j = 0; j < program->sub_type_count; j++) {
|
||||
snprintf(name, STR_LEN, "SUB_%d_PREFIX", j + 1);
|
||||
prefix = config_file_get_str(config, name, 0);
|
||||
for (k = 0; k < program->sub_variant_count; k++) {
|
||||
for (unsigned int k = 0; k < program->sub_variant_count; k++) {
|
||||
snprintf(name, STR_LEN, "%s%d", prefix, k + 1);
|
||||
program->sub_locations[i * program->sub_variant_count *
|
||||
program->sub_type_count +
|
||||
@@ -328,7 +321,7 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
|
||||
}
|
||||
|
||||
prefix = config_file_get_str(config, "UNIFORM_ACTIVE_PREFIX", "iActive");
|
||||
for (j = 0; j < program->active_count; j++) {
|
||||
for (unsigned int j = 0; j < program->active_count; j++) {
|
||||
snprintf(name, STR_LEN, "%s%d", prefix, j + 1);
|
||||
program->iactive_locations[i * program->active_count + j] =
|
||||
glGetUniformLocation(program->programs[i], name);
|
||||
@@ -336,8 +329,9 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
|
||||
|
||||
if (program->midi_lengths.length == 0) {
|
||||
index1 = 0;
|
||||
for (j = 0; j < state_config->midi_active_counts.length; j++) {
|
||||
for (k = 0; k < state_config->midi_active_counts.values[j]; k++) {
|
||||
for (unsigned int j = 0; j < state_config->midi_active_counts.length; j++) {
|
||||
for (unsigned int k = 0; k < state_config->midi_active_counts.values[j];
|
||||
k++) {
|
||||
program->midi_lengths.values[index1++] =
|
||||
state_config->midi_counts.values[j];
|
||||
}
|
||||
@@ -347,8 +341,9 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
|
||||
|
||||
prefix = config_file_get_str(config, "UNIFORM_MIDI_PREFIX", "iMidi");
|
||||
index2 = 0;
|
||||
for (j = 0; j < state_config->midi_active_counts.length; j++) {
|
||||
for (k = 0; k < state_config->midi_active_counts.values[j]; k++) {
|
||||
for (unsigned int j = 0; j < state_config->midi_active_counts.length; j++) {
|
||||
for (unsigned int k = 0; k < state_config->midi_active_counts.values[j];
|
||||
k++) {
|
||||
snprintf(name, STR_LEN, "%s%d_%d", prefix, j + 1, k + 1);
|
||||
program->imidi_locations[i * program->midi_lengths.length + index2++] =
|
||||
glGetUniformLocation(program->programs[i], name);
|
||||
@@ -357,7 +352,7 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
|
||||
|
||||
// create texX uniforms pointer
|
||||
prefix = config_file_get_str(config, "UNIFORM_TEX_PREFIX", "iTex");
|
||||
for (j = 0; j < program->tex_count; j++) {
|
||||
for (unsigned int j = 0; j < program->tex_count; j++) {
|
||||
snprintf(name, STR_LEN, "%s%d", prefix, j);
|
||||
program->textures_locations[i * program->tex_count + j] =
|
||||
glGetUniformLocation(program->programs[i], name);
|
||||
@@ -372,9 +367,7 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
|
||||
|
||||
static void init_programs(ShaderProgram *program, ConfigFile *config,
|
||||
StateConfig *state_config) {
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < program->frag_count; i++) {
|
||||
for (unsigned int i = 0; i < program->frag_count; i++) {
|
||||
init_single_program(program, i, config, state_config);
|
||||
}
|
||||
}
|
||||
@@ -440,13 +433,11 @@ void shaders_update(ShaderProgram *program, File *fragment_shader,
|
||||
}
|
||||
|
||||
static void update_viewport(ShaderProgram *program, SharedContext *context) {
|
||||
unsigned int i;
|
||||
|
||||
// viewport changed
|
||||
if (context->resolution[0] != program->last_resolution[0] ||
|
||||
context->resolution[1] != program->last_resolution[1]) {
|
||||
// clean and resize all textures
|
||||
for (i = 0; i < program->tex_count; i++) {
|
||||
for (unsigned int i = 0; i < program->tex_count; i++) {
|
||||
glActiveTexture(GL_TEXTURE0 + i);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, context->tex_resolution[0],
|
||||
context->tex_resolution[1], 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
|
||||
@@ -481,7 +472,9 @@ static void write_uniform_multi_3f(GLuint location, unsigned int count,
|
||||
|
||||
static void use_program(ShaderProgram *program, int i, bool output,
|
||||
SharedContext *context) {
|
||||
unsigned int j, k, offset, subcount;
|
||||
unsigned int k;
|
||||
unsigned int offset;
|
||||
unsigned int subcount;
|
||||
GLuint subroutines[ARRAY_SIZE];
|
||||
// use specific shader program
|
||||
glUseProgram(program->programs[i]);
|
||||
@@ -514,12 +507,12 @@ static void use_program(ShaderProgram *program, int i, bool output,
|
||||
write_uniform_2f(program->ires_locations[i], &context->resolution);
|
||||
write_uniform_2f(program->itexres_locations[i], &context->tex_resolution);
|
||||
|
||||
for (j = 0; j < program->active_count; j++) {
|
||||
for (unsigned int j = 0; j < program->active_count; j++) {
|
||||
write_uniform_1i(program->iactive_locations[i * program->active_count + j],
|
||||
context->active[j] + 1);
|
||||
}
|
||||
|
||||
for (j = 0; j < program->in_count; j++) {
|
||||
for (unsigned int j = 0; j < program->in_count; j++) {
|
||||
write_uniform_2f(program->iinres_locations[i * program->in_count + j],
|
||||
&context->input_resolutions[j]);
|
||||
write_uniform_1i(program->iinfmt_locations[i * program->in_count + j],
|
||||
@@ -529,18 +522,18 @@ static void use_program(ShaderProgram *program, int i, bool output,
|
||||
}
|
||||
|
||||
// set seeds uniforms
|
||||
for (j = 0; j < program->frag_count; j++) {
|
||||
for (unsigned int j = 0; j < program->frag_count; j++) {
|
||||
write_uniform_1i(program->iseed_locations[i * program->frag_count + j],
|
||||
context->seeds[j]);
|
||||
}
|
||||
|
||||
for (j = 0; j < program->frag_count; j++) {
|
||||
for (unsigned int j = 0; j < program->frag_count; j++) {
|
||||
write_uniform_1i(program->istate_locations[i * program->frag_count + j],
|
||||
context->state.values[j] + 1);
|
||||
}
|
||||
|
||||
offset = 0;
|
||||
for (j = 0; j < program->midi_lengths.length; j++) {
|
||||
for (unsigned int j = 0; j < program->midi_lengths.length; j++) {
|
||||
write_uniform_multi_3f(
|
||||
program->imidi_locations[i * program->midi_lengths.length + j],
|
||||
program->midi_lengths.values[j], context->values + offset);
|
||||
@@ -550,7 +543,7 @@ static void use_program(ShaderProgram *program, int i, bool output,
|
||||
// set subroutines for fragment and update state uniforms
|
||||
k = context->state.values[i];
|
||||
subcount = 0;
|
||||
for (j = 0; j < program->sub_type_count; j++) {
|
||||
for (unsigned int j = 0; j < program->sub_type_count; j++) {
|
||||
if (program->sub_locations[i * program->sub_variant_count *
|
||||
program->sub_type_count +
|
||||
j * program->sub_variant_count + k] !=
|
||||
@@ -567,7 +560,7 @@ static void use_program(ShaderProgram *program, int i, bool output,
|
||||
}
|
||||
|
||||
// set GL_TEXTURE(X) to uniform sampler2D texX
|
||||
for (j = 0; j < program->tex_count; j++) {
|
||||
for (unsigned int j = 0; j < program->tex_count; j++) {
|
||||
write_uniform_1i(program->textures_locations[i * program->tex_count + j],
|
||||
j);
|
||||
}
|
||||
@@ -578,14 +571,12 @@ static void use_program(ShaderProgram *program, int i, bool output,
|
||||
|
||||
void shaders_compute(ShaderProgram *program, SharedContext *context,
|
||||
bool monitor, bool output_only) {
|
||||
unsigned int i;
|
||||
|
||||
if (!output_only) {
|
||||
glBindVertexArray(program->vertex_array[0]);
|
||||
|
||||
update_viewport(program, context);
|
||||
|
||||
for (i = 0; i < program->frag_count; i++) {
|
||||
for (unsigned int i = 0; i < program->frag_count; i++) {
|
||||
if (i != program->frag_output_index && i != program->frag_monitor_index) {
|
||||
use_program(program, i, false, context);
|
||||
}
|
||||
@@ -603,9 +594,7 @@ void shaders_compute(ShaderProgram *program, SharedContext *context,
|
||||
}
|
||||
|
||||
void shaders_free(ShaderProgram *program) {
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < program->frag_count; i++) {
|
||||
for (unsigned int i = 0; i < program->frag_count; i++) {
|
||||
glDeleteProgram(program->programs[i]);
|
||||
}
|
||||
|
||||
|
||||
+34
-34
@@ -13,13 +13,14 @@
|
||||
#include "tempo.h"
|
||||
|
||||
void state_parse_config(StateConfig *state_config, ConfigFile *config) {
|
||||
unsigned int i, j, offset, count;
|
||||
unsigned int offset;
|
||||
unsigned int count;
|
||||
char name[STR_LEN];
|
||||
|
||||
state_config->select_page_codes.length =
|
||||
config_file_get_int(config, "SELECT_PAGE_COUNT", 0);
|
||||
|
||||
for (i = 0; i < state_config->select_page_codes.length; i++) {
|
||||
for (unsigned int i = 0; i < state_config->select_page_codes.length; i++) {
|
||||
snprintf(name, STR_LEN, "SELECT_PAGE_%d", i + 1);
|
||||
state_config->select_page_codes.values[i] =
|
||||
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
||||
@@ -28,7 +29,7 @@ void state_parse_config(StateConfig *state_config, ConfigFile *config) {
|
||||
state_config->select_item_codes.length =
|
||||
config_file_get_int(config, "SELECT_ITEM_COUNT", 0);
|
||||
|
||||
for (i = 0; i < state_config->select_item_codes.length; i++) {
|
||||
for (unsigned int i = 0; i < state_config->select_item_codes.length; i++) {
|
||||
snprintf(name, STR_LEN, "SELECT_ITEM_%d", i + 1);
|
||||
state_config->select_item_codes.values[i] =
|
||||
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
||||
@@ -40,7 +41,7 @@ void state_parse_config(StateConfig *state_config, ConfigFile *config) {
|
||||
state_config->select_frag_codes.length =
|
||||
config_file_get_int(config, "FRAG_COUNT", 1);
|
||||
|
||||
for (i = 0; i < state_config->select_frag_codes.length; i++) {
|
||||
for (unsigned int i = 0; i < state_config->select_frag_codes.length; i++) {
|
||||
snprintf(name, STR_LEN, "SELECT_FRAG_%d", i + 1);
|
||||
state_config->select_frag_codes.values[i] =
|
||||
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
||||
@@ -53,7 +54,7 @@ void state_parse_config(StateConfig *state_config, ConfigFile *config) {
|
||||
config_file_get_int(config, "MIDI_COUNT", 0);
|
||||
|
||||
count = 0;
|
||||
for (i = 0; i < state_config->midi_active_counts.length; i++) {
|
||||
for (unsigned int i = 0; i < state_config->midi_active_counts.length; i++) {
|
||||
snprintf(name, STR_LEN, "MIDI_%d_ACTIVE_COUNT", i + 1);
|
||||
state_config->midi_active_counts.values[i] =
|
||||
config_file_get_int(config, name, 1);
|
||||
@@ -63,8 +64,9 @@ void state_parse_config(StateConfig *state_config, ConfigFile *config) {
|
||||
|
||||
state_config->midi_active_codes.length = count;
|
||||
|
||||
for (i = 0; i < state_config->midi_active_counts.length; i++) {
|
||||
for (j = 0; j < state_config->midi_active_counts.values[i]; j++) {
|
||||
for (unsigned int i = 0; i < state_config->midi_active_counts.length; i++) {
|
||||
for (unsigned int j = 0; j < state_config->midi_active_counts.values[i];
|
||||
j++) {
|
||||
snprintf(name, STR_LEN, "MIDI_%d_ACTIVE_%d", i + 1, j + 1);
|
||||
state_config->midi_active_codes
|
||||
.values[state_config->midi_active_offsets.values[i] + j] =
|
||||
@@ -74,7 +76,7 @@ void state_parse_config(StateConfig *state_config, ConfigFile *config) {
|
||||
|
||||
count = 0;
|
||||
offset = 0;
|
||||
for (i = 0; i < state_config->midi_counts.length; i++) {
|
||||
for (unsigned int i = 0; i < state_config->midi_counts.length; i++) {
|
||||
snprintf(name, STR_LEN, "MIDI_%d_COUNT", i + 1);
|
||||
state_config->midi_counts.values[i] = config_file_get_int(config, name, 0);
|
||||
state_config->midi_offsets.values[i] = count;
|
||||
@@ -86,9 +88,9 @@ void state_parse_config(StateConfig *state_config, ConfigFile *config) {
|
||||
|
||||
state_config->midi_codes.length = count * 3;
|
||||
|
||||
for (i = 0; i < state_config->midi_counts.length; i++) {
|
||||
for (unsigned int i = 0; i < state_config->midi_counts.length; i++) {
|
||||
offset = state_config->midi_offsets.values[i];
|
||||
for (j = 0; j < state_config->midi_counts.values[i]; j++) {
|
||||
for (unsigned int j = 0; j < state_config->midi_counts.values[i]; j++) {
|
||||
snprintf(name, STR_LEN, "MIDI_%d_%d_X", i + 1, j + 1);
|
||||
state_config->midi_codes.values[(offset + j) * 3] =
|
||||
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
||||
@@ -106,7 +108,7 @@ void state_parse_config(StateConfig *state_config, ConfigFile *config) {
|
||||
state_config->fader_codes.length =
|
||||
config_file_get_int(config, "FADER_COUNT", 0);
|
||||
|
||||
for (i = 0; i < state_config->fader_codes.length; i++) {
|
||||
for (unsigned int i = 0; i < state_config->fader_codes.length; i++) {
|
||||
snprintf(name, STR_LEN, "FADER_%d", i + 1);
|
||||
state_config->fader_codes.values[i] =
|
||||
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
||||
@@ -125,9 +127,10 @@ static void safe_midi_write(MidiDevice *midi, unsigned int code,
|
||||
|
||||
static void update_page(SharedContext *context, StateConfig *state_config,
|
||||
MidiDevice *midi) {
|
||||
unsigned int i, page_item_min, page_item_max;
|
||||
unsigned int page_item_min;
|
||||
unsigned int page_item_max;
|
||||
// SHOW PAGE
|
||||
for (i = 0; i < state_config->select_page_codes.length; i++) {
|
||||
for (unsigned int i = 0; i < state_config->select_page_codes.length; i++) {
|
||||
safe_midi_write(midi, state_config->select_page_codes.values[i],
|
||||
i == context->page ? MIDI_MAX : 0);
|
||||
}
|
||||
@@ -138,7 +141,7 @@ static void update_page(SharedContext *context, StateConfig *state_config,
|
||||
|
||||
if (context->state.values[context->selected] >= page_item_min &&
|
||||
context->state.values[context->selected] < page_item_max) {
|
||||
for (i = 0; i < state_config->select_item_codes.length; i++) {
|
||||
for (unsigned int i = 0; i < state_config->select_item_codes.length; i++) {
|
||||
safe_midi_write(midi, state_config->select_item_codes.values[i],
|
||||
i == context->state.values[context->selected] -
|
||||
page_item_min
|
||||
@@ -146,7 +149,7 @@ static void update_page(SharedContext *context, StateConfig *state_config,
|
||||
: 0);
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < state_config->select_item_codes.length; i++) {
|
||||
for (unsigned int i = 0; i < state_config->select_item_codes.length; i++) {
|
||||
safe_midi_write(midi, state_config->select_item_codes.values[i], 0);
|
||||
}
|
||||
}
|
||||
@@ -154,10 +157,11 @@ static void update_page(SharedContext *context, StateConfig *state_config,
|
||||
|
||||
static void update_active(SharedContext *context, StateConfig *state_config,
|
||||
MidiDevice *midi) {
|
||||
unsigned int i, j, k;
|
||||
unsigned int k;
|
||||
|
||||
for (i = 0; i < state_config->midi_active_counts.length; i++) {
|
||||
for (j = 0; j < state_config->midi_active_counts.values[i]; j++) {
|
||||
for (unsigned int i = 0; i < state_config->midi_active_counts.length; i++) {
|
||||
for (unsigned int j = 0; j < state_config->midi_active_counts.values[i];
|
||||
j++) {
|
||||
k = state_config->midi_active_offsets.values[i] + j;
|
||||
safe_midi_write(midi, state_config->midi_active_codes.values[k],
|
||||
context->active[i] == j ? MIDI_MAX : 0);
|
||||
@@ -167,9 +171,11 @@ static void update_active(SharedContext *context, StateConfig *state_config,
|
||||
|
||||
static void update_values(SharedContext *context, StateConfig *state_config,
|
||||
MidiDevice *midi) {
|
||||
unsigned int i, j, k, part;
|
||||
unsigned int j;
|
||||
unsigned int k;
|
||||
unsigned int part;
|
||||
|
||||
for (i = 0; i < state_config->midi_codes.length; i++) {
|
||||
for (unsigned int i = 0; i < state_config->midi_codes.length; i++) {
|
||||
j = i / 3;
|
||||
part = arr_uint_remap_index(state_config->midi_offsets, &j);
|
||||
k = state_config->values_offsets.values[part] +
|
||||
@@ -325,7 +331,6 @@ static void state_load(SharedContext *context, StateConfig *state_config,
|
||||
char *state_file) {
|
||||
ConfigFile saved_state;
|
||||
char key[STR_LEN];
|
||||
unsigned int i;
|
||||
|
||||
config_file_read(&saved_state, state_file);
|
||||
|
||||
@@ -334,7 +339,7 @@ static void state_load(SharedContext *context, StateConfig *state_config,
|
||||
context->page = config_file_get_int(&saved_state, "page", 0);
|
||||
context->selected = config_file_get_int(&saved_state, "selected", 0);
|
||||
|
||||
for (i = 0; i < context->state.length; i++) {
|
||||
for (unsigned int i = 0; i < context->state.length; i++) {
|
||||
snprintf(key, STR_LEN, "seed_%d", i);
|
||||
context->seeds[i] =
|
||||
config_file_get_int(&saved_state, key, context->seeds[i]);
|
||||
@@ -342,12 +347,12 @@ static void state_load(SharedContext *context, StateConfig *state_config,
|
||||
context->state.values[i] = config_file_get_int(&saved_state, key, 0);
|
||||
}
|
||||
|
||||
for (i = 0; i < state_config->midi_active_counts.length; i++) {
|
||||
for (unsigned int i = 0; i < state_config->midi_active_counts.length; i++) {
|
||||
snprintf(key, STR_LEN, "active_%d", i);
|
||||
context->active[i] = config_file_get_int(&saved_state, key, 0);
|
||||
}
|
||||
|
||||
for (i = 0; i < state_config->midi_codes.length; i++) {
|
||||
for (unsigned int i = 0; i < state_config->midi_codes.length; i++) {
|
||||
snprintf(key, STR_LEN, "value_%d_x", i);
|
||||
context->values[i][0] =
|
||||
(float)config_file_get_int(&saved_state, key, 0) / MIDI_MAX;
|
||||
@@ -365,8 +370,6 @@ static void state_load(SharedContext *context, StateConfig *state_config,
|
||||
void state_init(SharedContext *context, StateConfig *state_config, bool demo,
|
||||
bool auto_random, unsigned int base_tempo, char *state_file,
|
||||
bool load_state) {
|
||||
unsigned int i;
|
||||
|
||||
tempo_init(&context->tempo);
|
||||
tempo_set(&context->tempo, base_tempo);
|
||||
context->demo = demo;
|
||||
@@ -387,7 +390,7 @@ void state_init(SharedContext *context, StateConfig *state_config, bool demo,
|
||||
|
||||
memset(context->seeds, 0, sizeof(context->seeds));
|
||||
|
||||
for (i = 0; i < context->state.length; i++) {
|
||||
for (unsigned int i = 0; i < context->state.length; i++) {
|
||||
context->seeds[i] = rand_uint(1000);
|
||||
}
|
||||
|
||||
@@ -397,9 +400,7 @@ void state_init(SharedContext *context, StateConfig *state_config, bool demo,
|
||||
}
|
||||
|
||||
void state_randomize(SharedContext *context, StateConfig *state_config) {
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < context->state.length; i++) {
|
||||
for (unsigned int i = 0; i < context->state.length; i++) {
|
||||
context->state.values[i] = rand_uint(state_config->state_max);
|
||||
}
|
||||
}
|
||||
@@ -407,7 +408,6 @@ void state_randomize(SharedContext *context, StateConfig *state_config) {
|
||||
void state_save(SharedContext *context, StateConfig *state_config,
|
||||
char *state_file) {
|
||||
StringArray lines;
|
||||
unsigned int i;
|
||||
|
||||
log_info("Saving state to '%s'...", state_file);
|
||||
|
||||
@@ -419,19 +419,19 @@ void state_save(SharedContext *context, StateConfig *state_config,
|
||||
snprintf(lines.values[lines.length++], STR_LEN, "selected=%d",
|
||||
context->selected);
|
||||
|
||||
for (i = 0; i < context->state.length; i++) {
|
||||
for (unsigned int i = 0; i < context->state.length; i++) {
|
||||
snprintf(lines.values[lines.length++], STR_LEN, "seed_%d=%d", i,
|
||||
context->seeds[i]);
|
||||
snprintf(lines.values[lines.length++], STR_LEN, "state_%d=%d", i,
|
||||
context->state.values[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < state_config->midi_active_counts.length; i++) {
|
||||
for (unsigned int i = 0; i < state_config->midi_active_counts.length; i++) {
|
||||
snprintf(lines.values[lines.length++], STR_LEN, "active_%d=%d", i,
|
||||
context->active[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < state_config->midi_codes.length; i++) {
|
||||
for (unsigned int i = 0; i < state_config->midi_codes.length; i++) {
|
||||
snprintf(lines.values[lines.length++], STR_LEN, "value_%d_x=%d", i,
|
||||
(unsigned int)(context->values[i][0] * MIDI_MAX));
|
||||
snprintf(lines.values[lines.length++], STR_LEN, "value_%d_y=%d", i,
|
||||
|
||||
+5
-2
@@ -41,16 +41,19 @@ static bool is_digit(char c) { return c >= '0' && c <= '9'; }
|
||||
|
||||
bool string_is_number(char *value) {
|
||||
unsigned long value_len;
|
||||
unsigned int i;
|
||||
|
||||
if (value == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
value_len = strnlen(value, STR_LEN);
|
||||
for (i = 0; i < value_len; i++) {
|
||||
|
||||
for (unsigned int i = 0; i < value_len; i++) {
|
||||
if (!is_digit(value[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -39,8 +39,9 @@ static bool is_chain_active(Tempo tempo, long t) {
|
||||
}
|
||||
|
||||
static long get_average_tap_duration(Tempo tempo) {
|
||||
unsigned int amount, i;
|
||||
long running_total, average_tap_duration;
|
||||
unsigned int amount;
|
||||
long running_total;
|
||||
long average_tap_duration;
|
||||
|
||||
amount = tempo.taps_in_chain - 1;
|
||||
if (amount > TOTAL_TAP_VALUES) {
|
||||
@@ -48,7 +49,7 @@ static long get_average_tap_duration(Tempo tempo) {
|
||||
}
|
||||
|
||||
running_total = 0;
|
||||
for (i = 0; i < amount; i++) {
|
||||
for (unsigned int i = 0; i < amount; i++) {
|
||||
running_total += tempo.tap_durations[i];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user