Tempo ramps - define_one_bar() delivers constant tempo.
authornick_m <mainsbridge@gmail.com>
Mon, 21 Dec 2015 14:21:54 +0000 (01:21 +1100)
committernick_m <mainsbridge@gmail.com>
Fri, 27 May 2016 13:38:09 +0000 (23:38 +1000)
- also some renaming and code review

12 files changed:
gtk2_ardour/editor_ops.cc
gtk2_ardour/tempo_dialog.cc
gtk2_ardour/tempo_dialog.h
libs/ardour/ardour/tempo.h
libs/ardour/audio_unit.cc
libs/ardour/midi_clock_slave.cc
libs/ardour/tempo.cc
libs/ardour/test/framepos_minus_beats_test.cc
libs/ardour/test/framepos_plus_beats_test.cc
libs/ardour/test/framewalk_to_beats_test.cc
libs/ardour/test/midi_clock_slave_test.h
libs/ardour/test/tempo_test.cc

index 8302f1b77811d6ecf18b1ad014e29146a080a24e..f094c793ace62a0033a53b8fee782f7ac62e427a 100644 (file)
@@ -6480,7 +6480,9 @@ Editor::define_one_bar (framepos_t start, framepos_t end)
 
        /* length = 1 bar */
 
-       /* now we want frames per beat.
+       /* We're going to deliver a constant tempo here,
+          so we can use frames per beat to determine length.
+          now we want frames per beat.
           we have frames per bar, and beats per bar, so ...
        */
 
@@ -6552,7 +6554,7 @@ Editor::define_one_bar (framepos_t start, framepos_t end)
        } else {
                Timecode::BBT_Time bbt;
                _session->tempo_map().bbt_time (start, bbt);
-               _session->tempo_map().add_tempo (Tempo (beats_per_minute, t.note_type()), bbt, TempoSection::TempoSectionType::Ramp);
+               _session->tempo_map().add_tempo (Tempo (beats_per_minute, t.note_type()), bbt, TempoSection::Type::Constant);
        }
 
        XMLNode& after (_session->tempo_map().get_state());
index 613a2d9a5a9eb2388fac3bfa27cebd10e4128b65..2c45d500857b91b874bbc739896c27e1ed6ce3fe 100644 (file)
@@ -108,9 +108,9 @@ TempoDialog::init (const Timecode::BBT_Time& when, double bpm, double note_type,
 
        strings.clear();
 
-       tempo_types.insert (make_pair (_("ramped"), TempoSection::TempoSectionType::Ramp));
+       tempo_types.insert (make_pair (_("ramped"), TempoSection::Type::Ramp));
        strings.push_back (_("ramped"));
-       tempo_types.insert (make_pair (_("constant"), TempoSection::TempoSectionType::Constant));
+       tempo_types.insert (make_pair (_("constant"), TempoSection::Type::Constant));
        strings.push_back (_("constant"));
        set_popdown_strings (tempo_type, strings);
        tempo_type.set_active_text (strings[0]); // "ramped"
@@ -272,14 +272,14 @@ TempoDialog::get_note_type ()
        return x->second;
 }
 
