Zrythm
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
region.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2018-2022 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
9#ifndef __AUDIO_REGION_H__
10#define __AUDIO_REGION_H__
11
13#include "dsp/chord_object.h"
14#include "dsp/midi_note.h"
15#include "dsp/position.h"
18#include "utils/yaml.h"
19
20#include <glib/gi18n.h>
21
22typedef struct Channel Channel;
23typedef struct Track Track;
24typedef struct MidiNote MidiNote;
25typedef struct TrackLane TrackLane;
26typedef struct RegionLinkGroup RegionLinkGroup;
27typedef struct Stretcher Stretcher;
28typedef struct AudioClip AudioClip;
29
36#define REGION_SCHEMA_VERSION 1
37
38#define REGION_MAGIC 93075327
39#define IS_REGION(x) (((ZRegion *) x)->magic == REGION_MAGIC)
40#define IS_REGION_AND_NONNULL(x) (x && IS_REGION (x))
41
42#define REGION_PRINTF_FILENAME "%s_%s.mid"
43
44#define region_is_selected(r) arranger_object_is_selected ((ArrangerObject *) r)
45
60
61static const cyaml_strval_t region_musical_mode_strings[] = {
62 {N_ ("Inherit"), REGION_MUSICAL_MODE_INHERIT},
63 { N_ ("Off"), REGION_MUSICAL_MODE_OFF },
64 { N_ ("On"), REGION_MUSICAL_MODE_ON },
65};
66
76typedef struct ZRegion
77{
82
85
87 char * name;
88
91
95 GdkRGBA color;
96
103
104 /* ==== MIDI REGION ==== */
105
110 int num_midi_notes;
111 size_t midi_notes_size;
112
128 int num_unended_notes;
129
130 /* ==== MIDI REGION END ==== */
131
132 /* ==== AUDIO REGION ==== */
133
137
144
149
152
157
159 float gain;
160
165
166#if 0
173 sample_t * frames;
174 size_t num_frames;
175
179 sample_t * ch_frames[16];
180#endif
181
184
187 int num_split_points;
188 size_t split_points_size;
189
190 /* ==== AUDIO REGION END ==== */
191
192 /* ==== AUTOMATION REGION ==== */
193
203 int num_aps;
204 size_t aps_size;
205
208
209 /* ==== AUTOMATION REGION END ==== */
210
211 /* ==== CHORD REGION ==== */
212
215 int num_chord_objects;
216 size_t chord_objects_size;
217
218 /* ==== CHORD REGION END ==== */
219
227
228 /* --- drawing caches --- */
229
230 /* New region drawing needs to be cached in the
231 * following situations:
232 *
233 * 1. when hidden part of the region is revealed
234 * (on x axis).
235 * TODO max 140% of the region should be
236 * cached (20% before and 20% after if before/
237 * after is not fully visible)
238 * 2. when full rect (x/width) changes
239 * 3. when a region marker is moved
240 * 4. when the clip actually changes (use
241 * last-change timestamp on the clip or region)
242 * 5. when fades change
243 * 6. when region height changes (track/lane)
244 */
245
247 PangoLayout * layout;
248
251 PangoLayout * chords_layout;
252
253 /* these are used for caching */
254 GdkRectangle last_main_full_rect;
255
258
259 /* these are used for caching */
260 GdkRectangle last_lane_full_rect;
261
264
268
271
275
276 /* --- drawing caches end --- */
277
278 int magic;
279} ZRegion;
280
284#define region_type_can_fade(rtype) (rtype == REGION_TYPE_AUDIO)
285
289void
291 ZRegion * region,
292 const Position * start_pos,
293 const Position * end_pos,
294 unsigned int track_name_hash,
295 int lane_pos,
296 int idx_inside_lane);
297
301HOT NONNULL ZRegion *
302region_find (const RegionIdentifier * const id);
303
304#if 0
305static inline void
306region_set_track_name_hash (
307 ZRegion * self,
308 unsigned int name_hash)
309{
310 self->id.track_name_hash = name_hash;
311}
312#endif
313
314NONNULL void
315region_print_to_str (const ZRegion * self, char * buf, const size_t buf_size);
316
322NONNULL void
323region_print (const ZRegion * region);
324
330TrackLane *
331region_get_lane (const ZRegion * region);
332
340
349void
350region_set_link_group (ZRegion * region, int group_idx, bool update_identifier);
351
352NONNULL bool
353region_has_link_group (ZRegion * region);
354
364MidiNote *
366
383NONNULL HOT signed_frame_t
385 const ZRegion * const self,
386 const signed_frame_t timeline_frames,
387 const bool normalize);
388
400NONNULL void
402 const ZRegion * const self,
403 const signed_frame_t timeline_frames,
404 signed_frame_t * ret_frames,
405 bool * is_loop);
406
412NONNULL void
413region_set_lane (ZRegion * self, const TrackLane * const lane);
414
422void
424 ZRegion * region,
425 const char * base_name,
426 AutomationTrack * at,
427 Track * track);
428
441NONNULL WARN_UNUSED_RESULT bool
442region_stretch (ZRegion * self, double ratio, GError ** error);
443
450NONNULL void
452
459NONNULL void
461
479void
481 ZRegion * region,
482 Track * track,
483 int lane_or_at_index,
484 int index);
485
490CONST
491static inline int
492region_type_has_lane (const RegionType type)
493{
494 return type == REGION_TYPE_MIDI || type == REGION_TYPE_AUDIO;
495}
496
502void
504
512
519void
521
534NONNULL PURE int
536 const ZRegion * region,
537 const signed_frame_t gframes,
538 const bool inclusive);
539
548int
550 const ZRegion * region,
551 const signed_frame_t gframes_start,
552 const signed_frame_t gframes_end,
553 const bool end_inclusive);
554
564NONNULL_ARGS (3)
566 const Track * track,
567 const AutomationTrack * at,
568 const Position * pos);
569
577char *
578region_generate_filename (ZRegion * region);
579
580void
581region_get_type_as_string (RegionType type, char * buf);
582
589bool
590region_is_recording (ZRegion * self);
591
600bool
601region_get_musical_mode (ZRegion * self);
602
608void
609region_add_arranger_object (
610 ZRegion * self,
611 ArrangerObject * obj,
612 bool fire_events);
613
614void
615region_create_link_group_if_none (ZRegion * region);
616
622void
623region_unlink (ZRegion * region);
624
630void
631region_remove_all_children (ZRegion * region);
632
637void
639
640NONNULL bool
641region_is_looped (const ZRegion * const self);
642
650region_get_arranger_selections (ZRegion * self);
651
658region_get_arranger_for_children (ZRegion * self);
659
668bool
669region_validate (ZRegion * self, bool is_project, double frames_per_tick);
670
679void
680region_disconnect (ZRegion * self);
681
686#endif // __AUDIO_REGION_H__
Macros for arranger object backends.
Automation point API.
Chord object in the TimelineArranger.
API for MIDI notes in the PianoRoll.
NONNULL_ARGS(1) int undo_manager_undo(UndoManager *self
Undo last action.
RegionLinkGroup * region_get_link_group(ZRegion *self)
Returns the region's link group.
PURE ZRegion * region_at_position(const Track *track, const AutomationTrack *at, const Position *pos)
Returns the region at the given position in the given Track.
NONNULL void region_update_link_group(ZRegion *self)
Updates all other regions in the region link group, if any.
NONNULL HOT signed_frame_t region_timeline_frames_to_local(const ZRegion *const self, const signed_frame_t timeline_frames, const bool normalize)
Converts frames on the timeline (global) to local frames (in the clip).
void region_copy_children(ZRegion *dest, ZRegion *src)
Clones and copies all children from src to dest.
NONNULL void region_print(const ZRegion *region)
Print region info for debugging.
NONNULL PURE int region_is_hit(const ZRegion *region, const signed_frame_t gframes, const bool inclusive)
Returns if the position is inside the region or not.
NONNULL WARN_UNUSED_RESULT bool region_stretch(ZRegion *self, double ratio, GError **error)
Stretch the region's contents.
void region_init(ZRegion *region, const Position *start_pos, const Position *end_pos, unsigned int track_name_hash, int lane_pos, int idx_inside_lane)
Only to be used by implementing structs.
int region_is_hit_by_range(const ZRegion *region, const signed_frame_t gframes_start, const signed_frame_t gframes_end, const bool end_inclusive)
Returns if any part of the ZRegion is inside the given range, inclusive.
NONNULL void region_get_frames_till_next_loop_or_end(const ZRegion *const self, const signed_frame_t timeline_frames, signed_frame_t *ret_frames, bool *is_loop)
Returns the number of frames until the next loop end point or the end of the region.
MidiNote * region_find_midi_note(ZRegion *r, MidiNote *_mn)
Returns the MidiNote matching the properties of the given MidiNote.
AutomationTrack * region_get_automation_track(const ZRegion *const region)
Gets the AutomationTrack using the saved index.
NONNULL void region_set_lane(ZRegion *self, const TrackLane *const lane)
Sets the track lane.
RegionMusicalMode
Musical mode setting for audio regions.
Definition region.h:50
RegionType
Type of Region.
void region_move_to_track(ZRegion *region, Track *track, int lane_or_at_index, int index)
Moves the ZRegion to the given Track, maintaining the selection status of the ZRegion.
TrackLane * region_get_lane(const ZRegion *region)
Get lane.
NONNULL void region_update_identifier(ZRegion *self)
To be called every time the identifier changes to update the region's children.
void region_gen_name(ZRegion *region, const char *base_name, AutomationTrack *at, Track *track)
Generates a name for the ZRegion, either using the given AutomationTrack or Track,...
void region_copy(ZRegion *src, ZRegion *dest)
Copies the data from src to dest.
HOT NONNULL ZRegion * region_find(const RegionIdentifier *const id)
Looks for the ZRegion matching the identifier.
void region_set_automation_track(ZRegion *region, AutomationTrack *at)
Sets the automation track.
void region_set_link_group(ZRegion *region, int group_idx, bool update_identifier)
Sets the link group to the region.
@ REGION_MUSICAL_MODE_ON
Musical mode on - auto-stretch when BPM changes.
Definition region.h:58
@ REGION_MUSICAL_MODE_OFF
Musical mode off - don't auto-stretch when BPM changes.
Definition region.h:55
@ REGION_MUSICAL_MODE_INHERIT
Inherit from global musical mode setting.
Definition region.h:52
int_fast64_t signed_frame_t
Signed type for frame index.
Definition types.h:55
float sample_t
The sample type.
Definition types.h:47
Position struct and API.
Region identifier.
Base struct for arranger objects.
The arranger widget is a canvas that draws all the arranger objects it contains.
Definition arranger.h:108
Audio clips for the pool.
Definition clip.h:33
An automation point inside an AutomationTrack.
A Channel is part of a Track (excluding Tracks that don't have Channels) and contains information rel...
Definition channel.h:61
A ChordObject to be shown in the TimelineArrangerWidget.
A MIDI note inside a ZRegion shown in the piano roll.
Definition midi_note.h:49
A Position is made up of bars.beats.sixteenths.ticks.
Definition position.h:129
Index/identifier for a Region, so we can get Region objects quickly with it without searching by name...
A group of linked regions.
Stretcher interface.
Definition stretcher.h:44
A TrackLane belongs to a Track (can have many TrackLanes in a Track) and contains Regions.
Definition track_lane.h:41
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
AutomationPoint * last_recorded_ap
Last recorded automation point.
Definition region.h:207
RegionIdentifier id
Unique ID.
Definition region.h:84
char * escaped_name
Escaped name for drawing.
Definition region.h:90
GdkRectangle last_main_draw_rect
Last main draw rect.
Definition region.h:257
int bounce
Set to ON during bouncing if this region should be included.
Definition region.h:226
ChordObject ** chord_objects
ChordObject's in this Region.
Definition region.h:214
gint64 last_clip_change
Last timestamp the audio clip or its contents changed.
Definition region.h:267
bool stretching
Whether currently running the stretching algorithm.
Definition region.h:143
MidiNote * unended_notes[12000]
Unended notes started in recording with MIDI NOTE ON signal but haven't received a NOTE OFF yet.
Definition region.h:127
AutomationPoint ** aps
The automation points this region contains.
Definition region.h:202
GdkRGBA color
Region color independent of track.
Definition region.h:95
ArrangerObject last_positions_obj
Last known marker positions (only positions are used).
Definition region.h:274
char * name
Name to be shown on the widget.
Definition region.h:87
PangoLayout * layout
Cache layout for drawing the name.
Definition region.h:247
GdkRectangle last_lane_draw_rect
Last lane draw rect.
Definition region.h:263
AudioClip * clip
Clip to read frames from, if not from the pool.
Definition region.h:164
int pool_id
Audio pool ID of the associated audio file, mostly used during serialization.
Definition region.h:136
double before_length
The length before stretching, in ticks.
Definition region.h:148
RegionMusicalMode musical_mode
Musical mode setting.
Definition region.h:183
float gain
Gain to apply to the audio (amplitude 0.0-2.0).
Definition region.h:159
Position * split_points
Array of split points.
Definition region.h:186
bool read_from_pool
Whether to read the clip from the pool (used in most cases).
Definition region.h:156
ArrangerObject base
Base struct.
Definition region.h:81
double stretch_ratio
Used during arranger UI overlay actions.
Definition region.h:151
gint64 last_cache_time
Last timestamp the region was cached.
Definition region.h:270
MidiNote ** midi_notes
MIDI notes.
Definition region.h:109
PangoLayout * chords_layout
Cache layout for drawing the chord names inside the region.
Definition region.h:251
bool use_color
Whether to use the custom color.
Definition region.h:102
YAML utils.