refactor: move static function on top of files
This commit is contained in:
+1
-1
@@ -121,7 +121,7 @@ make -f Makefile.dev release-arch
|
|||||||
- [x] `--auto-random-cycle=4`
|
- [x] `--auto-random-cycle=4`
|
||||||
- [x] Arrows (up-down: bpm / left-right: cycle)
|
- [x] Arrows (up-down: bpm / left-right: cycle)
|
||||||
- [x] Save states (numkey: load / shift + numkey: save)
|
- [x] Save states (numkey: load / shift + numkey: save)
|
||||||
- [ ] (clean) static functions at top of files
|
- [x] (clean) static functions at top of files
|
||||||
- [x] Configurable key codes
|
- [x] Configurable key codes
|
||||||
- [ ] Key codes as inputs
|
- [ ] Key codes as inputs
|
||||||
- [ ] Mouse position and scroll as inputs
|
- [ ] Mouse position and scroll as inputs
|
||||||
|
|||||||
+84
-84
@@ -391,90 +391,6 @@ static void init_programs(ShaderProgram *program, const ConfigFile *config,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void shaders_init(ShaderProgram *program, const Project *project,
|
|
||||||
const SharedContext *context, VideoCaptureArray *inputs,
|
|
||||||
bool rebind) {
|
|
||||||
if (!rebind) {
|
|
||||||
program->error = false;
|
|
||||||
program->last_resolution[0] = context->resolution[0];
|
|
||||||
program->last_resolution[1] = context->resolution[1];
|
|
||||||
program->tex_count = config_file_get_int(&project->config, "TEX_COUNT", 9);
|
|
||||||
program->frag_count = project->frag_count;
|
|
||||||
program->frag_output_index =
|
|
||||||
config_file_get_int(&project->config, "FRAG_OUTPUT", 1) - 1;
|
|
||||||
program->frag_monitor_index =
|
|
||||||
config_file_get_int(&project->config, "FRAG_MONITOR", 1) - 1;
|
|
||||||
program->sub_type_count =
|
|
||||||
config_file_get_int(&project->config, "SUB_TYPE_COUNT", 0);
|
|
||||||
program->in_count = config_file_get_int(&project->config, "IN_COUNT", 0);
|
|
||||||
program->sub_variant_count = project->state_config.state_max;
|
|
||||||
program->active_count = project->state_config.midi_active_counts.length;
|
|
||||||
program->midi_lengths.length = 0;
|
|
||||||
|
|
||||||
init_gl(program);
|
|
||||||
|
|
||||||
if (check_glerror(program)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
init_shaders(program, project);
|
|
||||||
|
|
||||||
if (program->error || check_glerror(program)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
init_textures(program, context);
|
|
||||||
|
|
||||||
if (check_glerror(program)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
init_input(program, &project->config, inputs);
|
|
||||||
|
|
||||||
if (check_glerror(program)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
init_framebuffers(program, &project->config);
|
|
||||||
|
|
||||||
if (check_glerror(program)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
init_programs(program, &project->config, &project->state_config);
|
|
||||||
|
|
||||||
if (check_glerror(program)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
init_vertices(program);
|
|
||||||
|
|
||||||
if (check_glerror(program)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bind_vertices(program, rebind ? 1 : 0);
|
|
||||||
|
|
||||||
if (check_glerror(program)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void shaders_update(ShaderProgram *program, const File *fragment_shader,
|
|
||||||
unsigned int i, const Project *project) {
|
|
||||||
bool result;
|
|
||||||
|
|
||||||
result = compile_shader(program->fragment_shaders[i], fragment_shader->path,
|
|
||||||
fragment_shader->content);
|
|
||||||
|
|
||||||
if (result) {
|
|
||||||
init_single_program(program, i, &project->config, &project->state_config);
|
|
||||||
|
|
||||||
log_info("Program %d updated", i + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void update_viewport(ShaderProgram *program,
|
static void update_viewport(ShaderProgram *program,
|
||||||
const SharedContext *context) {
|
const SharedContext *context) {
|
||||||
// viewport changed
|
// viewport changed
|
||||||
@@ -617,6 +533,90 @@ static void use_program(const ShaderProgram *program, int i, bool output,
|
|||||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void shaders_init(ShaderProgram *program, const Project *project,
|
||||||
|
const SharedContext *context, VideoCaptureArray *inputs,
|
||||||
|
bool rebind) {
|
||||||
|
if (!rebind) {
|
||||||
|
program->error = false;
|
||||||
|
program->last_resolution[0] = context->resolution[0];
|
||||||
|
program->last_resolution[1] = context->resolution[1];
|
||||||
|
program->tex_count = config_file_get_int(&project->config, "TEX_COUNT", 9);
|
||||||
|
program->frag_count = project->frag_count;
|
||||||
|
program->frag_output_index =
|
||||||
|
config_file_get_int(&project->config, "FRAG_OUTPUT", 1) - 1;
|
||||||
|
program->frag_monitor_index =
|
||||||
|
config_file_get_int(&project->config, "FRAG_MONITOR", 1) - 1;
|
||||||
|
program->sub_type_count =
|
||||||
|
config_file_get_int(&project->config, "SUB_TYPE_COUNT", 0);
|
||||||
|
program->in_count = config_file_get_int(&project->config, "IN_COUNT", 0);
|
||||||
|
program->sub_variant_count = project->state_config.state_max;
|
||||||
|
program->active_count = project->state_config.midi_active_counts.length;
|
||||||
|
program->midi_lengths.length = 0;
|
||||||
|
|
||||||
|
init_gl(program);
|
||||||
|
|
||||||
|
if (check_glerror(program)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
init_shaders(program, project);
|
||||||
|
|
||||||
|
if (program->error || check_glerror(program)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
init_textures(program, context);
|
||||||
|
|
||||||
|
if (check_glerror(program)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
init_input(program, &project->config, inputs);
|
||||||
|
|
||||||
|
if (check_glerror(program)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
init_framebuffers(program, &project->config);
|
||||||
|
|
||||||
|
if (check_glerror(program)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
init_programs(program, &project->config, &project->state_config);
|
||||||
|
|
||||||
|
if (check_glerror(program)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
init_vertices(program);
|
||||||
|
|
||||||
|
if (check_glerror(program)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bind_vertices(program, rebind ? 1 : 0);
|
||||||
|
|
||||||
|
if (check_glerror(program)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void shaders_update(ShaderProgram *program, const File *fragment_shader,
|
||||||
|
unsigned int i, const Project *project) {
|
||||||
|
bool result;
|
||||||
|
|
||||||
|
result = compile_shader(program->fragment_shaders[i], fragment_shader->path,
|
||||||
|
fragment_shader->content);
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
init_single_program(program, i, &project->config, &project->state_config);
|
||||||
|
|
||||||
|
log_info("Program %d updated", i + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void shaders_compute(ShaderProgram *program, const SharedContext *context,
|
void shaders_compute(ShaderProgram *program, const SharedContext *context,
|
||||||
bool monitor, bool output_only) {
|
bool monitor, bool output_only) {
|
||||||
if (!output_only) {
|
if (!output_only) {
|
||||||
|
|||||||
+2
-2
@@ -6,6 +6,8 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
|
||||||
|
static bool is_digit(char c) { return c >= '0' && c <= '9'; }
|
||||||
|
|
||||||
unsigned int string_trim(char *str) {
|
unsigned int string_trim(char *str) {
|
||||||
// https://www.delftstack.com/howto/c/trim-string-in-c/
|
// https://www.delftstack.com/howto/c/trim-string-in-c/
|
||||||
unsigned int start;
|
unsigned int start;
|
||||||
@@ -37,8 +39,6 @@ unsigned int string_trim(char *str) {
|
|||||||
return end - start + 1;
|
return end - start + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool is_digit(char c) { return c >= '0' && c <= '9'; }
|
|
||||||
|
|
||||||
bool string_is_number(const char *value) {
|
bool string_is_number(const char *value) {
|
||||||
unsigned long value_len;
|
unsigned long value_len;
|
||||||
|
|
||||||
|
|||||||
+11
-11
@@ -25,17 +25,6 @@ static void reset_tap_chain(Tempo *tempo, long t) {
|
|||||||
memset(tempo->tap_durations, 0, sizeof(tempo->tap_durations));
|
memset(tempo->tap_durations, 0, sizeof(tempo->tap_durations));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tempo_init(Tempo *tempo, float value) {
|
|
||||||
long t;
|
|
||||||
|
|
||||||
t = now();
|
|
||||||
|
|
||||||
reset_tap_chain(tempo, t);
|
|
||||||
|
|
||||||
tempo->tempo = value;
|
|
||||||
tempo->beat_length = 60000.0 / value;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool is_chain_active(const Tempo tempo, long t) {
|
static bool is_chain_active(const Tempo tempo, long t) {
|
||||||
return (tempo.last_tap + MAX_BEAT_LENGTH) > t &&
|
return (tempo.last_tap + MAX_BEAT_LENGTH) > t &&
|
||||||
(tempo.last_tap + (tempo.beat_length * BEATS_UNTIL_CHAIN_RESET)) > t;
|
(tempo.last_tap + (tempo.beat_length * BEATS_UNTIL_CHAIN_RESET)) > t;
|
||||||
@@ -101,6 +90,17 @@ static void add_tap_to_chain(Tempo *tempo, long t) {
|
|||||||
tempo->tempo = 60000.0 / tempo->beat_length;
|
tempo->tempo = 60000.0 / tempo->beat_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tempo_init(Tempo *tempo, float value) {
|
||||||
|
long t;
|
||||||
|
|
||||||
|
t = now();
|
||||||
|
|
||||||
|
reset_tap_chain(tempo, t);
|
||||||
|
|
||||||
|
tempo->tempo = value;
|
||||||
|
tempo->beat_length = 60000.0 / value;
|
||||||
|
}
|
||||||
|
|
||||||
void tempo_set(Tempo *tempo, float value) {
|
void tempo_set(Tempo *tempo, float value) {
|
||||||
long t;
|
long t;
|
||||||
long progress;
|
long progress;
|
||||||
|
|||||||
+18
-18
@@ -270,6 +270,24 @@ static void close_stream(const VideoCapture *video_capture) {
|
|||||||
ioctl(video_capture->fd, VIDIOC_STREAMOFF, &buf_type);
|
ioctl(video_capture->fd, VIDIOC_STREAMOFF, &buf_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool read_video(VideoCapture *video_capture) {
|
||||||
|
if (ioctl(video_capture->fd, VIDIOC_DQBUF, &video_capture->buf) == -1) {
|
||||||
|
ioctl_error(video_capture, "VIDIOC_DQBUF",
|
||||||
|
"buffer type not supported or no buffer allocated or the index "
|
||||||
|
"is out of bounds");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ioctl(video_capture->fd, VIDIOC_QBUF, &video_capture->buf) == -1) {
|
||||||
|
ioctl_error(video_capture, "VIDIOC_QBUF",
|
||||||
|
"buffer type not supported or no buffer allocated or the index "
|
||||||
|
"is out of bounds");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void video_init(VideoCapture *video_capture, const char *name,
|
void video_init(VideoCapture *video_capture, const char *name,
|
||||||
unsigned int preferred_height) {
|
unsigned int preferred_height) {
|
||||||
open_device(video_capture, name);
|
open_device(video_capture, name);
|
||||||
@@ -305,24 +323,6 @@ void video_init(VideoCapture *video_capture, const char *name,
|
|||||||
create_image_buffer(video_capture);
|
create_image_buffer(video_capture);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool read_video(VideoCapture *video_capture) {
|
|
||||||
if (ioctl(video_capture->fd, VIDIOC_DQBUF, &video_capture->buf) == -1) {
|
|
||||||
ioctl_error(video_capture, "VIDIOC_DQBUF",
|
|
||||||
"buffer type not supported or no buffer allocated or the index "
|
|
||||||
"is out of bounds");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ioctl(video_capture->fd, VIDIOC_QBUF, &video_capture->buf) == -1) {
|
|
||||||
ioctl_error(video_capture, "VIDIOC_QBUF",
|
|
||||||
"buffer type not supported or no buffer allocated or the index "
|
|
||||||
"is out of bounds");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool video_background_read(VideoCapture *video_capture, SharedContext *context,
|
bool video_background_read(VideoCapture *video_capture, SharedContext *context,
|
||||||
int input_index, bool trace_fps) {
|
int input_index, bool trace_fps) {
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|||||||
Reference in New Issue
Block a user