Zrythm
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
undo_manager.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2019-2022 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
10#ifndef __UNDO_UNDO_MANAGER_H__
11#define __UNDO_UNDO_MANAGER_H__
12
13#include "actions/undo_stack.h"
14
15#include "zix/sem.h"
16
17typedef struct AudioClip AudioClip;
18
25#define UNDO_MANAGER_SCHEMA_VERSION 1
26
27#define UNDO_MANAGER (PROJECT->undo_manager)
28
32typedef struct UndoManager
33{
34 int schema_version;
35
36 UndoStack * undo_stack;
37 UndoStack * redo_stack;
38
46
48 ZixSem action_sem;
50
51static const cyaml_schema_field_t undo_manager_fields_schema[] = {
52 YAML_FIELD_INT (UndoManager, schema_version),
55 undo_stack,
56 undo_stack_fields_schema),
59 redo_stack,
60 undo_stack_fields_schema),
61
62 CYAML_FIELD_END
63};
64
65static const cyaml_schema_value_t undo_manager_schema = {
66 YAML_VALUE_PTR (UndoManager, undo_manager_fields_schema),
67};
68
73NONNULL void
75
80WARN_UNUSED_RESULT UndoManager *
82
87int undo_manager_undo (UndoManager * self, GError ** error);
88
93int undo_manager_redo (UndoManager * self, GError ** error);
94
101NONNULL_ARGS (1, 2)
103 UndoManager * self,
104 UndoableAction * action,
105 GError ** error);
106
111#define UNDO_MANAGER_PERFORM_AND_PROPAGATE_ERR( \
112 action, err, ...) \
113 { \
114 g_return_val_if_fail ( \
115 router_is_processing_thread (ROUTER) == false, false); \
116 UndoableAction * ua = action (__VA_ARGS__); \
117 if (ua) \
118 { \
119 int ret = \
120 undo_manager_perform (UNDO_MANAGER, ua, err); \
121 if (ret == 0) \
122 return true; \
123 } \
124 return false; \
125 }
126
131NONNULL bool
133 UndoManager * self,
134 AudioClip * clip);
135
141NONNULL void
142undo_manager_get_plugins (UndoManager * self, GPtrArray * arr);
143
148NONNULL UndoableAction *
150
154NONNULL void
156
157NONNULL UndoManager *
158undo_manager_clone (const UndoManager * src);
159
160NONNULL void
161undo_manager_free (UndoManager * self);
162
167#endif
NONNULL void undo_manager_get_plugins(UndoManager *self, GPtrArray *arr)
Returns all plugins in the undo stacks.
NONNULL bool undo_manager_contains_clip(UndoManager *self, AudioClip *clip)
Returns whether the given clip is used by any stack.
int undo_manager_redo(UndoManager *self, GError **error)
Redo last undone action.
int undo_manager_perform(UndoManager *self, UndoableAction *action, GError **error)
Performs the action and pushes it to the undo stack.
WARN_UNUSED_RESULT UndoManager * undo_manager_new(void)
Inits the undo manager by creating the undo/redo stacks.
NONNULL void undo_manager_clear_stacks(UndoManager *self, bool free)
Clears the undo and redo stacks.
NONNULL UndoableAction * undo_manager_get_last_action(UndoManager *self)
Returns the last performed action, or NULL if the stack is empty.
int undo_manager_undo(UndoManager *self, GError **error)
Undo last action.
NONNULL void undo_manager_init_loaded(UndoManager *self)
Inits the undo manager by populating the undo/redo stacks.
COLD NONNULL_ARGS(1) void automation_track_init_loaded(AutomationTrack *self
Inits a loaded AutomationTracklist.
#define YAML_FIELD_MAPPING_PTR(owner, member, schema)
Mapping pointer to a struct.
Definition yaml.h:39
#define YAML_VALUE_PTR(cc, fields_schema)
Schema to be used as a pointer.
Definition yaml.h:221
Audio clips for the pool.
Definition clip.h:33
Undo manager.
bool redo_stack_locked
Whether the redo stack is currently locked.
ZixSem action_sem
Semaphore for performing actions.
Serializable stack for undoable actions.
Definition undo_stack.h:42
Base struct to be inherited by implementing undoable actions.
Undo stack.