feat: unify add/remove commands into queue and fix race on channel removal

Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
This commit is contained in:
Loic Coenen
2026-05-09 22:03:11 +00:00
parent a8a9c6164b
commit 437ac31913
4 changed files with 68 additions and 50 deletions

View File

@@ -8,10 +8,9 @@
#include <stdatomic.h>
extern atomic_int control_key_active;
extern atomic_int cmd_add;
extern atomic_int cmd_remove;
extern atomic_int bind_channel;
extern spsc_queue_t cmd_queue;
extern spsc_queue_t cmd_queue_main;
void midi_handle_events(void *port_buffer, jack_nframes_t nframes) {
(void)nframes;
@@ -42,11 +41,15 @@ void midi_handle_events(void *port_buffer, jack_nframes_t nframes) {
} else {
switch (note) {
case 60:
atomic_store(&cmd_add, 1);
break;
{
command_t cmd = { .type = CMD_ADD_CHANNEL, .channel = -1, .data = 0 };
queue_push(&cmd_queue_main, cmd);
} break;
case 61:
atomic_store(&cmd_remove, 1);
break;
{
command_t cmd = { .type = CMD_REMOVE_CHANNEL, .channel = -1, .data = 0 };
queue_push(&cmd_queue_main, cmd);
} break;
case 62:
{
int bch = atomic_load(&bind_channel);
@@ -73,11 +76,15 @@ void midi_handle_events(void *port_buffer, jack_nframes_t nframes) {
queue_push(&cmd_queue, cmd);
} break;
case 60:
atomic_store(&cmd_add, 1);
break;
{
command_t cmd = { .type = CMD_ADD_CHANNEL, .channel = -1, .data = 0 };
queue_push(&cmd_queue_main, cmd);
} break;
case 61:
atomic_store(&cmd_remove, 1);
break;
{
command_t cmd = { .type = CMD_REMOVE_CHANNEL, .channel = -1, .data = 0 };
queue_push(&cmd_queue_main, cmd);
} break;
default:
break;
}