wip state
This commit is contained in:
+6
-3
@@ -203,9 +203,8 @@ static void key_callback(Window *window, int key,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void midi_callback(unsigned char code, float value) {
|
static void midi_callback(unsigned char code, float value) {
|
||||||
log_debug("midi: %d %.2f", code, value);
|
state_apply_event(context, state_config, program.frag_count, midi, code,
|
||||||
midi_write(midi, code, value);
|
value);
|
||||||
// TODO treat in state file
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void loop(bool hr) {
|
static void loop(bool hr) {
|
||||||
@@ -268,6 +267,10 @@ void forge_run(Parameters params) {
|
|||||||
if (!midi_background_listen(midi, context, midi_callback)) {
|
if (!midi_background_listen(midi, context, midi_callback)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!state_background_midi_write(context, state_config, midi)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window_startup(error_callback);
|
window_startup(error_callback);
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
#include <log.h>
|
#include <log.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "config_file.h"
|
#include "config_file.h"
|
||||||
|
|||||||
+36
-1
@@ -1,7 +1,10 @@
|
|||||||
#include "state.h"
|
#include <log.h>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "config_file.h"
|
#include "config_file.h"
|
||||||
|
#include "midi.h"
|
||||||
#include "rand.h"
|
#include "rand.h"
|
||||||
|
#include "state.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
StateConfig state_parse_config(ConfigFile config) {
|
StateConfig state_parse_config(ConfigFile config) {
|
||||||
@@ -92,6 +95,38 @@ StateConfig state_parse_config(ConfigFile config) {
|
|||||||
return state_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,
|
void state_randomize(SharedContext *context, StateConfig state_config,
|
||||||
unsigned int state_count) {
|
unsigned int state_count) {
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|||||||
@@ -5,6 +5,13 @@
|
|||||||
|
|
||||||
StateConfig state_parse_config(ConfigFile config);
|
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,
|
void state_randomize(SharedContext *context, StateConfig state_config,
|
||||||
unsigned int state_count);
|
unsigned int state_count);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user