6#include "structure/arrangement/editor_settings.h"
7#include "utils/icloneable.h"
9namespace zrythm::structure::arrangement
14enum class MidiModifier
74class PianoRoll :
public QObject
80 getEditorSettings CONSTANT FINAL)
81 Q_PROPERTY (
int keyHeight READ getKeyHeight NOTIFY keyHeightChanged)
99 static constexpr std::array<bool, 12> BLACK_NOTES = {
100 false,
true,
false,
true,
false,
false,
101 true,
false,
true,
false,
true,
false
109 auto getEditorSettings ()
const {
return editor_settings_.get (); }
113 Q_SIGNAL
void keyHeightChanged ();
115 Q_INVOKABLE
int getKeyAtY (
double y)
const;
119 Q_INVOKABLE
static constexpr bool isBlackKey (
int note)
121 note = std::clamp (note, 0, 127);
122 return BLACK_NOTES.at (
static_cast<size_t> (note) % 12);
124 Q_INVOKABLE
static constexpr bool isWhiteKey (
int note)
129 Q_INVOKABLE
static constexpr bool isNextKeyBlack (
int note)
133 Q_INVOKABLE
static constexpr bool isNextKeyWhite (
int note)
135 return isWhiteKey (note + 1);
138 Q_INVOKABLE
static constexpr bool isPrevKeyBlack (
int note)
142 Q_INVOKABLE
static constexpr bool isPrevKeyWhite (
int note)
144 return isWhiteKey (note - 1);
164 void set_notes_zoom (
float notes_zoom,
bool fire_events);
189 for (
const auto i : std::views::iota (0_zu, 128_zu))
199 vec.push_back (*descr);
209 friend void init_from (
211 const PianoRoll &other,
214 obj.editor_settings_ =
215 utils::clone_unique_qobject (*other.editor_settings_, &obj);
219 static constexpr auto kEditorSettingsKey =
"editorSettings"sv;
220 static constexpr auto kNotesZoomKey =
"notesZoom"sv;
221 static constexpr auto kMidiModifierKey =
"midiModifier"sv;
222 friend void to_json (nlohmann::json &j,
const PianoRoll &piano_roll)
224 j[kEditorSettingsKey] = piano_roll.editor_settings_;
228 friend void from_json (
const nlohmann::json &j, PianoRoll &piano_roll)
230 j.at (kEditorSettingsKey).get_to (piano_roll.editor_settings_);
231 j.at (kNotesZoomKey).get_to (piano_roll.notes_zoom_);
232 j.at (kMidiModifierKey).get_to (piano_roll.midi_modifier_);
241 void init_descriptors ();
265 std::vector<MidiNoteDescriptor> (128);
281 std::vector<MidiNoteDescriptor> (128);
A descriptor for a MidiNote, used by the piano roll.
int value_
The actual value (0-127).
utils::Utf8String note_name_pango_
Note name with extra formatting.
bool visible_
Whether the note is visible or not.
int index_
The index to display the note at.
utils::Utf8String note_name_
Name of the note, from C-2 to B8.
utils::Utf8String custom_name_
Custom name, from midnam or GM MIDI specs, etc.
bool marked_
Whether the note is highlighted/marked or not.
Piano roll serializable backend.
Highlighting
Highlighting for the piano roll.
std::vector< MidiNoteDescriptor > drum_descriptors_
Drum mode descriptors.
const MidiNoteDescriptor * find_midi_note_descriptor_by_val(bool drum_mode, uint8_t val)
Returns the MidiNoteDescriptor matching the value (0-127).
void add_current_note(int note)
Adds the note if it doesn't exist in current_notes_.
int note_height_
Visual height per key in pixels.
void set_midi_modifier(MidiModifier modifier)
Sets the MIDI modifier.
std::vector< MidiNoteDescriptor > piano_descriptors_
Piano roll mode descriptors.
void get_visible_notes(bool drum_mode, std::vector< MidiNoteDescriptor > &vec)
Gets the visible notes.
float notes_zoom_
Notes zoom level.
void set_highlighting(Highlighting highlighting)
Updates the highlighting and notifies the UI.
static Q_INVOKABLE constexpr bool isBlackKey(int note)
Returns if the key is black.
bool contains_current_note(int note)
Returns whether the note exists in current_notes_.
void init()
Initializes the PianoRoll.
void remove_current_note(int note)
Removes the note if it exists in current_notes_.
Highlighting highlighting_
Highlighting notes depending on the current chord or scale.
std::vector< int > current_notes_
Currently pressed notes (used only at runtime).
MidiModifier midi_modifier_
Selected MidiModifier.
A unique pointer for QObject objects that also works with QObject-based ownership.
Lightweight UTF-8 string wrapper with safe conversions.