feat(trace): trace fps and midi with args

This commit is contained in:
2025-11-03 21:46:14 +01:00
parent 0039bbace2
commit 2657c2b732
8 changed files with 41 additions and 20 deletions
+2
View File
@@ -78,6 +78,8 @@ options:
-t, --tempo base tempo (default: 60)
--demo demonstration mode (assume --no-save-state and --no-load-state)
-w, --windowed not fullscreen
--trace-midi print midi code and values
--trace-fps print fps status of subsystems
```
## Release guide
+10 -2
View File
@@ -58,7 +58,9 @@ static void print_help(int status_code) {
" -t, --tempo base tempo (default: 60)\n"
" --demo demonstration mode (assume --no-save-state "
"and --no-load-state)\n"
" -w, --windowed not fullscreen\n");
" -w, --windowed not fullscreen\n"
" --trace-midi print midi code and values\n"
" --trace-fps print fps status of subsystems\n");
exit(status_code);
}
@@ -107,13 +109,15 @@ Parameters args_parse(int argc, char **argv) {
strncpy(params.config_path, DATADIR "/default.cfg", STR_LEN);
strncpy(params.state_file, "forge_saved_state.txt", STR_LEN);
params.load_state = true;
params.save_state = false;
params.save_state = true;
params.internal_size = 720;
params.video_size = 0;
params.base_tempo = 60.0f;
params.demo = false;
params.windowed = false;
params.video_in.length = 0;
params.trace_midi = false;
params.trace_fps = false;
for (i = 1; i < argc; i++) {
arg = argv[i];
@@ -171,6 +175,10 @@ Parameters args_parse(int argc, char **argv) {
params.save_state = false;
} else if (is_arg(arg, "-w") || is_arg(arg, "--windowed")) {
params.windowed = true;
} else if (is_arg(arg, "--trace-midi")) {
params.trace_midi = true;
} else if (is_arg(arg, "--trace-fps")) {
params.trace_fps = true;
} else {
invalid_arg(arg);
}
+14 -9
View File
@@ -31,15 +31,18 @@ static Timer timer;
static ConfigFile config;
static MidiDevice midi;
static StateConfig state_config;
static bool trace_midi;
static void compute_fps() {
static void compute_fps(bool trace_fps) {
double fps;
char title[100];
if (timer_inc(&timer)) {
fps = timer_reset(&timer);
log_trace("(main) %.2ffps", fps);
if (trace_fps) {
log_trace("(main) %.2ffps", fps);
}
if (window_output != NULL) {
sprintf(title, PACKAGE " " VERSION " - %.0ffps", fps);
@@ -148,12 +151,12 @@ static void init_inputs(StringArray video_in, unsigned int video_size) {
}
}
static bool start_video_captures(unsigned int video_count) {
static bool start_video_captures(unsigned int video_count, bool trace_fps) {
unsigned int i;
for (i = 0; i < video_count; i++) {
if (!inputs.values[i].error &&
!video_background_read(&inputs.values[i], context, i)) {
!video_background_read(&inputs.values[i], context, i, trace_fps)) {
return false;
}
}
@@ -197,15 +200,15 @@ static void key_callback(Window *window, int key,
}
static void midi_callback(unsigned char code, unsigned char value) {
state_apply_event(context, state_config, midi, code, value);
state_apply_event(context, state_config, midi, code, value, trace_midi);
}
static void loop(bool hr) {
static void loop(bool hr, bool trace_fps) {
if (hr) {
hot_reload();
}
compute_fps();
compute_fps(trace_fps);
context->time = window_get_time();
@@ -248,7 +251,7 @@ void forge_run(Parameters params) {
init_context(params, in_count);
if (!start_video_captures(params.video_in.length)) {
if (!start_video_captures(params.video_in.length, params.trace_fps)) {
return;
}
@@ -257,6 +260,8 @@ void forge_run(Parameters params) {
if (midi.error) {
params.demo = true;
} else {
trace_midi = params.trace_midi;
if (!midi_background_listen(midi, context, midi_callback)) {
return;
}
@@ -308,7 +313,7 @@ void forge_run(Parameters params) {
while ((window_output == NULL || !window_should_close(window_output)) &&
(window_monitor == NULL || !window_should_close(window_monitor))) {
loop(params.hot_reload);
loop(params.hot_reload, params.trace_fps);
}
context->stop = true;
+6 -4
View File
@@ -182,8 +182,8 @@ static void update_values(SharedContext *context, StateConfig state_config,
}
void state_apply_event(SharedContext *context, StateConfig state_config,
MidiDevice midi, unsigned char code,
unsigned char value) {
MidiDevice midi, unsigned char code, unsigned char value,
bool trace_midi) {
unsigned int i, j, k, part;
bool found;
@@ -263,9 +263,11 @@ void state_apply_event(SharedContext *context, StateConfig state_config,
}
if (!found) {
log_trace("unknown midi: %d %d", code, value);
if (trace_midi) {
log_trace("unknown midi: %d %d", code, value);
}
midi_write(midi, code, value);
} else {
} else if (trace_midi) {
log_trace("midi: %d %d", code, value);
}
}
+2 -2
View File
@@ -6,8 +6,8 @@
StateConfig state_parse_config(ConfigFile config);
void state_apply_event(SharedContext *context, StateConfig state_config,
MidiDevice midi, unsigned char code,
unsigned char value);
MidiDevice midi, unsigned char code, unsigned char value,
bool trace_midi);
bool state_background_midi_write(SharedContext *context,
StateConfig state_config, MidiDevice midi);
+2
View File
@@ -46,6 +46,8 @@ typedef struct Parameters {
bool demo;
bool windowed;
StringArray video_in;
bool trace_midi;
bool trace_fps;
} Parameters;
typedef struct Vertex {
+4 -2
View File
@@ -329,7 +329,7 @@ static bool read_video(VideoCapture *video_capture) {
}
bool video_background_read(VideoCapture *video_capture, SharedContext *context,
int input_index) {
int input_index, bool trace_fps) {
pid_t pid;
Timer timer;
double fps;
@@ -352,7 +352,9 @@ bool video_background_read(VideoCapture *video_capture, SharedContext *context,
fps = timer_reset(&timer);
context->input_fps[input_index] = (unsigned int)round(fps);
log_trace("(%s) %.2ffps", video_capture->name, fps);
if (trace_fps) {
log_trace("(%s) %.2ffps", video_capture->name, fps);
}
}
}
if (context->stop) {
+1 -1
View File
@@ -6,7 +6,7 @@
VideoCapture video_init(char *name, unsigned int preferred_height);
bool video_background_read(VideoCapture *video_capture, SharedContext *context,
int input_index);
int input_index, bool trace_fps);
void video_free(VideoCapture video_capture);