feat: implement undo/redo system with history tracking and tests

Co-authored-by: aider (deepseek/deepseek-coder) <aider@aider.chat>
This commit is contained in:
Loic Coenen
2026-05-01 20:10:45 +00:00
parent b64b0cd418
commit be3582bc13
4 changed files with 702 additions and 8 deletions

View File

@@ -56,9 +56,49 @@ typedef enum {
CMD_RESET_CLIP,
CMD_SET_QUANTIZE_MODE,
CMD_SET_QUANTIZE_THRESHOLD,
CMD_RESET_TRANSPORT
CMD_RESET_TRANSPORT,
CMD_UNDO,
CMD_REDO
} CommandType;
// Undo/Redo action types
typedef enum {
ACTION_TRIGGER_CLIP,
ACTION_TRIGGER_SCENE,
ACTION_RESET_CLIP,
ACTION_SET_QUANTIZE_MODE,
ACTION_SET_QUANTIZE_THRESHOLD,
ACTION_RESET_TRANSPORT
} ActionType;
// Undo/Redo action record
typedef struct {
ActionType type;
int index; // clip_index, scene_index, or mode value
jack_nframes_t value; // threshold value or other numeric param
ClipState previous_state; // For clip state changes
size_t previous_buffer_size;
size_t previous_write_position;
size_t previous_read_position;
bool previous_rolling;
uint32_t previous_clock_count;
uint32_t previous_beat_position;
uint32_t previous_bar_position;
uint32_t previous_sample_position;
QuantizeMode previous_quantize_mode;
jack_nframes_t previous_quantize_threshold;
} UndoAction;
// Undo/Redo history
#define MAX_UNDO_HISTORY 256
typedef struct {
UndoAction actions[MAX_UNDO_HISTORY];
int undo_index; // Points to next action to undo
int redo_index; // Points to next action to redo
int count; // Total actions in history
} UndoHistory;
typedef struct {
CommandType type;
int index; // clip_index, scene_index, or mode value
@@ -115,6 +155,9 @@ typedef struct {
atomic_uint quantize_threshold_atomic;
bool running;
// Undo/Redo
UndoHistory undo_history;
} Engine;
// Engine lifecycle
@@ -150,4 +193,11 @@ const char* clip_state_to_string(ClipState state);
uint8_t clip_state_to_velocity(ClipState state);
const char* quantize_mode_to_string(QuantizeMode mode);
// Undo/Redo
void engine_undo(Engine *engine);
void engine_redo(Engine *engine);
void engine_push_undo_action(Engine *engine, UndoAction *action);
void engine_undo_action(Engine *engine);
void engine_redo_action(Engine *engine);
#endif // ENGINE_H