refactor: improve TUI polling, FIFO reliability, and add stress tests
This commit is contained in:
committed by
Loic Coenen (aider)
parent
7c289e1496
commit
d6bd31fed5
@@ -96,23 +96,30 @@ static void exec_command(command_t cmd, jack_client_t *client) {
|
||||
|
||||
// Save the desired scene (may have been set by CMD_SET_SCENE)
|
||||
int requested_scene = atomic_load(&channels[ch].current_scene);
|
||||
// Clamp requested_scene to valid range
|
||||
if (requested_scene < 0) requested_scene = 0;
|
||||
if (requested_scene >= MAX_SCENES) requested_scene = MAX_SCENES - 1;
|
||||
|
||||
// Auto-create channel if it doesn't exist
|
||||
if (!channels[ch].active) {
|
||||
channel_add(client, ch);
|
||||
// Add scenes up to the requested scene
|
||||
int sc_count = atomic_load(&channels[ch].scene_count);
|
||||
while (sc_count <= requested_scene) {
|
||||
channel_add_scene(client, ch);
|
||||
sc_count = atomic_load(&channels[ch].scene_count);
|
||||
}
|
||||
// Restore the requested scene (channel_add resets to 0)
|
||||
atomic_store(&channels[ch].current_scene, requested_scene);
|
||||
// Give JACK time to register ports
|
||||
struct timespec req = {.tv_sec = 0, .tv_nsec = 200000000};
|
||||
nanosleep(&req, NULL);
|
||||
}
|
||||
|
||||
// Ensure enough scenes exist to satisfy requested_scene
|
||||
int sc_count = atomic_load(&channels[ch].scene_count);
|
||||
while (requested_scene >= sc_count && sc_count < MAX_SCENES) {
|
||||
channel_add_scene(client, ch);
|
||||
sc_count = atomic_load(&channels[ch].scene_count);
|
||||
}
|
||||
// Clamp requested_scene if MAX_SCENES prevents adding enough scenes
|
||||
if (requested_scene >= sc_count) requested_scene = sc_count - 1;
|
||||
// Restore the requested scene (channel_add or add_scene may have reset current_scene)
|
||||
atomic_store(&channels[ch].current_scene, requested_scene);
|
||||
|
||||
// Give JACK time to register ports if we created something
|
||||
struct timespec req = {.tv_sec = 0, .tv_nsec = 200000000};
|
||||
nanosleep(&req, NULL);
|
||||
|
||||
int sc_idx = atomic_load(&channels[ch].current_scene);
|
||||
scene_t *sc_ptr = &channels[ch].scenes[sc_idx];
|
||||
int state = atomic_load(&sc_ptr->state);
|
||||
@@ -197,8 +204,8 @@ static void exec_command(command_t cmd, jack_client_t *client) {
|
||||
|
||||
case CMD_SET_SCENE: {
|
||||
int sc = cmd.data;
|
||||
// Allow setting the scene even if channel is not yet active
|
||||
if (sc >= 0 && sc < MAX_SCENES) {
|
||||
// Allow any scene index; scenes will be added by CMD_CYCLE if needed
|
||||
if (sc >= 0) {
|
||||
atomic_store(&channels[ch].current_scene, sc);
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user