Zrythm v2.0.0-DEV
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, double 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 (units::precise_tick_t tick) const -> units::precise_second_t
 Convert fractional ticks to seconds.
units::precise_sample_t tick_to_samples (units::precise_tick_t tick) const
 Convert fractional ticks to samples.
units::sample_t tick_to_samples_rounded (units::precise_tick_t tick) const
units::precise_tick_t seconds_to_tick (units::precise_second_t seconds) const
 Convert seconds to fractional ticks.
units::precise_tick_t samples_to_tick (units::precise_sample_t samples) const
 Convert samples to fractional ticks.
TimeSignatureEvent time_signature_at_tick (units::tick_t tick) const
 Get the time signature event active at the given tick.
double tempo_at_tick (units::tick_t tick) const
 Get the tempo event active at the given 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
units::tick_t musical_position_to_tick (const MusicalPosition &pos) const
 Convert musical position to ticks.
double get_sample_rate () const
 Get current sample rate.
void set_default_bpm (double bpm)
void set_default_time_signature (int numerator, int denominator)

Static Public Member Functions

static consteval int 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
If no events are added, the tempo map will use defaults which can be modified.
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 115 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,
double bpm,
CurveType curve )
inline

Add a tempo event.

Parameters
tickPosition in ticks
bpmTempo in BPM
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

Definition at line 137 of file tempo_map.h.

◆ 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 )
inline

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

Definition at line 195 of file tempo_map.h.

◆ get_ppq()

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

Get pulses per quarter note.

Definition at line 624 of file tempo_map.h.

◆ get_sample_rate()

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

Get current sample rate.

Definition at line 627 of file tempo_map.h.

◆ musical_position_to_tick()

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

Convert musical position to ticks.

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

Definition at line 562 of file tempo_map.h.

◆ remove_tempo_event()

template<units::tick_t::NTTP PPQ>
void zrythm::dsp::FixedPpqTempoMap< PPQ >::remove_tempo_event ( units::tick_t tick)
inline

Remove a tempo event at the specified tick.

Definition at line 164 of file tempo_map.h.

◆ remove_time_signature_event()

template<units::tick_t::NTTP PPQ>
void zrythm::dsp::FixedPpqTempoMap< PPQ >::remove_time_signature_event ( units::tick_t tick)
inline

Remove a time signature event at the specified tick.

Definition at line 225 of file tempo_map.h.

◆ samples_to_musical_position()

template<units::tick_t::NTTP PPQ>
MusicalPosition zrythm::dsp::FixedPpqTempoMap< PPQ >::samples_to_musical_position ( units::sample_t samples) const
inline

Definition at line 545 of file tempo_map.h.

◆ samples_to_tick()

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

Convert samples to fractional ticks.

Definition at line 390 of file tempo_map.h.

◆ seconds_to_tick()

template<units::tick_t::NTTP PPQ>
units::precise_tick_t zrythm::dsp::FixedPpqTempoMap< PPQ >::seconds_to_tick ( units::precise_second_t seconds) const
inline

Convert seconds to fractional ticks.

Definition at line 323 of file tempo_map.h.

◆ set_default_bpm()

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

Definition at line 632 of file tempo_map.h.

◆ set_default_time_signature()

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

Definition at line 633 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 121 of file tempo_map.h.

◆ tempo_at_tick()

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

Get the tempo event active at the given tick.

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

Definition at line 424 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
inline

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

Parameters
tickPosition in ticks
Returns
Musical position

Definition at line 462 of file tempo_map.h.

◆ tick_to_samples()

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

Convert fractional ticks to samples.

Definition at line 312 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 ( units::precise_tick_t tick) const
inline

Definition at line 317 of file tempo_map.h.

◆ tick_to_seconds()

template<units::tick_t::NTTP PPQ>
auto zrythm::dsp::FixedPpqTempoMap< PPQ >::tick_to_seconds ( units::precise_tick_t tick) const->units::precise_second_t
inline

Convert fractional ticks to seconds.

Definition at line 242 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
inline

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)

Definition at line 401 of file tempo_map.h.

◆ from_json

template<units::tick_t::NTTP PPQ>
void from_json ( const nlohmann::json & j,
FixedPpqTempoMap< PPQ > & tempo_map )
friend

Definition at line 745 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.

◆ to_json

template<units::tick_t::NTTP PPQ>
void to_json ( nlohmann::json & j,
const FixedPpqTempoMap< PPQ > & tempo_map )
friend

Definition at line 740 of file tempo_map.h.


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