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_MAGIC 93075327
37#define IS_REGION(x) (((Region *) x)->magic == REGION_MAGIC)
38#define IS_REGION_AND_NONNULL(x) (x && IS_REGION (x))
39
40#define REGION_PRINTF_FILENAME "%s_%s.mid"
41
42#define region_is_selected(r) arranger_object_is_selected ((ArrangerObject *) r)
43
58
59const char *
60region_musical_mode_to_str (RegionMusicalMode mode);
61
71typedef struct Region
72{
77
80
82 char * name;
83
86
90 GdkRGBA color;
91
98
99 /* ==== MIDI REGION ==== */
100
105 int num_midi_notes;
106 size_t midi_notes_size;
107
123 int num_unended_notes;
124
125 /* ==== MIDI REGION END ==== */
126
127 /* ==== AUDIO REGION ==== */
128
132
139
144
147
152
154 float gain;
155
160
161#if 0
168 sample_t * frames;
169 size_t num_frames;
170
174 sample_t * ch_frames[16];
175#endif
176
179
182 int num_split_points;
183 size_t split_points_size;
184
185 /* ==== AUDIO REGION END ==== */
186
187 /* ==== AUTOMATION REGION ==== */
188
198 int num_aps;
199 size_t aps_size;
200
203
204 /* ==== AUTOMATION REGION END ==== */
205
206 /* ==== CHORD REGION ==== */
207
210 int num_chord_objects;
211 size_t chord_objects_size;
212
213 /* ==== CHORD REGION END ==== */
214
222
223 /* --- drawing caches --- */
224
225 /* New region drawing needs to be cached in the
226 * following situations:
227 *
228 * 1. when hidden part of the region is revealed
229 * (on x axis).
230 * TODO max 140% of the region should be
231 * cached (20% before and 20% after if before/
232 * after is not fully visible)
233 * 2. when full rect (x/width) changes
234 * 3. when a region marker is moved
235 * 4. when the clip actually changes (use
236 * last-change timestamp on the clip or region)
237 * 5. when fades change
238 * 6. when region height changes (track/lane)
239 */
240
242 PangoLayout * layout;
243
246 PangoLayout * chords_layout;
247
248 /* these are used for caching */
249 GdkRectangle last_main_full_rect;
250
253
254 /* these are used for caching */
255 GdkRectangle last_lane_full_rect;
256
259
263
266
270
271 /* --- drawing caches end --- */
272
273 TrackLane * owner_lane = nullptr;
274
275 int magic;
276} Region;
277
281#define region_type_can_fade(rtype) (rtype == RegionType::REGION_TYPE_AUDIO)
282
286void
288 Region * region,
289 const Position * start_pos,
290 const Position * end_pos,
291 unsigned int track_name_hash,
292 int lane_pos,
293 int idx_inside_lane);
294
298HOT NONNULL Region *
299region_find (const RegionIdentifier * const id);
300
301#if 0
302static inline void
303region_set_track_name_hash (
304 Region * self,
305 unsigned int name_hash)
306{
307 self->id.track_name_hash = name_hash;
308}
309#endif
310
311NONNULL void
312region_print_to_str (const Region * self, char * buf, const size_t buf_size);
313
319NONNULL void
320region_print (const Region * region);
321
327TrackLane *
328region_get_lane (const Region * region);
329
337
346void
347region_set_link_group (Region * region, int group_idx, bool update_identifier);
348
349NONNULL bool
350region_has_link_group (Region * region);
351
361MidiNote *
363
380NONNULL HOT signed_frame_t
382 const Region * const self,
383 const signed_frame_t timeline_frames,
384 const bool normalize);
385
397NONNULL void
399 const Region * const self,
400 const signed_frame_t timeline_frames,
401 signed_frame_t * ret_frames,
402 bool * is_loop);
403
409NONNULL void
411
419void
421 Region * region,
422 const char * base_name,
423 AutomationTrack * at,
424 Track * track);
425
438NONNULL WARN_UNUSED_RESULT bool
439region_stretch (Region * self, double ratio, GError ** error);
440
447NONNULL void
449
456NONNULL void
458
476void
478 Region * region,
479 Track * track,
480 int lane_or_at_index,
481 int index);
482
487CONST
488static inline int
489region_type_has_lane (const RegionType type)
490{
491 return type == RegionType::REGION_TYPE_MIDI
492 || type == RegionType::REGION_TYPE_AUDIO;
493}
494
500void
502
509region_get_automation_track (const Region * const region);
510
517void
518region_copy (Region * src, Region * dest);
519
532NONNULL int
534 const Region * region,
535 const signed_frame_t gframes,
536 const bool inclusive);
537
546int
548 const Region * region,
549 const signed_frame_t gframes_start,
550 const signed_frame_t gframes_end,
551 const bool end_inclusive);
552
562NONNULL_ARGS (3)
564 const Track * track,
565 const AutomationTrack * at,
566 const Position * pos);
567
575char *
576region_generate_filename (Region * region);
577
578void
579region_get_type_as_string (RegionType type, char * buf);
580
587bool
588region_is_recording (Region * self);
589
598bool
599region_get_musical_mode (Region * self);
600
606void
607region_add_arranger_object (Region * self, ArrangerObject * obj, bool fire_events);
608
609void
610region_create_link_group_if_none (Region * region);
611
617void
618region_unlink (Region * region);
619
625void
626region_remove_all_children (Region * region);
627
632void
634
635NONNULL bool
636region_is_looped (const Region * const self);
637
645region_get_arranger_selections (Region * self);
646
653region_get_arranger_for_children (Region * self);
654
663bool
664region_validate (Region * self, bool is_project, double frames_per_tick);
665
674void
675region_disconnect (Region * self);
676
681#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.
TrackLane * region_get_lane(const Region *region)
Get lane.
Region * region_at_position(const Track *track, const AutomationTrack *at, const Position *pos)
Returns the region at the given position in the given Track.
void region_copy(Region *src, Region *dest)
Copies the data from src to dest.
NONNULL void region_set_lane(Region *self, TrackLane *lane)
Sets the track lane.
int region_is_hit_by_range(const Region *region, const signed_frame_t gframes_start, const signed_frame_t gframes_end, const bool end_inclusive)
Returns if any part of the Region is inside the given range, inclusive.
NONNULL int region_is_hit(const Region *region, const signed_frame_t gframes, const bool inclusive)
Returns if the position is inside the region or not.
HOT NONNULL Region * region_find(const RegionIdentifier *const id)
Looks for the Region matching the identifier.
void region_set_automation_track(Region *region, AutomationTrack *at)
Sets the automation track.
void region_init(Region *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.
void region_gen_name(Region *region, const char *base_name, AutomationTrack *at, Track *track)
Generates a name for the Region, either using the given AutomationTrack or Track, or appending to the...
void region_move_to_track(Region *region, Track *track, int lane_or_at_index, int index)
Moves the Region to the given Track, maintaining the selection status of the Region.
NONNULL WARN_UNUSED_RESULT bool region_stretch(Region *self, double ratio, GError **error)
Stretch the region's contents.
MidiNote * region_find_midi_note(Region *r, MidiNote *_mn)
Returns the MidiNote matching the properties of the given MidiNote.
NONNULL HOT signed_frame_t region_timeline_frames_to_local(const Region *const self, const signed_frame_t timeline_frames, const bool normalize)
Converts frames on the timeline (global) to local frames (in the clip).
NONNULL void region_get_frames_till_next_loop_or_end(const Region *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.
RegionMusicalMode
Musical mode setting for audio regions.
Definition region.h:48
RegionType
Type of Region.
void region_copy_children(Region *dest, Region *src)
Clones and copies all children from src to dest.
NONNULL void region_update_identifier(Region *self)
To be called every time the identifier changes to update the region's children.
AutomationTrack * region_get_automation_track(const Region *const region)
Gets the AutomationTrack using the saved index.
RegionLinkGroup * region_get_link_group(Region *self)
Returns the region's link group.
NONNULL void region_print(const Region *region)
Print region info for debugging.
NONNULL void region_update_link_group(Region *self)
Updates all other regions in the region link group, if any.
void region_set_link_group(Region *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.
@ REGION_MUSICAL_MODE_OFF
Musical mode off - don't auto-stretch when BPM changes.
@ REGION_MUSICAL_MODE_INHERIT
Inherit from global musical mode setting.
int_fast64_t signed_frame_t
Signed type for frame index.
Definition types.h:59
float sample_t
The sample type.
Definition types.h:51
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:31
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:57
A ChordObject to be shown in the TimelineArrangerWidget.
A MIDI note inside a Region shown in the piano roll.
Definition midi_note.h:49
A Position is made up of bars.beats.sixteenths.ticks.
Definition position.h:124
Index/identifier for a Region, so we can get Region objects quickly with it without searching by name...
A group of linked regions.
A region (clip) is an object on the timeline that contains either MidiNote's or AudioClip's.
Definition region.h:72
ArrangerObject base
Base struct.
Definition region.h:76
bool read_from_pool
Whether to read the clip from the pool (used in most cases).
Definition region.h:151
PangoLayout * layout
Cache layout for drawing the name.
Definition region.h:242
GdkRGBA color
Region color independent of track.
Definition region.h:90
AudioClip * clip
Clip to read frames from, if not from the pool.
Definition region.h:159
gint64 last_cache_time
Last timestamp the region was cached.
Definition region.h:265
float gain
Gain to apply to the audio (amplitude 0.0-2.0).
Definition region.h:154
ChordObject ** chord_objects
ChordObject's in this Region.
Definition region.h:209
bool stretching
Whether currently running the stretching algorithm.
Definition region.h:138
PangoLayout * chords_layout
Cache layout for drawing the chord names inside the region.
Definition region.h:246
gint64 last_clip_change
Last timestamp the audio clip or its contents changed.
Definition region.h:262
Position * split_points
Array of split points.
Definition region.h:181
GdkRectangle last_lane_draw_rect
Last lane draw rect.
Definition region.h:258
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:122
double before_length
The length before stretching, in ticks.
Definition region.h:143
AutomationPoint * last_recorded_ap
Last recorded automation point.
Definition region.h:202
int pool_id
Audio pool ID of the associated audio file, mostly used during serialization.
Definition region.h:131
char * name
Name to be shown on the widget.
Definition region.h:82
int bounce
Set to ON during bouncing if this region should be included.
Definition region.h:221
char * escaped_name
Escaped name for drawing.
Definition region.h:85
GdkRectangle last_main_draw_rect
Last main draw rect.
Definition region.h:252
MidiNote ** midi_notes
MIDI notes.
Definition region.h:104
bool use_color
Whether to use the custom color.
Definition region.h:97
ArrangerObject last_positions_obj
Last known marker positions (only positions are used).
Definition region.h:269
RegionMusicalMode musical_mode
Musical mode setting.
Definition region.h:178
RegionIdentifier id
Unique ID.
Definition region.h:79
AutomationPoint ** aps
The automation points this region contains.
Definition region.h:197
double stretch_ratio
Used during arranger UI overlay actions.
Definition region.h:146
Stretcher interface.
Definition stretcher.h:43
A TrackLane belongs to a Track (can have many TrackLanes in a Track) and contains Regions.
Definition track_lane.h:45
Track to be inserted into the Project's Tracklist.
Definition track.h:177
YAML utils.