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
+28 -1
View File
@@ -16,10 +16,11 @@ void midi_close(MidiDevice device) {
MidiDevice midi_open(char *name) {
MidiDevice device;
device.name = name;
device.input = 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;
@@ -32,5 +33,31 @@ MidiDevice midi_open(char *name) {
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));
// snd_rawmidi_write(output, buffer, 3);