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 <string_view>
7
8#include "dsp/atomic_position_qml_adapter.h"
9#include "utils/icloneable.h"
10
11#include <boost/describe/class.hpp>
12#include <nlohmann/json_fwd.hpp>
13
14using std::literals::string_view_literals::operator""sv;
15
16namespace zrythm::structure::arrangement
17{
18
19using namespace std::string_view_literals;
20
29class ArrangerObjectBounds : public QObject
30{
31 Q_OBJECT
32 Q_PROPERTY (
33 zrythm::dsp::AtomicPositionQmlAdapter * length READ length CONSTANT)
34 QML_ELEMENT
35 QML_UNCREATABLE ("")
36
37public:
38 ArrangerObjectBounds (
39 const dsp::AtomicPositionQmlAdapter &start_position,
40 QObject * parent = nullptr);
41 ~ArrangerObjectBounds () override = default;
42 Q_DISABLE_COPY_MOVE (ArrangerObjectBounds)
43
44 // ========================================================================
45 // QML Interface
46 // ========================================================================
47
48 dsp::AtomicPositionQmlAdapter * length () const
49 {
50 return length_adapter_.get ();
51 }
52
53 // Convenience method
54 Q_INVOKABLE void setLengthTicks (double ticks)
55 {
56 length ()->setTicks (ticks);
57 }
58
59 // ========================================================================
60
61 units::sample_t get_end_position_samples (bool end_position_inclusive) const;
62
71 [[nodicard]] bool
72 is_hit (const units::sample_t frames, bool object_end_pos_inclusive = false)
73 const;
74
86 bool is_hit_by_range (
87 std::pair<units::sample_t, units::sample_t> global_frames,
88 bool range_start_inclusive = true,
89 bool range_end_inclusive = true,
90 bool object_end_pos_inclusive = false) const;
91
92private:
93 friend void init_from (
94 ArrangerObjectBounds &obj,
95 const ArrangerObjectBounds &other,
96 utils::ObjectCloneType clone_type);
97
98 static constexpr auto kLengthKey = "length"sv;
99 friend void to_json (nlohmann::json &j, const ArrangerObjectBounds &object);
100 friend void from_json (const nlohmann::json &j, ArrangerObjectBounds &object);
101
102 auto position () const -> const dsp::AtomicPositionQmlAdapter *
103 {
104 return std::addressof (position_);
105 }
106
107private:
108 const dsp::AtomicPositionQmlAdapter &position_;
109
111 dsp::AtomicPosition length_;
113
114 BOOST_DESCRIBE_CLASS (ArrangerObjectBounds, (), (), (), (length_))
115};
116
117} // 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:36