wip midi
This commit is contained in:
+28
-1
@@ -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);
|
||||
Reference in New Issue
Block a user