Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
chord_object.h
1// SPDX-FileCopyrightText: © 2018-2022, 2024-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "dsp/chord_descriptor.h"
7#include "gui/dsp/arranger_object.h"
8#include "gui/dsp/muteable_object.h"
9#include "gui/dsp/region_owned_object.h"
10#include "utils/icloneable.h"
11
17
18using namespace zrythm;
19
20namespace zrythm::dsp
21{
22class ChordDescriptor;
23}
24class ChordRegion;
25
39class ChordObject final
40 : public QObject,
41 public MuteableObject,
42 public RegionOwnedObject,
43 public ICloneable<ChordObject>
44{
45 Q_OBJECT
46 QML_ELEMENT
47 DEFINE_ARRANGER_OBJECT_QML_PROPERTIES (ChordObject)
48 Q_PROPERTY (
49 ChordDescriptor * chordDescriptor READ getChordDescriptor WRITE
50 setChordDescriptor NOTIFY chordDescriptorChanged)
51
52public:
53 using RegionT = ChordRegion;
54 using ChordDescriptor = dsp::ChordDescriptor;
55
56 static constexpr int WIDGET_TRIANGLE_WIDTH = 10;
57
58public:
59 DECLARE_FINAL_ARRANGER_OBJECT_CONSTRUCTORS (ChordObject)
60
61 // ========================================================================
62 // QML Interface
63 // ========================================================================
64
65 ChordDescriptor * getChordDescriptor () const;
66
67 void setChordDescriptor (ChordDescriptor * descr);
68 Q_SIGNAL void chordDescriptorChanged (ChordDescriptor *);
69
70 // ========================================================================
71
72 void set_chord_descriptor (int index);
73
74 ArrangerObjectPtrVariant
75 add_clone_to_project (bool fire_events) const override;
76
77 ArrangerObjectPtrVariant insert_clone_to_project () const override;
78
80
81 friend bool operator== (const ChordObject &lhs, const ChordObject &rhs)
82 {
83 return static_cast<const ArrangerObject &> (lhs)
84 == static_cast<const ArrangerObject &> (rhs)
85 && lhs.chord_index_ == rhs.chord_index_
86 && static_cast<const RegionOwnedObject &> (lhs)
87 == static_cast<const RegionOwnedObject &> (rhs)
88 && static_cast<const MuteableObject &> (lhs)
89 == static_cast<const MuteableObject &> (rhs);
90 }
91
92 bool
93 validate (bool is_project, dsp::FramesPerTick frames_per_tick) const override;
94
95 void init_after_cloning (const ChordObject &other, ObjectCloneType clone_type)
96 override;
97
98private:
99 static constexpr std::string_view kChordIndexKey = "chordIndex";
100 friend void to_json (nlohmann::json &j, const ChordObject &co)
101 {
102 to_json (j, static_cast<const ArrangerObject &> (co));
103 to_json (j, static_cast<const MuteableObject &> (co));
104 to_json (j, static_cast<const RegionOwnedObject &> (co));
105 j[kChordIndexKey] = co.chord_index_;
106 }
107 friend void from_json (const nlohmann::json &j, ChordObject &co)
108 {
109 from_json (j, static_cast<ArrangerObject &> (co));
110 from_json (j, static_cast<MuteableObject &> (co));
111 from_json (j, static_cast<RegionOwnedObject &> (co));
112 j.at (kChordIndexKey).get_to (co.chord_index_);
113 }
114
115public:
118};
119
121 return fmt::format (
122 "ChordObject [{}]: chord ID {}", co.get_position (), co.chord_index_);
123});
124
Base class for all objects in the arranger.
auto get_position() const
Getter.
The ChordObject class represents a chord inside a ChordRegion.
utils::Utf8String gen_human_friendly_name() const override
Generates a human readable name for the object.
ArrangerObjectPtrVariant insert_clone_to_project() const override
Inserts the object where it belongs in the project (eg, a Track).
void init_after_cloning(const ChordObject &other, ObjectCloneType clone_type) override
Initializes the cloned object.
ArrangerObjectPtrVariant add_clone_to_project(bool fire_events) const override
Appends the ArrangerObject to where it belongs in the project (eg, a Track), without taking into acco...
bool validate(bool is_project, dsp::FramesPerTick frames_per_tick) const override
Validates the arranger object.
int chord_index_
The index of the chord it belongs to (0 topmost).
A ChordDescriptor describes a chord and is not linked to any specific object by itself.
Lightweight UTF-8 string wrapper with safe conversions.
Definition string.h:39
#define DEFINE_OBJECT_FORMATTER(obj_type, function_prefix, formatter_func)
Defines a formatter for the given object type.
Definition format.h:80
ObjectCloneType
Definition icloneable.h:25