Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
|
Snap/grid information. More...
#include <src/gui/dsp/snap_grid.h>
Public Types | |
enum class | Type { Timeline , Editor } |
using | FramesPerTickProvider = std::function<dsp::FramesPerTick (void)> |
using | TicksPerBarProvider = std::function<int (void)> |
using | TicksPerBeatProvider = std::function<int (void)> |
using | Position = zrythm::dsp::Position |
using | Track = structure::tracks::Track |
using | Region = structure::arrangement::Region |
Public Member Functions | |
SnapGrid (Type type, utils::NoteLength note_length, bool adaptive, FramesPerTickProvider frames_per_tick_provider, TicksPerBarProvider ticks_per_bar_provider, TicksPerBeatProvider ticks_per_beat_provider) | |
void | set_ticks_per_bar_provider (TicksPerBarProvider ticks_per_bar_provider) |
void | set_ticks_per_beat_provider (TicksPerBeatProvider ticks_per_beat_provider) |
void | set_frames_per_tick_provider (FramesPerTickProvider frames_per_tick_provider) |
bool | any_snap () const |
Returns whether any snapping is enabled. | |
int | get_snap_ticks () const |
Gets a snap point's length in ticks. | |
double | get_snap_frames () const |
Get the snap length in frames. | |
int | get_default_ticks () const |
Gets a the default length in ticks. | |
utils::Utf8String | stringize () const |
Returns the grid intensity as a human-readable string. | |
bool | get_nearby_snap_point (Position &ret_pos, double ticks, bool return_prev) |
Returns the next or previous SnapGrid point. | |
bool | get_closest_snap_point (const Position &pivot_pos, Track *track, Region *region, Position &closest_sp) const |
Get closest snap point. | |
bool | get_next_snap_point (const Position &pivot_pos, Track *track, Region *region, Position &next_sp) const |
Get next snap point. | |
bool | get_prev_snap_point (const Position &pivot_pos, Track *track, Region *region, Position &prev_sp) const |
Gets the previous snap point. | |
bool | get_prev_or_next_snap_point (const Position &pivot_pos, Track *track, Region *region, Position &out_pos, bool get_prev_point) const |
Common logic for get_prev_snap_point and get_next_snap_point. | |
Position | snap (const Position &pivot_pos, const Position *start_pos, Track *track, Region *region) const |
Snaps pivot_pos using given options. | |
Position | snap_simple (const Position &pivot_pos) const |
Snaps pivot_pos using given options. | |
Position | get_snapped_end_position (const Position &start_pos) const |
Returns an end position that is 1 snap point away from start_pos . | |
Static Public Member Functions | |
static int | get_ticks_from_length_and_type (utils::NoteLength length, utils::NoteType type, int ticks_per_bar, int ticks_per_beat) |
static utils::Utf8String | stringize_length_and_type (utils::NoteLength note_length, utils::NoteType note_type) |
Returns the grid intensity as a human-readable string. | |
Data Fields | |
Type | type_ {} |
bool | snap_adaptive_ = false |
If this is on, the snap note length will be determined automatically based on the current zoom level. | |
utils::NoteLength | snap_note_length_ {} |
Snap note length. | |
utils::NoteType | snap_note_type_ { utils::NoteType::Normal } |
Snap note type. | |
bool | snap_to_grid_ = true |
Whether to snap to the grid. | |
bool | snap_to_grid_keep_offset_ = false |
Whether to keep the offset when moving items. | |
bool | snap_to_events_ = false |
Whether to snap to events. | |
utils::NoteLength | default_note_length_ {} |
Default note length. | |
utils::NoteType | default_note_type_ { utils::NoteType::Normal } |
Default note type. | |
bool | default_adaptive_ = false |
If this is on, the default note length will be determined automatically based on the current zoom level. | |
NoteLengthType | length_type_ = NoteLengthType::NOTE_LENGTH_LINK |
See NoteLengthType. | |
Static Public Attributes | |
static constexpr int | DEFAULT_MAX_BAR = 10000 |
Friends | |
void | to_json (nlohmann::json &j, const SnapGrid &p) |
void | from_json (const nlohmann::json &j, SnapGrid &p) |
Snap/grid information.
Definition at line 44 of file snap_grid.h.
using zrythm::gui::SnapGrid::FramesPerTickProvider = std::function<dsp::FramesPerTick (void)> |
Definition at line 55 of file snap_grid.h.
Definition at line 58 of file snap_grid.h.
Definition at line 60 of file snap_grid.h.
using zrythm::gui::SnapGrid::TicksPerBarProvider = std::function<int (void)> |
Definition at line 56 of file snap_grid.h.
using zrythm::gui::SnapGrid::TicksPerBeatProvider = std::function<int (void)> |
Definition at line 57 of file snap_grid.h.
Definition at line 59 of file snap_grid.h.
|
strong |
Definition at line 47 of file snap_grid.h.
|
inline |
Definition at line 65 of file snap_grid.h.
|
inline |
Returns whether any snapping is enabled.
Definition at line 98 of file snap_grid.h.
bool zrythm::gui::SnapGrid::get_closest_snap_point | ( | const Position & | pivot_pos, |
Track * | track, | ||
Region * | region, | ||
Position & | closest_sp ) const |
Get closest snap point.
pivot_pos | Position to check snap points for. |
track | Track, used when moving things in the timeline. If keep offset is on and this is passed, the objects in the track will be taken into account. If keep offset is on and this is nullptr, all applicable objects will be taken into account. Not used if keep offset is off. |
region | Region, used when moving things in the editor. Same behavior as track. |
closest_sp | Position to set. |
bool zrythm::gui::SnapGrid::get_nearby_snap_point | ( | Position & | ret_pos, |
double | ticks, | ||
bool | return_prev ) |
Returns the next or previous SnapGrid point.
[out] | ret_pos | Output position, if found. |
ticks | Position to search for. | |
return_prev | 1 to return the previous element or 0 to return the next. |
bool zrythm::gui::SnapGrid::get_next_snap_point | ( | const Position & | pivot_pos, |
Track * | track, | ||
Region * | region, | ||
Position & | next_sp ) const |
Get next snap point.
Must only be called on positive positions.
pivot_pos | Position to check snap points for. |
track | Track, used when moving things in the timeline. If keep offset is on and this is passed, the objects in the track will be taken into account. If keep offset is on and this is nullptr, all applicable objects will be taken into account. Not used if keep offset is off. |
region | Region, used when moving things in the editor. Same behavior as track. |
next_snap_point | Position to set. |
bool zrythm::gui::SnapGrid::get_prev_snap_point | ( | const Position & | pivot_pos, |
Track * | track, | ||
Region * | region, | ||
Position & | prev_sp ) const |
Gets the previous snap point.
Must only be called on positive positions.
TODO check what happens if there is no snap point & improve this API
pivot_pos | Position to check snap points for. |
track | Track, used when moving things in the timeline. If keep offset is on and this is passed, the objects in the track will be taken into account. If keep offset is on and this is nullptr, all applicable objects will be taken into account. Not used if keep offset is off. |
region | Region, used when moving things in the editor. Same behavior as track . |
prev_snap_point | The position to set. |
Returns an end position that is 1 snap point away from start_pos
.
start_pos | Start Position. |
|
inline |
Definition at line 90 of file snap_grid.h.
|
inline |
Definition at line 80 of file snap_grid.h.
|
inline |
Definition at line 85 of file snap_grid.h.
Position zrythm::gui::SnapGrid::snap | ( | const Position & | pivot_pos, |
const Position * | start_pos, | ||
Track * | track, | ||
Region * | region ) const |
Snaps pivot_pos
using given options.
start_pos | The previous position (ie, the position the drag started at. This is only used when the "keep offset" setting is on. |
track | Track, used when moving things in the timeline. If keep offset is on and this is passed, the objects in the track will be taken into account. If keep offset is on and this is nullptr, all applicable objects will be taken into account. Not used if keep offset is off. |
region | Region, used when moving things in the editor. Same behavior as track . |
|
friend |
Definition at line 285 of file snap_grid.h.
|
friend |
Definition at line 269 of file snap_grid.h.
bool zrythm::gui::SnapGrid::default_adaptive_ = false |
If this is on, the default note length will be determined automatically based on the current zoom level.
The default note type still applies.
TODO this will be done after v1.
Definition at line 343 of file snap_grid.h.
|
staticconstexpr |
Definition at line 53 of file snap_grid.h.
utils::NoteLength zrythm::gui::SnapGrid::default_note_length_ {} |
Default note length.
Definition at line 331 of file snap_grid.h.
utils::NoteType zrythm::gui::SnapGrid::default_note_type_ { utils::NoteType::Normal } |
Default note type.
Definition at line 333 of file snap_grid.h.
NoteLengthType zrythm::gui::SnapGrid::length_type_ = NoteLengthType::NOTE_LENGTH_LINK |
See NoteLengthType.
Definition at line 348 of file snap_grid.h.
bool zrythm::gui::SnapGrid::snap_adaptive_ = false |
If this is on, the snap note length will be determined automatically based on the current zoom level.
The snap note type still applies.
Definition at line 309 of file snap_grid.h.
utils::NoteLength zrythm::gui::SnapGrid::snap_note_length_ {} |
Snap note length.
Definition at line 312 of file snap_grid.h.
utils::NoteType zrythm::gui::SnapGrid::snap_note_type_ { utils::NoteType::Normal } |
Snap note type.
Definition at line 315 of file snap_grid.h.
bool zrythm::gui::SnapGrid::snap_to_events_ = false |
Whether to snap to events.
Definition at line 328 of file snap_grid.h.
bool zrythm::gui::SnapGrid::snap_to_grid_ = true |
Whether to snap to the grid.
Definition at line 318 of file snap_grid.h.
bool zrythm::gui::SnapGrid::snap_to_grid_keep_offset_ = false |
Whether to keep the offset when moving items.
This requires snap_to_grid to be enabled.
Definition at line 325 of file snap_grid.h.
Type zrythm::gui::SnapGrid::type_ {} |
Definition at line 301 of file snap_grid.h.