Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
PositionProxy Class Reference

QML-friendly position representation with real-time safety. More...

#include <src/gui/backend/position_proxy.h>

Inheritance diagram for PositionProxy:
Collaboration diagram for PositionProxy:

Public Member Functions

 PositionProxy (QObject *parent=nullptr, const Position *pos=nullptr, bool realtime_updateable=false)
signed_frame_t getFrames () const
void setFrames (signed_frame_t frames)
Q_SIGNAL void framesChanged ()
double getTicks () const
void setTicks (double ticks)
Q_SIGNAL void ticksChanged ()
Position get_position () const
Q_INVOKABLE void addTicks (double ticks)
Q_INVOKABLE QString getStringDisplay (const zrythm::dsp::Transport *transport, const zrythm::dsp::TempoMapWrapper *tempo_map) const
void set_frames_rtsafe (signed_frame_t frames, dsp::TicksPerFrame ticks_per_frame)
void set_ticks_rtsafe (double ticks, dsp::FramesPerTick frames_per_tick)
void update_from_ticks_rtsafe (dsp::FramesPerTick frames_per_tick)
void update_from_frames_rtsafe (dsp::TicksPerFrame ticks_per_frame)
void set_position_rtsafe (const Position &pos)
void add_frames_rtsafe (signed_frame_t frames, dsp::TicksPerFrame ticks_per_frame)
bool processUpdates () override
 Process pending updates from real-time thread.
Public Member Functions inherited from zrythm::dsp::Position
 Position (const char *str, int beats_per_bar, int sixteenths_per_beat, FramesPerTick frames_per_tick)
 Parses a position from the given string.
 Position (double ticks, dsp::FramesPerTick frames_per_tick)
 Construct from total number of ticks.
 Position (signed_frame_t frames, TicksPerFrame ticks_per_frame)
 Construct from total number of frames.
void zero ()
signed_frame_t get_total_frames () const
 Getter.
double get_total_ticks () const
 Getter.
bool ticks_equal (const Position &other) const
bool is_positive () const
bool is_between_frames_excluding_2nd (signed_frame_t f1, signed_frame_t f2) const
 Whether the position starts on or after f1 and before f2 (ie, the position is between f1 and f2, exclusive of f2).
bool is_between_excl_2nd (const Position &start, const Position &end) const
 Returns if the position is after or equal to start and before end.
bool is_between_incl_2nd (const Position &start, const Position &end) const
 Returns if the position is after or equal to start and before or equal to end (ie, inclusive of end).
bool is_between_excl_both (const Position &start, const Position &end) const
bool is_between_excl_1st_incl_2nd (const Position &start, const Position &end) const
void set_to_bar (int bar, int ticks_per_bar, dsp::FramesPerTick frames_per_tick)
 Sets position to given bar.
void add_frames (signed_frame_t frames, TicksPerFrame ticks_per_frame)
 Adds the frames to the position and updates the rest of the fields, and makes sure the frames are still accurate.
void from_seconds (double secs, sample_rate_t sample_rate, TicksPerFrame ticks_per_frame)
 Converts seconds to position and puts the result in the given Position.
void from_frames (const signed_frame_t frames, TicksPerFrame ticks_per_frame)
void from_ticks (double ticks, dsp::FramesPerTick frames_per_tick)
 Sets position to the given total tick count.
void from_ms (const double ms, sample_rate_t sample_rate, TicksPerFrame ticks_per_frame)
void from_bars (int bars, int ticks_per_bar, dsp::FramesPerTick frames_per_tick)
void add_bars (int bars, int ticks_per_bar, dsp::FramesPerTick frames_per_tick)
void add_beats (int beats, int ticks_per_beat, dsp::FramesPerTick frames_per_tick)
void add_sixteenths (int sixteenths, dsp::FramesPerTick frames_per_tick)
void add_ticks (double ticks, dsp::FramesPerTick frames_per_tick)
signed_ms_t to_ms (sample_rate_t sample_rate) const
 Returns the Position in milliseconds.
void add_ms (double ms, sample_rate_t sample_rate, TicksPerFrame ticks_per_frame)
void add_minutes (int mins, sample_rate_t sample_rate, TicksPerFrame ticks_per_frame)
void add_seconds (signed_sec_t seconds, sample_rate_t sample_rate, TicksPerFrame ticks_per_frame)
void update_ticks_from_frames (TicksPerFrame ticks_per_frame)
 Updates ticks.
void update_frames_from_ticks (FramesPerTick frames_per_tick)
 Updates frames.
void set_to_midway_pos (const Position &start_pos, const Position &end_pos, FramesPerTick frames_per_tick)
 Sets the position to the midway point between the two given positions.
std::string to_string (int beats_per_bar, int sixteenths_per_beat, FramesPerTick frames_per_tick, int decimal_places=4) const
 Creates a string in the form of "0.0.0.0" from the given position.
void to_string (int beats_per_bar, int sixteenths_per_beat, FramesPerTick frames_per_tick, char *buf, int decimal_places=4) const
void print (int beats_per_bar, int sixteenths_per_beat, FramesPerTick frames_per_tick) const
 Prints the Position in the "0.0.0.0" form.
int get_total_bars (bool include_current, int ticks_per_bar, FramesPerTick frames_per_tick) const
 Returns the total number of beats.
int get_total_beats (bool include_current, int beats_per_bar, int ticks_per_beat, FramesPerTick frames_per_tick) const
 Returns the total number of beats.
int get_total_sixteenths (bool include_current, dsp::FramesPerTick frames_per_tick) const
 Returns the total number of sixteenths not including the current one.
void change_sign ()
 Changes the sign of the position.
int get_bars (bool start_at_one, int ticks_per_bar) const
 Gets the bars of the position.
