Zrythm
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
snap_grid.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
10#ifndef __AUDIO_SNAP_GRID_H__
11#define __AUDIO_SNAP_GRID_H__
12
13#include <stdbool.h>
14
15#include "dsp/position.h"
16
17#include <glib/gi18n.h>
18
25#define SNAP_GRID_SCHEMA_VERSION 1
26
27#define SNAP_GRID_TIMELINE (PROJECT->snap_grid_timeline)
28#define SNAP_GRID_EDITOR (PROJECT->snap_grid_editor)
29
30#define SNAP_GRID_IS_EDITOR(sg) (SNAP_GRID_EDITOR == sg)
31#define SNAP_GRID_IS_TIMELINE(sg) (SNAP_GRID_TIMELINE == sg)
32/* if any snapping is enabled */
33#define SNAP_GRID_ANY_SNAP(sg) \
34 (sg->snap_to_grid || sg->snap_to_events)
35#define SNAP_GRID_DEFAULT_MAX_BAR 10000
36
37typedef enum NoteLength
38{
39 NOTE_LENGTH_BAR,
40 NOTE_LENGTH_BEAT,
41 NOTE_LENGTH_2_1,
42 NOTE_LENGTH_1_1,
43 NOTE_LENGTH_1_2,
44 NOTE_LENGTH_1_4,
45 NOTE_LENGTH_1_8,
46 NOTE_LENGTH_1_16,
47 NOTE_LENGTH_1_32,
48 NOTE_LENGTH_1_64,
49 NOTE_LENGTH_1_128
50} NoteLength;
51
52static const cyaml_strval_t note_length_strings[] = {
53 {N_ ("bar"), NOTE_LENGTH_BAR },
54 { N_ ("beat"), NOTE_LENGTH_BEAT },
55 { "2/1", NOTE_LENGTH_2_1 },
56 { "1/1", NOTE_LENGTH_1_1 },
57 { "1/2", NOTE_LENGTH_1_2 },
58 { "1/4", NOTE_LENGTH_1_4 },
59 { "1/8", NOTE_LENGTH_1_8 },
60 { "1/16", NOTE_LENGTH_1_16 },
61 { "1/32", NOTE_LENGTH_1_32 },
62 { "1/64", NOTE_LENGTH_1_64 },
63 { "1/128", NOTE_LENGTH_1_128},
64};
65
66typedef enum NoteType
67{
68 NOTE_TYPE_NORMAL,
72
73static const cyaml_strval_t note_type_strings[] = {
74 {N_ ("normal"), NOTE_TYPE_NORMAL },
75 { N_ ("dotted"), NOTE_TYPE_DOTTED },
76 { N_ ("triplet"), NOTE_TYPE_TRIPLET},
77};
78
83static const cyaml_strval_t note_type_short_strings[] = {
84 {"", NOTE_TYPE_NORMAL },
85 { ".", NOTE_TYPE_DOTTED },
86 { "t", NOTE_TYPE_TRIPLET},
87};
88
100
101static const cyaml_strval_t note_length_type_strings[] = {
102 {"link", NOTE_LENGTH_LINK },
103 { "last object", NOTE_LENGTH_LAST_OBJECT},
104 { "custom", NOTE_LENGTH_CUSTOM },
105};
106
110typedef enum SnapGridType
111{
112 SNAP_GRID_TYPE_TIMELINE,
113 SNAP_GRID_TYPE_EDITOR,
115
116static const cyaml_strval_t snap_grid_type_strings[] = {
117 {"timeline", SNAP_GRID_TYPE_TIMELINE},
118 { "editor", SNAP_GRID_TYPE_EDITOR },
119};
120
175
176static const cyaml_schema_field_t snap_grid_fields_schema[] = {
177 YAML_FIELD_INT (SnapGrid, schema_version),
178 YAML_FIELD_ENUM (SnapGrid, type, snap_grid_type_strings),
179 YAML_FIELD_ENUM (
180 SnapGrid,
181 snap_note_length,
182 note_length_strings),
183 YAML_FIELD_ENUM (SnapGrid, snap_note_type, note_type_strings),
184 YAML_FIELD_INT (SnapGrid, snap_adaptive),
185 YAML_FIELD_ENUM (
186 SnapGrid,
187 default_note_length,
188 note_length_strings),
189 YAML_FIELD_ENUM (
190 SnapGrid,
191 default_note_type,
192 note_type_strings),
193 YAML_FIELD_INT (SnapGrid, default_adaptive),
194 YAML_FIELD_ENUM (
195 SnapGrid,
196 length_type,
197 note_length_type_strings),
198 YAML_FIELD_INT (SnapGrid, snap_to_grid),
199 YAML_FIELD_INT (SnapGrid, snap_to_grid_keep_offset),
200 YAML_FIELD_INT (SnapGrid, snap_to_events),
201
202 CYAML_FIELD_END
203};
204
205static const cyaml_schema_value_t snap_grid_schema = {
206 CYAML_VALUE_MAPPING (
207 CYAML_FLAG_POINTER,
208 SnapGrid,
209 snap_grid_fields_schema),
210};
211
212void
213snap_grid_init (
214 SnapGrid * self,
215 SnapGridType type,
216 NoteLength note_length,
217 bool adaptive);
218
219int
220snap_grid_get_ticks_from_length_and_type (
221 NoteLength length,
222 NoteType type);
223
227NONNULL int
229
230NONNULL double
231snap_grid_get_snap_frames (const SnapGrid * self);
232
236int
238
245char *
247 NoteLength note_length,
248 NoteType note_type);
249
256char *
258
271NONNULL bool
273 Position * ret_pos,
274 const SnapGrid * const self,
275 const Position * pos,
276 const bool return_prev);
277
278SnapGrid *
279snap_grid_clone (SnapGrid * src);
280
281SnapGrid *
282snap_grid_new (void);
283
284void
285snap_grid_free (SnapGrid * self);
286
291#endif
NONNULL int snap_grid_get_snap_ticks(const SnapGrid *self)
Gets a snap point's length in ticks.
NoteType
Definition snap_grid.h:67
char * snap_grid_stringize(SnapGrid *self)
Returns the grid intensity as a human-readable string.
SnapGridType
Snap grid type.
Definition snap_grid.h:111
int snap_grid_get_default_ticks(SnapGrid *self)
Gets a the default length in ticks.
char * snap_grid_stringize_length_and_type(NoteLength note_length, NoteType note_type)
Returns the grid intensity as a human-readable string.
NONNULL bool snap_grid_get_nearby_snap_point(Position *ret_pos, const SnapGrid *const self, const Position *pos, const bool return_prev)
Returns the next or previous SnapGrid point.
NoteLengthType
Definition snap_grid.h:90
@ NOTE_TYPE_DOTTED
2/3 of its original size
Definition snap_grid.h:69
@ NOTE_TYPE_TRIPLET
3/2 of its original size
Definition snap_grid.h:70
@ NOTE_LENGTH_LINK
Link length with snap setting.
Definition snap_grid.h:92
@ NOTE_LENGTH_CUSTOM
Custom length.
Definition snap_grid.h:98
@ NOTE_LENGTH_LAST_OBJECT
Use last created object's length.
Definition snap_grid.h:95
Position struct and API.
A Position is made up of bars.beats.sixteenths.ticks.
Definition position.h:137
bool default_adaptive
If this is on, the default note length will be determined automatically based on the current zoom lev...
Definition snap_grid.h:168
bool snap_to_grid_keep_offset
Whether to keep the offset when moving items.
Definition snap_grid.h:149
NoteLengthType length_type
See NoteLengthType.
Definition snap_grid.h:173
NoteType snap_note_type
Snap note type.
Definition snap_grid.h:138
bool snap_to_grid
Whether to snap to the grid.
Definition snap_grid.h:141
NoteLength snap_note_length
Snap note length.
Definition snap_grid.h:135
bool snap_adaptive
If this is on, the snap note length will be determined automatically based on the current zoom level.
Definition snap_grid.h:132
bool snap_to_events
Whether to snap to events.
Definition snap_grid.h:152
NoteType default_note_type
Default note type.
Definition snap_grid.h:157
NoteLength default_note_length
Default note length.
Definition snap_grid.h:155