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) (sg->snap_to_grid || sg->snap_to_events)
34#define SNAP_GRID_DEFAULT_MAX_BAR 10000
35
36typedef enum NoteLength
37{
38 NOTE_LENGTH_BAR,
39 NOTE_LENGTH_BEAT,
40 NOTE_LENGTH_2_1,
41 NOTE_LENGTH_1_1,
42 NOTE_LENGTH_1_2,
43 NOTE_LENGTH_1_4,
44 NOTE_LENGTH_1_8,
45 NOTE_LENGTH_1_16,
46 NOTE_LENGTH_1_32,
47 NOTE_LENGTH_1_64,
48 NOTE_LENGTH_1_128
49} NoteLength;
50
51static const cyaml_strval_t note_length_strings[] = {
52 {N_ ("bar"), NOTE_LENGTH_BAR },
53 { N_ ("beat"), NOTE_LENGTH_BEAT },
54 { "2/1", NOTE_LENGTH_2_1 },
55 { "1/1", NOTE_LENGTH_1_1 },
56 { "1/2", NOTE_LENGTH_1_2 },
57 { "1/4", NOTE_LENGTH_1_4 },
58 { "1/8", NOTE_LENGTH_1_8 },
59 { "1/16", NOTE_LENGTH_1_16 },
60 { "1/32", NOTE_LENGTH_1_32 },
61 { "1/64", NOTE_LENGTH_1_64 },
62 { "1/128", NOTE_LENGTH_1_128},
63};
64
65typedef enum NoteType
66{
67 NOTE_TYPE_NORMAL,
71
72static const cyaml_strval_t note_type_strings[] = {
73 {N_ ("normal"), NOTE_TYPE_NORMAL },
74 { N_ ("dotted"), NOTE_TYPE_DOTTED },
75 { N_ ("triplet"), NOTE_TYPE_TRIPLET},
76};
77
82static const cyaml_strval_t note_type_short_strings[] = {
83 {"", NOTE_TYPE_NORMAL },
84 { ".", NOTE_TYPE_DOTTED },
85 { "t", NOTE_TYPE_TRIPLET},
86};
87
99
100static const cyaml_strval_t note_length_type_strings[] = {
101 {"link", NOTE_LENGTH_LINK },
102 { "last object", NOTE_LENGTH_LAST_OBJECT},
103 { "custom", NOTE_LENGTH_CUSTOM },
104};
105
109typedef enum SnapGridType
110{
111 SNAP_GRID_TYPE_TIMELINE,
112 SNAP_GRID_TYPE_EDITOR,
114
115static const cyaml_strval_t snap_grid_type_strings[] = {
116 {"timeline", SNAP_GRID_TYPE_TIMELINE},
117 { "editor", SNAP_GRID_TYPE_EDITOR },
118};
119
174
175static const cyaml_schema_field_t snap_grid_fields_schema[] = {
176 YAML_FIELD_INT (SnapGrid, schema_version),
177 YAML_FIELD_ENUM (SnapGrid, type, snap_grid_type_strings),
178 YAML_FIELD_ENUM (SnapGrid, snap_note_length, note_length_strings),
179 YAML_FIELD_ENUM (SnapGrid, snap_note_type, note_type_strings),
180 YAML_FIELD_INT (SnapGrid, snap_adaptive),
181 YAML_FIELD_ENUM (SnapGrid, default_note_length, note_length_strings),
182 YAML_FIELD_ENUM (SnapGrid, default_note_type, note_type_strings),
183 YAML_FIELD_INT (SnapGrid, default_adaptive),
184 YAML_FIELD_ENUM (SnapGrid, length_type, note_length_type_strings),
185 YAML_FIELD_INT (SnapGrid, snap_to_grid),
186 YAML_FIELD_INT (SnapGrid, snap_to_grid_keep_offset),
187 YAML_FIELD_INT (SnapGrid, snap_to_events),
188
189 CYAML_FIELD_END
190};
191
192static const cyaml_schema_value_t snap_grid_schema = {
193 CYAML_VALUE_MAPPING (CYAML_FLAG_POINTER, SnapGrid, snap_grid_fields_schema),
194};
195
196void
197snap_grid_init (
198 SnapGrid * self,
199 SnapGridType type,
200 NoteLength note_length,
201 bool adaptive);
202
203int
204snap_grid_get_ticks_from_length_and_type (NoteLength length, NoteType type);
205
209NONNULL int
211
212NONNULL double
213snap_grid_get_snap_frames (const SnapGrid * self);
214
218int
220
227char *
228snap_grid_stringize_length_and_type (NoteLength note_length, NoteType note_type);
229
236char *
238
251NONNULL bool
253 Position * ret_pos,
254 const SnapGrid * const self,
255 const Position * pos,
256 const bool return_prev);
257
258SnapGrid *
259snap_grid_clone (SnapGrid * src);
260
261SnapGrid *
262snap_grid_new (void);
263
264void
265snap_grid_free (SnapGrid * self);
266
271#endif
NONNULL int snap_grid_get_snap_ticks(const SnapGrid *self)
Gets a snap point's length in ticks.
NoteType
Definition snap_grid.h:66
char * snap_grid_stringize(SnapGrid *self)
Returns the grid intensity as a human-readable string.
SnapGridType
Snap grid type.
Definition snap_grid.h:110
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:89
@ NOTE_TYPE_DOTTED
2/3 of its original size
Definition snap_grid.h:68
@ NOTE_TYPE_TRIPLET
3/2 of its original size
Definition snap_grid.h:69
@ NOTE_LENGTH_LINK
Link length with snap setting.
Definition snap_grid.h:91
@ NOTE_LENGTH_CUSTOM
Custom length.
Definition snap_grid.h:97
@ NOTE_LENGTH_LAST_OBJECT
Use last created object's length.
Definition snap_grid.h:94
Position struct and API.
A Position is made up of bars.beats.sixteenths.ticks.
Definition position.h:129
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:167
bool snap_to_grid_keep_offset
Whether to keep the offset when moving items.
Definition snap_grid.h:148
NoteLengthType length_type
See NoteLengthType.
Definition snap_grid.h:172
NoteType snap_note_type
Snap note type.
Definition snap_grid.h:137
bool snap_to_grid
Whether to snap to the grid.
Definition snap_grid.h:140
NoteLength snap_note_length
Snap note length.
Definition snap_grid.h:134
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:131
bool snap_to_events
Whether to snap to events.
Definition snap_grid.h:151
NoteType default_note_type
Default note type.
Definition snap_grid.h:156
NoteLength default_note_length
Default note length.
Definition snap_grid.h:154