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:
64
engine.c
64
engine.c
@@ -551,6 +551,9 @@ void engine_undo(Engine *engine) {
|
|||||||
for (int ch = 0; ch < MAX_CHANNELS; ch++) {
|
for (int ch = 0; ch < MAX_CHANNELS; ch++) {
|
||||||
int clip_idx = CLIP_INDEX(scene_idx, ch);
|
int clip_idx = CLIP_INDEX(scene_idx, ch);
|
||||||
engine->clips[clip_idx].state = CLIP_EMPTY;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
@@ -607,23 +610,70 @@ void engine_redo(Engine *engine) {
|
|||||||
switch (action->type) {
|
switch (action->type) {
|
||||||
case ACTION_TRIGGER_CLIP: {
|
case ACTION_TRIGGER_CLIP: {
|
||||||
int clip_idx = action->index;
|
int clip_idx = action->index;
|
||||||
// Re-apply the trigger
|
// Re-apply the trigger by directly manipulating state
|
||||||
engine_trigger_clip(engine, clip_idx);
|
Clip *clip = &engine->clips[clip_idx];
|
||||||
engine_process_commands(engine);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case ACTION_TRIGGER_SCENE: {
|
case ACTION_TRIGGER_SCENE: {
|
||||||
int scene_idx = action->index;
|
int scene_idx = action->index;
|
||||||
engine_trigger_scene(engine, scene_idx);
|
for (int ch = 0; ch < MAX_CHANNELS; ch++) {
|
||||||
engine_process_commands(engine);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case ACTION_RESET_CLIP: {
|
case ACTION_RESET_CLIP: {
|
||||||
int clip_idx = action->index;
|
int clip_idx = action->index;
|
||||||
engine_reset_clip(engine, clip_idx);
|
Clip *clip = &engine->clips[clip_idx];
|
||||||
engine_process_commands(engine);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user