Zrythm
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
automation_track.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2018-2022 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
10#ifndef __AUDIO_AUTOMATION_TRACK_H__
11#define __AUDIO_AUTOMATION_TRACK_H__
12
13#include "zrythm-config.h"
14
15#include <stdbool.h>
16
18#include "dsp/port.h"
19#include "dsp/position.h"
20#include "dsp/region.h"
21
22typedef struct Port Port;
23typedef struct _AutomationTrackWidget AutomationTrackWidget;
24typedef struct Track Track;
28
35#define AUTOMATION_TRACK_SCHEMA_VERSION 2
36
37#define MAX_AUTOMATION_POINTS 1200
38
40#define AUTOMATION_RECORDING_TOUCH_REL_MS 800
41
42typedef enum AutomationMode
43{
44 AUTOMATION_MODE_READ,
45 AUTOMATION_MODE_RECORD,
46 AUTOMATION_MODE_OFF,
47 NUM_AUTOMATION_MODES,
48} AutomationMode;
49
50static const cyaml_strval_t automation_mode_strings[] = {
51 {"Read", AUTOMATION_MODE_READ },
52 { "Rec", AUTOMATION_MODE_RECORD},
53 { "Off", AUTOMATION_MODE_OFF },
54 { "<invalid>", NUM_AUTOMATION_MODES },
55};
56
57typedef enum AutomationRecordMode
58{
59 AUTOMATION_RECORD_MODE_TOUCH,
60 AUTOMATION_RECORD_MODE_LATCH,
61 NUM_AUTOMATION_RECORD_MODES,
62} AutomationRecordMode;
63
64static const cyaml_strval_t automation_record_mode_strings[] = {
65 {"Touch", AUTOMATION_RECORD_MODE_TOUCH},
66 { "Latch", AUTOMATION_RECORD_MODE_LATCH},
67 { "<invalid>", NUM_AUTOMATION_RECORD_MODES },
68};
69
70typedef struct AutomationTrack
71{
72 int schema_version;
73
75 int index;
76
80
83 bool created;
84
87 int num_regions;
88 size_t regions_size;
89
92 int num_region_snapshots;
93
103
105 int y;
106
108 double height;
109
113
115 AutomationMode automation_mode;
116
120 AutomationRecordMode record_mode;
121
126
129
140
150
153 int num_top_right_buttons;
154 CustomButtonWidget * top_left_buttons[8];
155 int num_top_left_buttons;
156 CustomButtonWidget * bot_right_buttons[8];
157 int num_bot_right_buttons;
158
161
162 CustomButtonWidget * bot_left_buttons[8];
163 int num_bot_left_buttons;
164
168
172
173static const cyaml_schema_field_t automation_track_fields_schema[] = {
174 YAML_FIELD_INT (AutomationTrack, schema_version),
175 YAML_FIELD_INT (AutomationTrack, index),
178 port_id,
179 port_identifier_fields_schema),
181 YAML_FIELD_INT (AutomationTrack, created),
182 YAML_FIELD_ENUM (AutomationTrack, automation_mode, automation_mode_strings),
183 YAML_FIELD_ENUM (AutomationTrack, record_mode, automation_record_mode_strings),
184 YAML_FIELD_INT (AutomationTrack, visible),
185 YAML_FIELD_FLOAT (AutomationTrack, height),
186
187 CYAML_FIELD_END
188};
189
190static const cyaml_schema_value_t automation_track_schema = {
191 YAML_VALUE_PTR (AutomationTrack, automation_track_fields_schema),
192};
193
194COLD NONNULL_ARGS (1) void automation_track_init_loaded (
195 AutomationTrack * self,
196 AutomationTracklist * atl);
197
202NONNULL AutomationTrack *
204
205NONNULL bool
206automation_track_validate (AutomationTrack * self);
207
211void
212automation_mode_get_localized (AutomationMode mode, char * buf);
213
217void
218automation_record_mode_get_localized (AutomationRecordMode mode, char * buf);
219
228NONNULL AutomationTrack *
230
238HOT AutomationTrack *
239automation_track_find_from_port (Port * port, Track * track, bool basic_search);
240
241void
242automation_track_set_automation_mode (
243 AutomationTrack * self,
244 AutomationMode mode,
245 bool fire_events);
246
247NONNULL static inline void
248automation_track_swap_record_mode (AutomationTrack * self)
249{
250 self->record_mode = (self->record_mode + 1) % NUM_AUTOMATION_RECORD_MODES;
251}
252
253NONNULL AutomationTracklist *
254automation_track_get_automation_tracklist (AutomationTrack * self);
255
264HOT NONNULL bool
266
289HOT NONNULL bool
291 const AutomationTrack * const at,
292 const gint64 cur_time,
293 const bool record_aps);
294
301NONNULL void
303
311NONNULL void
313
318//int
319//automation_track_get_visible_y_offset (
320//AutomationTrack * self);
321
330NONNULL void
332 AutomationTrack * self,
333 bool from_ticks,
334 bool bpm_change);
335
340NONNULL void
342
346NONNULL AutomationTrack *
348
349NONNULL Track *
350automation_track_get_track (AutomationTrack * self);
351
361NONNULL AutomationPoint *
363 const AutomationTrack * self,
364 const Position * pos,
365 bool ends_after,
366 bool use_snapshots);
367
377ZRegion *
379 const AutomationTrack * self,
380 const Position * pos,
381 bool ends_after,
382 bool use_snapshots);
383
387NONNULL void
389
393NONNULL void
395
400NONNULL void
402
418NONNULL float
420 AutomationTrack * self,
421 Position * pos,
422 bool normalized,
423 bool ends_after,
424 bool use_snapshots);
425
430NONNULL int
432 AutomationTrack * self,
433 float normalized_val);
434
435#if 0
436NONNULL
437Port *
438automation_track_get_port (
439 const AutomationTrack * const self);
440#endif
441
445NONNULL ZRegion *
447
448NONNULL void
449automation_track_set_caches (AutomationTrack * self, CacheTypes types);
450
451NONNULL bool
452automation_track_contains_automation (const AutomationTrack * self);
453
454NONNULL bool
455automation_track_verify (AutomationTrack * self);
456
460NONNULL void
462
463#endif // __AUDIO_AUTOMATION_TRACK_H__
Automation point API.
A region in the timeline.
ZRegion * automation_track_get_region_before_pos(const AutomationTrack *self, const Position *pos, bool ends_after, bool use_snapshots)
Returns the ZRegion that starts before given Position, if any.
NONNULL void automation_track_remove_region(AutomationTrack *self, ZRegion *region)
Removes a region from the automation track.
int y
Y local to track.
AutomationTracklist * atl
Pointer to owner automation tracklist, if any.
NONNULL AutomationTrack * automation_track_clone(AutomationTrack *src)
Clones the AutomationTrack.
NONNULL float automation_track_get_val_at_pos(AutomationTrack *self, Position *pos, bool normalized, bool ends_after, bool use_snapshots)
Returns the actual parameter value at the given position.
bool created
Whether it has been created by the user yet or not.
bool recording_paused
This must only be set by the RecordingManager when temporarily pausing recording, eg when looping or ...
HOT AutomationTrack * automation_track_find_from_port(Port *port, Track *track, bool basic_search)
Finds the AutomationTrack associated with port.
NONNULL int automation_track_get_y_px_from_normalized_val(AutomationTrack *self, float normalized_val)
Returns the y pixels from the value based on the allocation of the automation track.
AutomationRecordMode record_mode
Automation record mode, when AutomationTrack::automation_mode is set to record.
AutomationModeWidget * am_widget
Automation mode button group.
int index
Index in parent AutomationTracklist.
NONNULL void automation_track_set_index(AutomationTrack *self, int index)
Sets the index of the AutomationTrack in the AutomationTracklist.
Port * port
Cache used during DSP.
ZRegion * recording_region
Region currently recording to.
bool recording_start_sent
This is a flag to let the recording manager know that a START signal was already sent for recording.
NONNULL AutomationTrack * automation_track_new(Port *port)
Creates an automation track for the given Port.
NONNULL void automation_track_add_region(AutomationTrack *self, ZRegion *region)
Adds an automation ZRegion to the AutomationTrack.
ZRegion ** regions
The automation Region's.
NONNULL ZRegion * automation_track_get_last_region(AutomationTrack *self)
Gets the last ZRegion in the AutomationTrack.
ZRegion ** region_snapshots
Snapshots used during playback TODO unimplemented.
NONNULL void automation_track_insert_region(AutomationTrack *self, ZRegion *region, int idx)
Inserts an automation ZRegion to the AutomationTrack at the given index.
NONNULL void automation_track_clear(AutomationTrack *self)
Removes and frees all arranger objects recursively.
double height
Position of multipane handle.
NONNULL void automation_track_free(AutomationTrack *at)
Frees the automation track.
NONNULL void automation_track_update_positions(AutomationTrack *self, bool from_ticks, bool bpm_change)
Returns the visible y offset from the top of the track widget.
void automation_record_mode_get_localized(AutomationRecordMode mode, char *buf)
Gets the automation mode as a localized string.
NONNULL AutomationTrack * automation_track_find_from_port_id(PortIdentifier *id, bool basic_search)
NONNULL void automation_track_unselect_all(AutomationTrack *self)
Unselects all arranger objects.
HOT NONNULL bool automation_track_should_be_recording(const AutomationTrack *const at, const gint64 cur_time, const bool record_aps)
Returns if the automation track should currently be recording data.
CustomButtonWidget * top_right_buttons[8]
Buttons used by the track widget.
AutomationMode automation_mode
Automation mode.
PortIdentifier port_id
Identifier of the Port this AutomationTrack is for.
void automation_mode_get_localized(AutomationMode mode, char *buf)
Gets the automation mode as a localized string.
NONNULL AutomationPoint * automation_track_get_ap_before_pos(const AutomationTrack *self, const Position *pos, bool ends_after, bool use_snapshots)
Returns the automation point before the Position on the timeline.
bool recording_started
To be set to true when recording starts (when the first change is received) and false when recording ...
COLD NONNULL_ARGS(1) void automation_track_init_loaded(AutomationTrack *self
Inits a loaded AutomationTracklist.
float last_recorded_value
Last value recorded in this automation track.
HOT NONNULL bool automation_track_should_read_automation(AutomationTrack *at, gint64 cur_time)
Returns whether the automation in the automation track should be read.
bool visible
Whether visible or not.
#define YAML_FIELD_MAPPING_EMBEDDED(owner, member, schema)
Mapping embedded inside the struct.
Definition yaml.h:31
#define YAML_VALUE_PTR(cc, fields_schema)
Schema to be used as a pointer.
Definition yaml.h:202
#define YAML_FIELD_DYN_PTR_ARRAY_VAR_COUNT_OPT(owner, member, schema)
Dynamic-width (reallocated) array of pointers with variable count, nullable.
Definition yaml.h:127
Ports that transfer audio/midi/other signals to one another.
Position struct and API.
Custom button group to be drawn inside drawing areas.
An automation point inside an AutomationTrack.
Each track has an automation tracklist with automation tracks to be generated at runtime,...
Custom button to be drawn inside drawing areas.
Struct used to identify Ports in the project.
Must ONLY be created via port_new()
Definition port.h:140
A Position is made up of bars.beats.sixteenths.ticks.
Definition position.h:127
Track to be inserted into the Project's Tracklist.
Definition track.h:190
A region (clip) is an object on the timeline that contains either MidiNote's or AudioClip's.
Definition region.h:77