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