Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
scale_object.h
1// SPDX-FileCopyrightText: © 2018-2021, 2024-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#ifndef __AUDIO_SCALE_OBJECT_H__
5#define __AUDIO_SCALE_OBJECT_H__
6
7#include "dsp/musical_scale.h"
8#include "gui/dsp/bounded_object.h"
9#include "gui/dsp/muteable_object.h"
10#include "gui/dsp/timeline_object.h"
11#include "utils/icloneable.h"
12#include "utils/serialization.h"
13
19
20using namespace zrythm;
21
22class ScaleObject final
23 : public QObject,
24 public TimelineObject,
25 public MuteableObject,
26 public ICloneable<ScaleObject>
27{
28 Q_OBJECT
29 QML_ELEMENT
30 DEFINE_ARRANGER_OBJECT_QML_PROPERTIES (ScaleObject)
31 Q_PROPERTY (QString name READ getName NOTIFY nameChanged)
32
33public:
34 using MusicalScale = dsp::MusicalScale;
35
36public:
37 DECLARE_FINAL_ARRANGER_OBJECT_CONSTRUCTORS (ScaleObject)
38
39 // =========================================================
40 // QML Interface
41 // =========================================================
42
43 QString getName () const { return gen_human_friendly_name ().to_qstring (); }
44 Q_SIGNAL void nameChanged (const QString &name);
45
46 // =========================================================
47
48 void init_after_cloning (const ScaleObject &other, ObjectCloneType clone_type)
49 override;
50
51 void set_scale (const MusicalScale &scale) { scale_ = scale; }
52
54
55 ArrangerObjectPtrVariant
56 add_clone_to_project (bool fire_events) const override;
57
58 ArrangerObjectPtrVariant insert_clone_to_project () const override;
59
60 bool
61 validate (bool is_project, dsp::FramesPerTick frames_per_tick) const override;
62
63private:
64 static constexpr std::string_view kScaleKey = "scale";
65 friend void to_json (nlohmann::json &j, const ScaleObject &so)
66 {
67 to_json (j, static_cast<const ArrangerObject &> (so));
68 to_json (j, static_cast<const MuteableObject &> (so));
69 j[kScaleKey] = so.scale_;
70 }
71 friend void from_json (const nlohmann::json &j, ScaleObject &so)
72 {
73 from_json (j, static_cast<ArrangerObject &> (so));
74 from_json (j, static_cast<MuteableObject &> (so));
75 j.at (kScaleKey).get_to (so.scale_);
76 }
77
78public:
80 MusicalScale scale_;
81};
82
84 return fmt::format ("ScaleObject[position: {}]", so.get_position ());
85})
86
90
91#endif
Base class for all objects in the arranger.
auto get_position() const
Getter.
bool validate(bool is_project, dsp::FramesPerTick frames_per_tick) const override
Validates the arranger object.
ArrangerObjectPtrVariant insert_clone_to_project() const override
Inserts the object where it belongs in the project (eg, a Track).
utils::Utf8String gen_human_friendly_name() const override
Generates a human readable name for the object.
MusicalScale scale_
The scale descriptor.
void init_after_cloning(const ScaleObject &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...
Musical scale descriptor.
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