Zrythm v2.0.0-alpha.1+31.4967fd053471
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
chord_suggestion_provider.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_suggestion.h"
8#include "dsp/musical_scale.h"
9
10#include <QObject>
11#include <QPointer>
12#include <QTimer>
13#include <QVariantList>
14#include <QtQmlIntegration/qqmlintegration.h>
15
16namespace zrythm::gui::qquick
17{
18
19class ChordSuggestionProvider : public QObject
20{
21 Q_OBJECT
22 QML_ELEMENT
23
24 Q_PROPERTY (
25 zrythm::dsp::ChordDescriptor * currentChord READ currentChord WRITE
26 setCurrentChord NOTIFY currentChordChanged)
27 Q_PROPERTY (
28 zrythm::dsp::MusicalScale * currentScale READ currentScale WRITE
29 setCurrentScale NOTIFY currentScaleChanged)
30 Q_PROPERTY (
31 bool includeSevenths READ includeSevenths WRITE setIncludeSevenths NOTIFY
32 categoriesChanged)
33 Q_PROPERTY (
34 bool includeSecondaryDominants READ includeSecondaryDominants WRITE
35 setIncludeSecondaryDominants NOTIFY categoriesChanged)
36 Q_PROPERTY (
37 bool includeBorrowedChords READ includeBorrowedChords WRITE
38 setIncludeBorrowedChords NOTIFY categoriesChanged)
39 Q_PROPERTY (
40 QVariantList topSuggestions READ topSuggestions NOTIFY suggestionsChanged)
41 Q_PROPERTY (
42 int maxSuggestions READ maxSuggestions WRITE setMaxSuggestions NOTIFY
43 maxSuggestionsChanged)
44
45public:
46 explicit ChordSuggestionProvider (QObject * parent = nullptr);
47
48 zrythm::dsp::ChordDescriptor * currentChord () const
49 {
50 return current_chord_.data ();
51 }
52 void setCurrentChord (zrythm::dsp::ChordDescriptor * chord);
53
55 Q_INVOKABLE void clearSuggestions ();
56
58 Q_INVOKABLE void scheduleClear ();
59
60 zrythm::dsp::MusicalScale * currentScale () const
61 {
62 return current_scale_.data ();
63 }
64 void setCurrentScale (zrythm::dsp::MusicalScale * scale);
65
66 bool includeSevenths () const { return include_sevenths_; }
67 void setIncludeSevenths (bool v);
68
69 bool includeSecondaryDominants () const
70 {
71 return include_secondary_dominants_;
72 }
73 void setIncludeSecondaryDominants (bool v);
74
75 bool includeBorrowedChords () const { return include_borrowed_chords_; }
76 void setIncludeBorrowedChords (bool v);
77
78 QVariantList topSuggestions () const { return top_suggestions_; }
79
80 int maxSuggestions () const { return max_suggestions_; }
81 void setMaxSuggestions (int v);
82
83 Q_INVOKABLE float scoreForChord (zrythm::dsp::ChordDescriptor * chord) const;
84
85 Q_SIGNAL void currentChordChanged ();
86 Q_SIGNAL void currentScaleChanged ();
87 Q_SIGNAL void categoriesChanged ();
88 Q_SIGNAL void suggestionsChanged ();
89 Q_SIGNAL void maxSuggestionsChanged ();
90
91private:
92 void recalculate ();
93
94 QPointer<zrythm::dsp::ChordDescriptor> current_chord_;
95 QPointer<zrythm::dsp::MusicalScale> current_scale_;
96 bool include_sevenths_ = false;
97 bool include_secondary_dominants_ = false;
98 bool include_borrowed_chords_ = false;
99
100 std::vector<zrythm::dsp::chords::ChordSuggestion> cached_suggestions_;
101 QVariantList top_suggestions_;
102 int max_suggestions_ = 5;
103 QTimer auto_clear_timer_;
104};
105
106} // namespace zrythm::gui::qquick
Describes a musical chord by its root note, type, accent, inversion, and optional bass note.
Musical scale descriptor.
Q_INVOKABLE void clearSuggestions()
Clears suggestions (called by auto-clear timer).
Q_INVOKABLE void scheduleClear()
Starts the auto-clear countdown (call when the pad is released).