Zrythm
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
region_identifier.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2020-2022 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
13#ifndef __AUDIO_REGION_IDENTIFIER_H__
14#define __AUDIO_REGION_IDENTIFIER_H__
15
16#include "utils/general.h"
17
18#include "gtk_wrapper.h"
19
32enum class RegionType
33{
34 REGION_TYPE_MIDI = 1 << 0,
35 REGION_TYPE_AUDIO = 1 << 1,
36 REGION_TYPE_AUTOMATION = 1 << 2,
37 REGION_TYPE_CHORD = 1 << 3,
38};
39
40static const char * region_type_bitvals[] = {
41 "midi",
42 "audio",
43 "automation",
44 "chord",
45};
46
52typedef struct RegionIdentifier
53{
54 RegionType type;
55
58
59 unsigned int track_name_hash;
60 int lane_pos;
61
64 int at_idx;
65
67 int idx;
69
70void
71region_identifier_init (RegionIdentifier * self);
72
73static inline int
74region_identifier_is_equal (
75 const RegionIdentifier * a,
76 const RegionIdentifier * b)
77{
78 return a->idx == b->idx && a->track_name_hash == b->track_name_hash
79 && a->lane_pos == b->lane_pos && a->at_idx == b->at_idx
80 && a->link_group == b->link_group && a->type == b->type;
81}
82
83NONNULL static inline void
84region_identifier_copy (RegionIdentifier * dest, const RegionIdentifier * src)
85{
86 dest->idx = src->idx;
87 dest->track_name_hash = src->track_name_hash;
88 dest->lane_pos = src->lane_pos;
89 dest->at_idx = src->at_idx;
90 dest->type = src->type;
91 dest->link_group = src->link_group;
92}
93
94bool
95region_identifier_validate (RegionIdentifier * self);
96
97static inline const char *
98region_identifier_get_region_type_name (RegionType type)
99{
100 g_return_val_if_fail (
101 type >= RegionType::REGION_TYPE_MIDI && type <= RegionType::REGION_TYPE_CHORD,
102 NULL);
103
104 return region_type_bitvals[utils_get_uint_from_bitfield_val (
105 static_cast<unsigned int> (type))];
106}
107
108static inline void
109region_identifier_print (const RegionIdentifier * self)
110{
111 g_message (
112 "Region identifier: "
113 "type: %s, track name hash %u, lane pos %d, "
114 "at index %d, index %d, link_group: %d",
115 region_identifier_get_region_type_name (self->type), self->track_name_hash,
116 self->lane_pos, self->at_idx, self->idx, self->link_group);
117}
118
119void
120region_identifier_free (RegionIdentifier * self);
121
126#endif
General utils.
RegionType
Type of Region.
unsigned int utils_get_uint_from_bitfield_val(unsigned int bitfield)
From https://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightLinear.
Index/identifier for a Region, so we can get Region objects quickly with it without searching by name...
int link_group
Link group index, if any, or -1.
int at_idx
Automation track index in the automation tracklist, if automation region.
int idx
Index inside lane or automation track.