wip state

This commit is contained in:
2025-09-28 22:58:40 +02:00
parent 8762abe508
commit 4c2ce542e7
4 changed files with 49 additions and 5 deletions
+6 -3
View File
@@ -203,9 +203,8 @@ static void key_callback(Window *window, int key,
}
static void midi_callback(unsigned char code, float value) {
log_debug("midi: %d %.2f", code, value);
midi_write(midi, code, value);
// TODO treat in state file
state_apply_event(context, state_config, program.frag_count, midi, code,
value);
}
static void loop(bool hr) {
@@ -268,6 +267,10 @@ void forge_run(Parameters params) {
if (!midi_background_listen(midi, context, midi_callback)) {
return;
}
if (!state_background_midi_write(context, state_config, midi)) {
return;
}
}
window_startup(error_callback);
-1
View File
@@ -2,7 +2,6 @@
#include <log.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include "config.h"
#include "config_file.h"
+36 -1
View File
@@ -1,7 +1,10 @@
#include "state.h"
#include <log.h>
#include "config.h"
#include "config_file.h"
#include "midi.h"
#include "rand.h"
#include "state.h"
#include "types.h"
StateConfig state_parse_config(ConfigFile config) {
@@ -92,6 +95,38 @@ StateConfig state_parse_config(ConfigFile config) {
return state_config;
}
void state_apply_event(SharedContext *context, StateConfig state_config,
unsigned int state_count, MidiDevice midi,
unsigned char code, float value) {
log_debug("midi: %d %.2f", code, value);
midi_write(midi, code, value);
// TODO
}
bool state_background_midi_write(SharedContext *context,
StateConfig state_config, MidiDevice midi) {
pid_t pid;
int bytes_read;
unsigned char buffer[3];
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);
while (!context->stop) {
// TODO tap tempo and more
}
log_info("(state) background writing stopped by main thread (pid: %d)", pid);
return false;
}
void state_randomize(SharedContext *context, StateConfig state_config,
unsigned int state_count) {
unsigned int i;
+7
View File
@@ -5,6 +5,13 @@
StateConfig state_parse_config(ConfigFile config);
void state_apply_event(SharedContext *context, StateConfig state_config,
unsigned int state_count, MidiDevice midi,
unsigned char code, float value);
bool state_background_midi_write(SharedContext *context,
StateConfig state_config, MidiDevice midi);
void state_randomize(SharedContext *context, StateConfig state_config,
unsigned int state_count);