wip state
This commit is contained in:
@@ -17,4 +17,8 @@
|
||||
#define MAX_FRAG 64
|
||||
#endif
|
||||
|
||||
#ifndef UNSET_MIDI_CODE
|
||||
#define UNSET_MIDI_CODE 300
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_H */
|
||||
+15
-15
@@ -12,6 +12,7 @@
|
||||
#include "rand.h"
|
||||
#include "shaders.h"
|
||||
#include "shared.h"
|
||||
#include "state.h"
|
||||
#include "timer.h"
|
||||
#include "types.h"
|
||||
#include "video.h"
|
||||
@@ -27,6 +28,7 @@ static File common_shader_code;
|
||||
static Timer timer;
|
||||
static ConfigFile config;
|
||||
static MidiDevice midi;
|
||||
static StateConfig state_config;
|
||||
|
||||
static void compute_fps() {
|
||||
double fps;
|
||||
@@ -51,14 +53,6 @@ static void compute_fps() {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO put in state file
|
||||
static void randomize_context_state() {
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < program.frag_count; i++) {
|
||||
context->state[i] = rand_uint(program.sub_variant_count);
|
||||
}
|
||||
}
|
||||
static void init_context(Parameters params) {
|
||||
unsigned int i;
|
||||
|
||||
@@ -69,7 +63,7 @@ static void init_context(Parameters params) {
|
||||
memset(context->state, 0, sizeof(context->state));
|
||||
|
||||
if (params.demo) {
|
||||
randomize_context_state();
|
||||
state_randomize(context, state_config, program.frag_count);
|
||||
}
|
||||
|
||||
memset(context->seeds, 0, sizeof(context->seeds));
|
||||
@@ -206,7 +200,7 @@ static void key_callback(Window *window, int key,
|
||||
window_close(window);
|
||||
} else if (window_char_key(key, action, 82)) {
|
||||
// R: randomize
|
||||
randomize_context_state();
|
||||
state_randomize(context, state_config, program.frag_count);
|
||||
} else if (window_char_key(key, action, 68)) {
|
||||
// D: demo on/off
|
||||
context->demo = !context->demo;
|
||||
@@ -256,6 +250,8 @@ void forge_run(Parameters params) {
|
||||
|
||||
config = config_file_read(params.config_path, false);
|
||||
|
||||
state_config = state_parse_config(config);
|
||||
|
||||
frag_count = config_file_get_int(config, "FRAG_COUNT", 6);
|
||||
|
||||
init_files(params.frag_path, frag_count);
|
||||
@@ -286,8 +282,9 @@ void forge_run(Parameters params) {
|
||||
|
||||
window_use(window_output, context);
|
||||
|
||||
program = shaders_init(fragment_shaders, config, context, inputs,
|
||||
params.video_in_count, NULL);
|
||||
program = shaders_init(
|
||||
fragment_shaders, config, context, inputs, params.video_in_count,
|
||||
state_config.select_page_count * state_config.select_item_count, NULL);
|
||||
} else {
|
||||
window_output = NULL;
|
||||
}
|
||||
@@ -299,9 +296,10 @@ void forge_run(Parameters params) {
|
||||
|
||||
window_use(window_monitor, context);
|
||||
|
||||
program = shaders_init(fragment_shaders, config, context, inputs,
|
||||
params.video_in_count,
|
||||
window_output != NULL ? &program : NULL);
|
||||
program = shaders_init(
|
||||
fragment_shaders, config, context, inputs, params.video_in_count,
|
||||
state_config.select_page_count * state_config.select_item_count,
|
||||
window_output != NULL ? &program : NULL);
|
||||
} else {
|
||||
window_monitor = NULL;
|
||||
}
|
||||
@@ -347,5 +345,7 @@ void forge_run(Parameters params) {
|
||||
|
||||
config_file_free(config);
|
||||
|
||||
state_free_config(state_config);
|
||||
|
||||
window_terminate();
|
||||
}
|
||||
+4
-3
@@ -366,7 +366,9 @@ static void init_programs(ShaderProgram *program, ConfigFile config) {
|
||||
|
||||
ShaderProgram shaders_init(File *fragment_shaders, ConfigFile config,
|
||||
SharedContext *context, VideoCapture *inputs,
|
||||
unsigned int input_count, ShaderProgram *previous) {
|
||||
unsigned int input_count,
|
||||
unsigned int sub_variant_count,
|
||||
ShaderProgram *previous) {
|
||||
ShaderProgram program;
|
||||
|
||||
if (previous == NULL) {
|
||||
@@ -380,8 +382,7 @@ ShaderProgram shaders_init(File *fragment_shaders, ConfigFile config,
|
||||
program.frag_monitor_index =
|
||||
config_file_get_int(config, "FRAG_MONITOR", 1) - 1;
|
||||
program.sub_type_count = config_file_get_int(config, "SUB_TYPE_COUNT", 0);
|
||||
program.sub_variant_count =
|
||||
config_file_get_int(config, "SUB_VARIANT_COUNT", 0);
|
||||
program.sub_variant_count = sub_variant_count;
|
||||
program.in_count = config_file_get_int(config, "IN_COUNT", 0);
|
||||
|
||||
if (program.frag_count > MAX_FRAG) {
|
||||
|
||||
+3
-1
@@ -5,7 +5,9 @@
|
||||
|
||||
ShaderProgram shaders_init(File *fragment_shaders, ConfigFile config,
|
||||
SharedContext *context, VideoCapture *inputs,
|
||||
unsigned int input_count, ShaderProgram *previous);
|
||||
unsigned int input_count,
|
||||
unsigned int sub_variant_count,
|
||||
ShaderProgram *previous);
|
||||
|
||||
void shaders_update(ShaderProgram program, File *fragment_shaders,
|
||||
unsigned int i);
|
||||
|
||||
+47
-1
@@ -1 +1,47 @@
|
||||
#include "state.h"
|
||||
#include "state.h"
|
||||
#include "config.h"
|
||||
#include "config_file.h"
|
||||
#include "rand.h"
|
||||
#include "types.h"
|
||||
|
||||
StateConfig state_parse_config(ConfigFile config) {
|
||||
StateConfig state_config;
|
||||
|
||||
state_config.select_page_count =
|
||||
config_file_get_int(config, "SELECT_PAGE_COUNT", 0);
|
||||
|
||||
// TODO parse
|
||||
|
||||
state_config.select_item_count =
|
||||
config_file_get_int(config, "SELECT_ITEM_COUNT", 0);
|
||||
|
||||
// TODO parse
|
||||
|
||||
state_config.src_count = config_file_get_int(config, "SRC_COUNT", 0);
|
||||
|
||||
// TODO parse
|
||||
|
||||
state_config.fader_count = config_file_get_int(config, "FADER_COUNT", 0);
|
||||
|
||||
// TODO parse
|
||||
|
||||
state_config.tap_tempo_code =
|
||||
config_file_get_int(config, "TAP_TEMPO", UNSET_MIDI_CODE);
|
||||
|
||||
return state_config;
|
||||
}
|
||||
|
||||
void state_free_config(StateConfig state_config) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
void state_randomize(SharedContext *context, StateConfig state_config,
|
||||
unsigned int state_count) {
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < state_count; i++) {
|
||||
context->state[i] =
|
||||
rand_uint(state_config.select_page_count *
|
||||
state_config.select_item_count); // TODO from config
|
||||
}
|
||||
}
|
||||
@@ -3,4 +3,11 @@
|
||||
#ifndef STATE_H
|
||||
#define STATE_H
|
||||
|
||||
StateConfig state_parse_config(ConfigFile config);
|
||||
|
||||
void state_randomize(SharedContext *context, StateConfig state_config,
|
||||
unsigned int state_count);
|
||||
|
||||
void state_free_config(StateConfig state_config);
|
||||
|
||||
#endif /* STATE_H */
|
||||
+21
@@ -136,6 +136,27 @@ typedef struct SharedContext {
|
||||
bool stop;
|
||||
} SharedContext;
|
||||
|
||||
typedef struct StateConfig {
|
||||
unsigned int select_page_count;
|
||||
unsigned int *select_page_codes;
|
||||
|
||||
unsigned int select_item_count;
|
||||
unsigned int *select_item_codes;
|
||||
|
||||
unsigned int *select_frag_codes;
|
||||
|
||||
unsigned int src_count;
|
||||
unsigned int *src_active_counts;
|
||||
unsigned int *src_active;
|
||||
unsigned int *src_subcounts;
|
||||
unsigned int *src_codes;
|
||||
|
||||
unsigned int fader_count;
|
||||
unsigned int *fader_codes;
|
||||
|
||||
unsigned int tap_tempo_code;
|
||||
} StateConfig;
|
||||
|
||||
typedef struct Timer {
|
||||
struct timeval start;
|
||||
unsigned int counter;
|
||||
|
||||
Reference in New Issue
Block a user