6#include "structure/project/editor_settings.h"
7#include "utils/utf8_string.h"
9#include <QtQmlIntegration/qqmlintegration.h>
11#include <nlohmann/json_fwd.hpp>
13namespace zrythm::structure::project
19enum class MidiModifier
79class MidiEditor :
public EditorSettings
83 Q_PROPERTY (
int keyHeight READ keyHeight NOTIFY keyHeightChanged)
102 static constexpr std::array<bool, 12> BLACK_NOTES = {
103 false,
true,
false,
true,
false,
false,
104 true,
false,
true,
false,
true,
false
114 Q_SIGNAL
void keyHeightChanged ();
116 Q_INVOKABLE
int getKeyAtY (
double y)
const;
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);
185 for (
const auto i : std::views::iota (0zu, 128zu))
195 vec.push_back (*descr);
206 friend void init_from (
208 const MidiEditor &other,
210 friend void to_json (nlohmann::json &j,
const MidiEditor &midi_editor);
211 friend void from_json (
const nlohmann::json &j, MidiEditor &midi_editor);
214 static constexpr auto kNotesZoomKey =
"notesZoom"sv;
215 static constexpr auto kMidiModifierKey =
"midiModifier"sv;
223 void init_descriptors ();
245 std::vector<MidiNoteDescriptor> (128);
256 std::vector<MidiNoteDescriptor> (128);
MIDI editor serializable backend.
static Q_INVOKABLE constexpr bool isBlackKey(int note)
Returns if the key is black.
int note_height_
Visual height per key in pixels.
void init()
Initializes the MidiEditor.
Highlighting
Highlighting for the piano roll.
float notes_zoom_
Notes zoom level.
void add_current_note(int note)
Adds the note if it doesn't exist in current_notes_.
const MidiNoteDescriptor * find_midi_note_descriptor_by_val(bool drum_mode, uint8_t val)
Returns the MidiNoteDescriptor matching the value (0-127).
void set_midi_modifier(MidiModifier modifier)
Sets the MIDI modifier.
MidiModifier midi_modifier_
Selected MidiModifier.
void get_visible_notes(bool drum_mode, std::vector< MidiNoteDescriptor > &vec)
Gets the visible notes.
void remove_current_note(int note)
Removes the note if it exists in current_notes_.
std::vector< MidiNoteDescriptor > drum_descriptors_
Drum mode descriptors.
bool contains_current_note(int note)
Returns whether the note exists in current_notes_.
std::vector< MidiNoteDescriptor > piano_descriptors_
Piano roll mode descriptors.
std::vector< int > current_notes_
Currently pressed notes (used only at runtime).
A descriptor for a MidiNote, used by the piano roll.
int index_
The index to display the note at.
utils::Utf8String note_name_pango_
Note name with extra formatting.
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.
int value_
The actual value (0-127).
bool marked_
Whether the note is highlighted/marked or not.
bool visible_
Whether the note is visible or not.
Lightweight UTF-8 string wrapper with safe conversions.