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
15#include <stdbool.h>
16
18
19#include <cyaml/cyaml.h>
20
21typedef struct Track Track;
22
29#define PIANO_ROLL_SCHEMA_VERSION 1
30
31#define PIANO_ROLL (CLIP_EDITOR->piano_roll)
32
33#define DRUM_LABELS \
34 static const char * drum_labels[47] = { \
35 "Acoustic Bass Drum", \
36 "Bass Drum 1", \
37 "Side Stick", \
38 "Acoustic Snare", \
39 "Hand Clap", \
40 "Electric Snare", \
41 "Low Floor Tom", \
42 "Closed Hi Hat", \
43 "High Floor Tom", \
44 "Pedal Hi-Hat", \
45 "Low Tom", \
46 "Open Hi-Hat", \
47 "Low-Mid Tom", \
48 "Hi-Mid Tom", \
49 "Crash Cymbal 1", \
50 "High Tom", \
51 "Ride Cymbal 1", \
52 "Chinese Cymbal", \
53 "Ride Bell", \
54 "Tambourine", \
55 "Splash Cymbal", \
56 "Cowbell", \
57 "Crash Cymbal 2", \
58 "Vibraslap", \
59 "Ride Cymbal 2", \
60 "Hi Bongo", \
61 "Low Bongo", \
62 "Mute Hi Conga", \
63 "Open Hi Conga", \
64 "Low Conga", \
65 "High Timbale", \
66 "Low Timbale", \
67 "High Agogo", \
68 "Low Agogo", \
69 "Cabasa", \
70 "Maracas", \
71 "Short Whistle", \
72 "Long Whistle", \
73 "Short Guiro", \
74 "Long Guiro", \
75 "Claves", \
76 "Hi Wood Block", \
77 "Low Wood Block", \
78 "Mute Cuica", \
79 "Open Cuica", \
80 "Mute Triangle", \
81 "Open Triangle" \
82 }
83
87typedef enum MidiModifier
88{
89 MIDI_MODIFIER_VELOCITY,
90 MIDI_MODIFIER_PITCH_WHEEL,
91 MIDI_MODIFIER_MOD_WHEEL,
92 MIDI_MODIFIER_AFTERTOUCH,
94
99{
100 PR_HIGHLIGHT_NONE,
101 PR_HIGHLIGHT_CHORD,
102 PR_HIGHLIGHT_SCALE,
103 PR_HIGHLIGHT_BOTH,
105
106typedef enum PianoRollNoteNotation
107{
108 PIANO_ROLL_NOTE_NOTATION_MUSICAL,
109 PIANO_ROLL_NOTE_NOTATION_PITCH,
110} PianoRollNoteNotation;
111
112typedef struct ZRegion ZRegion;
113
121typedef struct MidiNoteDescriptor
122{
126 int index;
127
133 int value;
134
137
144
146 char * note_name;
147
150
155
157midi_note_descriptor_new (void);
158
159void
160midi_note_descriptor_free (MidiNoteDescriptor * self);
161
167typedef struct PianoRoll
168{
169 int schema_version;
170
173
176
179 int num_current_notes;
180
188
194
204
205 EditorSettings editor_settings;
206} PianoRoll;
207
208static const cyaml_strval_t midi_modifier_strings[] = {
209 {"Velocity", MIDI_MODIFIER_VELOCITY },
210 { "Pitch Wheel", MIDI_MODIFIER_PITCH_WHEEL},
211 { "Mod Wheel", MIDI_MODIFIER_MOD_WHEEL },
212 { "Aftertouch", MIDI_MODIFIER_AFTERTOUCH },
213};
214
215static const cyaml_schema_field_t piano_roll_fields_schema[] = {
216 YAML_FIELD_INT (PianoRoll, schema_version),
217 YAML_FIELD_FLOAT (PianoRoll, notes_zoom),
218 YAML_FIELD_ENUM (PianoRoll, midi_modifier, midi_modifier_strings),
220 PianoRoll,
221 editor_settings,
222 editor_settings_fields_schema),
223
224 CYAML_FIELD_END
225};
226
227static const cyaml_schema_value_t piano_roll_schema = {
228 YAML_VALUE_PTR (PianoRoll, piano_roll_fields_schema),
229};
230
234int
236
237#define piano_roll_is_next_key_black(x) piano_roll_is_key_black (x + 1)
238
239#define piano_roll_is_prev_key_black(x) piano_roll_is_key_black (x - 1)
240
244void
246
250void
252
257int
259
264Track *
266
267void
268piano_roll_set_notes_zoom (PianoRoll * self, float notes_zoom, int fire_events);
269
274void
276
281const MidiNoteDescriptor *
283 PianoRoll * self,
284 bool drum_mode,
285 const uint8_t val);
286
287static inline char *
288midi_note_descriptor_get_custom_name (MidiNoteDescriptor * descr)
289{
290 return descr->custom_name;
291}
292
293void
294midi_note_descriptor_set_custom_name (MidiNoteDescriptor * descr, char * str);
295
299void
301 PianoRoll * self,
302 PianoRollHighlighting highlighting);
303
307void
309
313static inline void
314piano_roll_get_visible_notes (
315 PianoRoll * self,
316 bool drum_mode,
317 MidiNoteDescriptor * arr,
318 int * num)
319{
320 *num = 0;
321
322 MidiNoteDescriptor * descr;
323 for (int i = 0; i < 128; i++)
324 {
325 if (drum_mode)
326 descr = self->drum_descriptors[i];
327 else
328 descr = self->piano_descriptors[i];
329
330 if (descr->visible)
331 {
332 arr[*num].index = descr->index;
333 arr[*num].value = descr->value;
334 arr[*num].marked = descr->marked;
335 arr[*num].visible = descr->visible;
336 arr[*num].custom_name = descr->custom_name;
337 arr[*num].note_name = descr->note_name;
338 (*num)++;
339 }
340 }
341}
342
346void
348
352PianoRoll *
354
355PianoRoll *
356piano_roll_new (void);
357
358void
359piano_roll_free (PianoRoll * self);
360
365#endif
Common editor settings.
MidiModifier
A MIDI modifier to use to display data for.
Definition piano_roll.h:88
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:99
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.
#define YAML_FIELD_MAPPING_EMBEDDED(owner, member, schema)
Mapping embedded inside the struct.
Definition yaml.h:31
#define YAML_VALUE_PTR(cc, fields_schema)
Schema to be used as a pointer.
Definition yaml.h:202
Common editor settings.
A descriptor for a MidiNote, used by the piano roll.
Definition piano_roll.h:122
int index
The index to display the note at.
Definition piano_roll.h:126
char * note_name
Name of the note, from C-2 to B8.
Definition piano_roll.h:146
int visible
Whether the note is visible or not.
Definition piano_roll.h:136
int marked
Whether the note is highlighted/marked or not.
Definition piano_roll.h:153
char * custom_name
Custom name, from midnam or GM MIDI specs, etc.
Definition piano_roll.h:143
char * note_name_pango
Note name with extra formatting.
Definition piano_roll.h:149
int value
The actual value (0-127).
Definition piano_roll.h:133
Piano roll serializable backend.
Definition piano_roll.h:168
MidiNoteDescriptor * drum_descriptors[128]
Drum mode descriptors.
Definition piano_roll.h:203
int current_notes[128]
Currently pressed notes (used only at runtime).
Definition piano_roll.h:178
float notes_zoom
Notes zoom level.
Definition piano_roll.h:172
PianoRollHighlighting highlighting
Highlighting notes depending on the current chord or scale.
Definition piano_roll.h:193
MidiModifier midi_modifier
Selected MidiModifier.
Definition piano_roll.h:175
MidiNoteDescriptor * piano_descriptors[128]
Piano roll mode descriptors.
Definition piano_roll.h:187
Track to be inserted into the Project's Tracklist.
Definition track.h:186
A region (clip) is an object on the timeline that contains either MidiNote's or AudioClip's.
Definition region.h:77