Fix framewalk_to_beats when it traverses more than one
authorCarl Hetherington <carl@carlh.net>
Sat, 10 Dec 2011 20:23:59 +0000 (20:23 +0000)
committerCarl Hetherington <carl@carlh.net>
Sat, 10 Dec 2011 20:23:59 +0000 (20:23 +0000)
metric change.

git-svn-id: svn://localhost/ardour2/branches/3.0@10970 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/tempo.cc
libs/ardour/test/framewalk_to_beats_test.cc
libs/ardour/test/framewalk_to_beats_test.h

index 7a653547da46dfa4411cd7a400521606b49593ac..f0880fed913c1cebafc39999c9ed088a59c22084 100644 (file)
@@ -2182,6 +2182,7 @@ TempoMap::framewalk_to_beats (framepos_t pos, framecnt_t distance) const
                double const sub = min (distance, distance_to_end);
 
                /* Update */
+               pos += sub;
                distance -= sub;
                beats += sub / tempo->frames_per_beat (_frame_rate, *meter);
 
index 6aca63c6c1a36596000b449b50093d3cc3468587..7e50aedcb54bb0f8b616be3b30c38a920d851123 100644 (file)
@@ -95,3 +95,42 @@ FramewalkToBeatsTest::doubleTempoTest ()
        CPPUNIT_ASSERT_EQUAL (r, 3.5);
 }
 
+void
+FramewalkToBeatsTest::tripleTempoTest ()
+{
+       int const sampling_rate = 48000;
+
+       TempoMap map (sampling_rate);
+       Meter meter (4, 4);
+       map.add_meter (meter, BBT_Time (1, 1, 0));
+
+       /*
+         120bpm at bar 1, 240bpm at bar 2, 160bpm at bar 3
+         
+         120bpm = 24e3 samples per beat
+         160bpm = 18e3 samples per beat
+         240bpm = 12e3 samples per beat
+       */
+       
+
+       /*
+         
+         120bpm            240bpm            160bpm
+         0 beats           4 beats           8 beats
+         0 frames          96e3 frames       144e3 frames
+         |                 |                 |                 |                 |
+         | 1.1 1.2 1.3 1.4 | 2.1 2.2 2.3.2.4 | 3.1 3.2 3.3 3.4 | 4.1 4.2 4.3 4.4 |
+
+       */
+
+       Tempo tempoA (120);
+       map.add_tempo (tempoA, BBT_Time (1, 1, 0));
+       Tempo tempoB (240);
+       map.add_tempo (tempoB, BBT_Time (2, 1, 0));
+       Tempo tempoC (160);
+       map.add_tempo (tempoC, BBT_Time (3, 1, 0));
+
+       /* Walk from 1|3 to 4|1 */
+       double r = map.framewalk_to_beats (2 * 24e3, (2 * 24e3) + (4 * 12e3) + (4 * 18e3));
+       CPPUNIT_ASSERT_EQUAL (10.0, r);
+}
index ae6ae646ebbd4ad8a5c2a425fae51468dd853f74..4acaeaddd67f8eed4fdf8e4eb2a58d3f6119a390 100644 (file)
@@ -7,6 +7,7 @@ class FramewalkToBeatsTest : public CppUnit::TestFixture
        CPPUNIT_TEST_SUITE (FramewalkToBeatsTest);
        CPPUNIT_TEST (singleTempoTest);
        CPPUNIT_TEST (doubleTempoTest);
+       CPPUNIT_TEST (tripleTempoTest);
        CPPUNIT_TEST_SUITE_END ();
 
 public:
@@ -15,5 +16,6 @@ public:
 
        void singleTempoTest ();
        void doubleTempoTest ();
+       void tripleTempoTest ();
 };