refactor: use struct pointers everywhere and bump max sizes
This commit is contained in:
+5
-5
@@ -18,7 +18,7 @@
|
||||
/* STRINGS */
|
||||
|
||||
#ifndef STR_LEN
|
||||
#define STR_LEN 1024
|
||||
#define STR_LEN 2048
|
||||
#endif
|
||||
|
||||
/* TYPES */
|
||||
@@ -32,7 +32,7 @@
|
||||
#endif
|
||||
|
||||
#ifndef MAX_SUB_FILE
|
||||
#define MAX_SUB_FILE 32
|
||||
#define MAX_SUB_FILE 63
|
||||
#endif
|
||||
|
||||
/* MIDI */
|
||||
@@ -48,7 +48,7 @@
|
||||
/* ARRAY */
|
||||
|
||||
#ifndef ARRAY_SIZE
|
||||
#define ARRAY_SIZE 512
|
||||
#define ARRAY_SIZE 1024
|
||||
#endif
|
||||
|
||||
#ifndef ARRAY_NOT_FOUND
|
||||
@@ -63,8 +63,8 @@
|
||||
#endif
|
||||
|
||||
#ifndef MIN_BEAT_LENGTH
|
||||
// 240.0 bpm
|
||||
#define MIN_BEAT_LENGTH 250
|
||||
// 480.0 bpm
|
||||
#define MIN_BEAT_LENGTH 125
|
||||
#endif
|
||||
|
||||
#ifndef BEATS_UNTIL_CHAIN_RESET
|
||||
|
||||
+3
-3
@@ -99,7 +99,7 @@ static bool start_video_captures(unsigned int video_count, bool trace_fps) {
|
||||
|
||||
for (i = 0; i < video_count; i++) {
|
||||
if (!inputs.values[i].error &&
|
||||
!video_background_read(inputs.values[i], context, i, trace_fps)) {
|
||||
!video_background_read(&inputs.values[i], context, i, trace_fps)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -207,12 +207,12 @@ void forge_run(Parameters *params) {
|
||||
} else {
|
||||
trace_midi = params->trace_midi;
|
||||
|
||||
if (!midi_background_listen(midi, context, midi_callback)) {
|
||||
if (!midi_background_listen(&midi, context, midi_callback)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!state_background_write(context, project.state_config, midi)) {
|
||||
if (!state_background_write(context, &project.state_config, &midi)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -28,7 +28,7 @@ void midi_write(MidiDevice *device, unsigned char code, unsigned char value) {
|
||||
snd_rawmidi_write(device->output, buffer, 3);
|
||||
}
|
||||
|
||||
bool midi_background_listen(MidiDevice device, SharedContext *context,
|
||||
bool midi_background_listen(MidiDevice *device, SharedContext *context,
|
||||
void (*event_callback)(unsigned char code,
|
||||
unsigned char value)) {
|
||||
pid_t pid;
|
||||
@@ -43,16 +43,16 @@ bool midi_background_listen(MidiDevice device, SharedContext *context,
|
||||
if (pid == 0) {
|
||||
return true;
|
||||
}
|
||||
log_info("(%s) background acquisition started (pid: %d)", device.name, pid);
|
||||
log_info("(%s) background acquisition started (pid: %d)", device->name, pid);
|
||||
|
||||
while (!context->stop) {
|
||||
bytes_read = snd_rawmidi_read(device.input, buffer, 3);
|
||||
bytes_read = snd_rawmidi_read(device->input, buffer, 3);
|
||||
if (bytes_read == 3) {
|
||||
event_callback(buffer[1], buffer[2]);
|
||||
}
|
||||
}
|
||||
|
||||
log_info("(%s) background acquisition stopped by main thread (pid: %d)",
|
||||
device.name, pid);
|
||||
device->name, pid);
|
||||
return false;
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
|
||||
void midi_open(MidiDevice *device, char *name);
|
||||
void midi_write(MidiDevice *device, unsigned char code, unsigned char value);
|
||||
bool midi_background_listen(MidiDevice device, SharedContext *context,
|
||||
bool midi_background_listen(MidiDevice *device, SharedContext *context,
|
||||
void (*event_callback)(unsigned char code,
|
||||
unsigned char value));
|
||||
|
||||
|
||||
+11
-11
@@ -270,8 +270,8 @@ void state_apply_event(SharedContext *context, StateConfig *state_config,
|
||||
}
|
||||
}
|
||||
|
||||
bool state_background_write(SharedContext *context, StateConfig state_config,
|
||||
MidiDevice midi) {
|
||||
bool state_background_write(SharedContext *context, StateConfig *state_config,
|
||||
MidiDevice *midi) {
|
||||
pid_t pid;
|
||||
bool beat_active, last_active, change, last_change;
|
||||
|
||||
@@ -285,10 +285,10 @@ bool state_background_write(SharedContext *context, StateConfig state_config,
|
||||
}
|
||||
log_info("(state) background writing started (pid: %d)", pid);
|
||||
|
||||
if (!midi.error) {
|
||||
update_page(context, &state_config, &midi);
|
||||
update_active(context, &state_config, &midi);
|
||||
update_values(context, &state_config, &midi);
|
||||
if (!midi->error) {
|
||||
update_page(context, state_config, midi);
|
||||
update_active(context, state_config, midi);
|
||||
update_values(context, state_config, midi);
|
||||
}
|
||||
|
||||
last_active = false;
|
||||
@@ -297,12 +297,12 @@ bool state_background_write(SharedContext *context, StateConfig state_config,
|
||||
while (!context->stop) {
|
||||
beat_active = tempo_progress(&context->tempo, 1.0) < 0.25;
|
||||
|
||||
if (!midi.error && beat_active != last_active) {
|
||||
safe_midi_write(&midi, state_config.tap_tempo_code,
|
||||
if (!midi->error && beat_active != last_active) {
|
||||
safe_midi_write(midi, state_config->tap_tempo_code,
|
||||
beat_active ? MIDI_MAX : 0);
|
||||
|
||||
safe_midi_write(&midi,
|
||||
state_config.select_frag_codes.values[context->selected],
|
||||
safe_midi_write(midi,
|
||||
state_config->select_frag_codes.values[context->selected],
|
||||
beat_active ? MIDI_MAX : 0);
|
||||
}
|
||||
|
||||
@@ -311,7 +311,7 @@ bool state_background_write(SharedContext *context, StateConfig state_config,
|
||||
change = tempo_progress(&context->tempo, 4.0) < 0.25;
|
||||
|
||||
if (context->auto_random && change && !last_change) {
|
||||
state_randomize(context, &state_config);
|
||||
state_randomize(context, state_config);
|
||||
}
|
||||
|
||||
last_change = change;
|
||||
|
||||
+2
-2
@@ -9,8 +9,8 @@ void state_apply_event(SharedContext *context, StateConfig *state_config,
|
||||
MidiDevice *midi, unsigned char code,
|
||||
unsigned char value, bool trace_midi);
|
||||
|
||||
bool state_background_write(SharedContext *context, StateConfig state_config,
|
||||
MidiDevice midi);
|
||||
bool state_background_write(SharedContext *context, StateConfig *state_config,
|
||||
MidiDevice *midi);
|
||||
|
||||
void state_init(SharedContext *context, StateConfig *state_config, bool demo,
|
||||
bool auto_random, unsigned int base_tempo, char *state_file,
|
||||
|
||||
+6
-6
@@ -322,7 +322,7 @@ static bool read_video(VideoCapture *video_capture) {
|
||||
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) {
|
||||
pid_t pid;
|
||||
Timer timer;
|
||||
@@ -336,27 +336,27 @@ bool video_background_read(VideoCapture video_capture, SharedContext *context,
|
||||
if (pid == 0) {
|
||||
return true;
|
||||
}
|
||||
log_info("(%s) background acquisition started (pid: %d)", video_capture.name,
|
||||
log_info("(%s) background acquisition started (pid: %d)", video_capture->name,
|
||||
pid);
|
||||
timer_init(&timer, 30);
|
||||
|
||||
while (!context->stop && read_video(&video_capture)) {
|
||||
while (!context->stop && read_video(video_capture)) {
|
||||
// repeat infinitely
|
||||
if (timer_inc(&timer)) {
|
||||
fps = timer_reset(&timer);
|
||||
|
||||
context->input_fps[input_index] = (unsigned int)round(fps);
|
||||
if (trace_fps) {
|
||||
log_trace("(%s) %.2ffps", video_capture.name, fps);
|
||||
log_trace("(%s) %.2ffps", video_capture->name, fps);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (context->stop) {
|
||||
log_info("(%s) background acquisition stopped by main thread (pid: %d)",
|
||||
video_capture.name, pid);
|
||||
video_capture->name, pid);
|
||||
} else {
|
||||
log_info("(%s) background acquisition stopped after error (pid: %d)",
|
||||
video_capture.name, pid);
|
||||
video_capture->name, pid);
|
||||
}
|
||||
exit(context->stop ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
return false;
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
void video_init(VideoCapture *video_capture, char *name,
|
||||
unsigned int preferred_height);
|
||||
|
||||
bool video_background_read(VideoCapture video_capture, SharedContext *context,
|
||||
bool video_background_read(VideoCapture *video_capture, SharedContext *context,
|
||||
int input_index, bool trace_fps);
|
||||
|
||||
void video_free(VideoCapture *video_capture);
|
||||
|
||||
Reference in New Issue
Block a user