remove public pulse methods from TempoMap.

- the only object whose musical position is not expressed in
	  quarter notes is MetricSection.
	  there is now no need to expose this.
This commit is contained in:
nick_m 2016-11-01 21:54:11 +11:00
parent 3db68b4f9e
commit 594137f5cc
8 changed files with 51 additions and 90 deletions

View File

@ -3427,7 +3427,7 @@ TempoMarkerDrag::aborted (bool moved)
BBTRulerDrag::BBTRulerDrag (Editor* e, ArdourCanvas::Item* i)
: Drag (e, i)
, _pulse (0.0)
, _grab_qn (0.0)
, _tempo (0)
, before_state (0)
{
@ -3467,9 +3467,9 @@ BBTRulerDrag::setup_pointer_frame_offset ()
beat = floor (beat_at_frame) + (floor (((beat_at_frame - floor (beat_at_frame)) * 4)) / 4);
}
_pulse = map.pulse_at_beat (beat);
_grab_qn = map.quarter_note_at_beat (beat);
_pointer_frame_offset = raw_grab_frame() - map.frame_at_pulse (_pulse);
_pointer_frame_offset = raw_grab_frame() - map.frame_at_quarter_note (_grab_qn);
}
@ -3494,7 +3494,7 @@ BBTRulerDrag::motion (GdkEvent* event, bool first_move)
if (ArdourKeyboard::indicates_constraint (event->button.state)) {
/* adjust previous tempo to match pointer frame */
_editor->session()->tempo_map().gui_dilate_tempo (_tempo, map.frame_at_pulse (_pulse), pf, _pulse);
_editor->session()->tempo_map().gui_dilate_tempo (_tempo, map.frame_at_quarter_note (_grab_qn), pf);
}
ostringstream sstr;
sstr << "^" << fixed << setprecision(3) << map.tempo_at_frame (pf).beats_per_minute() << "\n";

View File

@ -771,7 +771,7 @@ public:
void setup_pointer_frame_offset ();
private:
double _pulse;
double _grab_qn;
ARDOUR::TempoSection* _tempo;
XMLNode* before_state;
};

View File

@ -419,12 +419,6 @@ class LIBARDOUR_API TempoMap : public PBD::StatefulDestructible
const Meter& meter_at_frame (framepos_t) const;
double pulse_at_beat (const double& beat) const;
double beat_at_pulse (const double& pulse) const;
double pulse_at_frame (const framecnt_t& frame) const;
framepos_t frame_at_pulse (const double& pulse) const;
/* bbt - it's nearly always better to use beats.*/
Timecode::BBT_Time bbt_at_frame (framepos_t when);
Timecode::BBT_Time bbt_at_frame_rt (framepos_t when);
@ -433,9 +427,7 @@ class LIBARDOUR_API TempoMap : public PBD::StatefulDestructible
double beat_at_bbt (const Timecode::BBT_Time& bbt);
Timecode::BBT_Time bbt_at_beat (const double& beats);
double pulse_at_bbt (const Timecode::BBT_Time& bbt);
double pulse_at_bbt_rt (const Timecode::BBT_Time& bbt);
Timecode::BBT_Time bbt_at_pulse (const double& pulse);
double quarter_note_at_bbt_rt (const Timecode::BBT_Time& bbt);
framecnt_t bbt_duration_at (framepos_t, const Timecode::BBT_Time&, int dir);
@ -457,6 +449,7 @@ class LIBARDOUR_API TempoMap : public PBD::StatefulDestructible
double quarter_note_at_frame (const framepos_t frame);
double quarter_note_at_frame_rt (const framepos_t frame);
framepos_t frame_at_quarter_note (const double quarter_note);
double quarter_note_at_beat (const double beat);
double beat_at_quarter_note (const double beat);
@ -465,7 +458,7 @@ class LIBARDOUR_API TempoMap : public PBD::StatefulDestructible
void gui_move_tempo (TempoSection*, const framepos_t& frame, const int& sub_num);
void gui_move_meter (MeterSection*, const framepos_t& frame);
bool gui_change_tempo (TempoSection*, const Tempo& bpm);
void gui_dilate_tempo (TempoSection* tempo, const framepos_t& frame, const framepos_t& end_frame, const double& pulse);
void gui_dilate_tempo (TempoSection* tempo, const framepos_t& frame, const framepos_t& end_frame);
double exact_beat_at_frame (const framepos_t& frame, const int32_t sub_num);
double exact_qn_at_frame (const framepos_t& frame, const int32_t sub_num);

