Zrythm v2.0.0-alpha.1
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
zrythm::dsp::FixedPpqTempoMap< PPQ > Class Template Reference

Manages tempo and time signature events for a DAW timeline. More...

#include <src/dsp/tempo_map.h>

Data Structures

struct  TempoEvent
 Tempo event definition. More...
struct  TimeSignatureEvent
 Time signature event definition. More...
struct  MusicalPosition
 Musical position representation. More...

Public Types

enum class  CurveType : std::uint8_t { Constant , Linear }
 Tempo curve type (constant or linear ramp). More...

Public Member Functions

 FixedPpqTempoMap (units::precise_sample_rate_t sampleRate)
 Construct a new FixedPpqTempoMap object.
void set_sample_rate (units::precise_sample_rate_t sampleRate)
 Set the sample rate.
void add_tempo_event (units::tick_t tick, units::bpm_t bpm, CurveType curve)
 Add a tempo event.
void remove_tempo_event (units::tick_t tick)
 Remove a tempo event at the specified tick.
void add_time_signature_event (units::tick_t tick, int numerator, int denominator)
 Add a time signature event.
void remove_time_signature_event (units::tick_t tick)
 Remove a time signature event at the specified tick.
auto tick_to_seconds (TimelineTick tick) const -> units::precise_second_t
 Convert timeline ticks to seconds.
units::precise_sample_t tick_to_samples (TimelineTick tick) const
 Convert timeline ticks to samples.
units::sample_t tick_to_samples_rounded (TimelineTick tick) const
TimelineTick seconds_to_tick (units::precise_second_t seconds) const
 Convert seconds to timeline ticks.
TimelineTick samples_to_tick (units::precise_sample_t samples) const
 Convert samples to timeline ticks.
TimeSignatureEvent time_signature_at_tick (units::tick_t tick) const
 Get the time signature event active at the given tick.
units::bpm_t tempo_at_tick (units::tick_t tick) const
 Get the tempo (BPM) active at the given tick.
std::span< const TempoEventtempo_events () const noexcept
 Read-only view of all inserted tempo events, sorted ascending by tick.
std::span< const TimeSignatureEventtime_signature_events () const noexcept
 Read-only view of all inserted time signature events, sorted ascending by tick.
MusicalPosition tick_to_musical_position (units::tick_t tick) const
 Convert ticks to musical position (bar:beat:sixteenth:tick).
MusicalPosition samples_to_musical_position (units::sample_t samples) const
TimelineTickI musical_position_to_tick (const MusicalPosition &pos) const
 Convert musical position to ticks.
auto get_sample_rate () const
 Get current sample rate.
units::bpm_t base_bpm () const
 Base tempo at tick 0.
void set_base_bpm (units::bpm_t bpm)
 Set the base tempo at tick 0 and recompute the lead-segment timing.
const TimeSignatureEventbase_time_signature () const
 Base time signature at tick 0.
void set_base_time_signature (int numerator, int denominator)
 Set the base time signature at tick 0.
std::span< const TimeSignatureEventeffective_time_signature_events () const noexcept
 Read-only view of the time signature events with the base signature prepended at tick 0 when no inserted event sits at tick 0.

Static Public Member Functions

static consteval auto get_ppq ()
 Get pulses per quarter note.

Friends

class TempoMapWrapper
void to_json (nlohmann::json &j, const FixedPpqTempoMap &tempo_map)
void from_json (const nlohmann::json &j, FixedPpqTempoMap &tempo_map)

Detailed Description

template<units::tick_t::NTTP PPQ>
class zrythm::dsp::FixedPpqTempoMap< PPQ >

Manages tempo and time signature events for a DAW timeline.

The FixedPpqTempoMap class handles:

  • Tempo events (constant and linear ramps)
  • Time signature changes
  • Conversion between musical time (ticks) and absolute time (seconds/samples)
  • Conversion between ticks and musical position (bar:beat:sixteenth:tick)

All tempo events are stored in musical time (ticks) and automatically adjust to time signature changes. A precondition for this is that tempo events are only added after all time signature events are added.

