Zrythm v2.0.0-alpha.1+31.4967fd053471
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
chord_pad_bank.h
1// SPDX-FileCopyrightText: © 2026 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/chord_preset.h"
8#include "dsp/musical_scale.h"
9#include "utils/midi.h"
10#include "utils/qt.h"
11
12#include <QAbstractListModel>
13#include <QtQmlIntegration/qqmlintegration.h>
14
15#include <farbot/RealtimeObject.hpp>
16#include <nlohmann/json_fwd.hpp>
17
18using namespace std::string_view_literals;
19
20namespace zrythm::structure::project
21{
22
32class ChordPadBank : public QAbstractListModel
33{
34 Q_OBJECT
35 QML_ELEMENT
36 QML_UNCREATABLE ("")
37
38public:
39 enum Roles
40 {
41 ChordDescriptorRole = Qt::UserRole + 1,
42 };
43
44 explicit ChordPadBank (QObject * parent = nullptr);
45
46 // ========================================================================
47 // QAbstractListModel interface
48 // ========================================================================
49
50 QHash<int, QByteArray> roleNames () const override;
51 int rowCount (const QModelIndex &parent = {}) const override;
52 QVariant data (const QModelIndex &index, int role) const override;
53
54 // ========================================================================
55 // QML Interface
56 // ========================================================================
57
58 void addChord (
59 dsp::MusicalNote root,
60 dsp::ChordType type,
61 dsp::ChordAccent accent = dsp::ChordAccent::None,
62 int inversion = 0,
63 std::optional<dsp::MusicalNote> bass = std::nullopt);
64
65 void insertChord (
66 int index,
67 dsp::MusicalNote root,
68 dsp::ChordType type,
69 dsp::ChordAccent accent = dsp::ChordAccent::None,
70 int inversion = 0,
71 std::optional<dsp::MusicalNote> bass = std::nullopt);
72
73 void removeChord (int index);
74
75 void moveChord (int from, int to);
76
77 void transposeChords (bool up);
78
79 void applyPresetFromScale (
81 dsp::MusicalNote root_note);
82
83 void applyPreset (ChordPreset * preset);
84
85 void apply_preset (const ChordPreset &preset);
86
87 // ========================================================================
88
98 std::optional<dsp::ChordDescriptor::ChordPitches>
99 get_pitches_for_note (midi_byte_t note_number) noexcept [[clang::nonblocking]];
100
101 Q_INVOKABLE dsp::ChordDescriptor * chordAt (int index);
102
103 friend void to_json (nlohmann::json &j, const ChordPadBank &bank);
104 friend void from_json (const nlohmann::json &j, ChordPadBank &bank);
105
106private:
107 static constexpr auto kChordsKey = "chords"sv;
108
114 struct ChordPadPlaybackData
115 {
116 struct Slot
117 {
118 bool has_chord = false;
120 };
121 std::array<Slot, 12> slots{};
122 };
123
124 void rebuild_playback_data ();
125 void connect_chord_signals ();
126 void connect_chord_signal (int index);
127
128 std::vector<zrythm::utils::QObjectUniquePtr<dsp::ChordDescriptor>> chords_;
129
130 farbot::RealtimeObject<
131 ChordPadPlaybackData,
132 farbot::RealtimeObjectOptions::nonRealtimeMutatable>
133 playback_data_;
134};
135
136}
A named collection of chord descriptors, optionally grouped by category.
Describes a musical chord by its root note, type, accent, inversion, and optional bass note.
ScaleType
Scale type (name) eg Aeolian.
std::optional< dsp::ChordDescriptor::ChordPitches > get_pitches_for_note(midi_byte_t note_number) noexcept
Returns the pre-computed MIDI pitches for a pad triggered by the given MIDI note number.
MIDI utils.
std::uint8_t midi_byte_t
MIDI byte.
Definition midi.h:43
Stack-allocated container for chord MIDI pitches.