Zrythm
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
arranger_selections.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2019-2023 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
11#ifndef __GUI_BACKEND_ARRANGER_SELECTIONS_H__
12#define __GUI_BACKEND_ARRANGER_SELECTIONS_H__
13
14#include <stdbool.h>
15
16#include "utils/yaml.h"
17
18typedef struct ArrangerObject ArrangerObject;
19typedef struct Position Position;
20typedef struct AudioClip AudioClip;
21typedef struct UndoableAction UndoableAction;
24typedef struct ZRegion ZRegion;
25
32#define ARRANGER_SELECTIONS_SCHEMA_VERSION 1
33
34#define ARRANGER_SELECTIONS_MAGIC 35867752
35#define IS_ARRANGER_SELECTIONS(x) \
36 (((ArrangerSelections *) x)->magic \
37 == ARRANGER_SELECTIONS_MAGIC)
38#define IS_ARRANGER_SELECTIONS_AND_NONNULL(x) \
39 (x && IS_ARRANGER_SELECTIONS (x))
40#define ARRANGER_SELECTIONS(x) arranger_selections_cast (x)
41
42#define ARRANGER_SELECTIONS_DEFAULT_NUDGE_TICKS 0.1
43
44typedef enum ArrangerSelectionsType
45{
46 ARRANGER_SELECTIONS_TYPE_NONE,
47 ARRANGER_SELECTIONS_TYPE_CHORD,
48 ARRANGER_SELECTIONS_TYPE_TIMELINE,
49 ARRANGER_SELECTIONS_TYPE_MIDI,
50 ARRANGER_SELECTIONS_TYPE_AUTOMATION,
51 ARRANGER_SELECTIONS_TYPE_AUDIO,
52} ArrangerSelectionsType;
53
54static const cyaml_strval_t arranger_selections_type_strings[] = {
55 {"None", ARRANGER_SELECTIONS_TYPE_NONE },
56 { "Chord", ARRANGER_SELECTIONS_TYPE_CHORD },
57 { "Timeline", ARRANGER_SELECTIONS_TYPE_TIMELINE },
58 { "MIDI", ARRANGER_SELECTIONS_TYPE_MIDI },
59 { "Automation", ARRANGER_SELECTIONS_TYPE_AUTOMATION},
60 { "Audio", ARRANGER_SELECTIONS_TYPE_AUDIO },
61};
62
63typedef struct ArrangerSelections
64{
65 int schema_version;
66
68 ArrangerSelectionsType type;
69
70 int magic;
72
73static const cyaml_schema_field_t
74 arranger_selections_fields_schema[] = {
75 YAML_FIELD_INT (ArrangerSelections, schema_version),
76 YAML_FIELD_ENUM (
78 type,
79 arranger_selections_type_strings),
80
81 CYAML_FIELD_END
82 };
83
84static const cyaml_schema_value_t arranger_selections_schema = {
87 arranger_selections_fields_schema),
88};
89
90typedef enum ArrangerSelectionsProperty
91{
92 ARRANGER_SELECTIONS_PROPERTY_HAS_LENGTH,
93 ARRANGER_SELECTIONS_PROPERTY_CAN_LOOP,
94 ARRANGER_SELECTIONS_PROPERTY_HAS_LOOPED,
95 ARRANGER_SELECTIONS_PROPERTY_CAN_FADE,
96} ArrangerSelectionsProperty;
97
98static inline ArrangerSelections *
99arranger_selections_cast (void * sel)
100{
101 if (!IS_ARRANGER_SELECTIONS ((ArrangerSelections *) sel))
102 {
103 g_warning ("%s", __func__);
104 }
105 return (ArrangerSelections *) sel;
106}
107
116NONNULL_ARGS (1)
118 ArrangerSelections * self,
119 bool project,
120 UndoableAction * action);
121
125NONNULL void
127 ArrangerSelections * self,
128 ArrangerSelectionsType type);
129
134arranger_selections_new (ArrangerSelectionsType type);
135
139NONNULL bool
141
145NONNULL void
147 ArrangerSelections * self,
148 ArrangerObject * obj);
149
154NONNULL void
156 ArrangerSelections * dest,
157 ArrangerSelections * src);
158
168NONNULL void
170 ArrangerSelections * sel,
171 int desc);
172
173NONNULL void
174arranger_selections_sort_by_positions (
175 ArrangerSelections * self,
176 int desc);
177
181NONNULL ArrangerSelections *
183
187NONNULL bool
189
199NONNULL void
201 const ArrangerSelections * self,
202 Position * pos,
203 const bool global);
204
213NONNULL void
215 ArrangerSelections * self,
216 Position * pos,
217 int global);
218
222NONNULL int
224 const ArrangerSelections * self);
225
229NONNULL ArrangerObject *
231 const ArrangerSelections * self);
232
239NONNULL ArrangerObject *
241 const ArrangerSelections * self,
242 bool ends_last);
243
248NONNULL void
250 ArrangerSelections * self,
251 Position * pos,
252 bool undoable);
253
257NONNULL void
259 const ArrangerSelections * self,
260 GPtrArray * arr);
261
262#if 0
266NONNULL
267void
268arranger_selections_redraw (
269 ArrangerSelections * self);
270#endif
271
279void
281 ArrangerSelections * self,
282 ZRegion * region,
283 bool clone);
284
291NONNULL void
293 ArrangerSelections * self,
294 const double ticks);
295
300NONNULL bool
302 ArrangerSelections * self);
303
307NONNULL void
309 ArrangerSelections * self,
310 bool fire_events);
311
315NONNULL void
317 ArrangerSelections * self,
318 bool free,
319 bool fire_events);
320
324NONNULL void
326 ArrangerSelections * self);
327
328NONNULL bool
329arranger_selections_validate (ArrangerSelections * self);
330
335NONNULL void
337
341NONNULL void
343
350NONNULL void
352
360NONNULL int
362 ArrangerSelections * self,
363 ArrangerObject * obj);
364
369NONNULL bool
371 const ArrangerSelections * self);
372
377NONNULL bool
379 const ArrangerSelections * self);
380
381NONNULL bool
382arranger_selections_contains_unrenamable_object (
383 const ArrangerSelections * self);
384
394NONNULL bool
396 ArrangerSelections * self,
397 ArrangerSelectionsProperty property,
398 bool value);
399
403NONNULL void
405 ArrangerSelections * self,
406 ArrangerObject * obj);
407
413NONNULL void
415
419NONNULL bool
421
422NONNULL bool
423arranger_selections_contains_looped (
424 ArrangerSelections * self);
425
426NONNULL bool
427arranger_selections_can_be_merged (ArrangerSelections * self);
428
429NONNULL double
430arranger_selections_get_length_in_ticks (
431 ArrangerSelections * self);
432
433NONNULL bool
434arranger_selections_contains_clip (
435 ArrangerSelections * self,
436 AudioClip * clip);
437
438NONNULL bool
439arranger_selections_can_split_at_pos (
440 const ArrangerSelections * self,
441 const Position * pos);
442
443NONNULL ArrangerSelections *
444arranger_selections_get_for_type (ArrangerSelectionsType type);
445
450#endif
ArrangerSelectionsActionEditType
Type used when the action is an EDIT action.
COLD NONNULL_ARGS(1) void automation_track_init_loaded(AutomationTrack *self
Inits a loaded AutomationTracklist.
NONNULL bool arranger_selections_contains_object_with_property(ArrangerSelections *self, ArrangerSelectionsProperty property, bool value)
Checks whether an object matches the given parameters.
NONNULL void arranger_selections_remove_object(ArrangerSelections *self, ArrangerObject *obj)
Removes the arranger object from the selections.
NONNULL void arranger_selections_add_ticks(ArrangerSelections *self, const double ticks)
Moves the selections by the given amount of ticks.
NONNULL void arranger_selections_merge(ArrangerSelections *self)
Merges the given selections into one region.
NONNULL void arranger_selections_set_from_selections(ArrangerSelections *dest, ArrangerSelections *src)
Sets the values of each object in the dest selections to the values in the src selections.
NONNULL bool arranger_selections_verify(ArrangerSelections *self)
Verify that the objects are not invalid.
NONNULL void arranger_selections_post_deserialize(ArrangerSelections *self)
Code to run after deserializing.
NONNULL void arranger_selections_free_members(ArrangerSelections *self)
Frees anything allocated by the selections but not the objects or self itself.
NONNULL void arranger_selections_get_all_objects(const ArrangerSelections *self, GPtrArray *arr)
Appends all objects in the given array.
NONNULL ArrangerObject * arranger_selections_get_last_object(const ArrangerSelections *self, bool ends_last)
Gets last object.
NONNULL bool arranger_selections_all_on_same_lane(ArrangerSelections *self)
Returns whether all the selections are on the same lane (track lane or automation lane).
NONNULL void arranger_selections_get_start_pos(const ArrangerSelections *self, Position *pos, const bool global)
Returns the position of the leftmost object.
NONNULL void arranger_selections_free(ArrangerSelections *self)
Frees the selections but not the objects.
NONNULL void arranger_selections_add_object(ArrangerSelections *self, ArrangerObject *obj)
Appends the given object to the selections.
NONNULL void arranger_selections_init(ArrangerSelections *self, ArrangerSelectionsType type)
Initializes the selections.
void arranger_selections_add_to_region(ArrangerSelections *self, ZRegion *region, bool clone)
Adds each object in the selection to the given region (if applicable).
NONNULL int arranger_selections_get_num_objects(const ArrangerSelections *self)
Returns the number of selected objects.
NONNULL bool arranger_selections_can_be_pasted(ArrangerSelections *self)
Returns if the selections can be pasted.
NONNULL int arranger_selections_contains_object(ArrangerSelections *self, ArrangerObject *obj)
Returns if the arranger object is in the selections or not.
NONNULL void arranger_selections_paste_to_pos(ArrangerSelections *self, Position *pos, bool undoable)
Pastes the given selections to the given Position.
NONNULL void arranger_selections_select_all(ArrangerSelections *self, bool fire_events)
Selects all possible objects from the project.
NONNULL void arranger_selections_free_full(ArrangerSelections *self)
Frees all the objects as well.
NONNULL void arranger_selections_clear(ArrangerSelections *self, bool free, bool fire_events)
Clears selections.
NONNULL ArrangerObject * arranger_selections_get_first_object(const ArrangerSelections *self)
Gets first object.
NONNULL bool arranger_selections_contains_unclonable_object(const ArrangerSelections *self)
Returns if the selections contain an unclonable object (such as the start marker).
NONNULL void arranger_selections_sort_by_indices(ArrangerSelections *sel, int desc)
Sorts the selections by their indices (eg, for regions, their track indices, then the lane indices,...
NONNULL bool arranger_selections_has_any(ArrangerSelections *self)
Returns if there are any selections.
ArrangerSelections * arranger_selections_new(ArrangerSelectionsType type)
Creates new arranger selections.
NONNULL bool arranger_selections_contains_undeletable_object(const ArrangerSelections *self)
Returns if the selections contain an undeletable object (such as the start marker).
void arranger_selections_init_loaded(ArrangerSelections *self, bool project, UndoableAction *action)
Inits the selections after loading a project.
NONNULL void arranger_selections_get_end_pos(ArrangerSelections *self, Position *pos, int global)
Returns the end position of the rightmost object.
NONNULL ArrangerSelections * arranger_selections_clone(const ArrangerSelections *self)
Clone the struct for copying, undoing, etc.
#define YAML_VALUE_PTR(cc, fields_schema)
Schema to be used as a pointer.
Definition yaml.h:221
Base struct for arranger objects.
ArrangerSelectionsType type
Type of selections.
Audio clips for the pool.
Definition clip.h:33
A Position is made up of bars.beats.sixteenths.ticks.
Definition position.h:137
Base struct to be inherited by implementing undoable actions.
A region (clip) is an object on the timeline that contains either MidiNote's or AudioClip's.
Definition region.h:78
YAML utils.