Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
zrythm::gui::SnapGrid Class Referencefinal

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)
 

Detailed Description

Snap/grid information.

Definition at line 44 of file snap_grid.h.

Member Typedef Documentation

◆ FramesPerTickProvider

using zrythm::gui::SnapGrid::FramesPerTickProvider = std::function<dsp::FramesPerTick (void)>

Definition at line 55 of file snap_grid.h.

◆ Position

◆ Region

◆ TicksPerBarProvider

using zrythm::gui::SnapGrid::TicksPerBarProvider = std::function<int (void)>

Definition at line 56 of file snap_grid.h.

◆ TicksPerBeatProvider

using zrythm::gui::SnapGrid::TicksPerBeatProvider = std::function<int (void)>

Definition at line 57 of file snap_grid.h.

◆ Track

Member Enumeration Documentation

◆ Type

enum class zrythm::gui::SnapGrid::Type
strong

Definition at line 47 of file snap_grid.h.

Constructor & Destructor Documentation

◆ SnapGrid()

zrythm::gui::SnapGrid::SnapGrid ( Type type,
utils::NoteLength note_length,
bool adaptive,
FramesPerTickProvider frames_per_tick_provider,
TicksPerBarProvider ticks_per_bar_provider,
TicksPerBeatProvider ticks_per_beat_provider )
inline

Definition at line 65 of file snap_grid.h.

Member Function Documentation

◆ any_snap()

bool zrythm::gui::SnapGrid::any_snap ( ) const
inline

Returns whether any snapping is enabled.

Definition at line 98 of file snap_grid.h.

◆ get_closest_snap_point()

bool zrythm::gui::SnapGrid::get_closest_snap_point ( const Position & pivot_pos,
Track * track,
Region * region,
Position & closest_sp ) const

Get closest snap point.

Parameters
pivot_posPosition to check snap points for.
trackTrack, 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.
regionRegion, used when moving things in the editor. Same behavior as track.
closest_spPosition to set.
Returns
Whether a snap point was found or not.

◆ get_nearby_snap_point()

bool zrythm::gui::SnapGrid::get_nearby_snap_point ( Position & ret_pos,
double ticks,
bool return_prev )

Returns the next or previous SnapGrid point.

Parameters
[out]ret_posOutput position, if found.
ticksPosition to search for.
return_prev1 to return the previous element or 0 to return the next.
Returns
Whether successful.

◆ get_next_snap_point()

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.

Parameters
pivot_posPosition to check snap points for.
trackTrack, 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.
regionRegion, used when moving things in the editor. Same behavior as track.
next_snap_pointPosition to set.
Returns
Whether a snap point was found or not.

◆ get_prev_snap_point()

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

Parameters
pivot_posPosition to check snap points for.
trackTrack, 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.
regionRegion, used when moving things in the editor. Same behavior as track.
prev_snap_pointThe position to set.
Returns
Whether a snap point was found or not.

◆ get_snapped_end_position()

Position zrythm::gui::SnapGrid::get_snapped_end_position ( const Position & start_pos) const

Returns an end position that is 1 snap point away from start_pos.

Parameters
start_posStart Position.

◆ set_frames_per_tick_provider()

void zrythm::gui::SnapGrid::set_frames_per_tick_provider ( FramesPerTickProvider frames_per_tick_provider)
inline

Definition at line 90 of file snap_grid.h.

◆ set_ticks_per_bar_provider()

void zrythm::gui::SnapGrid::set_ticks_per_bar_provider ( TicksPerBarProvider ticks_per_bar_provider)
inline

Definition at line 80 of file snap_grid.h.

◆ set_ticks_per_beat_provider()

void zrythm::gui::SnapGrid::set_ticks_per_beat_provider ( TicksPerBeatProvider ticks_per_beat_provider)
inline

Definition at line 85 of file snap_grid.h.

◆ snap()

Position zrythm::gui::SnapGrid::snap ( const Position & pivot_pos,
const Position * start_pos,
Track * track,
Region * region ) const

Snaps pivot_pos using given options.

Parameters
start_posThe previous position (ie, the position the drag started at. This is only used when the "keep offset" setting is on.
trackTrack, 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.
regionRegion, used when moving things in the editor. Same behavior as track.

◆ snap_simple()

Position zrythm::gui::SnapGrid::snap_simple ( const Position & pivot_pos) const
inline

Snaps pivot_pos using given options.

Parameters
sg

Definition at line 245 of file snap_grid.h.

Friends And Related Symbol Documentation

◆ from_json

void from_json ( const nlohmann::json & j,
SnapGrid & p )
friend

Definition at line 285 of file snap_grid.h.

◆ to_json

void to_json ( nlohmann::json & j,
const SnapGrid & p )
friend

Definition at line 269 of file snap_grid.h.

Field Documentation

◆ default_adaptive_

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.

◆ DEFAULT_MAX_BAR

int zrythm::gui::SnapGrid::DEFAULT_MAX_BAR = 10000
staticconstexpr

Definition at line 53 of file snap_grid.h.

◆ default_note_length_

utils::NoteLength zrythm::gui::SnapGrid::default_note_length_ {}

Default note length.

Definition at line 331 of file snap_grid.h.

◆ default_note_type_

utils::NoteType zrythm::gui::SnapGrid::default_note_type_ { utils::NoteType::Normal }

Default note type.

Definition at line 333 of file snap_grid.h.

◆ length_type_

NoteLengthType zrythm::gui::SnapGrid::length_type_ = NoteLengthType::NOTE_LENGTH_LINK

See NoteLengthType.

Definition at line 348 of file snap_grid.h.

◆ snap_adaptive_

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.

◆ snap_note_length_

utils::NoteLength zrythm::gui::SnapGrid::snap_note_length_ {}

Snap note length.

Definition at line 312 of file snap_grid.h.

◆ snap_note_type_

utils::NoteType zrythm::gui::SnapGrid::snap_note_type_ { utils::NoteType::Normal }

Snap note type.

Definition at line 315 of file snap_grid.h.

◆ snap_to_events_

bool zrythm::gui::SnapGrid::snap_to_events_ = false

Whether to snap to events.

Definition at line 328 of file snap_grid.h.

◆ snap_to_grid_

bool zrythm::gui::SnapGrid::snap_to_grid_ = true

Whether to snap to the grid.

Definition at line 318 of file snap_grid.h.

◆ snap_to_grid_keep_offset_

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_

Type zrythm::gui::SnapGrid::type_ {}

Definition at line 301 of file snap_grid.h.


The documentation for this class was generated from the following file: