6#include "structure/arrangement/editor_settings.h"
7#include "utils/icloneable.h"
8#include "utils/utf8_string.h"
10namespace zrythm::structure::arrangement
15enum class MidiModifier
75class PianoRoll :
public QObject
81 getEditorSettings CONSTANT FINAL)
82 Q_PROPERTY (
int keyHeight READ getKeyHeight NOTIFY keyHeightChanged)
100 static constexpr std::array<bool, 12> BLACK_NOTES = {
101 false,
true,
false,
true,
false,
false,
102 true,
false,
true,
false,
true,
false
110 auto getEditorSettings ()
const {
return editor_settings_.get (); }
114 Q_SIGNAL
void keyHeightChanged ();
116 Q_INVOKABLE
int getKeyAtY (
double y)
const;
120 Q_INVOKABLE
static constexpr bool isBlackKey (
int note)
122 note = std::clamp (note, 0, 127);
123 return BLACK_NOTES.at (
static_cast<size_t> (note) % 12);
125 Q_INVOKABLE
static constexpr bool isWhiteKey (
int note)
130 Q_INVOKABLE
static constexpr bool isNextKeyBlack (
int note)
134 Q_INVOKABLE
static constexpr bool isNextKeyWhite (
int note)
136 return isWhiteKey (note + 1);
139 Q_INVOKABLE
static constexpr bool isPrevKeyBlack (
int note)
143 Q_INVOKABLE
static constexpr bool isPrevKeyWhite (
int note)
145 return isWhiteKey (note - 1);
165 void set_notes_zoom (
float notes_zoom,
bool fire_events);
190 for (
const auto i : std::views::iota (0zu, 128zu))
200 vec.push_back (*descr);
210 friend void init_from (
212 const PianoRoll &other,
215 obj.editor_settings_ =
216 utils::clone_unique_qobject (*other.editor_settings_, &obj);
220 static constexpr auto kEditorSettingsKey =
"editorSettings"sv;
221 static constexpr auto kNotesZoomKey =
"notesZoom"sv;
222 static constexpr auto kMidiModifierKey =
"midiModifier"sv;
223 friend void to_json (nlohmann::json &j,
const PianoRoll &piano_roll);
224 friend void from_json (
const nlohmann::json &j,
PianoRoll &piano_roll);
232 void init_descriptors ();
256 std::vector<MidiNoteDescriptor> (128);
272 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.