page and item selection
This commit is contained in:
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
AUTOMAKE_OPTIONS = foreign subdir-objects -Wall
|
AUTOMAKE_OPTIONS = foreign subdir-objects -Wall
|
||||||
bin_PROGRAMS = forge
|
bin_PROGRAMS = forge
|
||||||
forge_SOURCES = src/main.c src/args.c src/forge.c src/file.c src/window.c src/shaders.c src/timer.c src/string.c src/config_file.c src/rand.c src/video.c src/shared.c src/midi.c src/state.c $(top_srcdir)/include/glad/gl.h $(top_srcdir)/include/glad/egl.h $(top_srcdir)/hashmap.c/hashmap.c $(top_srcdir)/log.c/src/log.c
|
forge_SOURCES = src/main.c src/args.c src/forge.c src/file.c src/window.c src/shaders.c src/timer.c src/string.c src/config_file.c src/rand.c src/video.c src/shared.c src/midi.c src/state.c src/arr.c $(top_srcdir)/include/glad/gl.h $(top_srcdir)/include/glad/egl.h $(top_srcdir)/hashmap.c/hashmap.c $(top_srcdir)/log.c/src/log.c
|
||||||
forge_CFLAGS = -Ofast -march=native -flto -funroll-loops -fprefetch-loop-arrays -fno-exceptions -fopenmp -I$(top_srcdir)/include -DGLFW_INCLUDE_NONE -DGLFW_EXPOSE_NATIVE_EGL -DGLFW_NATIVE_INCLUDE_NONE -DLOG_USE_COLOR
|
forge_CFLAGS = -Ofast -march=native -flto -funroll-loops -fprefetch-loop-arrays -fno-exceptions -fopenmp -I$(top_srcdir)/include -DGLFW_INCLUDE_NONE -DGLFW_EXPOSE_NATIVE_EGL -DGLFW_NATIVE_INCLUDE_NONE -DLOG_USE_COLOR
|
||||||
forge_LDADD = -lm -lGL -lglfw
|
forge_LDADD = -lm -lGL -lglfw
|
||||||
include_HEADERS = src/main.h src/args.h src/config.h src/types.h src/forge.h src/file.h src/constants.h src/window.h src/shaders.h src/timer.h src/string.h src/config_file.h src/rand.h src/video.h src/shared.h src/midi.h src/state.h $(top_srcdir)/include/glad/gl.h $(top_srcdir)/include/glad/egl.h $(top_srcdir)/include/linmath.h $(top_srcdir)/include/hashmap.h $(top_srcdir)/include/log.h
|
include_HEADERS = src/main.h src/args.h src/config.h src/types.h src/forge.h src/file.h src/constants.h src/window.h src/shaders.h src/timer.h src/string.h src/config_file.h src/rand.h src/video.h src/shared.h src/midi.h src/state.h src/arr.h $(top_srcdir)/include/glad/gl.h $(top_srcdir)/include/glad/egl.h $(top_srcdir)/include/linmath.h $(top_srcdir)/include/hashmap.h $(top_srcdir)/include/log.h
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
#include "arr.h"
|
||||||
|
|
||||||
|
unsigned int arr_uint_index_of(UintArray array, unsigned int value) {
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
for (i = 0; i < array.length; i++) {
|
||||||
|
if (array.values[i] == value) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ARRAY_NOT_FOUND;
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
#ifndef ARR_H
|
||||||
|
#define ARR_H
|
||||||
|
|
||||||
|
unsigned int arr_uint_index_of(UintArray array, unsigned int value);
|
||||||
|
|
||||||
|
#endif /* ARR_H */
|
||||||
@@ -25,4 +25,8 @@
|
|||||||
#define ARRAY_SIZE 1024
|
#define ARRAY_SIZE 1024
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef ARRAY_NOT_FOUND
|
||||||
|
#define ARRAY_NOT_FOUND ARRAY_SIZE + 1
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* CONFIG_H */
|
#endif /* CONFIG_H */
|
||||||
+10
-12
@@ -64,7 +64,7 @@ static void init_context(Parameters params, unsigned int in_count,
|
|||||||
memset(context->state, 0, sizeof(context->state));
|
memset(context->state, 0, sizeof(context->state));
|
||||||
|
|
||||||
if (params.demo) {
|
if (params.demo) {
|
||||||
state_randomize(context, state_config, frag_count);
|
state_randomize(context, state_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(context->active, 0, sizeof(context->active));
|
memset(context->active, 0, sizeof(context->active));
|
||||||
@@ -200,7 +200,7 @@ static void key_callback(Window *window, int key,
|
|||||||
window_close(window);
|
window_close(window);
|
||||||
} else if (window_char_key(key, action, 82)) {
|
} else if (window_char_key(key, action, 82)) {
|
||||||
// R: randomize
|
// R: randomize
|
||||||
state_randomize(context, state_config, program.frag_count);
|
state_randomize(context, state_config);
|
||||||
} else if (window_char_key(key, action, 68)) {
|
} else if (window_char_key(key, action, 68)) {
|
||||||
// D: demo on/off
|
// D: demo on/off
|
||||||
context->demo = !context->demo;
|
context->demo = !context->demo;
|
||||||
@@ -208,8 +208,7 @@ static void key_callback(Window *window, int key,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void midi_callback(unsigned char code, float value) {
|
static void midi_callback(unsigned char code, float value) {
|
||||||
state_apply_event(context, state_config, program.frag_count, midi, code,
|
state_apply_event(context, state_config, midi, code, value);
|
||||||
value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void loop(bool hr) {
|
static void loop(bool hr) {
|
||||||
@@ -288,10 +287,9 @@ void forge_run(Parameters params) {
|
|||||||
|
|
||||||
window_use(window_output, context);
|
window_use(window_output, context);
|
||||||
|
|
||||||
program = shaders_init(
|
program = shaders_init(fragment_shaders, config, context, inputs,
|
||||||
fragment_shaders, config, context, inputs, params.video_in_count,
|
params.video_in_count, state_config.state_max,
|
||||||
state_config.select_page_count * state_config.select_item_count,
|
state_config.src_count, NULL);
|
||||||
state_config.src_count, NULL);
|
|
||||||
} else {
|
} else {
|
||||||
window_output = NULL;
|
window_output = NULL;
|
||||||
}
|
}
|
||||||
@@ -303,10 +301,10 @@ void forge_run(Parameters params) {
|
|||||||
|
|
||||||
window_use(window_monitor, context);
|
window_use(window_monitor, context);
|
||||||
|
|
||||||
program = shaders_init(
|
program = shaders_init(fragment_shaders, config, context, inputs,
|
||||||
fragment_shaders, config, context, inputs, params.video_in_count,
|
params.video_in_count, state_config.state_max,
|
||||||
state_config.select_page_count * state_config.select_item_count,
|
state_config.src_count,
|
||||||
state_config.src_count, window_output != NULL ? &program : NULL);
|
window_output != NULL ? &program : NULL);
|
||||||
} else {
|
} else {
|
||||||
window_monitor = NULL;
|
window_monitor = NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -493,7 +493,7 @@ static void use_program(ShaderProgram program, int i, bool output,
|
|||||||
write_uniform_1i(program.ifps_locations[i], context->fps);
|
write_uniform_1i(program.ifps_locations[i], context->fps);
|
||||||
write_uniform_1i(program.idemo_locations[i], context->demo ? 1 : 0);
|
write_uniform_1i(program.idemo_locations[i], context->demo ? 1 : 0);
|
||||||
write_uniform_1i(program.ipage_locations[i], context->page);
|
write_uniform_1i(program.ipage_locations[i], context->page);
|
||||||
write_uniform_1i(program.iselected_locations[i], context->page);
|
write_uniform_1i(program.iselected_locations[i], context->selected);
|
||||||
write_uniform_2f(program.ires_locations[i], &resolution);
|
write_uniform_2f(program.ires_locations[i], &resolution);
|
||||||
write_uniform_2f(program.itexres_locations[i], &tex_resolution);
|
write_uniform_2f(program.itexres_locations[i], &tex_resolution);
|
||||||
|
|
||||||
|
|||||||
+56
-17
@@ -1,5 +1,6 @@
|
|||||||
#include <log.h>
|
#include <log.h>
|
||||||
|
|
||||||
|
#include "arr.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "config_file.h"
|
#include "config_file.h"
|
||||||
#include "midi.h"
|
#include "midi.h"
|
||||||
@@ -12,32 +13,37 @@ StateConfig state_parse_config(ConfigFile config) {
|
|||||||
StateConfig state_config;
|
StateConfig state_config;
|
||||||
char name[256];
|
char name[256];
|
||||||
|
|
||||||
state_config.select_page_count =
|
state_config.select_page_codes.length =
|
||||||
config_file_get_int(config, "SELECT_PAGE_COUNT", 0);
|
config_file_get_int(config, "SELECT_PAGE_COUNT", 0);
|
||||||
|
|
||||||
for (i = 0; i < state_config.select_page_count; i++) {
|
for (i = 0; i < state_config.select_page_codes.length; i++) {
|
||||||
sprintf(name, "SELECT_PAGE_%d", i + 1);
|
sprintf(name, "SELECT_PAGE_%d", i + 1);
|
||||||
state_config.select_page_codes[i] =
|
state_config.select_page_codes.values[i] =
|
||||||
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
state_config.select_item_count =
|
state_config.select_item_codes.length =
|
||||||
config_file_get_int(config, "SELECT_ITEM_COUNT", 0);
|
config_file_get_int(config, "SELECT_ITEM_COUNT", 0);
|
||||||
|
|
||||||
for (i = 0; i < state_config.select_item_count; i++) {
|
for (i = 0; i < state_config.select_item_codes.length; i++) {
|
||||||
sprintf(name, "SELECT_ITEM_%d", i + 1);
|
sprintf(name, "SELECT_ITEM_%d", i + 1);
|
||||||
state_config.select_item_codes[i] =
|
state_config.select_item_codes.values[i] =
|
||||||
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
frag_count = config_file_get_int(config, "FRAG_COUNT", 1);
|
state_config.state_max = state_config.select_page_codes.length *
|
||||||
|
state_config.select_item_codes.length;
|
||||||
|
|
||||||
for (i = 0; i < frag_count; i++) {
|
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++) {
|
||||||
sprintf(name, "SELECT_FRAG_%d", i + 1);
|
sprintf(name, "SELECT_FRAG_%d", i + 1);
|
||||||
state_config.select_frag_codes[i] =
|
state_config.select_frag_codes.values[i] =
|
||||||
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO uint arrays
|
||||||
state_config.src_count = config_file_get_int(config, "SRC_COUNT", 0);
|
state_config.src_count = config_file_get_int(config, "SRC_COUNT", 0);
|
||||||
|
|
||||||
total = 0;
|
total = 0;
|
||||||
@@ -96,9 +102,44 @@ StateConfig state_parse_config(ConfigFile config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void state_apply_event(SharedContext *context, StateConfig state_config,
|
void state_apply_event(SharedContext *context, StateConfig state_config,
|
||||||
unsigned int state_count, MidiDevice midi,
|
MidiDevice midi, unsigned char code, float value) {
|
||||||
unsigned char code, float value) {
|
unsigned int index;
|
||||||
log_debug("midi: %d %.2f", code, value);
|
bool found;
|
||||||
|
|
||||||
|
found = false;
|
||||||
|
|
||||||
|
if (value > 0) {
|
||||||
|
index =
|
||||||
|
arr_uint_index_of(state_config.select_page_codes, (unsigned int)code);
|
||||||
|
|
||||||
|
// PAGE CHANGE
|
||||||
|
if (index != ARRAY_NOT_FOUND) {
|
||||||
|
context->page = index;
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
index = arr_uint_index_of(state_config.select_frag_codes, code);
|
||||||
|
|
||||||
|
// TARGET CHANGE
|
||||||
|
if (index != ARRAY_NOT_FOUND) {
|
||||||
|
context->selected = index + 1;
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
index = arr_uint_index_of(state_config.select_item_codes, code);
|
||||||
|
|
||||||
|
// ITEM CHANGE
|
||||||
|
if (index != ARRAY_NOT_FOUND) {
|
||||||
|
context->state[context->selected - 1] =
|
||||||
|
context->page * state_config.select_item_codes.length + index;
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found) {
|
||||||
|
log_debug("unknown midi: %d %.2f", code, value);
|
||||||
|
}
|
||||||
|
|
||||||
midi_write(midi, code, value);
|
midi_write(midi, code, value);
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
@@ -127,12 +168,10 @@ bool state_background_midi_write(SharedContext *context,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void state_randomize(SharedContext *context, StateConfig state_config,
|
void state_randomize(SharedContext *context, StateConfig state_config) {
|
||||||
unsigned int state_count) {
|
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
for (i = 0; i < state_count; i++) {
|
for (i = 0; i < state_config.select_frag_codes.length; i++) {
|
||||||
context->state[i] = rand_uint(state_config.select_page_count *
|
context->state[i] = rand_uint(state_config.state_max);
|
||||||
state_config.select_item_count);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
-4
@@ -6,13 +6,11 @@
|
|||||||
StateConfig state_parse_config(ConfigFile config);
|
StateConfig state_parse_config(ConfigFile config);
|
||||||
|
|
||||||
void state_apply_event(SharedContext *context, StateConfig state_config,
|
void state_apply_event(SharedContext *context, StateConfig state_config,
|
||||||
unsigned int state_count, MidiDevice midi,
|
MidiDevice midi, unsigned char code, float value);
|
||||||
unsigned char code, float value);
|
|
||||||
|
|
||||||
bool state_background_midi_write(SharedContext *context,
|
bool state_background_midi_write(SharedContext *context,
|
||||||
StateConfig state_config, MidiDevice midi);
|
StateConfig state_config, MidiDevice midi);
|
||||||
|
|
||||||
void state_randomize(SharedContext *context, StateConfig state_config,
|
void state_randomize(SharedContext *context, StateConfig state_config);
|
||||||
unsigned int state_count);
|
|
||||||
|
|
||||||
#endif /* STATE_H */
|
#endif /* STATE_H */
|
||||||
+10
-5
@@ -14,6 +14,11 @@
|
|||||||
#ifndef TYPES_H
|
#ifndef TYPES_H
|
||||||
#define TYPES_H
|
#define TYPES_H
|
||||||
|
|
||||||
|
typedef struct UintArray {
|
||||||
|
unsigned int values[ARRAY_SIZE];
|
||||||
|
unsigned int length;
|
||||||
|
} UintArray;
|
||||||
|
|
||||||
typedef struct Parameters {
|
typedef struct Parameters {
|
||||||
bool hot_reload;
|
bool hot_reload;
|
||||||
bool output;
|
bool output;
|
||||||
@@ -135,14 +140,14 @@ typedef struct SharedContext {
|
|||||||
} SharedContext;
|
} SharedContext;
|
||||||
|
|
||||||
typedef struct StateConfig {
|
typedef struct StateConfig {
|
||||||
unsigned int select_page_count;
|
unsigned int state_max;
|
||||||
unsigned int select_page_codes[ARRAY_SIZE];
|
|
||||||
|
|
||||||
unsigned int select_item_count;
|
UintArray select_page_codes;
|
||||||
unsigned int select_item_codes[ARRAY_SIZE];
|
UintArray select_item_codes;
|
||||||
|
|
||||||
unsigned int select_frag_codes[ARRAY_SIZE];
|
UintArray select_frag_codes;
|
||||||
|
|
||||||
|
// TODO Uint arrays
|
||||||
unsigned int src_count;
|
unsigned int src_count;
|
||||||
unsigned int src_active_counts[ARRAY_SIZE];
|
unsigned int src_active_counts[ARRAY_SIZE];
|
||||||
unsigned int src_active_offsets[ARRAY_SIZE];
|
unsigned int src_active_offsets[ARRAY_SIZE];
|
||||||
|
|||||||
Reference in New Issue
Block a user