fix: prevent command queue overflow by directly manipulating state in undo/redo

Co-authored-by: aider (deepseek/deepseek-coder) <aider@aider.chat>
This commit is contained in:
Loic Coenen
2026-05-01 20:20:14 +00:00
parent 5dc533e3a2
commit de4f6ef581

View File

@@ -551,6 +551,9 @@ void engine_undo(Engine *engine) {
for (int ch = 0; ch < MAX_CHANNELS; ch++) {
int clip_idx = CLIP_INDEX(scene_idx, ch);
engine->clips[clip_idx].state = CLIP_EMPTY;
engine->clips[clip_idx].buffer_size = 0;
engine->clips[clip_idx].write_position = 0;
engine->clips[clip_idx].read_position = 0;
}
break;
}
@@ -607,23 +610,70 @@ void engine_redo(Engine *engine) {
switch (action->type) {
case ACTION_TRIGGER_CLIP: {
int clip_idx = action->index;
// Re-apply the trigger
engine_trigger_clip(engine, clip_idx);
engine_process_commands(engine);
// Re-apply the trigger by directly manipulating state
Clip *clip = &engine->clips[clip_idx];
switch (clip->state) {
case CLIP_EMPTY:
clip->state = CLIP_RECORDING;
clip->write_position = 0;
clip->buffer_size = 0;
clip->read_position = 0;
break;
case CLIP_RECORDING:
clip->state = CLIP_LOOPING;
clip->buffer_size = clip->write_position;
clip->read_position = 0;
break;
case CLIP_LOOPING:
clip->state = CLIP_STOPPED;
clip->read_position = 0;
break;
case CLIP_STOPPED:
clip->state = CLIP_LOOPING;
clip->read_position = 0;
break;
}
break;
}
case ACTION_TRIGGER_SCENE: {
int scene_idx = action->index;
engine_trigger_scene(engine, scene_idx);
engine_process_commands(engine);
for (int ch = 0; ch < MAX_CHANNELS; ch++) {
int clip_idx = CLIP_INDEX(scene_idx, ch);
Clip *clip = &engine->clips[clip_idx];
switch (clip->state) {
case CLIP_EMPTY:
clip->state = CLIP_RECORDING;
clip->write_position = 0;
clip->buffer_size = 0;
clip->read_position = 0;
break;
case CLIP_RECORDING:
clip->state = CLIP_LOOPING;
clip->buffer_size = clip->write_position;
clip->read_position = 0;
break;
case CLIP_LOOPING:
clip->state = CLIP_STOPPED;
clip->read_position = 0;
break;
case CLIP_STOPPED:
clip->state = CLIP_LOOPING;
clip->read_position = 0;
break;
}
}
break;
}
case ACTION_RESET_CLIP: {
int clip_idx = action->index;
engine_reset_clip(engine, clip_idx);
engine_process_commands(engine);
Clip *clip = &engine->clips[clip_idx];
clip->state = CLIP_EMPTY;
clip->buffer_size = 0;
clip->write_position = 0;
clip->read_position = 0;
memset(clip->buffer, 0, MAX_BUFFER_SIZE * sizeof(float));
break;
}