feat: video auto reconnect
Clang Lint CI / lint-no-video (push) Successful in 56s
Clang Build CI / run-no-video (push) Successful in 59s
Clang Build CI / run-video (push) Successful in 1m15s
Clang Build CI / build-release (push) Successful in 2m23s
Clang Lint CI / lint-video (push) Successful in 2m14s
Clang Lint CI / lint-no-video (push) Successful in 56s
Clang Build CI / run-no-video (push) Successful in 59s
Clang Build CI / run-video (push) Successful in 1m15s
Clang Build CI / build-release (push) Successful in 2m23s
Clang Lint CI / lint-video (push) Successful in 2m14s
This commit is contained in:
+33
-41
@@ -1,6 +1,6 @@
|
||||
#include <log.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
@@ -20,8 +20,7 @@ static void safe_midi_write(const MidiDevice *midi, unsigned int code,
|
||||
}
|
||||
}
|
||||
|
||||
static void update_page(const SharedContext *context,
|
||||
const StateConfig *state_config,
|
||||
static void update_page(const Context *context, const StateConfig *state_config,
|
||||
const MidiDevice *midi) {
|
||||
unsigned int page_item_min;
|
||||
unsigned int page_item_max;
|
||||
@@ -51,7 +50,7 @@ static void update_page(const SharedContext *context,
|
||||
}
|
||||
}
|
||||
|
||||
static void update_active(const SharedContext *context,
|
||||
static void update_active(const Context *context,
|
||||
const StateConfig *state_config,
|
||||
const MidiDevice *midi) {
|
||||
unsigned int k;
|
||||
@@ -66,7 +65,7 @@ static void update_active(const SharedContext *context,
|
||||
}
|
||||
}
|
||||
|
||||
static void update_values(const SharedContext *context,
|
||||
static void update_values(const Context *context,
|
||||
const StateConfig *state_config,
|
||||
const MidiDevice *midi) {
|
||||
unsigned int j;
|
||||
@@ -83,12 +82,12 @@ static void update_values(const SharedContext *context,
|
||||
}
|
||||
}
|
||||
|
||||
static void reset(SharedContext *context) {
|
||||
static void reset(Context *context) {
|
||||
memset(context->values, 0, sizeof(context->values));
|
||||
memset(context->state.values, 0, sizeof(context->state.values));
|
||||
}
|
||||
|
||||
static void randomize(SharedContext *context, const StateConfig *state_config) {
|
||||
static void randomize(Context *context, const StateConfig *state_config) {
|
||||
unsigned int j;
|
||||
unsigned int l;
|
||||
unsigned int part;
|
||||
@@ -116,8 +115,7 @@ static void randomize(SharedContext *context, const StateConfig *state_config) {
|
||||
}
|
||||
}
|
||||
|
||||
static void load_from_file(SharedContext *context,
|
||||
const StateConfig *state_config,
|
||||
static void load_from_file(Context *context, const StateConfig *state_config,
|
||||
const char *state_file) {
|
||||
ConfigFile saved_state;
|
||||
char key[STR_LEN];
|
||||
@@ -161,7 +159,7 @@ static void load_from_file(SharedContext *context,
|
||||
config_file_free(&saved_state);
|
||||
}
|
||||
|
||||
static void load_from_default_file(SharedContext *context,
|
||||
static void load_from_default_file(Context *context,
|
||||
const StateConfig *state_config) {
|
||||
char state_file[STR_LEN];
|
||||
|
||||
@@ -170,7 +168,7 @@ static void load_from_default_file(SharedContext *context,
|
||||
load_from_file(context, state_config, state_file);
|
||||
}
|
||||
|
||||
static void load_from_index_file(SharedContext *context,
|
||||
static void load_from_index_file(Context *context,
|
||||
const StateConfig *state_config,
|
||||
unsigned int index) {
|
||||
char state_file[STR_LEN];
|
||||
@@ -181,7 +179,7 @@ static void load_from_index_file(SharedContext *context,
|
||||
load_from_file(context, state_config, state_file);
|
||||
}
|
||||
|
||||
static void save_to_file(const SharedContext *context,
|
||||
static void save_to_file(const Context *context,
|
||||
const StateConfig *state_config,
|
||||
const char *state_file) {
|
||||
StringArray lines;
|
||||
@@ -220,7 +218,7 @@ static void save_to_file(const SharedContext *context,
|
||||
file_write(state_file, &lines);
|
||||
}
|
||||
|
||||
static void save_to_default_file(const SharedContext *context,
|
||||
static void save_to_default_file(const Context *context,
|
||||
const StateConfig *state_config) {
|
||||
char state_file[STR_LEN];
|
||||
|
||||
@@ -229,7 +227,7 @@ static void save_to_default_file(const SharedContext *context,
|
||||
save_to_file(context, state_config, state_file);
|
||||
}
|
||||
|
||||
static void save_to_index_file(const SharedContext *context,
|
||||
static void save_to_index_file(const Context *context,
|
||||
const StateConfig *state_config,
|
||||
unsigned int index) {
|
||||
char state_file[STR_LEN];
|
||||
@@ -414,7 +412,7 @@ void state_parse_config(StateConfig *state_config, const ConfigFile *config) {
|
||||
}
|
||||
}
|
||||
|
||||
void state_midi_event(SharedContext *context, const StateConfig *state_config,
|
||||
void state_midi_event(Context *context, const StateConfig *state_config,
|
||||
const MidiDevice *midi, unsigned char code,
|
||||
unsigned char value, bool trace_midi) {
|
||||
unsigned int i;
|
||||
@@ -508,7 +506,7 @@ void state_midi_event(SharedContext *context, const StateConfig *state_config,
|
||||
}
|
||||
}
|
||||
|
||||
void state_key_event(SharedContext *context, const StateConfig *state_config,
|
||||
void state_key_event(Context *context, const StateConfig *state_config,
|
||||
unsigned int code, const MidiDevice *midi) {
|
||||
unsigned int index;
|
||||
|
||||
@@ -565,29 +563,23 @@ void state_key_event(SharedContext *context, const StateConfig *state_config,
|
||||
}
|
||||
}
|
||||
|
||||
bool state_background_write(SharedContext *context,
|
||||
const StateConfig *state_config,
|
||||
const MidiDevice *midi) {
|
||||
pid_t pid;
|
||||
void *state_background_write(void *args) {
|
||||
StateBackgroundWriteArgs *process_args = (StateBackgroundWriteArgs *)args;
|
||||
Context *context = process_args->context;
|
||||
StateConfig state_config = process_args->state_config;
|
||||
MidiDevice *midi = process_args->midi;
|
||||
|
||||
bool beat_active;
|
||||
bool last_active;
|
||||
bool change;
|
||||
bool last_change;
|
||||
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
log_error("Could not create subprocess");
|
||||
return false;
|
||||
}
|
||||
if (pid == 0) {
|
||||
return true;
|
||||
}
|
||||
log_info("(state) background writing started (pid: %d)", pid);
|
||||
log_info("(state) background writing started");
|
||||
|
||||
if (!midi->error) {
|
||||
update_page(context, state_config, midi);
|
||||
update_active(context, state_config, midi);
|
||||
update_values(context, state_config, midi);
|
||||
update_page(context, &state_config, midi);
|
||||
update_active(context, &state_config, midi);
|
||||
update_values(context, &state_config, midi);
|
||||
}
|
||||
|
||||
last_active = false;
|
||||
@@ -597,11 +589,11 @@ bool state_background_write(SharedContext *context,
|
||||
beat_active = tempo_progress(&context->tempo, 1.0) < 0.5;
|
||||
|
||||
if (!midi->error && beat_active != last_active) {
|
||||
safe_midi_write(midi, state_config->tap_tempo_code,
|
||||
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],
|
||||
state_config.select_frag_codes.values[context->selected],
|
||||
beat_active ? MIDI_MAX : 0);
|
||||
}
|
||||
|
||||
@@ -611,20 +603,20 @@ bool state_background_write(SharedContext *context,
|
||||
(double)context->auto_random_cycle) < 0.5;
|
||||
|
||||
if (context->auto_random && change && !last_change) {
|
||||
randomize(context, state_config);
|
||||
randomize(context, &state_config);
|
||||
|
||||
update_values(context, state_config, midi);
|
||||
update_values(context, &state_config, midi);
|
||||
}
|
||||
|
||||
last_change = change;
|
||||
}
|
||||
|
||||
log_info("(state) background writing stopped by main thread (pid: %d)", pid);
|
||||
exit(EXIT_SUCCESS);
|
||||
log_info("(state) background writing stopped by main thread");
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
void state_init(SharedContext *context, const StateConfig *state_config,
|
||||
bool demo, bool auto_random, unsigned int auto_random_cycles,
|
||||
void state_init(Context *context, const StateConfig *state_config, bool demo,
|
||||
bool auto_random, unsigned int auto_random_cycles,
|
||||
unsigned int base_tempo, bool load_state) {
|
||||
tempo_init(&context->tempo, base_tempo);
|
||||
context->demo = demo;
|
||||
@@ -655,6 +647,6 @@ void state_init(SharedContext *context, const StateConfig *state_config,
|
||||
}
|
||||
}
|
||||
|
||||
void state_save(const SharedContext *context, const StateConfig *state_config) {
|
||||
void state_save(const Context *context, const StateConfig *state_config) {
|
||||
save_to_default_file(context, state_config);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user