-TempoSection::TempoSectionType
+TempoSection::Type
 TempoDialog::get_tempo_type ()
 {
        TempoTypes::iterator x = tempo_types.find (tempo_type.get_active_text());
 
        if (x == tempo_types.end()) {
                error << string_compose(_("incomprehensible pulse note type (%1)"), tempo_type.get_active_text()) << endmsg;
-               return TempoSection::TempoSectionType::Constant;
+               return TempoSection::Type::Constant;
        }
 
        return x->second;
index 842c2f2c3c3b532e273247ce8a232ba94ae42034..89f93016a2500e38c5b2eb08cceebeb9e1ecdcff 100644 (file)
@@ -44,7 +44,7 @@ public:
        double get_bpm ();
        double get_note_type ();
        bool   get_bbt_time (Timecode::BBT_Time&);
-       ARDOUR::TempoSection::TempoSectionType get_tempo_type ();
+       ARDOUR::TempoSection::Type get_tempo_type ();
 
 private:
        void init (const Timecode::BBT_Time& start, double, double, bool);
@@ -61,7 +61,7 @@ private:
        typedef std::map<std::string,float> NoteTypes;
        NoteTypes note_types;
 
-       typedef std::map<std::string, ARDOUR::TempoSection::TempoSectionType> TempoTypes;
+       typedef std::map<std::string, ARDOUR::TempoSection::Type> TempoTypes;
        TempoTypes tempo_types;
 
        bool tapped;      // whether the tap-tempo button has been clicked
index 9a2248414224f1e778109ead4f039a4cdee0eb95..5f511243723d00baedef171d468c92131e1afb21 100644 (file)
@@ -147,14 +147,14 @@ class LIBARDOUR_API MeterSection : public MetricSection, public Meter {
 /** A section of timeline with a certain Tempo. */
 class LIBARDOUR_API TempoSection : public MetricSection, public Tempo {
   public:
-       enum TempoSectionType {
+       enum Type {
                Ramp,
                Constant,
        };
 
-       TempoSection (const Timecode::BBT_Time& start, double qpm, double note_type, TempoSectionType tempo_type)
+       TempoSection (const Timecode::BBT_Time& start, double qpm, double note_type, Type tempo_type)
                : MetricSection (start), Tempo (qpm, note_type), _bar_offset (-1.0), _type (tempo_type)  {}
-       TempoSection (framepos_t start, double qpm, double note_type, TempoSectionType tempo_type)
+       TempoSection (framepos_t start, double qpm, double note_type, Type tempo_type)
                : MetricSection (start), Tempo (qpm, note_type), _bar_offset (-1.0), _type (tempo_type) {}
        TempoSection (const XMLNode&);
 
@@ -166,8 +166,8 @@ class LIBARDOUR_API TempoSection : public MetricSection, public Tempo {
        void update_bbt_time_from_bar_offset (const Meter&);
        double bar_offset() const { return _bar_offset; }
 
-       void set_type (TempoSectionType type);
-       TempoSectionType type () const { return _type; }
+       void set_type (Type type);
+       Type type () const { return _type; }
 
        double tempo_at_frame (framepos_t frame, double end_bpm, framepos_t end_frame, framecnt_t frame_rate) const;
        framepos_t frame_at_tempo (double tempo, double end_bpm, framepos_t end_frame, framecnt_t frame_rate) const;
@@ -210,7 +210,7 @@ class LIBARDOUR_API TempoSection : public MetricSection, public Tempo {
           position within the bar if/when the meter changes.
        */
        double _bar_offset;
-       TempoSectionType _type;
+       Type _type;
 };
 
 typedef std::list<MetricSection*> Metrics;
@@ -343,13 +343,13 @@ class LIBARDOUR_API TempoMap : public PBD::StatefulDestructible
        TempoSection* tempo_section_after (framepos_t) const;
        const MeterSection& meter_section_at (framepos_t) const;
 
-       void add_tempo (const Tempo&, Timecode::BBT_Time where, TempoSection::TempoSectionType type);
+       void add_tempo (const Tempo&, Timecode::BBT_Time where, TempoSection::Type type);
        void add_meter (const Meter&, Timecode::BBT_Time where);
 
        void remove_tempo (const TempoSection&, bool send_signal);
        void remove_meter (const MeterSection&, bool send_signal);
 
-       void replace_tempo (const TempoSection&, const Tempo&, const Timecode::BBT_Time& where, TempoSection::TempoSectionType type);
+       void replace_tempo (const TempoSection&, const Tempo&, const Timecode::BBT_Time& where, TempoSection::Type type);
        void replace_meter (const MeterSection&, const Meter&, const Timecode::BBT_Time& where);
 
        framepos_t round_to_bar  (framepos_t frame, RoundMode dir);
@@ -415,7 +415,7 @@ class LIBARDOUR_API TempoMap : public PBD::StatefulDestructible
 
        void do_insert (MetricSection* section);
 
-       void add_tempo_locked (const Tempo&, Timecode::BBT_Time where, bool recompute, TempoSection::TempoSectionType type);
+       void add_tempo_locked (const Tempo&, Timecode::BBT_Time where, bool recompute, TempoSection::Type type);
        void add_meter_locked (const Meter&, Timecode::BBT_Time where, bool recompute);
 
        bool remove_tempo_locked (const TempoSection&);
index 6a927680aa4f6a0eeaf43e0119bc953ab0c16351..3b6f227b1079bef9d06c33870485b0dccadd4aa0 100644 (file)
@@ -1810,7 +1810,7 @@ AUPlugin::get_musical_time_location_callback (UInt32*   outDeltaSampleOffsetToNe
                        *outDeltaSampleOffsetToNextBeat = 0;
                } else {
                        *outDeltaSampleOffsetToNextBeat = (UInt32)
-                               double beat_frac_to_next = (Timecode::BBT_Time::ticks_per_beat - bbt.ticks) / Timecode::BBT_Time::ticks_per_beat ;
+                               double const beat_frac_to_next = (Timecode::BBT_Time::ticks_per_beat - bbt.ticks) / Timecode::BBT_Time::ticks_per_beat;
                                tmap.frame_at_beat (tmap.beat_at_frame (_session.transport_frame() + input_offset) + beat_frac_to_next);
                }
        }
index 44bb31e05c6a1827d8a50a7662f18ecf0b31dd74..c7acb1b58c7df98ff8de4ffb643a65ddfc926ae7 100644 (file)
@@ -83,7 +83,7 @@ void
 MIDIClock_Slave::calculate_one_ppqn_in_frames_at(framepos_t time)
 {
        const Tempo& current_tempo = session->tempo_map().tempo_at(time);
-       double frames_per_beat = session->tempo_map().frames_per_beat_at (time, session->frame_rate());
+       double const frames_per_beat = session->tempo_map().frames_per_beat_at (time, session->frame_rate());
 
        double quarter_notes_per_beat = 4.0 / current_tempo.note_type();
        double frames_per_quarter_note = frames_per_beat / quarter_notes_per_beat;
index 50ec59264cf208959bc0cd752961bb1bde828706..ef7c7d0239ce69d6893cfd1f0efc7d0036ce1288 100644 (file)
@@ -128,12 +128,12 @@ TempoSection::TempoSection (const XMLNode& node)
        }
 
        if ((prop = node.property ("tempo-type")) == 0) {
-               _type = TempoSectionType::Constant;
+               _type = Type::Constant;
        } else {
                if (strstr(prop->value().c_str(),"Constant")) {
-                       _type = TempoSectionType::Constant;
+                       _type = Type::Constant;
                } else {
-                       _type = TempoSectionType::Ramp;
+                       _type = Type::Ramp;
                }
        }
 }
@@ -176,7 +176,7 @@ TempoSection::update_bar_offset_from_bbt (const Meter& m)
 }
 
 void
-TempoSection::set_type (TempoSectionType type)
+TempoSection::set_type (Type type)
 {
        _type = type;
 }
@@ -433,7 +433,7 @@ TempoMap::TempoMap (framecnt_t fr)
        start.beats = 1;
        start.ticks = 0;
 
-       TempoSection *t = new TempoSection (start, _default_tempo.beats_per_minute(), _default_tempo.note_type(), TempoSection::TempoSectionType::Ramp);
+       TempoSection *t = new TempoSection (start, _default_tempo.beats_per_minute(), _default_tempo.note_type(), TempoSection::Type::Ramp);
        MeterSection *m = new MeterSection (start, _default_meter.divisions_per_bar(), _default_meter.note_divisor());
 
        t->set_movable (false);
@@ -637,7 +637,7 @@ TempoMap::do_insert (MetricSection* section)
 }
 
 void
-TempoMap::replace_tempo (const TempoSection& ts, const Tempo& tempo, const BBT_Time& where, TempoSection::TempoSectionType type)
+TempoMap::replace_tempo (const TempoSection& ts, const Tempo& tempo, const BBT_Time& where, TempoSection::Type type)
 {
        {
                Glib::Threads::RWLock::WriterLock lm (lock);
@@ -660,7 +660,7 @@ TempoMap::replace_tempo (const TempoSection& ts, const Tempo& tempo, const BBT_T
 }
 
 void
-TempoMap::add_tempo (const Tempo& tempo, BBT_Time where, ARDOUR::TempoSection::TempoSectionType type)
+TempoMap::add_tempo (const Tempo& tempo, BBT_Time where, ARDOUR::TempoSection::Type type)
 {
        {
                Glib::Threads::RWLock::WriterLock lm (lock);
@@ -672,7 +672,7 @@ TempoMap::add_tempo (const Tempo& tempo, BBT_Time where, ARDOUR::TempoSection::T
 }
 
 void
-TempoMap::add_tempo_locked (const Tempo& tempo, BBT_Time where, bool recompute, ARDOUR::TempoSection::TempoSectionType type)
+TempoMap::add_tempo_locked (const Tempo& tempo, BBT_Time where, bool recompute, ARDOUR::TempoSection::Type type)
 {
        /* new tempos always start on a beat */
        where.ticks = 0;
@@ -1058,7 +1058,7 @@ TempoMap::_extend_map (TempoSection* tempo, MeterSection* meter,
                                                        double ticks_relative_to_prev_ts = ticks_at_ts - ticks_at_prev_ts;
                                                        /* assume (falsely) that the target tempo is constant */
                                                        double length_estimate = (ticks_relative_to_prev_ts /  BBT_Time::ticks_per_beat) * meter->frames_per_grid (*t, _frame_rate);
-                                                       if (prev_ts->type() == TempoSection::TempoSectionType::Constant) {
+                                                       if (prev_ts->type() == TempoSection::Type::Constant) {
                                                                cerr << "constant type " << endl;
                                                                length_estimate = (ticks_relative_to_prev_ts / BBT_Time::ticks_per_beat) * prev_ts->frames_per_beat (_frame_rate);
                                                        }
index 7b6941e5070a48f86f3b186d3cb49765d865cd4e..6f1bba53b2412978640583f667a054fcc295d5b7 100644 (file)
@@ -23,7 +23,7 @@ FrameposMinusBeatsTest::singleTempoTest ()
        Meter meter (4, 4);
 
        map.add_meter (meter, BBT_Time (1, 1, 0));
-       map.add_tempo (tempo, BBT_Time (1, 1, 0), TempoSection::TempoSectionType::Constant);
+       map.add_tempo (tempo, BBT_Time (1, 1, 0), TempoSection::Type::Constant);
 
        /* Subtract 1 beat from beat 3 of the first bar */
        framepos_t r = map.framepos_minus_beats (frames_per_beat * 2, Beats(1));
@@ -63,9 +63,9 @@ FrameposMinusBeatsTest::doubleTempoTest ()
        */
 
        Tempo tempoA (120);
-       map.add_tempo (tempoA, BBT_Time (1, 1, 0), TempoSection::TempoSectionType::Constant);
+       map.add_tempo (tempoA, BBT_Time (1, 1, 0), TempoSection::Type::Constant);
        Tempo tempoB (240);
-       map.add_tempo (tempoB, BBT_Time (4, 1, 0), TempoSection::TempoSectionType::Constant);
+       map.add_tempo (tempoB, BBT_Time (4, 1, 0), TempoSection::Type::Constant);
 
        /* Now some tests */
 
@@ -115,9 +115,9 @@ FrameposMinusBeatsTest::doubleTempoWithMeterTest ()
        */
 
        Tempo tempoA (120);
-       map.add_tempo (tempoA, BBT_Time (1, 1, 0), TempoSection::TempoSectionType::Constant);
+       map.add_tempo (tempoA, BBT_Time (1, 1, 0), TempoSection::Type::Constant);
        Tempo tempoB (240);
-       map.add_tempo (tempoB, BBT_Time (4, 1, 0), TempoSection::TempoSectionType::Constant);
+       map.add_tempo (tempoB, BBT_Time (4, 1, 0), TempoSection::Type::Constant);
        Meter meterB (3, 4);
        map.add_meter (meterB, BBT_Time (4, 1, 0));
 
index 442c9b3d5645874f7b5d4e6163006aef83c12471..425ae843433601365a035e9990d225e3705b4e9e 100644 (file)
@@ -22,7 +22,7 @@ FrameposPlusBeatsTest::singleTempoTest ()
        Meter meter (4, 4);
 
        map.add_meter (meter, BBT_Time (1, 1, 0));
-       map.add_tempo (tempo, BBT_Time (1, 1, 0), TempoSection::TempoSectionType::Constant);
+       map.add_tempo (tempo, BBT_Time (1, 1, 0), TempoSection::Type::Constant);
 
        /* Add 1 beat to beat 3 of the first bar */
        framepos_t r = map.framepos_plus_beats (frames_per_beat * 2, Evoral::Beats(1));
@@ -62,9 +62,9 @@ FrameposPlusBeatsTest::doubleTempoTest ()
        */
 
        Tempo tempoA (120);
-       map.add_tempo (tempoA, BBT_Time (1, 1, 0), TempoSection::TempoSectionType::Constant);
+       map.add_tempo (tempoA, BBT_Time (1, 1, 0), TempoSection::Type::Constant);
        Tempo tempoB (240);
-       map.add_tempo (tempoB, BBT_Time (4, 1, 0), TempoSection::TempoSectionType::Constant);
+       map.add_tempo (tempoB, BBT_Time (4, 1, 0), TempoSection::Type::Constant);
 
        /* Now some tests */
 
@@ -114,9 +114,9 @@ FrameposPlusBeatsTest::doubleTempoWithMeterTest ()
        */
 
        Tempo tempoA (120);
-       map.add_tempo (tempoA, BBT_Time (1, 1, 0), TempoSection::TempoSectionType::Constant);
+       map.add_tempo (tempoA, BBT_Time (1, 1, 0), TempoSection::Type::Constant);
        Tempo tempoB (240);
-       map.add_tempo (tempoB, BBT_Time (4, 1, 0), TempoSection::TempoSectionType::Constant);
+       map.add_tempo (tempoB, BBT_Time (4, 1, 0), TempoSection::Type::Constant);
        Meter meterB (3, 4);
        map.add_meter (meterB, BBT_Time (4, 1, 0));
 
index 67a9be72c4f4d7ad298c8a355ca6a302bcd8ef43..84ddf6fc30344c28a26f60e7c1de745d305cf761 100644 (file)
@@ -21,7 +21,7 @@ FramewalkToBeatsTest::singleTempoTest ()
        Meter meter (4, 4);
 
        map.add_meter (meter, BBT_Time (1, 1, 0));
-       map.add_tempo (tempo, BBT_Time (1, 1, 0), TempoSection::TempoSectionType::Constant);
+       map.add_tempo (tempo, BBT_Time (1, 1, 0), TempoSection::Type::Constant);
 
        /* Walk 1 beats-worth of frames from beat 3 */
        double r = map.framewalk_to_beats (frames_per_beat * 2, frames_per_beat * 1).to_double();
@@ -70,9 +70,9 @@ FramewalkToBeatsTest::doubleTempoTest ()
        */
 
        Tempo tempoA (120);
-       map.add_tempo (tempoA, BBT_Time (1, 1, 0), TempoSection::TempoSectionType::Constant);
+       map.add_tempo (tempoA, BBT_Time (1, 1, 0), TempoSection::Type::Constant);
        Tempo tempoB (240);
-       map.add_tempo (tempoB, BBT_Time (4, 1, 0), TempoSection::TempoSectionType::Constant);
+       map.add_tempo (tempoB, BBT_Time (4, 1, 0), TempoSection::Type::Constant);
 
        /* Now some tests */
 
@@ -125,11 +125,11 @@ FramewalkToBeatsTest::tripleTempoTest ()
        */
 
        Tempo tempoA (120);
-       map.add_tempo (tempoA, BBT_Time (1, 1, 0), TempoSection::TempoSectionType::Constant);
+       map.add_tempo (tempoA, BBT_Time (1, 1, 0), TempoSection::Type::Constant);
        Tempo tempoB (240);
-       map.add_tempo (tempoB, BBT_Time (2, 1, 0), TempoSection::TempoSectionType::Constant);
+       map.add_tempo (tempoB, BBT_Time (2, 1, 0), TempoSection::Type::Constant);
        Tempo tempoC (160);
-       map.add_tempo (tempoC, BBT_Time (3, 1, 0), TempoSection::TempoSectionType::Constant);
+       map.add_tempo (tempoC, BBT_Time (3, 1, 0), TempoSection::Type::Constant);
 
        /* Walk from 1|3 to 4|1 */
        double r = map.framewalk_to_beats (2 * 24e3, (2 * 24e3) + (4 * 12e3) + (4 * 18e3)).to_double();
index d5d7a86153c46006c93b809d94d8df9a383d46a1..392e2876e9fc5ac7bf6a76b81a04cbee38695a69 100644 (file)
@@ -48,7 +48,7 @@ class TestSlaveSessionProxy : public ISlaveSessionProxy {
           meter             (4.0, 4.0)
         {
           _tempo_map = new TempoMap (FRAME_RATE);
-          _tempo_map->add_tempo (tempo, Timecode::BBT_Time(1, 1, 0), TempoSection::TempoSectionType::Constant);
+          _tempo_map->add_tempo (tempo, Timecode::BBT_Time(1, 1, 0), TempoSection::Type::Constant);
           _tempo_map->add_meter (meter, Timecode::BBT_Time(1, 1, 0));
         }
 
index 21bd8eb627e7af493a397acf87de100abd0544f1..04b24f6d738aa1251ceb12fa3dd510c72049d0e3 100644 (file)
@@ -35,9 +35,9 @@ TempoTest::recomputeMapTest ()
        */
 
        Tempo tempoA (120);
-       map.add_tempo (tempoA, BBT_Time (1, 1, 0), TempoSection::TempoSectionType::Constant);
+       map.add_tempo (tempoA, BBT_Time (1, 1, 0), TempoSection::Type::Constant);
        Tempo tempoB (240);
-       map.add_tempo (tempoB, BBT_Time (4, 1, 0), TempoSection::TempoSectionType::Constant);
+       map.add_tempo (tempoB, BBT_Time (4, 1, 0), TempoSection::Type::Constant);
        Meter meterB (3, 4);
        map.add_meter (meterB, BBT_Time (4, 1, 0));