View File

@ -2607,7 +2607,7 @@ LV2Plugin::connect_and_run(BufferSet& bufs,
} else {
tmetric.set_metric(metric);
Timecode::BBT_Time bbt;
bbt = tmap.bbt_at_pulse (metric->pulse());
bbt = tmap.bbt_at_frame (metric->frame());
double bpm = tmap.tempo_at_frame (start/*XXX*/).beats_per_minute();
write_position(&_impl->forge, _ev_buffers[port_index],
tmetric, bbt, speed, bpm,

View File

@ -225,7 +225,7 @@ intptr_t Session::vst_callback (
bbt.beats = 1;
bbt.ticks = 0;
/* exact quarter note */
double ppqBar = session->tempo_map().pulse_at_bbt_rt (bbt) * 4.0;
double ppqBar = session->tempo_map().quarter_note_at_bbt_rt (bbt);
/* quarter note at frame position (not rounded to note subdivision) */
double ppqPos = session->tempo_map().quarter_note_at_frame_rt (now);
if (value & (kVstPpqPosValid)) {

View File

@ -1584,7 +1584,7 @@ TempoMap::minute_at_beat_locked (const Metrics& metrics, const double& beat) con
return prev_t->minute_at_pulse (((beat - prev_m->beat()) / prev_m->note_divisor()) + prev_m->pulse());
}
/** Returns a Tempo corresponding to the supplied frame.
/** Returns a Tempo corresponding to the supplied frame position.
* @param frame The audio frame.
* @return a Tempo according to the tempo map at the supplied frame.
*
@ -1744,6 +1744,7 @@ TempoMap::pulse_at_tempo_locked (const Metrics& metrics, const Tempo& tempo) con
/** Returns a Tempo corresponding to the supplied BBT (meter-based) beat.
* @param beat The BBT (meter-based) beat.
* @return the Tempo at the supplied BBT (meter-based) beat.
*/
Tempo
TempoMap::tempo_at_beat (const double& beat) const
@ -1757,6 +1758,7 @@ TempoMap::tempo_at_beat (const double& beat) const
/** Returns a BBT (meter-based) beat corresponding to the supplied Tempo.
* @param tempo The tempo.
* @return the BBT (meter-based) beat at the supplied Tempo.
*/
double
TempoMap::beat_at_tempo (const Tempo& tempo) const
@ -1766,20 +1768,16 @@ TempoMap::beat_at_tempo (const Tempo& tempo) const
return beat_at_pulse_locked (_metrics, pulse);
}
/** Returns the whole-note pulse corresponding to the supplied BBT (meter-based) beat.
* @param metrics the list of metric sections used to calculate the pulse.
* @param beat The BBT (meter-based) beat.
* @return the whole-note pulse at the supplied BBT (meter-based) beat.
*
* a pulse or whole note is the base musical position of a MetricSection.
* it is equivalent to four quarter notes.
*
*/
double
TempoMap::pulse_at_beat (const double& beat) const
{
Glib::Threads::RWLock::ReaderLock lm (lock);
return pulse_at_beat_locked (_metrics, beat);
}
double
TempoMap::pulse_at_beat_locked (const Metrics& metrics, const double& beat) const
{
@ -1789,18 +1787,13 @@ TempoMap::pulse_at_beat_locked (const Metrics& metrics, const double& beat) cons
}
/** Returns the BBT (meter-based) beat corresponding to the supplied whole-note pulse .
* @param metrics the list of metric sections used to calculate the beat.
* @param pulse the whole-note pulse.
* @return the meter-based beat at the supplied whole-note pulse.
*
* a pulse or whole note is the base musical position of a MetricSection.
* it is equivalent to four quarter notes.
*/
double
TempoMap::beat_at_pulse (const double& pulse) const
{
Glib::Threads::RWLock::ReaderLock lm (lock);
return beat_at_pulse_locked (_metrics, pulse);
}
double
TempoMap::beat_at_pulse_locked (const Metrics& metrics, const double& pulse) const
{
@ -1821,13 +1814,6 @@ TempoMap::beat_at_pulse_locked (const Metrics& metrics, const double& pulse) con
return ret;
}
double
TempoMap::pulse_at_frame (const framepos_t& frame) const
{
Glib::Threads::RWLock::ReaderLock lm (lock);
return pulse_at_minute_locked (_metrics, minute_at_frame (frame));
}
/* tempo section based */
double
TempoMap::pulse_at_minute_locked (const Metrics& metrics, const double& minute) const
@ -1861,14 +1847,6 @@ TempoMap::pulse_at_minute_locked (const Metrics& metrics, const double& minute)
return pulses_in_section + prev_t->pulse();
}
framepos_t
TempoMap::frame_at_pulse (const double& pulse) const
{
Glib::Threads::RWLock::ReaderLock lm (lock);
return frame_at_minute (minute_at_pulse_locked (_metrics, pulse));
}
/* tempo section based */
double
TempoMap::minute_at_pulse_locked (const Metrics& metrics, const double& pulse) const
@ -1900,6 +1878,7 @@ TempoMap::minute_at_pulse_locked (const Metrics& metrics, const double& pulse) c
/** Returns the BBT (meter-based) beat corresponding to the supplied BBT time.
* @param bbt The BBT time (meter-based).
* @return bbt The BBT beat (meter-based) at the supplied BBT time.
*
*/
double
@ -1944,6 +1923,7 @@ TempoMap::beat_at_bbt_locked (const Metrics& metrics, const Timecode::BBT_Time&
/** Returns the BBT time corresponding to the supplied BBT (meter-based) beat.
* @param beat The BBT (meter-based) beat.
* @return The BBT time (meter-based) at the supplied meter-based beat.
*
*/
Timecode::BBT_Time
@ -2005,31 +1985,24 @@ TempoMap::bbt_at_beat_locked (const Metrics& metrics, const double& b) const
return ret;
}
/** Returns the whole-note pulse corresponding to the supplied BBT time (meter-based).
/** Returns the quarter-note beat corresponding to the supplied BBT time (meter-based).
* @param bbt The BBT time (meter-based).
* @return the quarter note beat at the supplied BBT time
*
* quarter-notes ignore meter and are based on pulse (the musical unit of MetricSection).
*
* a pulse or whole note is the basic musical position of a MetricSection.
* it is equivalent to four quarter notes.
* while the input uses meter, the output does not.
*/
double
TempoMap::pulse_at_bbt (const Timecode::BBT_Time& bbt)
{
Glib::Threads::RWLock::ReaderLock lm (lock);
return pulse_at_bbt_locked (_metrics, bbt);
}
double
TempoMap::pulse_at_bbt_rt (const Timecode::BBT_Time& bbt)
TempoMap::quarter_note_at_bbt_rt (const Timecode::BBT_Time& bbt)
{
Glib::Threads::RWLock::ReaderLock lm (lock);
if (!lm.locked()) {
throw std::logic_error ("TempoMap::pulse_at_bbt_rt() could not lock tempo map");
throw std::logic_error ("TempoMap::quarter_note_at_bbt_rt() could not lock tempo map");
}
return pulse_at_bbt_locked (_metrics, bbt);
return pulse_at_bbt_locked (_metrics, bbt) * 4.0;
}
double
@ -2062,21 +2035,16 @@ TempoMap::pulse_at_bbt_locked (const Metrics& metrics, const Timecode::BBT_Time&
return ret;
}
/** Returns the BBT time (meter-based) corresponding to the supplied whole-note pulse.
/** Returns the BBT time (meter-based) corresponding to the supplied whole-note pulse position.
* @param metrics The list of metric sections used to determine the result.
* @param pulse The whole-note pulse.
* @return The BBT time at the supplied whole-note pulse.
*
* a pulse or whole note is the basic musical position of a MetricSection.
* it is equivalent to four quarter notes.
* while the input uses meter, the output does not.
* while the output uses meter, the input does not.
*/
Timecode::BBT_Time
TempoMap::bbt_at_pulse (const double& pulse)
{
Glib::Threads::RWLock::ReaderLock lm (lock);
return bbt_at_pulse_locked (_metrics, pulse);
}
Timecode::BBT_Time
TempoMap::bbt_at_pulse_locked (const Metrics& metrics, const double& pulse) const
{
@ -3199,14 +3167,14 @@ TempoMap::gui_change_tempo (TempoSection* ts, const Tempo& bpm)
}
void
TempoMap::gui_dilate_tempo (TempoSection* ts, const framepos_t& frame, const framepos_t& end_frame, const double& pulse)
TempoMap::gui_dilate_tempo (TempoSection* ts, const framepos_t& frame, const framepos_t& end_frame)
{
/*
Ts (future prev_t) Tnext
| |
| [drag^] |
|----------|----------
e_f pulse(frame)
e_f qn_beats(frame)
*/
Metrics future_map;
@ -3300,7 +3268,7 @@ TempoMap::gui_dilate_tempo (TempoSection* ts, const framepos_t& frame, const fra
double frame_ratio = 1.0;
double pulse_ratio = 1.0;
const double pulse_pos = prev_t->frame_at_pulse (pulse);
const double pulse_pos = frame;
if (prev_to_prev_t) {
if (pulse_pos > prev_to_prev_t->frame() + min_dframe && (pulse_pos - fr_off) > prev_to_prev_t->frame() + min_dframe) {

View File

@ -69,14 +69,14 @@ TempoTest::recomputeMapTest48 ()
/* pulse */
/* pulse - frame*/
CPPUNIT_ASSERT_EQUAL (framepos_t (288e3), map.frame_at_pulse (3.0));
CPPUNIT_ASSERT_EQUAL (framepos_t (144e3), map.frame_at_pulse (1.5));
CPPUNIT_ASSERT_EQUAL (framepos_t (96e3), map.frame_at_pulse (1.0));
CPPUNIT_ASSERT_EQUAL (framepos_t (288e3), map.frame_at_quarter_note (12.0));
CPPUNIT_ASSERT_EQUAL (framepos_t (144e3), map.frame_at_quarter_note (6.0));
CPPUNIT_ASSERT_EQUAL (framepos_t (96e3), map.frame_at_quarter_note (4.0));
/* frame - pulse*/
CPPUNIT_ASSERT_DOUBLES_EQUAL (3.0, map.pulse_at_frame (288e3), 1e-17);
CPPUNIT_ASSERT_DOUBLES_EQUAL (1.5, map.pulse_at_frame (144e3), 1e-17);
CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, map.pulse_at_frame (96e3), 1e-17);
CPPUNIT_ASSERT_DOUBLES_EQUAL (12.0, map.quarter_note_at_frame (288e3), 1e-17);
CPPUNIT_ASSERT_DOUBLES_EQUAL (6.0, map.quarter_note_at_frame (144e3), 1e-17);
CPPUNIT_ASSERT_DOUBLES_EQUAL (4.0, map.quarter_note_at_frame (96e3), 1e-17);
/* pulse - internal minute based interface */
CPPUNIT_ASSERT_DOUBLES_EQUAL (0.1, map.minute_at_pulse_locked (map._metrics, 3.0), 1e-17);
@ -170,14 +170,14 @@ TempoTest::recomputeMapTest44 ()
/* pulse */
/* pulse - frame*/
CPPUNIT_ASSERT_EQUAL (framepos_t (264600), map.frame_at_pulse (3.0));
CPPUNIT_ASSERT_EQUAL (framepos_t (132300), map.frame_at_pulse (1.5));
CPPUNIT_ASSERT_EQUAL (framepos_t (88200), map.frame_at_pulse (1.0));
CPPUNIT_ASSERT_EQUAL (framepos_t (264600), map.frame_at_quarter_note (12.0));
CPPUNIT_ASSERT_EQUAL (framepos_t (132300), map.frame_at_quarter_note (6.0));
CPPUNIT_ASSERT_EQUAL (framepos_t (88200), map.frame_at_quarter_note (4.0));
/* frame - pulse*/
CPPUNIT_ASSERT_DOUBLES_EQUAL (3.0, map.pulse_at_frame (264600), 1e-17);
CPPUNIT_ASSERT_DOUBLES_EQUAL (1.5, map.pulse_at_frame (132300), 1e-17);
CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, map.pulse_at_frame (88200), 1e-17);
CPPUNIT_ASSERT_DOUBLES_EQUAL (12.0, map.quarter_note_at_frame (264600), 1e-17);
CPPUNIT_ASSERT_DOUBLES_EQUAL (6.0, map.quarter_note_at_frame (132300), 1e-17);
CPPUNIT_ASSERT_DOUBLES_EQUAL (4.0, map.quarter_note_at_frame (88200), 1e-17);
/* pulse - internal minute based interface */
CPPUNIT_ASSERT_DOUBLES_EQUAL (0.1, map.minute_at_pulse_locked (map._metrics, 3.0), 1e-17);

View File

@ -68,7 +68,7 @@ write_bbt_source_to_source (boost::shared_ptr<MidiSource> bbt_source, boost::sh
TempoMap& map (source->session().tempo_map());
for (Evoral::Sequence<MidiModel::TimeType>::const_iterator i = bbt_source->model()->begin(MidiModel::TimeType(), true); i != bbt_source->model()->end(); ++i) {
const double new_time = map.quarter_note_at_beat ((*i).time().to_double() + map.beat_at_pulse (session_offset)) - (session_offset * 4.0);
const double new_time = map.quarter_note_at_beat ((*i).time().to_double() + map.beat_at_quarter_note (session_offset * 4.0)) - (session_offset * 4.0);
Evoral::Event<Evoral::Beats> new_ev (*i, true);
new_ev.set_time (Evoral::Beats (new_time));
source->append_event_beats (source_lock, new_ev);
@ -206,7 +206,7 @@ reset_start (Session* session, boost::shared_ptr<MidiRegion> region)
{
/* set start_beats to quarter note value from incorrect bbt*/
TempoMap& tmap (session->tempo_map());
double new_start_qn = (tmap.pulse_at_beat (region->beat()) - tmap.pulse_at_beat (region->beat() - region->start_beats())) * 4.0;
double new_start_qn = tmap.quarter_note_at_beat (region->beat()) - tmap.quarter_note_at_beat (region->beat() - region->start_beats());
/* force a change to start and start_beats */
PositionLockStyle old_pls = region->position_lock_style();
@ -222,8 +222,8 @@ reset_length (Session* session, boost::shared_ptr<MidiRegion> region)
{
/* set length_beats to quarter note value */
TempoMap& tmap (session->tempo_map());
double new_length_qn = (tmap.pulse_at_beat (region->beat() + region->length_beats())
- tmap.pulse_at_beat (region->beat())) * 4.0;
double new_length_qn = tmap.quarter_note_at_beat (region->beat() + region->length_beats())
- tmap.quarter_note_at_beat (region->beat());
/* force a change to length and length_beats */
PositionLockStyle old_pls = region->position_lock_style();