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) (((ZRegion *) 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 ZRegion
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 int magic;
274} ZRegion;
275
279#define region_type_can_fade(rtype) (rtype == REGION_TYPE_AUDIO)
280
284void
286 ZRegion * region,
287 const Position * start_pos,
288 const Position * end_pos,
289 unsigned int track_name_hash,
290 int lane_pos,
291 int idx_inside_lane);
292
296HOT NONNULL ZRegion *
297region_find (const RegionIdentifier * const id);
298
299#if 0
300static inline void
301region_set_track_name_hash (
302 ZRegion * self,
303 unsigned int name_hash)
304{
305 self->id.track_name_hash = name_hash;
306}
307#endif
308
309NONNULL void
310region_print_to_str (const ZRegion * self, char * buf, const size_t buf_size);
311
317NONNULL void
318region_print (const ZRegion * region);
319
325TrackLane *
326region_get_lane (const ZRegion * region);
327
335
344void
345region_set_link_group (ZRegion * region, int group_idx, bool update_identifier);
346
347NONNULL bool
348region_has_link_group (ZRegion * region);
349
359MidiNote *
361
378NONNULL HOT signed_frame_t
380 const ZRegion * const self,
381 const signed_frame_t timeline_frames,
382 const bool normalize);
383
395NONNULL void
397 const ZRegion * const self,
398 const signed_frame_t timeline_frames,
399 signed_frame_t * ret_frames,
400 bool * is_loop);
401
407NONNULL void
408region_set_lane (ZRegion * self, const TrackLane * const lane);
409
417void
419 ZRegion * region,
420 const char * base_name,
421 AutomationTrack * at,
422 Track * track);
423
436NONNULL WARN_UNUSED_RESULT bool
437region_stretch (ZRegion * self, double ratio, GError ** error);
438
445NONNULL void
447
454NONNULL void
456
474void
476 ZRegion * region,
477 Track * track,
478 int lane_or_at_index,
479 int index);
480
485CONST
486static inline int
487region_type_has_lane (const RegionType type)
488{
489 return type == REGION_TYPE_MIDI || type == REGION_TYPE_AUDIO;
490}
491
497void
499
507
514void
516
529NONNULL PURE int
531 const ZRegion * region,
532 const signed_frame_t gframes,
533 const bool inclusive);
534
543int
545 const ZRegion * region,
546 const signed_frame_t gframes_start,
547 const signed_frame_t gframes_end,
548 const bool end_inclusive);
549
559NONNULL_ARGS (3)
561 const Track * track,
562 const AutomationTrack * at,
563 const Position * pos);
564
572char *
573region_generate_filename (ZRegion * region);
574
575void
576region_get_type_as_string (RegionType type, char * buf);
577
584bool
585region_is_recording (ZRegion * self);
586
595bool
596region_get_musical_mode (ZRegion * self);
597
603void
604region_add_arranger_object (
605 ZRegion * self,
606 ArrangerObject * obj,
607 bool fire_events);
608
609void
610region_create_link_group_if_none (ZRegion * region);
611
617void
618region_unlink (ZRegion * region);
619
625void
626region_remove_all_children (ZRegion * region);
627
632void
634
635NONNULL bool
636region_is_looped (const ZRegion * const self);
637
645region_get_arranger_selections (ZRegion * self);
646
653region_get_arranger_for_children (ZRegion * self);
654
663bool
664region_validate (ZRegion * self, bool is_project, double frames_per_tick);
665
674void
675region_disconnect (ZRegion * 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.
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:48
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:56
@ REGION_MUSICAL_MODE_OFF
Musical mode off - don't auto-stretch when BPM changes.
Definition region.h:53
@ REGION_MUSICAL_MODE_INHERIT
Inherit from global musical mode setting.
Definition region.h:50
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:126
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:177
A region (clip) is an object on the timeline that contains either MidiNote's or AudioClip's.
Definition region.h:72
AutomationPoint * last_recorded_ap
Last recorded automation point.
Definition region.h:202
RegionIdentifier id
Unique ID.
Definition region.h:79
char * escaped_name
Escaped name for drawing.
Definition region.h:85
GdkRectangle last_main_draw_rect
Last main draw rect.
Definition region.h:252
int bounce
Set to ON during bouncing if this region should be included.
Definition region.h:221
ChordObject ** chord_objects
ChordObject's in this Region.
Definition region.h:209
gint64 last_clip_change
Last timestamp the audio clip or its contents changed.
Definition region.h:262
bool stretching
Whether currently running the stretching algorithm.
Definition region.h:138
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
AutomationPoint ** aps
The automation points this region contains.
Definition region.h:197
GdkRGBA color
Region color independent of track.
Definition region.h:90
ArrangerObject last_positions_obj
Last known marker positions (only positions are used).
Definition region.h:269
char * name
Name to be shown on the widget.
Definition region.h:82
PangoLayout * layout
Cache layout for drawing the name.
Definition region.h:242
GdkRectangle last_lane_draw_rect
Last lane draw rect.
Definition region.h:258
AudioClip * clip
Clip to read frames from, if not from the pool.
Definition region.h:159
int pool_id
Audio pool ID of the associated audio file, mostly used during serialization.
Definition region.h:131
double before_length
The length before stretching, in ticks.
Definition region.h:143
RegionMusicalMode musical_mode
Musical mode setting.
Definition region.h:178
float gain
Gain to apply to the audio (amplitude 0.0-2.0).
Definition region.h:154
Position * split_points
Array of split points.
Definition region.h:181
bool read_from_pool
Whether to read the clip from the pool (used in most cases).
Definition region.h:151
ArrangerObject base
Base struct.
Definition region.h:76
double stretch_ratio
Used during arranger UI overlay actions.
Definition region.h:146
gint64 last_cache_time
Last timestamp the region was cached.
Definition region.h:265
MidiNote ** midi_notes
MIDI notes.
Definition region.h:104
PangoLayout * chords_layout
Cache layout for drawing the chord names inside the region.
Definition region.h:246
bool use_color
Whether to use the custom color.
Definition region.h:97
YAML utils.