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_TIMELINE (PROJECT->snap_grid_timeline)
26#define SNAP_GRID_EDITOR (PROJECT->snap_grid_editor)
27
28#define SNAP_GRID_IS_EDITOR(sg) (SNAP_GRID_EDITOR == sg)
29#define SNAP_GRID_IS_TIMELINE(sg) (SNAP_GRID_TIMELINE == sg)
30/* if any snapping is enabled */
31#define SNAP_GRID_ANY_SNAP(sg) (sg->snap_to_grid || sg->snap_to_events)
32#define SNAP_GRID_DEFAULT_MAX_BAR 10000
33
34typedef enum NoteLength
35{
36 NOTE_LENGTH_BAR,
37 NOTE_LENGTH_BEAT,
38 NOTE_LENGTH_2_1,
39 NOTE_LENGTH_1_1,
40 NOTE_LENGTH_1_2,
41 NOTE_LENGTH_1_4,
42 NOTE_LENGTH_1_8,
43 NOTE_LENGTH_1_16,
44 NOTE_LENGTH_1_32,
45 NOTE_LENGTH_1_64,
46 NOTE_LENGTH_1_128
47} NoteLength;
48
49const char **
50note_length_get_strings (void);
51const char *
52note_length_to_str (NoteLength len);
53
54typedef enum NoteType
55{
56 NOTE_TYPE_NORMAL,
60
61const char **
62note_type_get_strings (void);
63const char *
64note_type_to_str (NoteType type);
65
77
81typedef enum SnapGridType
82{
83 SNAP_GRID_TYPE_TIMELINE,
84 SNAP_GRID_TYPE_EDITOR,
86
140
141void
142snap_grid_init (
143 SnapGrid * self,
144 SnapGridType type,
145 NoteLength note_length,
146 bool adaptive);
147
148int
149snap_grid_get_ticks_from_length_and_type (NoteLength length, NoteType type);
150
154NONNULL int
156
157NONNULL double
158snap_grid_get_snap_frames (const SnapGrid * self);
159
163int
165
172char *
173snap_grid_stringize_length_and_type (NoteLength note_length, NoteType note_type);
174
181char *
183
196NONNULL bool
198 Position * ret_pos,
199 const SnapGrid * const self,
200 const Position * pos,
201 const bool return_prev);
202
203SnapGrid *
204snap_grid_clone (SnapGrid * src);
205
206SnapGrid *
207snap_grid_new (void);
208
209void
210snap_grid_free (SnapGrid * self);
211
216#endif
NONNULL int snap_grid_get_snap_ticks(const SnapGrid *self)
Gets a snap point's length in ticks.
NoteType
Definition snap_grid.h:55
char * snap_grid_stringize(SnapGrid *self)
Returns the grid intensity as a human-readable string.
SnapGridType
Snap grid type.
Definition snap_grid.h:82
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:67
@ NOTE_TYPE_DOTTED
2/3 of its original size
Definition snap_grid.h:57
@ NOTE_TYPE_TRIPLET
3/2 of its original size
Definition snap_grid.h:58
@ NOTE_LENGTH_LINK
Link length with snap setting.
Definition snap_grid.h:69
@ NOTE_LENGTH_CUSTOM
Custom length.
Definition snap_grid.h:75
@ NOTE_LENGTH_LAST_OBJECT
Use last created object's length.
Definition snap_grid.h:72
Position struct and API.
A Position is made up of bars.beats.sixteenths.ticks.
Definition position.h:126
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:133
bool snap_to_grid_keep_offset
Whether to keep the offset when moving items.
Definition snap_grid.h:114
NoteLengthType length_type
See NoteLengthType.
Definition snap_grid.h:138
NoteType snap_note_type
Snap note type.
Definition snap_grid.h:103
bool snap_to_grid
Whether to snap to the grid.
Definition snap_grid.h:106
NoteLength snap_note_length
Snap note length.
Definition snap_grid.h:100
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:97
bool snap_to_events
Whether to snap to events.
Definition snap_grid.h:117
NoteType default_note_type
Default note type.
Definition snap_grid.h:122
NoteLength default_note_length
Default note length.
Definition snap_grid.h:120