4#ifndef __AUDIO_AUTOMATION_TRACK_H__
5#define __AUDIO_AUTOMATION_TRACK_H__
7#include "zrythm-config.h"
9#include "dsp/position.h"
10#include "gui/dsp/arranger_object_all.h"
11#include "gui/dsp/arranger_object_owner.h"
12#include "gui/dsp/automation_point.h"
13#include "gui/dsp/port.h"
15#include <QtQmlIntegration>
29constexpr int AUTOMATION_TRACK_DEFAULT_HEIGHT = 48;
31enum class AutomationRecordMode
35 NUM_AUTOMATION_RECORD_MODES,
38DEFINE_ENUM_FORMATTER (
41 QT_TR_NOOP_UTF8 (
"Touch"),
42 QT_TR_NOOP_UTF8 (
"Latch"));
46 public ICloneable<AutomationTrack>,
47 public ArrangerObjectOwner<AutomationRegion>
51 Q_PROPERTY (
double height READ getHeight WRITE setHeight NOTIFY heightChanged)
52 Q_PROPERTY (QString label READ getLabel NOTIFY labelChanged)
54 int automationMode READ getAutomationMode WRITE setAutomationMode NOTIFY
55 automationModeChanged)
57 int recordMode READ getRecordMode WRITE setRecordMode NOTIFY
59 DEFINE_ARRANGER_OBJECT_OWNER_QML_PROPERTIES (
67 using TrackGetter = std::function<TrackPtrVariant ()>;
72 PortRegistry &port_registry,
73 ArrangerObjectRegistry &obj_registry,
74 TrackGetter track_getter,
82 QString getLabel ()
const;
83 Q_SIGNAL
void labelChanged (QString label);
85 double getHeight ()
const {
return height_; }
86 void setHeight (
double height);
87 Q_SIGNAL
void heightChanged (
double height);
89 int getAutomationMode ()
const
93 void setAutomationMode (
int automation_mode);
94 Q_SIGNAL
void automationModeChanged (
int automation_mode);
96 int getRecordMode ()
const {
return ENUM_VALUE_TO_INT (
record_mode_); }
97 void setRecordMode (
int record_mode);
98 Q_SIGNAL
void recordModeChanged (
int record_mode);
104 bool validate ()
const;
139 void swap_record_mode ()
143 %
static_cast<int> (AutomationRecordMode::NUM_AUTOMATION_RECORD_MODES));
189 TrackPtrVariant get_track ()
const;
233 bool use_snapshots)
const;
235 static int get_y_px_from_height_and_normalized_val (
237 const float normalized_val)
239 return static_cast<int> (height - normalized_val * height);
248 return get_y_px_from_height_and_normalized_val (
249 static_cast<float> (
height_), normalized_val);
252 void set_caches (CacheType types);
254 bool contains_automation ()
const {
return !get_children_vector ().empty (); }
256 bool verify ()
const;
258 Location get_location (
const AutomationRegion &)
const override;
261 get_field_name_for_serialization (
const AutomationRegion *)
const override
267 static constexpr std::string_view kIndexKey =
"index";
268 static constexpr std::string_view kPortIdKey =
"portId";
269 static constexpr std::string_view kCreatedKey =
"created";
270 static constexpr std::string_view kAutomationModeKey =
"automationMode";
271 static constexpr std::string_view kRecordModeKey =
"recordMode";
272 static constexpr std::string_view kVisibleKey =
"visible";
273 static constexpr std::string_view kHeightKey =
"height";
276 to_json (j,
static_cast<const ArrangerObjectOwner &
> (track));
277 j[kIndexKey] = track.
index_;
285 friend void from_json (
const nlohmann::json &j,
AutomationTrack &track)
287 from_json (j,
static_cast<ArrangerObjectOwner &
> (track));
288 j.at (kIndexKey).get_to (track.
index_);
289 j.at (kPortIdKey).get_to (track.
port_id_);
290 j.at (kCreatedKey).get_to (track.
created_);
293 j.at (kVisibleKey).get_to (track.
visible_);
294 j.at (kHeightKey).get_to (track.
height_);
298 PortRegistry &port_registry_;
299 ArrangerObjectRegistry &object_registry_;
300 TrackGetter track_getter_;
324 double height_ = AUTOMATION_TRACK_DEFAULT_HEIGHT;
Interface for a track that has automatable parameters.
An automation point inside an AutomationTrack.
Represents an automation region, which contains a collection of automation points.
Each track has an automation tracklist with automation tracks to be generated at runtime,...
Represents the position of an object.
AutomationRegion * get_region_before_pos(const Position &pos, bool ends_after, bool use_snapshots) const
Returns the Region that starts before given Position, if any.
int get_y_px_from_normalized_val(float normalized_val) const
Returns the y pixels from the value based on the allocation of the automation track.
double height_
Position of multipane handle.
void set_port_id(const PortUuid &port_id)
Clone the given port identifier and take ownership of the clone.
bool should_read_automation(RtTimePoint cur_time) const
Returns whether the automation in the automation track should be read.
bool recording_start_sent_
This is a flag to let the recording manager know that a START signal was already sent for recording.
bool created_
Whether it has been created by the user yet or not.
AutomationMode
FIXME: move to a more appropriate place.
bool visible_
Whether visible or not.
static AutomationTrack * find_from_port_id(const PortUuid &id, bool basic_search)
void init_after_cloning(const AutomationTrack &other, ObjectCloneType clone_type) override
Clones the AutomationTrack.
PortUuid port_id_
Identifier of the Port this AutomationTrack is for (owned pointer).
AutomationTrack(PortRegistry &port_registry, ArrangerObjectRegistry &obj_registry, TrackGetter track_getter, const ControlPort::Uuid &port_id)
Creates an automation track for the given Port.
void set_index(int index)
Sets the index of the AutomationTrack in the AutomationTracklist.
bool recording_paused_
This must only be set by the RecordingManager when temporarily pausing recording, eg when looping or ...
float get_val_at_pos(const Position &pos, bool normalized, bool ends_after, bool use_snapshots) const
Returns the actual parameter value at the given position.
int index_
Index in parent AutomationTracklist.
constexpr int AUTOMATION_RECORDING_TOUCH_REL_MS
Release time in ms when in touch record mode.
bool should_be_recording(RtTimePoint cur_time, bool record_aps) const
Returns if the automation track should currently be recording data.
AutomationMode automation_mode_
Automation mode.
static AutomationTrack * find_from_port(const ControlPort &port, const AutomatableTrack *track, bool basic_search)
Finds the AutomationTrack associated with port.
float last_recorded_value_
Last value recorded in this automation track.
AutomationPoint * get_ap_before_pos(const Position &pos, bool ends_after, bool use_snapshots) const
Returns the automation point before the Position on the timeline.
AutomationRecordMode record_mode_
Automation record mode, when automation_mode_ is set to record.
AutomationRegion * recording_region_
Region currently recording to.
bool recording_started_
To be set to true when recording starts (when the first change is received) and false when recording ...