4#ifndef __GUI_BACKEND_ARRANGER_OBJECT_H__
5#define __GUI_BACKEND_ARRANGER_OBJECT_H__
7#include "gui/backend/position_proxy.h"
8#include "gui/dsp/arranger_object_fwd.h"
9#include "gui/dsp/track_fwd.h"
13using namespace zrythm;
15#define DEFINE_ARRANGER_OBJECT_QML_PROPERTIES(ClassType) \
20 Q_PROPERTY (int type READ getType CONSTANT) \
21 int getType () const \
23 return ENUM_VALUE_TO_INT (get_type ()); \
28 Q_PROPERTY (bool hasLength READ getHasLength CONSTANT) \
29 bool getHasLength () const \
31 return std::derived_from<ClassType, BoundedObject>; \
36 Q_PROPERTY (bool selected READ getSelected NOTIFY selectedChanged) \
37 bool getSelected () const \
39 if (selection_status_getter_) \
41 return (*selection_status_getter_) (get_uuid ()); \
45 Q_SIGNAL void selectedChanged (bool selected); \
49 Q_PROPERTY (PositionProxy * position READ getPosition CONSTANT) \
50 PositionProxy * getPosition () const \
57 Q_SIGNAL void addedToProject (); \
58 Q_SIGNAL void removedFromProject ();
60#define DECLARE_FINAL_ARRANGER_OBJECT_CONSTRUCTORS(ClassType) \
63 ArrangerObjectRegistry &obj_registry, TrackResolver track_resolver, \
64 QObject * parent = nullptr);
76 Z_DISABLE_COPY_MOVE (ArrangerObject)
79 using SelectionStatusGetter = std::function<bool (
const Uuid &)>;
81 static constexpr double DEFAULT_NUDGE_TICKS = 0.1;
130 enum class PositionType
141 using Position = zrythm::dsp::Position;
144 ~ArrangerObject () noexcept override = default;
146 using ArrangerObjectPtr = ArrangerObject *;
148 auto get_type ()
const {
return type_; }
160 z_return_val_if_reached ({});
175 bool range_start_inclusive =
true,
176 bool range_end_inclusive =
false)
const
179 start.
frames_, end.
frames_, range_start_inclusive, range_end_inclusive);
188 bool range_start_inclusive =
true,
189 bool range_end_inclusive =
false)
const
191 return (range_start_inclusive
192 ? (
pos_->frames_ >= global_frames_start)
193 : (
pos_->frames_ > global_frames_start))
194 && (range_end_inclusive ? (
pos_->frames_ <= global_frames_end) : (
pos_->frames_ < global_frames_end));
237 PositionType pos_type,
252 PositionType pos_type,
261 void set_track_id (
const TrackUuid &track_id) {
track_id_ = track_id; }
262 void set_track_id (std::optional<TrackUuid> track_id)
266 void unset_track_id () {
track_id_ = std::nullopt; }
290 std::optional<TrackUuid> get_track_id ()
const {
return track_id_; }
312 virtual ArrangerObjectPtrVariant
335 std::optional<ArrangerObjectPtrVariant>
338 void set_selection_status_getter (SelectionStatusGetter getter)
351 return lhs.type_ == rhs.type_ && *lhs.
pos_ == *rhs.
pos_
356 ArrangerObject (
Type type, TrackResolver track_resolver)
noexcept;
359 copy_members_from (
const ArrangerObject &other,
ObjectCloneType clone_type);
370 friend void to_json (nlohmann::json &j,
const ArrangerObject &arranger_object)
372 to_json (j,
static_cast<const UuidIdentifiableObject &
> (arranger_object));
373 j[
"type"] = arranger_object.type_;
374 j[
"flags"] = arranger_object.
flags_;
375 j[
"trackId"] = arranger_object.
track_id_;
376 j[
"pos"] = arranger_object.
pos_;
379 from_json (
const nlohmann::json &j,
ArrangerObject &arranger_object)
381 j.at (
"type").get_to (arranger_object.type_);
382 j.at (
"flags").get_to (arranger_object.
flags_);
383 j.at (
"trackId").get_to (arranger_object.
track_id_);
384 j.at (
"pos").get_to (*arranger_object.
pos_);
388 TrackResolver track_resolver_;
429using ArrangerObjectRegistry =
432using ArrangerObjectSelectionManager =
442DEFINE_ENUM_FORMATTER (
447 QT_TR_NOOP (
"Region"),
448 QT_TR_NOOP (
"Midi Note"),
449 QT_TR_NOOP (
"Chord Object"),
450 QT_TR_NOOP (
"Scale Object"),
451 QT_TR_NOOP (
"Marker"),
452 QT_TR_NOOP (
"Automation Point"));
Base class for all objects in the arranger.
void position_setter_validated(const dsp::Position &pos, dsp::TicksPerFrame ticks_per_frame)
The setter is for use in e.g.
virtual bool is_deletable() const
Returns whether the given object is deletable or not (eg, start marker).
std::optional< SelectionStatusGetter > selection_status_getter_
Whether part of an auditioner track.
std::optional< ArrangerObjectPtrVariant > remove_from_project(bool free_obj, bool fire_events=false)
Removes the object (which can be obtained from find_in_project()) from its parent in the project.
std::optional< TrackUuid > track_id_
ID of the track this object belongs to.
bool is_start_hit_by_range(const dsp::Position &start, const dsp::Position &end, bool range_start_inclusive=true, bool range_end_inclusive=false) const
Returns whether the given object is hit by the given range.
void update_positions(bool from_ticks, bool bpm_change, dsp::FramesPerTick frames_per_tick)
Updates the positions in each child recursively.
bool are_members_valid(bool is_project, dsp::FramesPerTick frames_per_tick) const
To be called by validate() implementations.
bool is_position_valid(const dsp::Position &pos, PositionType pos_type, dsp::TicksPerFrame ticks_per_frame) const
Returns if the given Position is valid.
bool is_start_hit_by_range(const signed_frame_t global_frames_start, const signed_frame_t global_frames_end, bool range_start_inclusive=true, bool range_end_inclusive=false) const
void set_parent_on_base_qproperties(QObject &derived)
Set the parent on QObject's that are children of this class.
virtual utils::Utf8String gen_human_friendly_name() const
Generates a human readable name for the object.
auto get_position() const
Getter.
virtual bool validate(bool is_project, dsp::FramesPerTick frames_per_tick) const =0
Validates the arranger object.
virtual ArrangerObjectPtrVariant insert_clone_to_project() const =0
Inserts the object where it belongs in the project (eg, a Track).
bool set_position(const dsp::Position &pos, PositionType pos_type, bool validate, dsp::TicksPerFrame ticks_per_frame)
Sets the given position on the object, optionally attempting to validate before.
auto get_track() const
Returns the Track this ArrangerObject is in.
Type
The type of the object.
virtual ArrangerObjectPtrVariant add_clone_to_project(bool fire_events) const =0
Appends the ArrangerObject to where it belongs in the project (eg, a Track), without taking into acco...
@ NonProject
This object is not a project object, but an object used temporarily eg.
ResizeType
Flag used in some functions.
@ StretchTempoChange
Used when we want to resize to contents when BPM changes.
Flags flags_
Track this object belongs to (cache to be set during graph calculation).
PositionProxy * pos_
Position (or start Position if the object has length).
void move(double ticks, dsp::FramesPerTick frames_per_tick)
Moves the object by the given amount of ticks.
Represents the position of an object.
signed_frame_t frames_
Position in frames (samples).
A registry that owns and manages objects identified by a UUID.
Lightweight UTF-8 string wrapper with safe conversions.
Base class for objects that need to be uniquely identified by UUID.
A reference-counted RAII wrapper for a UUID in a registry.
int_fast64_t signed_frame_t
Signed type for frame index.