From bfc79cef2cb743fedba3e93fd005d25b0a4923dc Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Wed, 9 Oct 2024 17:59:41 +0200 Subject: Added mutex and proper audio playback --- midi.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'midi.c') diff --git a/midi.c b/midi.c index 3d21f79..f389826 100644 --- a/midi.c +++ b/midi.c @@ -5,6 +5,7 @@ #include #include "midi.h" +#include "mutex.h" static snd_seq_t *seq_handle; static snd_seq_addr_t *ports; @@ -81,8 +82,12 @@ void *midi(void *arg) { } if (ev) { + pthread_mutex_lock(&mutex); switch (ev->type) { case SND_SEQ_EVENT_NOTEON: + shared_data.note = ev->data.note.note; + shared_data.state = 1; + shared_data.velocity = ev->data.note.velocity; printf("%3d:%-3dNote on %2d, note %d, velocity: %3d\n", ev->source.client, ev->source.port, ev->data.note.channel, @@ -91,14 +96,23 @@ void *midi(void *arg) { break; case SND_SEQ_EVENT_NOTEOFF: + shared_data.note = ev->data.note.note; + shared_data.state = 0; + shared_data.velocity = 0; printf("%3d:%-3dNote off\t%2d, note %d\n", ev->source.client, ev->source.port, ev->data.note.channel, ev->data.note.note); break; + default: + break; + } + shared_data.action = 1; + shared_data.preset = 3; - } + pthread_cond_signal(&cond_synth); + pthread_mutex_unlock(&mutex); } } -- cgit v1.2.3