Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
chord_editor.h
1// SPDX-FileCopyrightText: © 2019-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 "dsp/musical_scale.h"
8#include "structure/arrangement/editor_settings.h"
9#include "utils/icloneable.h"
10
11class ChordPreset;
12
13namespace zrythm::structure::arrangement
14{
15
16constexpr int CHORD_EDITOR_NUM_CHORDS = 12;
17
21class ChordEditor : public QObject
22{
23 Q_OBJECT
24 Q_PROPERTY (
26 getEditorSettings CONSTANT FINAL)
27 QML_ELEMENT
28 QML_UNCREATABLE ("")
29
30public:
31 using ChordDescriptor = dsp::ChordDescriptor;
32 using ChordAccent = dsp::ChordAccent;
33 using ChordType = dsp::ChordType;
34 using MusicalScale = dsp::MusicalScale;
35 using MusicalNote = dsp::MusicalNote;
36
37 ChordEditor (QObject * parent = nullptr);
38
39 // =========================================================
40 // QML interface
41 // =========================================================
42
43 auto getEditorSettings () const { return editor_settings_.get (); }
44
45 // =========================================================
46
50 void init ();
51
52 void
53 apply_single_chord (const ChordDescriptor &chord, int idx, bool undoable);
54
55 void apply_chords (const std::vector<ChordDescriptor> &chords, bool undoable);
56
57 void apply_preset_from_scale (
59 MusicalNote root_note,
60 bool undoable);
61
62 void transpose_chords (bool up, bool undoable);
63
68 ChordDescriptor * get_chord_from_note_number (midi_byte_t note_number);
69
70 int get_chord_index (const ChordDescriptor &chord) const;
71
72 auto &get_chord_at_index (size_t index) { return chords_.at (index); }
73 auto &get_chord_at_index (size_t index) const { return chords_.at (index); }
74
75 friend void init_from (
76 ChordEditor &obj,
77 const ChordEditor &other,
78 utils::ObjectCloneType clone_type)
79
80 {
81 obj.editor_settings_ =
82 utils::clone_unique_qobject (*other.editor_settings_, &obj);
83 }
84
85 void add_chord_descriptor (ChordDescriptor &&chord_descr)
86 {
87 chords_.emplace_back (std::move (chord_descr));
88 chords_.back ().update_notes ();
89 }
90
91 void
92 replace_chord_descriptor (const auto index, ChordDescriptor &&chord_descr)
93 {
94 chords_.erase (chords_.begin () + index);
95 chords_.insert (chords_.begin () + index, std::move (chord_descr));
96 get_chord_at_index (index).update_notes ();
97 }
98
99private:
100 static constexpr auto kEditorSettingsKey = "editorSettings"sv;
101 static constexpr auto kChordsKey = "chords"sv;
102 friend void to_json (nlohmann::json &j, const ChordEditor &editor)
103 {
104 j[kEditorSettingsKey] = editor.editor_settings_;
105 j[kChordsKey] = editor.chords_;
106 }
107 friend void from_json (const nlohmann::json &j, ChordEditor &editor)
108 {
109 j.at (kEditorSettingsKey).get_to (editor.editor_settings_);
110 j.at (kChordsKey).get_to (editor.chords_);
111 }
112
113public:
120 std::vector<ChordDescriptor> chords_;
121
122private:
124};
125
126}
A preset of chord descriptors.
A ChordDescriptor describes a chord and is not linked to any specific object by itself.
Musical scale descriptor.
ScaleType
Scale type (name) eg Aeolian.
std::vector< ChordDescriptor > chords_
The chords to show on the left.
void init()
Initializes the ChordEditor.
ChordDescriptor * get_chord_from_note_number(midi_byte_t note_number)
Returns the ChordDescriptor for the given note number, otherwise NULL if the given note number is not...
A unique pointer for QObject objects that also works with QObject-based ownership.
Definition qt.h:38
uint8_t midi_byte_t
MIDI byte.
Definition types.h:55