midi write state

This commit is contained in:
2025-09-30 19:14:05 +02:00
parent 81ea1b54ff
commit e379df8665
6 changed files with 26 additions and 20 deletions
+4 -5
View File
@@ -1,7 +1,6 @@
#include <GLFW/glfw3.h>
#include <alsa/asoundlib.h>
#include "config.h"
#include "log.h"
#include "types.h"
@@ -21,19 +20,19 @@ MidiDevice midi_open(char *name) {
return device;
}
void midi_write(MidiDevice device, unsigned char code, float value) {
void midi_write(MidiDevice device, unsigned char code, unsigned char value) {
unsigned char buffer[3];
buffer[0] = 0xB0;
buffer[1] = code;
buffer[2] = (unsigned char)(128 * value);
buffer[2] = value;
snd_rawmidi_write(device.output, buffer, 3);
}
bool midi_background_listen(MidiDevice device, SharedContext *context,
void (*event_callback)(unsigned char code,
float value)) {
unsigned char value)) {
pid_t pid;
int bytes_read;
unsigned char buffer[3];
@@ -51,7 +50,7 @@ bool midi_background_listen(MidiDevice device, SharedContext *context,
while (!context->stop) {
bytes_read = snd_rawmidi_read(device.input, buffer, 3);
if (bytes_read == 3) {
event_callback(buffer[1], (float)buffer[2] / 256.0);
event_callback(buffer[1], buffer[2]);
}
}