Zrythm
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
piano_roll.h
Go to the documentation of this file.
1// clang-format off
2// SPDX-FileCopyrightText: © 2019-2021, 2023 Alexandros Theodotou <alex@zrythm.org>
3// SPDX-License-Identifier: LicenseRef-ZrythmLicense
4// clang-format on
5
12#ifndef __GUI_BACKEND_PIANO_ROLL_H__
13#define __GUI_BACKEND_PIANO_ROLL_H__
14
16
17typedef struct Track Track;
18
25#define PIANO_ROLL_SCHEMA_VERSION 1
26
27#define PIANO_ROLL (CLIP_EDITOR->piano_roll)
28
29#define DRUM_LABELS \
30 static const char * drum_labels[47] = { \
31 "Acoustic Bass Drum", \
32 "Bass Drum 1", \
33 "Side Stick", \
34 "Acoustic Snare", \
35 "Hand Clap", \
36 "Electric Snare", \
37 "Low Floor Tom", \
38 "Closed Hi Hat", \
39 "High Floor Tom", \
40 "Pedal Hi-Hat", \
41 "Low Tom", \
42 "Open Hi-Hat", \
43 "Low-Mid Tom", \
44 "Hi-Mid Tom", \
45 "Crash Cymbal 1", \
46 "High Tom", \
47 "Ride Cymbal 1", \
48 "Chinese Cymbal", \
49 "Ride Bell", \
50 "Tambourine", \
51 "Splash Cymbal", \
52 "Cowbell", \
53 "Crash Cymbal 2", \
54 "Vibraslap", \
55 "Ride Cymbal 2", \
56 "Hi Bongo", \
57 "Low Bongo", \
58 "Mute Hi Conga", \
59 "Open Hi Conga", \
60 "Low Conga", \
61 "High Timbale", \
62 "Low Timbale", \
63 "High Agogo", \
64 "Low Agogo", \
65 "Cabasa", \
66 "Maracas", \
67 "Short Whistle", \
68 "Long Whistle", \
69 "Short Guiro", \
70 "Long Guiro", \
71 "Claves", \
72 "Hi Wood Block", \
73 "Low Wood Block", \
74 "Mute Cuica", \
75 "Open Cuica", \
76 "Mute Triangle", \
77 "Open Triangle" \
78 }
79
83enum class MidiModifier
84{
85 MIDI_MODIFIER_VELOCITY,
86 MIDI_MODIFIER_PITCH_WHEEL,
87 MIDI_MODIFIER_MOD_WHEEL,
88 MIDI_MODIFIER_AFTERTOUCH,
89};
90
95{
96 PR_HIGHLIGHT_NONE,
97 PR_HIGHLIGHT_CHORD,
98 PR_HIGHLIGHT_SCALE,
99 PR_HIGHLIGHT_BOTH,
100};
101
102enum class PianoRollNoteNotation
103{
104 PIANO_ROLL_NOTE_NOTATION_MUSICAL,
105 PIANO_ROLL_NOTE_NOTATION_PITCH,
106};
107
108typedef struct Region Region;
109
117typedef struct MidiNoteDescriptor
118{
122 int index;
123
129 int value;
130
133
140
142 char * note_name;
143
146
151
153midi_note_descriptor_new (void);
154
155void
156midi_note_descriptor_free (MidiNoteDescriptor * self);
157
163typedef struct PianoRoll
164{
167
170
173 int num_current_notes;
174
182
188
198
199 EditorSettings editor_settings;
200} PianoRoll;
201
205int
207
208#define piano_roll_is_next_key_black(x) piano_roll_is_key_black (x + 1)
209
210#define piano_roll_is_prev_key_black(x) piano_roll_is_key_black (x - 1)
211
215void
217
221void
223
228int
230
235Track *
237
238void
239piano_roll_set_notes_zoom (PianoRoll * self, float notes_zoom, int fire_events);
240
245void
247
252const MidiNoteDescriptor *
254 PianoRoll * self,
255 bool drum_mode,
256 const uint8_t val);
257
258static inline char *
259midi_note_descriptor_get_custom_name (MidiNoteDescriptor * descr)
260{
261 return descr->custom_name;
262}
263
264void
265midi_note_descriptor_set_custom_name (MidiNoteDescriptor * descr, char * str);
266
270void
272 PianoRoll * self,
273 PianoRollHighlighting highlighting);
274
278void
280
284static inline void
285piano_roll_get_visible_notes (
286 PianoRoll * self,
287 bool drum_mode,
288 MidiNoteDescriptor * arr,
289 int * num)
290{
291 *num = 0;
292
293 MidiNoteDescriptor * descr;
294 for (int i = 0; i < 128; i++)
295 {
296 if (drum_mode)
297 descr = self->drum_descriptors[i];
298 else
299 descr = self->piano_descriptors[i];
300
301 if (descr->visible)
302 {
303 arr[*num].index = descr->index;
304 arr[*num].value = descr->value;
305 arr[*num].marked = descr->marked;
306 arr[*num].visible = descr->visible;
307 arr[*num].custom_name = descr->custom_name;
308 arr[*num].note_name = descr->note_name;
309 (*num)++;
310 }
311 }
312}
313
317void
319
323PianoRoll *
325
326PianoRoll *
327piano_roll_new (void);
328
329void
330piano_roll_free (PianoRoll * self);
331
336#endif
Common editor settings.
MidiModifier
A MIDI modifier to use to display data for.
Definition piano_roll.h:84
Track * piano_roll_get_current_track(const PianoRoll *self)
Returns the current track whose regions are being shown in the piano roll.
PianoRoll * piano_roll_clone(const PianoRoll *src)
Only clones what is needed for serialization.
int piano_roll_is_key_black(int note)
Returns if the key is black.
void piano_roll_set_midi_modifier(PianoRoll *self, MidiModifier modifier)
Sets the MIDI modifier.
void piano_roll_add_current_note(PianoRoll *self, int note)
Adds the note if it doesn't exist in the array.
int piano_roll_contains_current_note(PianoRoll *self, int note)
Returns 1 if it contains the given note, 0 otherwise.
const MidiNoteDescriptor * piano_roll_find_midi_note_descriptor_by_val(PianoRoll *self, bool drum_mode, const uint8_t val)
Returns the MidiNoteDescriptor matching the value (0-127).
PianoRollHighlighting
Highlighting for the piano roll.
Definition piano_roll.h:95
void piano_roll_remove_current_note(PianoRoll *self, int note)
Removes the note if it exists in the array.
void piano_roll_init_loaded(PianoRoll *self)
Inits the PianoRoll after a Project has been loaded.
void piano_roll_init(PianoRoll *self)
Initializes the PianoRoll.
void piano_roll_set_highlighting(PianoRoll *self, PianoRollHighlighting highlighting)
Updates the highlighting and notifies the UI.
Common editor settings.
A descriptor for a MidiNote, used by the piano roll.
Definition piano_roll.h:118
int index
The index to display the note at.
Definition piano_roll.h:122
char * note_name
Name of the note, from C-2 to B8.
Definition piano_roll.h:142
int visible
Whether the note is visible or not.
Definition piano_roll.h:132
int marked
Whether the note is highlighted/marked or not.
Definition piano_roll.h:149
char * custom_name
Custom name, from midnam or GM MIDI specs, etc.
Definition piano_roll.h:139
char * note_name_pango
Note name with extra formatting.
Definition piano_roll.h:145
int value
The actual value (0-127).
Definition piano_roll.h:129
Piano roll serializable backend.
Definition piano_roll.h:164
MidiNoteDescriptor * drum_descriptors[128]
Drum mode descriptors.
Definition piano_roll.h:197
int current_notes[128]
Currently pressed notes (used only at runtime).
Definition piano_roll.h:172
float notes_zoom
Notes zoom level.
Definition piano_roll.h:166
PianoRollHighlighting highlighting
Highlighting notes depending on the current chord or scale.
Definition piano_roll.h:187
MidiModifier midi_modifier
Selected MidiModifier.
Definition piano_roll.h:169
MidiNoteDescriptor * piano_descriptors[128]
Piano roll mode descriptors.
Definition piano_roll.h:181
A region (clip) is an object on the timeline that contains either MidiNote's or AudioClip's.
Definition region.h:72
Track to be inserted into the Project's Tracklist.
Definition track.h:177