int get_beats (bool start_at_one, int beats_per_bar, int ticks_per_beat) const
 Gets the beats of the position.
int get_sixteenths (bool start_at_one, int beats_per_bar, int sixteenths_per_beat, FramesPerTick frames_per_tick) const
 Gets the sixteenths of the position.
double get_ticks_part (FramesPerTick frames_per_tick) const
 Gets the ticks of the position.
void set_to_position (const Position &pos)
Positionget_closest_position (Position &p1, Position &p2) const
 Returns the closest position.

Static Public Member Functions

static double getTicksPerSixteenthNote ()
Static Public Member Functions inherited from zrythm::dsp::Position
static signed_frame_t compare_frames (const Position &p1, const Position &p2)
 Compares 2 positions based on their frames.
static const Positionget_min (const Position &p1, const Position &p2)
 Returns minimum of p1 and p2.
static const Positionget_max (const Position &p1, const Position &p2)
 Returns maximum of p1 and p2.
static signed_frame_t ms_to_frames (double ms, sample_rate_t sample_rate)
static double ms_to_ticks (double ms, sample_rate_t sample_rate, TicksPerFrame ticks_per_frame)
static signed_frame_t get_frames_from_ticks (double ticks, dsp::FramesPerTick frames_per_tick)
 Converts ticks to frames.
static void print_range (int beats_per_bar, int sixteenths_per_beat, FramesPerTick frames_per_tick, const Position &p1, const Position &p2)

Properties

QML_ELEMENT double ticks
signed_frame_t frames
double ticksPerSixteenthNote

Friends

void init_from (PositionProxy &obj, const PositionProxy &other, utils::ObjectCloneType clone_type)
auto operator<=> (const PositionProxy &lhs, const PositionProxy &rhs)
bool operator== (const PositionProxy &lhs, const PositionProxy &rhs)

Additional Inherited Members

Data Fields inherited from zrythm::dsp::Position
double ticks_ = 0.0
 Precise total number of ticks.
signed_frame_t frames_ = 0
 Position in frames (samples).
Static Public Attributes inherited from zrythm::dsp::Position
static constexpr int TICKS_PER_QUARTER_NOTE = 960
static constexpr int TICKS_PER_SIXTEENTH_NOTE = 240
static constexpr double TICKS_PER_QUARTER_NOTE_DBL = 960.0
static constexpr double TICKS_PER_SIXTEENTH_NOTE_DBL = 240.0
static constexpr double TICKS_PER_NINETYSIXTH_NOTE_DBL = 40.0
static constexpr int POSITION_MAX_BAR = 160000

Detailed Description

QML-friendly position representation with real-time safety.

Exposes Position functionality as Q_PROPERTYs with change notifications. Supports atomic updates from real-time threads when realtime_updateable=true.

Definition at line 32 of file position_proxy.h.

Member Function Documentation

◆ add_frames_rtsafe()

void PositionProxy::add_frames_rtsafe ( signed_frame_t frames,
dsp::TicksPerFrame ticks_per_frame )
inline

Definition at line 113 of file position_proxy.h.

◆ addTicks()

Q_INVOKABLE void PositionProxy::addTicks ( double ticks)
inline

Definition at line 69 of file position_proxy.h.

◆ get_position()

Position PositionProxy::get_position ( ) const
inline

Definition at line 64 of file position_proxy.h.

◆ getFrames()

signed_frame_t PositionProxy::getFrames ( ) const
inline

Definition at line 52 of file position_proxy.h.

◆ getTicks()

double PositionProxy::getTicks ( ) const
inline

Definition at line 56 of file position_proxy.h.

◆ getTicksPerSixteenthNote()

double PositionProxy::getTicksPerSixteenthNote ( )
inlinestatic

Definition at line 60 of file position_proxy.h.

◆ processUpdates()

bool PositionProxy::processUpdates ( )
overridevirtual

Process pending updates from real-time thread.

Returns
true if updates were processed

Implements IRealtimeProperty.

◆ set_frames_rtsafe()

void PositionProxy::set_frames_rtsafe ( signed_frame_t frames,
dsp::TicksPerFrame ticks_per_frame )
inline

Definition at line 79 of file position_proxy.h.

◆ set_position_rtsafe()

void PositionProxy::set_position_rtsafe ( const Position & pos)
inline

Definition at line 102 of file position_proxy.h.

◆ set_ticks_rtsafe()

void PositionProxy::set_ticks_rtsafe ( double ticks,
dsp::FramesPerTick frames_per_tick )
inline

Definition at line 84 of file position_proxy.h.

◆ update_from_frames_rtsafe()

void PositionProxy::update_from_frames_rtsafe ( dsp::TicksPerFrame ticks_per_frame)
inline

Definition at line 96 of file position_proxy.h.

◆ update_from_ticks_rtsafe()

void PositionProxy::update_from_ticks_rtsafe ( dsp::FramesPerTick frames_per_tick)
inline

Definition at line 90 of file position_proxy.h.

◆ operator<=>

auto operator<=> ( const PositionProxy & lhs,
const PositionProxy & rhs )
friend

Definition at line 129 of file position_proxy.h.

◆ operator==

bool operator== ( const PositionProxy & lhs,
const PositionProxy & rhs )
friend

Definition at line 135 of file position_proxy.h.

Property Documentation

◆ frames

signed_frame_t PositionProxy::frames
readwrite

Definition at line 41 of file position_proxy.h.

◆ ticks

QML_ELEMENT double PositionProxy::ticks
readwrite

Definition at line 40 of file position_proxy.h.

◆ ticksPerSixteenthNote

double PositionProxy::ticksPerSixteenthNote
read

Definition at line 42 of file position_proxy.h.


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