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#include "utils/midi.h"
11
12class ChordPreset;
13
14namespace zrythm::structure::arrangement
15{
16
17constexpr int CHORD_EDITOR_NUM_CHORDS = 12;
18
22class ChordEditor : public QObject
23{
24 Q_OBJECT
25 Q_PROPERTY (
27 getEditorSettings CONSTANT FINAL)
28 QML_ELEMENT
29 QML_UNCREATABLE ("")
30
31public:
32 using ChordDescriptor = dsp::ChordDescriptor;
33 using ChordAccent = dsp::ChordAccent;
34 using ChordType = dsp::ChordType;
35 using MusicalScale = dsp::MusicalScale;
36 using MusicalNote = dsp::MusicalNote;
37
38 ChordEditor (QObject * parent = nullptr);
39
40 // =========================================================
41 // QML interface
42 // =========================================================
43
44 auto getEditorSettings () const { return editor_settings_.get (); }
45
46 // =========================================================
47
51 void init ();
52
53 void
54 apply_single_chord (const ChordDescriptor &chord, int idx, bool undoable);
55
56 void apply_chords (const std::vector<ChordDescriptor> &chords, bool undoable);
57
58 void apply_preset_from_scale (
60 MusicalNote root_note,
61 bool undoable);
62
63 void transpose_chords (bool up, bool undoable);
64
69 ChordDescriptor * get_chord_from_note_number (midi_byte_t note_number);
70
71 int get_chord_index (const ChordDescriptor &chord) const;
72
73 auto &get_chord_at_index (size_t index) { return chords_.at (index); }
74 auto &get_chord_at_index (size_t index) const { return chords_.at (index); }
75
76 friend void init_from (
77 ChordEditor &obj,
78 const ChordEditor &other,
79 utils::ObjectCloneType clone_type)
80
81 {
82 obj.editor_settings_ =
83 utils::clone_unique_qobject (*other.editor_settings_, &obj);
84 }
85
86 void add_chord_descriptor (ChordDescriptor &&chord_descr)
87 {
88 chords_.emplace_back (std::move (chord_descr));
89 chords_.back ().update_notes ();
90 }
91
92 void
93 replace_chord_descriptor (const auto index, ChordDescriptor &&chord_descr)
94 {
95 chords_.erase (chords_.begin () + index);
96 chords_.insert (chords_.begin () + index, std::move (chord_descr));
97 get_chord_at_index (index).update_notes ();
98 }
99
100private:
101 static constexpr auto kEditorSettingsKey = "editorSettings"sv;
102 static constexpr auto kChordsKey = "chords"sv;
103 friend void to_json (nlohmann::json &j, const ChordEditor &editor);
104 friend void from_json (const nlohmann::json &j, ChordEditor &editor);
105
106public:
113 std::vector<ChordDescriptor> chords_;
114
115private:
117};
118
119}
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:36
MIDI utils.
std::uint8_t midi_byte_t
MIDI byte.
Definition midi.h:43