Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
bounded_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 "dsp/atomic_position_qml_adapter.h"
7#include "utils/icloneable.h"
8
9namespace zrythm::structure::arrangement
10{
11
20class ArrangerObjectBounds : public QObject
21{
22 Q_OBJECT
23 Q_PROPERTY (
24 zrythm::dsp::AtomicPositionQmlAdapter * length READ length CONSTANT)
25 QML_ELEMENT
26 QML_UNCREATABLE ("")
27
28public:
29 ArrangerObjectBounds (
30 const dsp::AtomicPositionQmlAdapter &start_position,
31 QObject * parent = nullptr);
32 ~ArrangerObjectBounds () override = default;
33 Z_DISABLE_COPY_MOVE (ArrangerObjectBounds)
34
35 // ========================================================================
36 // QML Interface
37 // ========================================================================
38
39 dsp::AtomicPositionQmlAdapter * length () const
40 {
41 return length_adapter_.get ();
42 }
43
44 // Convenience method
45 Q_INVOKABLE void setLengthTicks (double ticks)
46 {
47 length ()->setTicks (ticks);
48 }
49
50 // ========================================================================
51
52 units::sample_t get_end_position_samples (bool end_position_inclusive) const;
53
62 [[nodicard]] bool
63 is_hit (const units::sample_t frames, bool object_end_pos_inclusive = false)
64 const;
65
77 bool is_hit_by_range (
78 std::pair<units::sample_t, units::sample_t> global_frames,
79 bool range_start_inclusive = true,
80 bool range_end_inclusive = true,
81 bool object_end_pos_inclusive = false) const;
82
83private:
84 friend void init_from (
85 ArrangerObjectBounds &obj,
86 const ArrangerObjectBounds &other,
87 utils::ObjectCloneType clone_type);
88
89 static constexpr auto kLengthKey = "length"sv;
90 friend auto to_json (nlohmann::json &j, const ArrangerObjectBounds &object)
91 {
92 j[kLengthKey] = object.length_;
93 }
94 friend auto from_json (const nlohmann::json &j, ArrangerObjectBounds &object)
95 {
96 j.at (kLengthKey).get_to (object.length_);
97 }
98
99 auto position () const -> const dsp::AtomicPositionQmlAdapter *
100 {
101 return std::addressof (position_);
102 }
103
104private:
105 const dsp::AtomicPositionQmlAdapter &position_;
106
108 dsp::AtomicPosition length_;
110
111 BOOST_DESCRIBE_CLASS (ArrangerObjectBounds, (), (), (), (length_))
112};
113
114} // namespace zrythm::structure::arrangement
Thread-safe position storage with automatic musical/absolute time conversion.
Adds length functionality to arranger objects.
bool is_hit_by_range(std::pair< units::sample_t, units::sample_t > global_frames, bool range_start_inclusive=true, bool range_end_inclusive=true, bool object_end_pos_inclusive=false) const
Whether the object is hit by the given range.
bool is_hit(const units::sample_t frames, bool object_end_pos_inclusive=false) const
Returns whether the object is hit by the given position (local position if non-timeline object).
A unique pointer for QObject objects that also works with QObject-based ownership.
Definition qt.h:38