Note
The map always carries a base tempo (base_bpm_) and base time signature (base_time_sig_) anchored at tick 0. These govern the region from tick 0 up to the first inserted event (as a constant segment), or the whole timeline if no events exist. An inserted event at tick 0 shadows the base for the region it covers.
Template Parameters
PPQPulses (ticks) per quarter note

Definition at line 41 of file tempo_map.h.

Member Enumeration Documentation

◆ CurveType

template<units::tick_t::NTTP PPQ>
enum class zrythm::dsp::FixedPpqTempoMap::CurveType : std::uint8_t
strong

Tempo curve type (constant or linear ramp).

Enumerator
Constant 

Constant tempo.

Linear 

Linear tempo ramp.

Definition at line 47 of file tempo_map.h.

Constructor & Destructor Documentation

◆ FixedPpqTempoMap()

template<units::tick_t::NTTP PPQ>
zrythm::dsp::FixedPpqTempoMap< PPQ >::FixedPpqTempoMap ( units::precise_sample_rate_t sampleRate)
inlineexplicit

Construct a new FixedPpqTempoMap object.

Parameters
sampleRateSample rate in Hz

Definition at line 113 of file tempo_map.h.

Member Function Documentation

◆ add_tempo_event()

template<units::tick_t::NTTP PPQ>
void zrythm::dsp::FixedPpqTempoMap< PPQ >::add_tempo_event ( units::tick_t tick,
units::bpm_t bpm,
CurveType curve )

Add a tempo event.

Parameters
tickPosition in ticks
bpmTempo
curveCurve type
Warning
Tempo events must only be added after all time signature events have been added.
Exceptions
std::invalid_argumentfor invalid BPM or tick values

◆ add_time_signature_event()

template<units::tick_t::NTTP PPQ>
void zrythm::dsp::FixedPpqTempoMap< PPQ >::add_time_signature_event ( units::tick_t tick,
int numerator,
int denominator )

Add a time signature event.

Parameters
tickPosition in ticks
numeratorBeats per bar
denominatorBeat unit (2,4,8,16).

For the beat unit:

  • 2 means 1 beat is a 1/2 note (8 sixteenths).
  • 4 means 1 beat is a 1/4 note (4 sixteenths).
  • 8 means 1 beat is a 1/8 note (2 sixteenths).
  • 16 means 1 beat is a 1/16 note (1 sixteenth).
Exceptions
std::invalid_argumentfor invalid parameters

◆ base_bpm()

template<units::tick_t::NTTP PPQ>
units::bpm_t zrythm::dsp::FixedPpqTempoMap< PPQ >::base_bpm ( ) const
inline

Base tempo at tick 0.

Definition at line 245 of file tempo_map.h.

◆ base_time_signature()

template<units::tick_t::NTTP PPQ>
const TimeSignatureEvent & zrythm::dsp::FixedPpqTempoMap< PPQ >::base_time_signature ( ) const
inline

Base time signature at tick 0.

Definition at line 255 of file tempo_map.h.

◆ effective_time_signature_events()

template<units::tick_t::NTTP PPQ>
std::span< const TimeSignatureEvent > zrythm::dsp::FixedPpqTempoMap< PPQ >::effective_time_signature_events ( ) const
inlinenoexcept

Read-only view of the time signature events with the base signature prepended at tick 0 when no inserted event sits at tick 0.

Backed by a cache (effective_time_sig_events_) rebuilt on mutation, so the read path is allocation-free.

Note
Realtime safety relies on a caller-enforced contract: the cache must not be mutated while the audio thread is mid-read. All mutation entry points (add/remove/clear/set_base and project reload) must run while the engine is stopped or paused.

Definition at line 279 of file tempo_map.h.

◆ get_ppq()

template<units::tick_t::NTTP PPQ>
consteval auto zrythm::dsp::FixedPpqTempoMap< PPQ >::get_ppq ( )
inlinestaticconsteval

Get pulses per quarter note.

Definition at line 239 of file tempo_map.h.

◆ get_sample_rate()

template<units::tick_t::NTTP PPQ>
auto zrythm::dsp::FixedPpqTempoMap< PPQ >::get_sample_rate ( ) const
inline

Get current sample rate.

Definition at line 242 of file tempo_map.h.

◆ musical_position_to_tick()

