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 "dsp/position.h"
14
15#include <glib/gi18n.h>
16
23#define SNAP_GRID_TIMELINE (PROJECT->snap_grid_timeline)
24#define SNAP_GRID_EDITOR (PROJECT->snap_grid_editor)
25
26#define SNAP_GRID_IS_EDITOR(sg) (SNAP_GRID_EDITOR == sg)
27#define SNAP_GRID_IS_TIMELINE(sg) (SNAP_GRID_TIMELINE == sg)
28/* if any snapping is enabled */
29#define SNAP_GRID_ANY_SNAP(sg) (sg->snap_to_grid || sg->snap_to_events)
30#define SNAP_GRID_DEFAULT_MAX_BAR 10000
31
32enum class NoteLength
33{
34 NOTE_LENGTH_BAR,
35 NOTE_LENGTH_BEAT,
36 NOTE_LENGTH_2_1,
37 NOTE_LENGTH_1_1,
38 NOTE_LENGTH_1_2,
39 NOTE_LENGTH_1_4,
40 NOTE_LENGTH_1_8,
41 NOTE_LENGTH_1_16,
42 NOTE_LENGTH_1_32,
43 NOTE_LENGTH_1_64,
44 NOTE_LENGTH_1_128
45};
46
47const char **
48note_length_get_strings (void);
49const char *
50note_length_to_str (NoteLength len);
51
52enum class NoteType
53{
54 NOTE_TYPE_NORMAL,
57};
58
59const char **
60note_type_get_strings (void);
61const char *
62note_type_to_str (NoteType type);
63
75
79enum class SnapGridType
80{
81 SNAP_GRID_TYPE_TIMELINE,
82 SNAP_GRID_TYPE_EDITOR,
83};
84
138
139void
140snap_grid_init (
141 SnapGrid * self,
142 SnapGridType type,
143 NoteLength note_length,
144 bool adaptive);
145
146int
147snap_grid_get_ticks_from_length_and_type (NoteLength length, NoteType type);
148
152NONNULL int
154
155NONNULL double
156snap_grid_get_snap_frames (const SnapGrid * self);
157
161int
163
170char *
171snap_grid_stringize_length_and_type (NoteLength note_length, NoteType note_type);
172
179char *
181
194NONNULL bool
196 Position * ret_pos,
197 const SnapGrid * const self,
198 const Position * pos,
199 const bool return_prev);
200
201SnapGrid *
202snap_grid_clone (SnapGrid * src);
203
204SnapGrid *
205snap_grid_new (void);
206
207void
208snap_grid_free (SnapGrid * self);
209
214#endif
NONNULL int snap_grid_get_snap_ticks(const SnapGrid *self)
Gets a snap point's length in ticks.
NoteType
Definition snap_grid.h:53
char * snap_grid_stringize(SnapGrid *self)
Returns the grid intensity as a human-readable string.
SnapGridType
Snap grid type.
Definition snap_grid.h:80
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:65
@ NOTE_TYPE_TRIPLET
3/2 of its original size
@ NOTE_TYPE_DOTTED
2/3 of its original size
@ NOTE_LENGTH_LAST_OBJECT
Use last created object's length.
@ NOTE_LENGTH_LINK
Link length with snap setting.
@ NOTE_LENGTH_CUSTOM
Custom length.
Position struct and API.
A Position is made up of bars.beats.sixteenths.ticks.
Definition position.h:124
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:131
bool snap_to_grid_keep_offset
Whether to keep the offset when moving items.
Definition snap_grid.h:112
NoteLengthType length_type
See NoteLengthType.
Definition snap_grid.h:136
NoteType snap_note_type
Snap note type.
Definition snap_grid.h:101
bool snap_to_grid
Whether to snap to the grid.
Definition snap_grid.h:104
NoteLength snap_note_length
Snap note length.
Definition snap_grid.h:98
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:95
bool snap_to_events
Whether to snap to events.
Definition snap_grid.h:115
NoteType default_note_type
Default note type.
Definition snap_grid.h:120
NoteLength default_note_length
Default note length.
Definition snap_grid.h:118