From 2f5b6b6b85f0f518aa702925946bac2a0589b563 Mon Sep 17 00:00:00 2001 From: nick_m Date: Tue, 29 Dec 2015 01:46:34 +1100 Subject: [PATCH] Tempo ramps - clean up TempoSection, fix thinko in position function. --- libs/ardour/ardour/tempo.h | 9 +++---- libs/ardour/tempo.cc | 50 +++++++++++++++++++++++--------------- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/libs/ardour/ardour/tempo.h b/libs/ardour/ardour/tempo.h index 341198f1fe..c5cb665223 100644 --- a/libs/ardour/ardour/tempo.h +++ b/libs/ardour/ardour/tempo.h @@ -105,9 +105,9 @@ class LIBARDOUR_API MetricSection { : _beat (0), _frame (frame), _movable (true), _position_lock_style (MusicTime) {} virtual ~MetricSection() {} - const double start () const { return _beat; } - const double& beat() const { return _beat; } + const double start () const { return _beat; } + const double& beat () const { return _beat; } void set_beat (double beat) { _beat = beat;} framepos_t frame() const { return _frame; } @@ -123,6 +123,7 @@ class LIBARDOUR_API MetricSection { XML state information. */ virtual XMLNode& get_state() const = 0; + PositionLockStyle position_lock_style () const { return _position_lock_style; } void set_position_lock_style (PositionLockStyle ps) { _position_lock_style = ps; } @@ -205,10 +206,8 @@ class LIBARDOUR_API TempoSection : public MetricSection, public Tempo { * time relative to section start. */ double c_func (double end_tpm, double end_time) const; - double a_func (double begin_tpm, double end_tpm, double end_time) const; + double a_func (double end_tpm, double c_func) const; - double tempo_at_time (double time, double end_bpm, double end_time) const; - double time_at_tempo (double tempo, double end_bpm, double end_time) const; double tick_tempo_at_time (double time, double end_tpm, double end_time) const; double time_at_tick_tempo (double tick_tempo, double end_tpm, double end_time) const; diff --git a/libs/ardour/tempo.cc b/libs/ardour/tempo.cc index 5dcbf3761c..6112fb7c54 100644 --- a/libs/ardour/tempo.cc +++ b/libs/ardour/tempo.cc @@ -182,6 +182,8 @@ TempoSection::set_type (Type type) _type = type; } +/** returns the tempo at the zero-based (relative to tempo section) frame. +*/ double TempoSection::tempo_at_frame (framepos_t frame, double end_bpm, framepos_t end_frame, framecnt_t frame_rate) const { @@ -193,6 +195,9 @@ TempoSection::tempo_at_frame (framepos_t frame, double end_bpm, framepos_t end_f return tick_tempo_at_time (frame_to_minute (frame, frame_rate), end_bpm * BBT_Time::ticks_per_beat, frame_to_minute (end_frame, frame_rate)) / BBT_Time::ticks_per_beat; } +/** returns the zero-based frame (relative to tempo section) + where the tempo occurs. +*/ framepos_t TempoSection::frame_at_tempo (double tempo, double end_bpm, framepos_t end_frame, framecnt_t frame_rate) const { @@ -203,6 +208,10 @@ TempoSection::frame_at_tempo (double tempo, double end_bpm, framepos_t end_frame return minute_to_frame (time_at_tick_tempo (tempo * BBT_Time::ticks_per_beat, end_bpm * BBT_Time::ticks_per_beat, frame_to_minute (end_frame, frame_rate)), frame_rate); } +/** returns the zero-based tick (relative to tempo section) + where the zero-based frame (relative to tempo section) + lies. +*/ double TempoSection::tick_at_frame (framepos_t frame, double end_bpm, framepos_t end_frame, framecnt_t frame_rate) const { @@ -213,6 +222,10 @@ TempoSection::tick_at_frame (framepos_t frame, double end_bpm, framepos_t end_fr return tick_at_time (frame_to_minute (frame, frame_rate), end_bpm * BBT_Time::ticks_per_beat, frame_to_minute (end_frame, frame_rate)); } +/** returns the zero-based frame (relative to tempo section) + where the zero-based tick (relative to tempo section) + falls. +*/ framepos_t TempoSection::frame_at_tick (double tick, double end_bpm, framepos_t end_frame, framecnt_t frame_rate) const { @@ -223,12 +236,23 @@ TempoSection::frame_at_tick (double tick, double end_bpm, framepos_t end_frame, return minute_to_frame (time_at_tick (tick, end_bpm * BBT_Time::ticks_per_beat, frame_to_minute (end_frame, frame_rate)), frame_rate); } -double TempoSection::beat_at_frame (framepos_t frame, double end_bpm, framepos_t end_frame, framecnt_t frame_rate) const +/** returns the zero-based beat (relative to tempo section) + where the zero-based frame (relative to tempo section) + lies. +*/ +double +TempoSection::beat_at_frame (framepos_t frame, double end_bpm, framepos_t end_frame, framecnt_t frame_rate) const { return tick_at_frame (frame, end_bpm, end_frame, frame_rate) / BBT_Time::ticks_per_beat; } -framepos_t TempoSection::frame_at_beat (double beat, double end_bpm, framepos_t end_frame, framecnt_t frame_rate) const +/** returns the zero-based frame (relative to tempo section start frame) + where the zero-based beat (relative to tempo section start) + falls. +*/ + +framepos_t +TempoSection::frame_at_beat (double beat, double end_bpm, framepos_t end_frame, framecnt_t frame_rate) const { return frame_at_tick (beat * BBT_Time::ticks_per_beat, end_bpm, end_frame, frame_rate); } @@ -245,12 +269,14 @@ TempoSection::frame_to_minute (framecnt_t frame, framecnt_t frame_rate) const return (frame / (double) frame_rate) / 60.0; } -/* constant for exp */ +/* position function */ double -TempoSection::a_func (double begin_tpm, double end_tpm, double end_time) const +TempoSection::a_func (double end_tpm, double c_func) const { - return log (end_tpm / ticks_per_minute()) / c_func (end_tpm, end_time); + return log (end_tpm / ticks_per_minute()) / c_func; } + +/*function constant*/ double TempoSection::c_func (double end_tpm, double end_time) const { @@ -271,20 +297,6 @@ TempoSection::time_at_tick_tempo (double tick_tempo, double end_tpm, double end_ return log (tick_tempo / ticks_per_minute()) / c_func (end_tpm, end_time); } -/* tempo in bpm at time in minutes */ -double -TempoSection::tempo_at_time (double time, double end_bpm, double end_time) const -{ - return tick_tempo_at_time (time, end_bpm * BBT_Time::ticks_per_beat, end_time) / BBT_Time::ticks_per_beat; -} - -/* time in minutes at tempo in bpm */ -double -TempoSection::time_at_tempo (double tempo, double end_bpm, double end_time) const -{ - return time_at_tick_tempo (tempo * BBT_Time::ticks_per_beat, end_bpm * BBT_Time::ticks_per_beat, end_time); -} - /* tick at time in minutes */ double TempoSection::tick_at_time (double time, double end_tpm, double end_time) const -- 2.30.2