This commit is contained in:
2025-09-28 16:47:36 +02:00
parent 32eb037710
commit fb071f95b4
6 changed files with 51 additions and 8 deletions
+4 -1
View File
@@ -37,4 +37,7 @@ SUB_2_PREFIX=fx_
SUB_3_PREFIX=mix_ SUB_3_PREFIX=mix_
SUB_VARIANT_COUNT=16 SUB_VARIANT_COUNT=16
MIDI_HW=hw:CARD=nanoKONTROL2 MIDI_HW=hw:CARD=nanoKONTROL2
SELECT_PAGE_COUNT=3
SELECT_PAGE1=
+14 -2
View File
@@ -8,6 +8,7 @@
#include "config_file.h" #include "config_file.h"
#include "file.h" #include "file.h"
#include "forge.h" #include "forge.h"
#include "midi.h"
#include "rand.h" #include "rand.h"
#include "shaders.h" #include "shaders.h"
#include "shared.h" #include "shared.h"
@@ -25,6 +26,7 @@ static File *fragment_shaders;
static File common_shader_code; static File common_shader_code;
static Timer timer; static Timer timer;
static ConfigFile config; static ConfigFile config;
static MidiDevice midi;
static void compute_fps() { static void compute_fps() {
double fps; double fps;
@@ -251,6 +253,16 @@ void forge_run(Parameters params) {
init_inputs(params.video_in, params.video_in_count, params.video_size); init_inputs(params.video_in, params.video_in_count, params.video_size);
start_video_captures(params.video_in_count);
midi = midi_open(config_file_get_str(config, "MIDI_HW", "hw"));
if (midi.error) {
params.demo = true;
} else {
midi_background_listen(midi, context);
}
window_startup(error_callback); window_startup(error_callback);
context->internal_height = params.internal_size; context->internal_height = params.internal_size;
@@ -290,8 +302,6 @@ void forge_run(Parameters params) {
timer = timer_init(30); timer = timer_init(30);
start_video_captures(params.video_in_count);
log_info("Initialized"); log_info("Initialized");
while ((window_output == NULL || !window_should_close(window_output)) && while ((window_output == NULL || !window_should_close(window_output)) &&
@@ -319,6 +329,8 @@ void forge_run(Parameters params) {
free_video_captures(params.video_in_count); free_video_captures(params.video_in_count);
midi_close(midi);
free_context(); free_context();
free_files(frag_count); free_files(frag_count);
+28 -1
View File
@@ -16,10 +16,11 @@ void midi_close(MidiDevice device) {
MidiDevice midi_open(char *name) { MidiDevice midi_open(char *name) {
MidiDevice device; MidiDevice device;
device.name = name;
device.input = NULL; device.input = NULL;
device.output = NULL; device.output = NULL;
snd_rawmidi_open(&device.input, &device.output, name, 0); snd_rawmidi_open(&device.input, &device.output, name, SND_RAWMIDI_NONBLOCK);
device.error = device.input == NULL || device.output == NULL; device.error = device.input == NULL || device.output == NULL;
@@ -32,5 +33,31 @@ MidiDevice midi_open(char *name) {
return device; return device;
} }
void midi_background_listen(MidiDevice device, SharedContext *context) {
pid_t pid;
int bytes_read;
unsigned char buffer[3];
pid = fork();
if (pid < 0) {
log_error("Could not create subprocess");
return;
}
if (pid == 0) {
return;
}
log_info("(%s) background acquisition started (pid: %d)", device.name, pid);
while (!context->stop) {
bytes_read = snd_rawmidi_read(device.input, buffer, 3);
if (bytes_read == 3) {
log_debug("midi: %d %.2f", buffer[1], (float)buffer[2] / 256);
}
}
log_info("(%s) background acquisition stopped by main thread (pid: %d)",
device.name, pid);
}
// int bytes_read = snd_rawmidi_read(input, input_buffer, sizeof(input_buffer)); // int bytes_read = snd_rawmidi_read(input, input_buffer, sizeof(input_buffer));
// snd_rawmidi_write(output, buffer, 3); // snd_rawmidi_write(output, buffer, 3);
+1
View File
@@ -5,5 +5,6 @@
MidiDevice midi_open(char *name); MidiDevice midi_open(char *name);
void midi_close(MidiDevice device); void midi_close(MidiDevice device);
void midi_background_listen(MidiDevice device, SharedContext *context);
#endif /* MIDI_H */ #endif /* MIDI_H */
+1
View File
@@ -153,6 +153,7 @@ typedef struct ConfigFileItem {
typedef struct MidiDevice { typedef struct MidiDevice {
bool error; bool error;
char *name;
snd_rawmidi_t *input; snd_rawmidi_t *input;
snd_rawmidi_t *output; snd_rawmidi_t *output;
} MidiDevice; } MidiDevice;
+3 -4
View File
@@ -341,7 +341,7 @@ void video_background_read(VideoCapture *video_capture, SharedContext *context,
if (pid == 0) { if (pid == 0) {
return; return;
} }
log_info("%s background acquisition started (pid: %d)", video_capture->name, log_info("(%s) background acquisition started (pid: %d)", video_capture->name,
pid); pid);
timer = timer_init(30); timer = timer_init(30);
@@ -355,13 +355,12 @@ void video_background_read(VideoCapture *video_capture, SharedContext *context,
} }
} }
if (context->stop) { if (context->stop) {
log_info("%s background acquisition stopped by main thread (pid: %d)", log_info("(%s) background acquisition stopped by main thread (pid: %d)",
video_capture->name, pid); video_capture->name, pid);
} else { } else {
log_info("%s background acquisition stopped after error (pid: %d)", log_info("(%s) background acquisition stopped after error (pid: %d)",
video_capture->name, pid); video_capture->name, pid);
} }
window_terminate();
exit(context->stop ? EXIT_SUCCESS : EXIT_FAILURE); exit(context->stop ? EXIT_SUCCESS : EXIT_FAILURE);
} }