Tempo ramps - rename bbt_time() -> bbt_at_frame(), frame_time() -> frame_at_bbt()
authornick_m <mainsbridge@gmail.com>
Thu, 26 May 2016 17:22:24 +0000 (03:22 +1000)
committernick_m <mainsbridge@gmail.com>
Fri, 27 May 2016 13:38:17 +0000 (23:38 +1000)
14 files changed:
gtk2_ardour/audio_clock.cc
gtk2_ardour/editor_drag.cc
gtk2_ardour/editor_regions.cc
gtk2_ardour/editor_rulers.cc
gtk2_ardour/editor_tempodisplay.cc
gtk2_ardour/midi_list_editor.cc
gtk2_ardour/tempo_dialog.cc
libs/ardour/ardour/tempo.h
libs/ardour/lv2_plugin.cc
libs/ardour/session_time.cc
libs/ardour/session_vst.cc
libs/ardour/tempo.cc
libs/backends/jack/jack_session.cc
libs/surfaces/control_protocol/basic_ui.cc

index 7cdf66123dc7f309b34b5a20e22fa953c2aa14ec..ee28f138e2edd342847aed60838f5d1dfee18281 100644 (file)
@@ -1258,12 +1258,12 @@ AudioClock::set_bbt (framepos_t when, bool /*force*/)
                        BBT.beats = 0;
                        BBT.ticks = 0;
                } else {
-                       _session->tempo_map().bbt_time (when, BBT);
+                       BBT = _session->tempo_map().bbt_at_frame (when);
                        BBT.bars--;
                        BBT.beats--;
                }
        } else {
-               _session->tempo_map().bbt_time (when, BBT);
+               BBT = _session->tempo_map().bbt_at_frame (when);
        }
 
        if (negative) {
index 07b2eabbadc06c7d1b3f014411b7c8e9e0384178..12216bc3c0d8b36a3672517f8f35c15f948d17ce 100644 (file)
@@ -3180,7 +3180,7 @@ MeterMarkerDrag::motion (GdkEvent* event, bool first_move)
                        }
                        const double beat = map.beat_at_bbt (bbt);
                        _real_section = map.add_meter (Meter (_marker->meter().divisions_per_bar(), _marker->meter().note_divisor())
-                                                      , beat, bbt, map.frame_time (bbt), _real_section->position_lock_style());
+                                                      , beat, bbt, map.frame_at_bbt (bbt), _real_section->position_lock_style());
 
                }
        }
