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 <stdbool.h>
17
18#include "utils/general.h"
19#include "utils/yaml.h"
20
27#define REGION_IDENTIFIER_SCHEMA_VERSION 1
28
37typedef enum RegionType
38{
39 REGION_TYPE_MIDI = 1 << 0,
40 REGION_TYPE_AUDIO = 1 << 1,
41 REGION_TYPE_AUTOMATION = 1 << 2,
42 REGION_TYPE_CHORD = 1 << 3,
44
45static const cyaml_bitdef_t region_type_bitvals[] = {
46 {.name = "midi", .offset = 0, .bits = 1},
47 { .name = "audio", .offset = 1, .bits = 1},
48 { .name = "automation", .offset = 2, .bits = 1},
49 { .name = "chord", .offset = 3, .bits = 1},
50};
51
57typedef struct RegionIdentifier
58{
59 RegionType type;
60
63
64 unsigned int track_name_hash;
65 int lane_pos;
66
69 int at_idx;
70
72 int idx;
74
75void
76region_identifier_init (RegionIdentifier * self);
77
78static inline int
79region_identifier_is_equal (
80 const RegionIdentifier * a,
81 const RegionIdentifier * b)
82{
83 return a->idx == b->idx && a->track_name_hash == b->track_name_hash
84 && a->lane_pos == b->lane_pos && a->at_idx == b->at_idx
85 && a->link_group == b->link_group && a->type == b->type;
86}
87
88NONNULL static inline void
89region_identifier_copy (RegionIdentifier * dest, const RegionIdentifier * src)
90{
91 dest->idx = src->idx;
92 dest->track_name_hash = src->track_name_hash;
93 dest->lane_pos = src->lane_pos;
94 dest->at_idx = src->at_idx;
95 dest->type = src->type;
96 dest->link_group = src->link_group;
97}
98
99bool
100region_identifier_validate (RegionIdentifier * self);
101
102static inline const char *
103region_identifier_get_region_type_name (RegionType type)
104{
105 g_return_val_if_fail (
106 type >= REGION_TYPE_MIDI && type <= REGION_TYPE_CHORD, NULL);
107
108 return region_type_bitvals[utils_get_uint_from_bitfield_val (type)].name;
109}
110
111static inline void
112region_identifier_print (const RegionIdentifier * self)
113{
114 g_message (
115 "Region identifier: "
116 "type: %s, track name hash %u, lane pos %d, "
117 "at index %d, index %d, link_group: %d",
118 region_identifier_get_region_type_name (self->type), self->track_name_hash,
119 self->lane_pos, self->at_idx, self->idx, self->link_group);
120}
121
122void
123region_identifier_free (RegionIdentifier * self);
124
129#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.
YAML utils.