Zrythm v2.0.0-alpha.1+31.4967fd053471
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
chord_pad_commands.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 "structure/project/chord_pad_bank.h"
8
9#include <QUndoCommand>
10
11namespace zrythm::commands
12{
13
15{
16 dsp::MusicalNote rootNote = dsp::MusicalNote::C;
17 dsp::ChordType type = dsp::ChordType::None;
18 dsp::ChordAccent accent = dsp::ChordAccent::None;
19 int inversion = 0;
20 std::optional<dsp::MusicalNote> bass = std::nullopt;
21
22 static ChordPadState from_descriptor (const dsp::ChordDescriptor &d)
23 {
24 return {
25 d.rootNote (), d.chordType (), d.chordAccent (), d.inversion (),
26 d.hasBass () ? std::optional (d.bassNote ()) : std::nullopt
27 };
28 }
29
30 void apply_to (dsp::ChordDescriptor &d) const
31 {
32 d.setRootNote (rootNote);
33 d.setChordType (type);
34 d.setChordAccent (accent);
35 d.setInversion (inversion);
36 if (bass.has_value ())
37 {
38 d.setBassNote (*bass);
39 }
40 else
41 {
42 d.setHasBass (false);
43 }
44 }
45
46 bool operator== (const ChordPadState &other) const = default;
47};
48
49class EditChordPadCommand : public QUndoCommand
50{
51public:
52 EditChordPadCommand (
54 int index,
55 ChordPadState after)
56 : QUndoCommand (QObject::tr ("Edit Chord Pad")), bank_ (bank),
57 index_ (index),
58 before_ (ChordPadState::from_descriptor (*bank.chordAt (index))),
59 after_ (std::move (after))
60 {
61 }
62
63 void undo () override { before_.apply_to (*bank_.chordAt (index_)); }
64 void redo () override { after_.apply_to (*bank_.chordAt (index_)); }
65
66private:
68 int index_;
69 ChordPadState before_;
70 ChordPadState after_;
71};
72
73class AddChordPadCommand : public QUndoCommand
74{
75public:
76 AddChordPadCommand (structure::project::ChordPadBank &bank, ChordPadState state)
77 : QUndoCommand (QObject::tr ("Add Chord Pad")), bank_ (bank),
78 state_ (std::move (state))
79 {
80 }
81
82 void redo () override;
83 void undo () override;
84
85private:
87 ChordPadState state_;
88};
89
90class RemoveChordPadCommand : public QUndoCommand
91{
92public:
93 RemoveChordPadCommand (structure::project::ChordPadBank &bank, int index)
94 : QUndoCommand (QObject::tr ("Remove Chord Pad")), bank_ (bank),
95 index_ (index),
96 state_ (ChordPadState::from_descriptor (*bank.chordAt (index)))
97 {
98 }
99
100 void redo () override;
101 void undo () override;
102
103private:
105 int index_;
106 ChordPadState state_;
107};
108
109class MoveChordPadCommand : public QUndoCommand
110{
111public:
112 MoveChordPadCommand (structure::project::ChordPadBank &bank, int from, int to)
113 : QUndoCommand (QObject::tr ("Move Chord Pad")), bank_ (bank),
114 from_ (from), to_ (to)
115 {
116 }
117
118 void redo () override;
119 void undo () override;
120
121private:
123 int from_;
124 int to_;
125};
126
127class ReplaceAllChordPadsCommand : public QUndoCommand
128{
129public:
130 ReplaceAllChordPadsCommand (
132 std::vector<ChordPadState> after,
133 const QString &text = QObject::tr ("Replace Chord Pads"))
134 : QUndoCommand (text), bank_ (bank), after_ (std::move (after))
135 {
136 const auto count = bank.rowCount ();
137 before_.reserve (count);
138 for (int i = 0; i < count; ++i)
139 {
140 before_.push_back (ChordPadState::from_descriptor (*bank.chordAt (i)));
141 }
142 }
143
144 void redo () override;
145 void undo () override;
146
147private:
148 static void apply_states (
150 const std::vector<ChordPadState> &states);
151
153 std::vector<ChordPadState> before_;
154 std::vector<ChordPadState> after_;
155};
156
157} // namespace zrythm::commands
Describes a musical chord by its root note, type, accent, inversion, and optional bass note.
A list model of chord descriptors for the chord pad panel.