index f95e5b797e2cf25c48e7fe6ff1efffd60ca7192e..83219318716f4e8bb1a30ef0a2aa3cc1898b60fd 100644 (file)
@@ -728,7 +728,7 @@ EditorRegions::format_position (framepos_t pos, char* buf, size_t bufsize, bool
 
        switch (ARDOUR_UI::instance()->secondary_clock->mode ()) {
        case AudioClock::BBT:
-               _session->tempo_map().bbt_time (pos, bbt);
+               bbt = _session->tempo_map().bbt_at_frame (pos);
                if (onoff) {
                        snprintf (buf, bufsize, "%03d|%02d|%04d" , bbt.bars, bbt.beats, bbt.ticks);
                } else {
index f2b42fccc34dd9731ae769ab4f3c05c7a3564482..596f4f26b9bcd2bb499c47a4cf8aedfeac5576d6 100644 (file)
@@ -1275,7 +1275,7 @@ Editor::metric_get_bbt (std::vector<ArdourCanvas::Ruler::Mark>& marks, gdouble l
                                next_beat.beats = (*i).beat;
                                next_beat.bars = (*i).bar;
                                next_beat.ticks = tick;
-                               pos = _session->tempo_map().frame_time (next_beat);
+                               pos = _session->tempo_map().frame_at_bbt (next_beat);
 
                                if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
                                        i_am_accented = true;
@@ -1345,7 +1345,7 @@ Editor::metric_get_bbt (std::vector<ArdourCanvas::Ruler::Mark>& marks, gdouble l
                                next_beat.beats = (*i).beat;
                                next_beat.bars = (*i).bar;
                                next_beat.ticks = tick;
-                               pos = _session->tempo_map().frame_time (next_beat);
+                               pos = _session->tempo_map().frame_at_bbt (next_beat);
 
                                if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
                                        i_am_accented = true;
@@ -1421,7 +1421,7 @@ Editor::metric_get_bbt (std::vector<ArdourCanvas::Ruler::Mark>& marks, gdouble l
                        while (tick < Timecode::BBT_Time::ticks_per_beat && (n < bbt_nmarks)) {
 
                                next_beat.ticks = tick;
-                               pos = _session->tempo_map().frame_time (next_beat);
+                               pos = _session->tempo_map().frame_at_bbt (next_beat);
                                if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
                                        i_am_accented = true;
                                }
index adf0f72fe37969518ec8c175ad700b22e2aacfe3..7af6fef05979db04b521db1b7614e6ff5e1baaf4 100644 (file)
@@ -358,7 +358,7 @@ Editor::mouse_add_new_meter_event (framepos_t frame)
        if (meter_dialog.get_lock_style() == MusicTime) {
                map.add_meter (Meter (bpb, note_type), map.beat_at_bbt (requested), requested, 0, MusicTime);
        } else {
-               map.add_meter (Meter (bpb, note_type), map.beat_at_bbt (requested), requested, map.frame_time (requested), AudioTime);
+               map.add_meter (Meter (bpb, note_type), map.beat_at_bbt (requested), requested, map.frame_at_bbt (requested), AudioTime);
        }
 
        _session->add_command(new MementoCommand<TempoMap>(map, &before, &map.get_state()));
@@ -406,7 +406,7 @@ Editor::edit_meter_section (MeterSection* section)
        double const note_type = meter_dialog.get_note_type ();
        Timecode::BBT_Time when;
        meter_dialog.get_bbt_time (when);
-       framepos_t const frame = _session->tempo_map().frame_time (when);
+       framepos_t const frame = _session->tempo_map().frame_at_bbt (when);
 
        begin_reversible_command (_("replace meter mark"));
         XMLNode &before = _session->tempo_map().get_state();
index 6334c38dcc304aac759b3d75be562ca8b16888c5..e0eda7a53647737105762ca2ec20ce3f08242cdb 100644 (file)
@@ -764,9 +764,7 @@ MidiListEditor::redisplay_model ()
                        row[columns.note] = (*i)->note();
                        row[columns.velocity] = (*i)->velocity();
 
-                       Timecode::BBT_Time bbt;
-
-                       _session->tempo_map().bbt_time (conv.to ((*i)->time()), bbt);
+                       Timecode::BBT_Time bbt (_session->tempo_map().bbt_at_frame (conv.to ((*i)->time())));
 
                        ss.str ("");
                        ss << bbt;
index b4951f35ca272df27249729933e856d1767d29b2..68a781a54f35a49e78680c6c54bf74a47d897298 100644 (file)
@@ -45,9 +45,8 @@ TempoDialog::TempoDialog (TempoMap& map, framepos_t frame, const string&)
        , pulse_selector_label (_("Pulse note"), ALIGN_LEFT, ALIGN_CENTER)
        , tap_tempo_button (_("Tap tempo"))
 {
-       Timecode::BBT_Time when;
        Tempo tempo (map.tempo_at_frame (frame));
-       map.bbt_time (frame, when);
+       Timecode::BBT_Time when (map.bbt_at_frame (frame));
 
        init (when, tempo.beats_per_minute(), tempo.note_type(), TempoSection::Constant, true, MusicTime);
 }
@@ -63,8 +62,7 @@ TempoDialog::TempoDialog (TempoMap& map, TempoSection& section, const string&)
        , pulse_selector_label (_("Pulse note"), ALIGN_LEFT, ALIGN_CENTER)
        , tap_tempo_button (_("Tap tempo"))
 {
-       Timecode::BBT_Time when;
-       map.bbt_time (section.frame(), when);
+       Timecode::BBT_Time when (map.bbt_at_frame (section.frame()));
        init (when, section.beats_per_minute(), section.note_type(), section.type(), section.movable(), section.position_lock_style());
 }
 
@@ -420,19 +418,18 @@ TempoDialog::tap_tempo_focus_out (GdkEventFocus* )
 MeterDialog::MeterDialog (TempoMap& map, framepos_t frame, const string&)
        : ArdourDialog (_("New Meter"))
 {
-       Timecode::BBT_Time when;
        frame = map.round_to_bar(frame, RoundNearest);
+       Timecode::BBT_Time when (map.bbt_at_frame (frame));
        Meter meter (map.meter_at_frame (frame));
 
-       map.bbt_time (frame, when);
        init (when, meter.divisions_per_bar(), meter.note_divisor(), true, MusicTime);
 }
 
 MeterDialog::MeterDialog (TempoMap& map, MeterSection& section, const string&)
        : ArdourDialog (_("Edit Meter"))
 {
-       Timecode::BBT_Time when;
-       map.bbt_time (section.frame(), when);
+       Timecode::BBT_Time when (map.bbt_at_frame (section.frame()));
+
        init (when, section.divisions_per_bar(), section.note_divisor(), section.movable(), section.position_lock_style());
 }
 
index f08ffa64b9ef6696f5ac0bec07de4eeee33bce11..8227a968a0ef7b5899fdd3e28e27346ef687b7b6 100644 (file)
@@ -330,13 +330,13 @@ class LIBARDOUR_API TempoMap : public PBD::StatefulDestructible
        static const Tempo& default_tempo() { return _default_tempo; }
        static const Meter& default_meter() { return _default_meter; }
 
+       /* because tempos may be ramped, this is only valid for the instant requested.*/
        double frames_per_beat_at (const framepos_t&, const framecnt_t& sr) const;
 
        const TempoSection& tempo_section_at (framepos_t frame) const;
        const MeterSection& meter_section_at (framepos_t frame) const;
        const MeterSection& meter_section_at_beat (double beat) const;
 
-
        /** add a tempo section locked to pls. ignored values will be set in recompute_tempos()
         * @param pulse pulse position of new section. ignored if pls == AudioTime
         * @param frame frame position of new section. ignored if pls == MusicTime
@@ -366,8 +366,6 @@ class LIBARDOUR_API TempoMap : public PBD::StatefulDestructible
 
        void set_length (framepos_t frames);
 
-       void fix_legacy_session();
-
        XMLNode& get_state (void);
        int set_state (const XMLNode&, int version);
 
@@ -417,6 +415,9 @@ class LIBARDOUR_API TempoMap : public PBD::StatefulDestructible
        const Tempo tempo_at_frame (const framepos_t& frame) const;
        const Meter& meter_at_frame (framepos_t) const;
 
+       const Timecode::BBT_Time bbt_at_frame (framepos_t when);
+       const framepos_t frame_at_bbt (const Timecode::BBT_Time&);
+
        double beat_at_bbt (const Timecode::BBT_Time& bbt);
        Timecode::BBT_Time bbt_at_beat (const double& beats);
 
@@ -425,8 +426,6 @@ class LIBARDOUR_API TempoMap : public PBD::StatefulDestructible
 
        std::pair<double, framepos_t> predict_tempo_position (TempoSection* section, const Timecode::BBT_Time& bbt);
 
-       void bbt_time (framepos_t when, Timecode::BBT_Time&);
-       framepos_t frame_time (const Timecode::BBT_Time&);
        framecnt_t bbt_duration_at (framepos_t, const Timecode::BBT_Time&, int dir);
 
        /* TEMPO-SENSITIVE FUNCTIONS
@@ -452,6 +451,7 @@ class LIBARDOUR_API TempoMap : public PBD::StatefulDestructible
        bool can_solve_bbt (TempoSection* section, const Timecode::BBT_Time& bbt);
 
        PBD::Signal0<void> MetricPositionChanged;
+       void fix_legacy_session();
 
 private:
        double pulse_at_beat_locked (const Metrics& metrics, const double& beat) const;
@@ -469,9 +469,10 @@ private:
        double pulse_at_bbt_locked (const Metrics& metrics, const Timecode::BBT_Time& bbt) const;
        Timecode::BBT_Time bbt_at_pulse_locked (const Metrics& metrics, const double& pulse) const;
 
-       const Tempo tempo_at_frame_locked (const Metrics& metrics, const framepos_t& frame) const;
+       Timecode::BBT_Time bbt_at_frame_locked (const Metrics& metrics, const framepos_t& frame) const;
+       framepos_t frame_at_bbt_locked (const Metrics& metrics, const Timecode::BBT_Time&) const;
 
-       framepos_t frame_time_locked (const Metrics& metrics, const Timecode::BBT_Time&) const;
+       const Tempo tempo_at_frame_locked (const Metrics& metrics, const framepos_t& frame) const;
 
        const TempoSection& tempo_section_at_locked (const Metrics& metrics, framepos_t frame) const;
        const TempoSection& tempo_section_at_beat_locked (const Metrics& metrics, const double& beat) const;
index fa11f7b051227543516357615dc9aaec4117cc1b..4c3ca31d2dca53d1e3263fcdde2adbc7babe1486 100644 (file)
@@ -2310,7 +2310,7 @@ LV2Plugin::connect_and_run(BufferSet& bufs,
                                        if (_session.transport_frame() != _next_cycle_start ||
                                            _session.transport_speed() != _next_cycle_speed) {
                                                // Transport has changed, write position at cycle start
-                                               tmap.bbt_time(_session.transport_frame(), bbt);
+                                               bbt = tmap.bbt_at_frame (_session.transport_frame());
                                                write_position(&_impl->forge, _ev_buffers[port_index],
                                                               tmetric, bbt, _session.transport_speed(),
                                                               _session.transport_frame(), 0);
index 6bb018649fd5bdff8c0ebd51a0de04417c664759..54770d5cc8a16b5f4e64ef757a7de6980166e56a 100644 (file)
@@ -46,7 +46,7 @@ using namespace PBD;
 void
 Session::bbt_time (framepos_t when, Timecode::BBT_Time& bbt)
 {
-       _tempo_map->bbt_time (when, bbt);
+       bbt = _tempo_map->bbt_at_frame (when);
 }
 
 /* Timecode TIME */
@@ -226,7 +226,7 @@ Session::convert_to_frames (AnyTime const & position)
 
        switch (position.type) {
        case AnyTime::BBT:
-               return _tempo_map->frame_time (position.bbt);
+               return _tempo_map->frame_at_bbt (position.bbt);
                break;
 
        case AnyTime::Timecode:
index ad732e052a185f632a77233b7e0af7e68c08e84f..3741ceb9a100cc5b2b7e70466b344560bc14529c 100644 (file)
@@ -223,7 +223,7 @@ intptr_t Session::vst_callback (
                                Timecode::BBT_Time bbt;
 
                                try {
-                                       session->tempo_map().bbt_time (now, bbt);
+                                       bbt = session->tempo_map().bbt_at_frame (now);
 
                                        /* PPQ = pulse per quarter
                                         * VST's "pulse" is our "division".
index 44c59bd6d25e51a7d2157633d0e9ecf26ac07e88..97c468e1b6bdf1974437b9c09f9fe74e2c6e5ecc 100644 (file)
@@ -1805,25 +1805,40 @@ TempoMap::bbt_at_pulse_locked (const Metrics& metrics, const double& pulse) cons
        return ret;
 }
 
-void
-TempoMap::bbt_time (framepos_t frame, BBT_Time& bbt)
+const BBT_Time
+TempoMap::bbt_at_frame (framepos_t frame)
 {
-
        if (frame < 0) {
+               BBT_Time bbt;
                bbt.bars = 1;
                bbt.beats = 1;
                bbt.ticks = 0;
                warning << string_compose (_("tempo map asked for BBT time at frame %1\n"), frame) << endmsg;
-               return;
+               return bbt;
        }
        Glib::Threads::RWLock::ReaderLock lm (lock);
-       const double beat = beat_at_frame_locked (_metrics, frame);
 
-       bbt = bbt_at_beat_locked (_metrics, beat);
+       return bbt_at_frame_locked (_metrics, frame);
 }
 
-framepos_t
-TempoMap::frame_time (const BBT_Time& bbt)
+Timecode::BBT_Time
+TempoMap::bbt_at_frame_locked (const Metrics& metrics, const framepos_t& frame) const
+{
+       if (frame < 0) {
+               BBT_Time bbt;
+               bbt.bars = 1;
+               bbt.beats = 1;
+               bbt.ticks = 0;
+               warning << string_compose (_("tempo map asked for BBT time at frame %1\n"), frame) << endmsg;
+               return bbt;
+       }
+       const double beat = beat_at_frame_locked (metrics, frame);
+
+       return bbt_at_beat_locked (metrics, beat);
+}
+
+const framepos_t
+TempoMap::frame_at_bbt (const BBT_Time& bbt)
 {
        if (bbt.bars < 1) {
                warning << string_compose (_("tempo map asked for frame time at bar < 1  (%1)\n"), bbt) << endmsg;
@@ -1835,12 +1850,12 @@ TempoMap::frame_time (const BBT_Time& bbt)
        }
        Glib::Threads::RWLock::ReaderLock lm (lock);
 
-       return frame_time_locked (_metrics, bbt);
+       return frame_at_bbt_locked (_metrics, bbt);
 }
 
-/* meter section based */
+/* meter & tempo section based */
 framepos_t
-TempoMap::frame_time_locked (const Metrics& metrics, const BBT_Time& bbt) const
+TempoMap::frame_at_bbt_locked (const Metrics& metrics, const BBT_Time& bbt) const
 {
        /* HOLD THE READER LOCK */
 
@@ -2802,22 +2817,22 @@ TempoMap::round_to_type (framepos_t frame, RoundMode dir, BBTPointType type)
                        /* find bar previous to 'frame' */
                        bbt.beats = 1;
                        bbt.ticks = 0;
-                       return frame_time_locked (_metrics, bbt);
+                       return frame_at_bbt_locked (_metrics, bbt);
 
                } else if (dir > 0) {
                        /* find bar following 'frame' */
                        ++bbt.bars;
                        bbt.beats = 1;
                        bbt.ticks = 0;
-                       return frame_time_locked (_metrics, bbt);
+                       return frame_at_bbt_locked (_metrics, bbt);
                } else {
                        /* true rounding: find nearest bar */
-                       framepos_t raw_ft = frame_time_locked (_metrics, bbt);
+                       framepos_t raw_ft = frame_at_bbt_locked (_metrics, bbt);
                        bbt.beats = 1;
                        bbt.ticks = 0;
-                       framepos_t prev_ft = frame_time_locked (_metrics, bbt);
+                       framepos_t prev_ft = frame_at_bbt_locked (_metrics, bbt);
                        ++bbt.bars;
-                       framepos_t next_ft = frame_time_locked (_metrics, bbt);
+                       framepos_t next_ft = frame_at_bbt_locked (_metrics, bbt);
 
                        if ((raw_ft - prev_ft) > (next_ft - prev_ft) / 2) { 
                                return next_ft;
@@ -3354,7 +3369,7 @@ TempoMap::insert_time (framepos_t where, framecnt_t amount)
                                tempo = t;
                                // cerr << "NEW TEMPO, frame = " << (*i)->frame() << " beat = " << (*i)->pulse() <<endl;
                        } else if ((m = dynamic_cast<MeterSection*>(*i)) != 0) {
-                               bbt_time (m->frame(), bbt);
+                               bbt = bbt_at_frame_locked (_metrics, m->frame());
 
                                // cerr << "timestamp @ " << (*i)->frame() << " with " << bbt.bars << "|" << bbt.beats << "|" << bbt.ticks << " => ";
 
@@ -3493,7 +3508,7 @@ TempoMap::framepos_plus_bbt (framepos_t pos, BBT_Time op) const
        }
        pos_bbt.bars += op.bars;
 
-       return frame_time_locked (_metrics, pos_bbt);
+       return frame_at_bbt_locked (_metrics, pos_bbt);
 }
 
 /** Count the number of beats that are equivalent to distance when going forward,
index 430ee5b0e7d1e56e89fb996b26971d0fd0043919..0c78d9a908fce9086c5961967e8f2c4f9c9e6499 100644 (file)
@@ -121,7 +121,7 @@ JACKSession::timebase_callback (jack_transport_state_t /*state*/,
        TempoMetric metric (tempo_map.metric_at (tf));
 
        try {
-               tempo_map.bbt_time (tf, bbt);
+               bbt = tempo_map.bbt_at_frame (tf);
 
                pos->bar = bbt.bars;
                pos->beat = bbt.beats;
index 8227c55ca542419fd88a7e36370bee30efe22a9d..dd5e84cfd757366ecd5c44e26c691238ef76eaa8 100644 (file)
@@ -402,9 +402,8 @@ BasicUI::jump_by_seconds (double secs)
 void
 BasicUI::jump_by_bars (double bars)
 {
-       Timecode::BBT_Time bbt;
        TempoMap& tmap (session->tempo_map());
-       tmap.bbt_time (session->transport_frame(), bbt);
+       Timecode::BBT_Time bbt (tmap.bbt_at_frame (session->transport_frame()));
 
        bars += bbt.bars;
        if (bars < 0) bars = 0;