template<units::tick_t::NTTP PPQ>
TimelineTickI zrythm::dsp::FixedPpqTempoMap< PPQ >::musical_position_to_tick ( const MusicalPosition & pos) const

Convert musical position to ticks.

Parameters
posMusical position
Returns
Position in ticks
Exceptions
std::invalid_argumentfor invalid position

◆ samples_to_tick()

template<units::tick_t::NTTP PPQ>
TimelineTick zrythm::dsp::FixedPpqTempoMap< PPQ >::samples_to_tick ( units::precise_sample_t samples) const
inline

Convert samples to timeline ticks.

Definition at line 179 of file tempo_map.h.

◆ set_base_bpm()

template<units::tick_t::NTTP PPQ>
void zrythm::dsp::FixedPpqTempoMap< PPQ >::set_base_bpm ( units::bpm_t bpm)
inline

Set the base tempo at tick 0 and recompute the lead-segment timing.

Definition at line 248 of file tempo_map.h.

◆ set_base_time_signature()

template<units::tick_t::NTTP PPQ>
void zrythm::dsp::FixedPpqTempoMap< PPQ >::set_base_time_signature ( int numerator,
int denominator )
inline

Set the base time signature at tick 0.

Definition at line 261 of file tempo_map.h.

◆ set_sample_rate()

template<units::tick_t::NTTP PPQ>
void zrythm::dsp::FixedPpqTempoMap< PPQ >::set_sample_rate ( units::precise_sample_rate_t sampleRate)
inline

Set the sample rate.

Definition at line 120 of file tempo_map.h.

◆ tempo_at_tick()

template<units::tick_t::NTTP PPQ>
units::bpm_t zrythm::dsp::FixedPpqTempoMap< PPQ >::tempo_at_tick ( units::tick_t tick) const

Get the tempo (BPM) active at the given tick.

Parameters
tickPosition in ticks
Returns
Tempo (or default 120 BPM if none found)

◆ tempo_events()

template<units::tick_t::NTTP PPQ>
std::span< const TempoEvent > zrythm::dsp::FixedPpqTempoMap< PPQ >::tempo_events ( ) const
inlinenoexcept

Read-only view of all inserted tempo events, sorted ascending by tick.

The base tempo (base_bpm_) governs any region not covered by these events, starting from tick 0.

Definition at line 206 of file tempo_map.h.

◆ tick_to_musical_position()

template<units::tick_t::NTTP PPQ>
MusicalPosition zrythm::dsp::FixedPpqTempoMap< PPQ >::tick_to_musical_position ( units::tick_t tick) const

Convert ticks to musical position (bar:beat:sixteenth:tick).

Parameters
tickPosition in ticks
Returns
Musical position

◆ tick_to_samples()

template<units::tick_t::NTTP PPQ>
units::precise_sample_t zrythm::dsp::FixedPpqTempoMap< PPQ >::tick_to_samples ( TimelineTick tick) const
inline

Convert timeline ticks to samples.

Definition at line 165 of file tempo_map.h.

◆ tick_to_samples_rounded()

template<units::tick_t::NTTP PPQ>
units::sample_t zrythm::dsp::FixedPpqTempoMap< PPQ >::tick_to_samples_rounded ( TimelineTick tick) const
inline

Definition at line 170 of file tempo_map.h.

◆ time_signature_at_tick()

template<units::tick_t::NTTP PPQ>
TimeSignatureEvent zrythm::dsp::FixedPpqTempoMap< PPQ >::time_signature_at_tick ( units::tick_t tick) const

Get the time signature event active at the given tick.

Parameters
tickPosition in ticks
Returns
Time signature event (or default 4/4 if none found)

◆ time_signature_events()

template<units::tick_t::NTTP PPQ>
std::span< const TimeSignatureEvent > zrythm::dsp::FixedPpqTempoMap< PPQ >::time_signature_events ( ) const
inlinenoexcept

Read-only view of all inserted time signature events, sorted ascending by tick.

The base time signature (base_time_sig_) governs any region not covered by these events, starting from tick 0.

Definition at line 215 of file tempo_map.h.

◆ TempoMapWrapper

template<units::tick_t::NTTP PPQ>
friend class TempoMapWrapper
friend

Definition at line 43 of file tempo_map.h.


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