Zrythm
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
midi_note.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2018-2023 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
10#ifndef __AUDIO_MIDI_NOTE_H__
11#define __AUDIO_MIDI_NOTE_H__
12
13#include <stdint.h>
14
15#include "dsp/midi_region.h"
16#include "dsp/position.h"
17#include "dsp/velocity.h"
19
20typedef struct _MidiNoteWidget MidiNoteWidget;
21typedef struct Channel Channel;
22typedef struct Track Track;
23typedef struct MidiEvents MidiEvents;
24typedef struct Position Position;
25typedef struct Velocity Velocity;
26typedef enum PianoRollNoteNotation PianoRollNoteNotation;
27
34#define MIDI_NOTE_SCHEMA_VERSION 1
35
36#define MIDI_NOTE_MAGIC 3588791
37#define IS_MIDI_NOTE(tr) \
38 ((MidiNote *) tr \
39 && ((MidiNote *) tr)->magic == MIDI_NOTE_MAGIC)
40
41#define midi_note_is_selected(r) \
42 arranger_object_is_selected ((ArrangerObject *) r)
43
49typedef struct MidiNote
50{
53
54 int schema_version;
55
58
60 uint8_t val;
61
63 uint8_t cache_val;
64
66 int muted;
67
71
75
77 int pos;
78
79 int magic;
80
82 PangoLayout * layout;
83} MidiNote;
84
85static const cyaml_schema_field_t midi_note_fields_schema[] = {
88 base,
89 arranger_object_fields_schema),
90 YAML_FIELD_INT (MidiNote, schema_version),
91 YAML_FIELD_MAPPING_PTR (MidiNote, vel, velocity_fields_schema),
92 YAML_FIELD_UINT (MidiNote, val),
93 YAML_FIELD_INT (MidiNote, muted),
94 YAML_FIELD_INT (MidiNote, pos),
95 CYAML_FIELD_END
96};
97
98static const cyaml_schema_value_t midi_note_schema = {
99 /* allow nullable for mn_r1 in
100 * ArrangerSelectionsAction */
101 YAML_VALUE_PTR_NULLABLE (MidiNote, midi_note_fields_schema),
102};
103
110void
112 MidiNote * self,
113 Position * pos);
114
118MidiNote *
120 RegionIdentifier * region_id,
121 Position * start_pos,
122 Position * end_pos,
123 uint8_t val,
124 uint8_t vel);
125
129void
131 MidiNote * self,
132 ZRegion * region,
133 int idx);
134
135void
136midi_note_set_cache_val (MidiNote * self, const uint8_t val);
137
141NONNULL PURE int
143
150void
152 const MidiNote * self,
153 char * buf,
154 PianoRollNoteNotation notation,
155 const int use_markup);
156
160void
162
169void
170midi_note_listen (MidiNote * mn, bool listen);
171
177void
178midi_note_shift_pitch (MidiNote * self, const int delta);
179
184int
185midi_note_hit (MidiNote * self, const signed_frame_t gframes);
186
195void
197 MidiNote ** midi_notes,
198 int num_notes,
199 Position * pos,
200 MidiEvents * events);
201
206void
207midi_note_set_val (MidiNote * midi_note, const uint8_t val);
208
209ZRegion *
210midi_note_get_region (MidiNote * self);
211
216#endif // __AUDIO_MIDI_NOTE_H__
Macros for arranger object backends.
Velocities for MidiNote's.
void midi_note_listen(MidiNote *mn, bool listen)
Listen to the given MidiNote.
int midi_note_hit(MidiNote *self, const signed_frame_t gframes)
Returns if the MIDI note is hit at given pos (in the timeline).
void midi_note_notes_to_events(MidiNote **midi_notes, int num_notes, Position *pos, MidiEvents *events)
Converts an array of MIDI notes to MidiEvents.
NONNULL PURE int midi_note_is_equal(MidiNote *src, MidiNote *dest)
Returns 1 if the MidiNotes match, 0 if not.
void midi_note_shift_pitch(MidiNote *self, const int delta)
Shifts MidiNote's position and/or value.
MidiNote * midi_note_new(RegionIdentifier *region_id, Position *start_pos, Position *end_pos, uint8_t val, uint8_t vel)
Creates a new MidiNote.
void midi_note_set_region_and_index(MidiNote *self, ZRegion *region, int idx)
Sets the region the MidiNote belongs to.
void midi_note_get_val_as_string(const MidiNote *self, char *buf, PianoRollNoteNotation notation, const int use_markup)
Gets the MIDI note's value as a string (eg "C#4").
void midi_note_print(MidiNote *mn)
For debugging.
void midi_note_get_global_start_pos(MidiNote *self, Position *pos)
Gets the global Position of the MidiNote's start_pos.
void midi_note_set_val(MidiNote *midi_note, const uint8_t val)
Sends a note off if currently playing and sets the pitch of the MidiNote.
#define YAML_FIELD_MAPPING_EMBEDDED(owner, member, schema)
Mapping embedded inside the struct.
Definition yaml.h:32
int_fast64_t signed_frame_t
Signed type for frame index.
Definition types.h:54
#define YAML_FIELD_MAPPING_PTR(owner, member, schema)
Mapping pointer to a struct.
Definition yaml.h:39
#define YAML_VALUE_PTR_NULLABLE(cc, fields_schema)
Schema to be used as a pointer that can be NULL.
Definition yaml.h:228
API for Region's specific to instrument Track's.
Position struct and API.
Base struct for arranger objects.
A Channel is part of a Track (excluding Tracks that don't have Channels) and contains information rel...
Definition channel.h:63
Container for passing midi events through ports.
Definition midi_event.h:68
A MIDI note inside a ZRegion shown in the piano roll.
Definition midi_note.h:50
uint8_t last_listened_val
The note/pitch that is currently playing, if MidiNote::currently_listened is true.
Definition midi_note.h:74
Velocity * vel
Velocity.
Definition midi_note.h:57
int muted
Muted or not.
Definition midi_note.h:66
uint8_t cache_val
Cached note, for live operations.
Definition midi_note.h:63
uint8_t val
The note/pitch, (0-127).
Definition midi_note.h:60
PangoLayout * layout
Cache layout for drawing the name.
Definition midi_note.h:82
int pos
Index in the parent region.
Definition midi_note.h:77
ArrangerObject base
Base struct.
Definition midi_note.h:52
int currently_listened
Whether or not this note is currently listened to.
Definition midi_note.h:70
A Position is made up of bars.beats.sixteenths.ticks.
Definition position.h:137
Index/identifier for a Region, so we can get Region objects quickly with it without searching by name...
Track to be inserted into the Project's Tracklist.
Definition track.h:193
The MidiNote velocity.
Definition velocity.h:45
A region (clip) is an object on the timeline that contains either MidiNote's or AudioClip's.
Definition region.h:78