Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
region_owned_object.h
1// SPDX-FileCopyrightText: © 2024-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "structure/arrangement/arranger_object.h"
7
8namespace zrythm::structure::arrangement
9{
10
11class Region;
12
13class RegionOwnedObject : virtual public ArrangerObject
14{
15public:
16 RegionOwnedObject (ArrangerObjectRegistry &obj_registry) noexcept
17 : object_registry_ (obj_registry)
18 {
19 }
20 ~RegionOwnedObject () override = default;
21 Q_DISABLE_COPY_MOVE (RegionOwnedObject)
22
23
26 void set_region_and_index (const Region &region);
27
33 template <typename SelfT>
35 this const SelfT &self,
36 dsp::Position &pos,
37 dsp::FramesPerTick frames_per_tick)
38 {
39 auto r = self.get_region ();
40 pos = self.get_position ();
41 pos.add_ticks (r->get_position ().ticks_, frames_per_tick);
42 }
43
47 template <typename SelfT>
48 [[gnu::hot]] auto get_region (this const SelfT &self)
49 {
50 assert (self.region_id_.has_value ());
51 return std::get<typename SelfT::RegionT *> (
52 self.object_registry_.find_by_id_or_throw (*self.region_id_));
53 }
54
55 friend bool
56 operator== (const RegionOwnedObject &lhs, const RegionOwnedObject &rhs);
57
58protected:
59 friend void init_from (
61 const RegionOwnedObject &other,
62 utils::ObjectCloneType clone_type);
63
64private:
65 static constexpr std::string_view kRegionIdKey = "regionId";
66 friend void to_json (nlohmann::json &j, const RegionOwnedObject &object)
67 {
68 j[kRegionIdKey] = object.region_id_;
69 }
70 friend void from_json (const nlohmann::json &j, RegionOwnedObject &object)
71 {
72 j.at (kRegionIdKey).get_to (object.region_id_);
73 }
74
75 friend bool
76 operator== (const RegionOwnedObject &lhs, const RegionOwnedObject &rhs)
77 {
78 return lhs.region_id_ == rhs.region_id_
79 && static_cast<const ArrangerObject &> (lhs)
80 == static_cast<const ArrangerObject &> (rhs);
81 }
82
83public:
84 ArrangerObjectRegistry &object_registry_;
85
87 std::optional<ArrangerObject::Uuid> region_id_;
88
89 BOOST_DESCRIBE_CLASS (RegionOwnedObject, (ArrangerObject), (region_id_), (), ())
90};
91
92template <typename T>
93concept RegionOwnedObjectSubclass = std::derived_from<T, RegionOwnedObject>;
94
95} // namespace zrythm::structure::arrangement
std::optional< ArrangerObject::Uuid > region_id_
Parent region identifier for objects that are part of a region.
void get_global_start_pos(this const SelfT &self, dsp::Position &pos, dsp::FramesPerTick frames_per_tick)
Gets the global (timeline-based) start Position of the object.
auto get_region(this const SelfT &self)
If the object is part of a Region, returns it, otherwise returns NULL.
void set_region_and_index(const Region &region)
Sets the region the object belongs to and the related index inside it.
A region (clip) is an object on the timeline that contains either MidiNote's or AudioClip's.
Definition region.h:110