More s/frame/sample/ - fixes unit-test compilation
authorRobin Gareus <robin@gareus.org>
Tue, 19 Sep 2017 03:36:57 +0000 (05:36 +0200)
committerRobin Gareus <robin@gareus.org>
Tue, 19 Sep 2017 03:37:58 +0000 (05:37 +0200)
"frame" in #include file-names was replaced, this actually renames
the files to follow suit.

13 files changed:
libs/ardour/test/framepos_minus_beats_test.cc [deleted file]
libs/ardour/test/framepos_minus_beats_test.h [deleted file]
libs/ardour/test/framepos_plus_beats_test.cc [deleted file]
libs/ardour/test/framepos_plus_beats_test.h [deleted file]
libs/ardour/test/framewalk_to_beats_test.cc [deleted file]
libs/ardour/test/framewalk_to_beats_test.h [deleted file]
libs/ardour/test/samplepos_minus_beats_test.cc [new file with mode: 0644]
libs/ardour/test/samplepos_minus_beats_test.h [new file with mode: 0644]
libs/ardour/test/samplepos_plus_beats_test.cc [new file with mode: 0644]
libs/ardour/test/samplepos_plus_beats_test.h [new file with mode: 0644]
libs/ardour/test/samplewalk_to_beats_test.cc [new file with mode: 0644]
libs/ardour/test/samplewalk_to_beats_test.h [new file with mode: 0644]
libs/ardour/wscript

diff --git a/libs/ardour/test/framepos_minus_beats_test.cc b/libs/ardour/test/framepos_minus_beats_test.cc
deleted file mode 100644 (file)
index 5d2d95a..0000000
+++ /dev/null
@@ -1,141 +0,0 @@
-#include "samplepos_minus_beats_test.h"
-#include "ardour/tempo.h"
-#include "timecode/bbt_time.h"
-
-CPPUNIT_TEST_SUITE_REGISTRATION (FrameposMinusBeatsTest);
-
-using namespace std;
-using namespace ARDOUR;
-using namespace Timecode;
-using namespace Evoral;
-
-/* Basic tests with no tempo / meter changes */
-void
-FrameposMinusBeatsTest::singleTempoTest ()
-{
-       int const sampling_rate = 48000;
-       int const bpm = 120;
-
-       double const samples_per_beat = (60 / double (bpm)) * double (sampling_rate);
-
-       TempoMap map (sampling_rate);
-       Tempo tempo (bpm);
-       Meter meter (4, 4);
-
-       map.replace_meter (map.first_meter(), meter, BBT_Time (1, 1, 0), (samplepos_t) 0, AudioTime);
-       map.replace_tempo (map.first_tempo(), tempo, 0.0, 0, TempoSection::Constant, AudioTime);
-
-       /* Subtract 1 beat from beat 3 of the first bar */
-       samplepos_t r = map.samplepos_minus_qn (samples_per_beat * 2, Beats(1));
-       CPPUNIT_ASSERT_EQUAL (r, samplepos_t (samples_per_beat * 1));
-
-       /* Subtract 4 beats from 3 beats in, to go beyond zero */
-       r = map.samplepos_minus_qn (samples_per_beat * 3, Beats(4));
-       CPPUNIT_ASSERT_EQUAL (r, samplepos_t (- samples_per_beat));
-}
-
-/* Test adding things that overlap a tempo change */
-void
-FrameposMinusBeatsTest::doubleTempoTest ()
-{
-       int const sampling_rate = 48000;
-
-       TempoMap map (sampling_rate);
-       Meter meter (4, 4);
-       map.replace_meter (map.first_meter(), meter, BBT_Time (1, 1, 0), (samplepos_t) 0, AudioTime);
-
-       /*
-         120bpm at bar 1, 240bpm at bar 4
-
-         120bpm = 24e3 samples per beat
-         240bpm = 12e3 samples per beat
-       */
-
-
-       /*
-
-         120bpm                                                240bpm
-         0 beats                                               12 beats
-         0 samples                                              288e3 samples
-         0 pulses                                              4 pulses
-         |                 |                 |                 |                 |
-         | 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.replace_tempo (map.first_tempo(), tempoA, 0.0, 0, TempoSection::Constant, AudioTime);
-       Tempo tempoB (240);
-       map.add_tempo (tempoB, 12.0 / tempoA.note_type(), 0, TempoSection::Constant, MusicTime);
-
-       /* Now some tests */
-
-       /* Subtract 1 beat from 1|2 */
-       samplepos_t r = map.samplepos_minus_qn (24e3, Beats(1));
-       CPPUNIT_ASSERT_EQUAL (r, samplepos_t (0));
-
-       /* Subtract 2 beats from 4|2 (over the tempo change) */
-       r = map.samplepos_minus_qn (288e3 + 12e3, Beats(2));
-       CPPUNIT_ASSERT_EQUAL (r, samplepos_t (288e3 - 24e3));
-
-       /* Subtract 2.5 beats from 4|2 (over the tempo change) */
-       r = map.samplepos_minus_qn (288e3 + 12e3, Beats(2.5));
-       CPPUNIT_ASSERT_EQUAL (r, samplepos_t (288e3 - 24e3 - 12e3));
-}
-
-/* Same as doubleTempoTest () except put a meter change at the same time as the
-   tempo change (which shouldn't affect anything, since we are just dealing with
-   beats)
-*/
-
-void
-FrameposMinusBeatsTest::doubleTempoWithMeterTest ()
-{
-       int const sampling_rate = 48000;
-
-       TempoMap map (sampling_rate);
-       Meter meterA (4, 4);
-       map.replace_meter (map.first_meter(), meterA, BBT_Time (1, 1, 0), (samplepos_t) 0, AudioTime);
-
-       /*
-         120bpm at bar 1, 240bpm at bar 4
-
-         120bpm = 24e3 samples per beat
-         240bpm = 12e3 samples per beat
-       */
-
-
-       /*
-
-         120bpm                                                240bpm
-         0 beats                                               12 beats
-         0 samples                                              288e3 samples
-         0 pulses                                              3 pulses
-         |                 |                 |                 |             |
-         | 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 |
-
-       */
-
-       Tempo tempoA (120);
-       map.replace_tempo (map.first_tempo(), tempoA, 0.0, 0, TempoSection::Constant, AudioTime);
-       Tempo tempoB (240);
-       map.add_tempo (tempoB, 12.0 / tempoA.note_type(), 0, TempoSection::Constant, MusicTime);
-       Meter meterB (3, 4);
-       map.add_meter (meterB, 12.0, BBT_Time (4, 1, 0), 0, MusicTime);
-
-       /* Now some tests */
-
-       /* Subtract 1 beat from 1|2 */
-       samplepos_t r = map.samplepos_minus_qn (24e3, Beats(1));
-       CPPUNIT_ASSERT_EQUAL (r, samplepos_t (0));
-
-       /* Subtract 2 beats from 4|2 (over the tempo change) */
-       r = map.samplepos_minus_qn (288e3 + 12e3, Beats(2));
-       CPPUNIT_ASSERT_EQUAL (r, samplepos_t (288e3 - 24e3));
-
-       /* Subtract 2.5 beats from 4|2 (over the tempo change) */
-       r = map.samplepos_minus_qn (288e3 + 12e3, Beats(2.5));
-       CPPUNIT_ASSERT_EQUAL (r, samplepos_t (288e3 - 24e3 - 12e3));
-}
-
-
diff --git a/libs/ardour/test/framepos_minus_beats_test.h b/libs/ardour/test/framepos_minus_beats_test.h
deleted file mode 100644 (file)
index 648ef71..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-#include <sigc++/sigc++.h>
-#include <cppunit/TestFixture.h>
-#include <cppunit/extensions/HelperMacros.h>
-
-class FrameposMinusBeatsTest : public CppUnit::TestFixture
-{
-       CPPUNIT_TEST_SUITE (FrameposMinusBeatsTest);
-       CPPUNIT_TEST (singleTempoTest);
-       CPPUNIT_TEST (doubleTempoTest);
-       CPPUNIT_TEST (doubleTempoWithMeterTest);
-       CPPUNIT_TEST_SUITE_END ();
-
-public:
-       void setUp () {}
-       void tearDown () {}
-
-       void singleTempoTest ();
-       void doubleTempoTest ();
-       void doubleTempoWithMeterTest ();
-};
-
diff --git a/libs/ardour/test/framepos_plus_beats_test.cc b/libs/ardour/test/framepos_plus_beats_test.cc
deleted file mode 100644 (file)
index d567f46..0000000
+++ /dev/null
@@ -1,196 +0,0 @@
-#include "samplepos_plus_beats_test.h"
-#include "ardour/tempo.h"
-#include "timecode/bbt_time.h"
-
-CPPUNIT_TEST_SUITE_REGISTRATION (FrameposPlusBeatsTest);
-
-using namespace std;
-using namespace ARDOUR;
-using namespace Timecode;
-
-/* Basic tests with no tempo / meter changes */
-void
-FrameposPlusBeatsTest::singleTempoTest ()
-{
-       int const sampling_rate = 48000;
-       int const bpm = 120;
-
-       double const samples_per_beat = (60 / double (bpm)) * double (sampling_rate);
-
-       TempoMap map (sampling_rate);
-       Tempo tempo (bpm, 4.0);
-       Meter meter (4, 4);
-
-       map.replace_meter (map.first_meter(), meter, BBT_Time (1, 1, 0), 0, AudioTime);
-       map.replace_tempo (map.first_tempo(), tempo, 0.0, 0, AudioTime);
-
-       /* Add 1 beat to beat 3 of the first bar */
-       samplepos_t r = map.samplepos_plus_qn (samples_per_beat * 2, Evoral::Beats(1));
-       CPPUNIT_ASSERT_EQUAL (samplepos_t (samples_per_beat * 3), r);
-
-       /* Add 4 beats to a -ve sample of 1 beat before zero */
-       r = map.samplepos_plus_qn (-samples_per_beat * 1, Evoral::Beats(4));
-       CPPUNIT_ASSERT_EQUAL (samplepos_t (samples_per_beat * 3), r);
-}
-
-/* Test adding things that overlap a tempo change */
-void
-FrameposPlusBeatsTest::doubleTempoTest ()
-{
-       int const sampling_rate = 48000;
-
-       TempoMap map (sampling_rate);
-       Meter meter (4, 4);
-       map.replace_meter (map.first_meter(), meter, BBT_Time (1, 1, 0), 0, AudioTime);
-
-       /*
-         120bpm at bar 1, 240bpm at bar 4
-
-         120bpm = 24e3 samples per beat
-         240bpm = 12e3 samples per beat
-       */
-
-
-       /*
-
-         120bpm                                                240bpm
-         0 beats                                               12 beats
-         0 samples                                              288e3 samples
-         0 pulses                                              3 pulses
-         |                 |                 |                 |                 |
-         | 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, 4.0);
-       map.replace_tempo (map.first_tempo(), tempoA, 0.0, 0, AudioTime);
-       Tempo tempoB (240, 4.0);
-       map.add_tempo (tempoB, 12.0 / tempoA.note_type(), 0, MusicTime);
-
-       /* Now some tests */
-
-       /* Add 1 beat to 1|2 */
-       samplepos_t r = map.samplepos_plus_qn (24e3, Evoral::Beats(1));
-       CPPUNIT_ASSERT_EQUAL (samplepos_t (48e3), r);
-
-       /* Add 2 beats to 3|4 (over the tempo change) */
-       r = map.samplepos_plus_qn (264e3, Evoral::Beats(2));
-       CPPUNIT_ASSERT_EQUAL (samplepos_t (264e3 + 24e3 + 12e3), r);
-
-       /* Add 2.5 beats to 3|3|960 (over the tempo change) */
-       r = map.samplepos_plus_qn (264e3 - 12e3, Evoral::Beats(2.5));
-       CPPUNIT_ASSERT_EQUAL (samplepos_t (264e3 + 24e3 + 12e3), r);
-}
-
-/* Same as doubleTempoTest () except put a meter change at the same time as the
-   tempo change (which shouldn't affect anything, since we are just dealing with
-   beats)
-*/
-
-void
-FrameposPlusBeatsTest::doubleTempoWithMeterTest ()
-{
-       int const sampling_rate = 48000;
-
-       TempoMap map (sampling_rate);
-       Meter meterA (4, 4);
-       map.replace_meter (map.first_meter(), meterA, BBT_Time (1, 1, 0), 0, AudioTime);
-
-       /*
-         120bpm at bar 1, 240bpm at bar 4
-
-         120bpm = 24e3 samples per beat
-         240bpm = 12e3 samples per beat
-       */
-
-
-       /*
-
-         120bpm                                                240bpm
-         0 beats                                               12 beats
-         0 samples                                              288e3 samples
-         0 pulses                                              3 pulses
-         |                 |                 |                 |             |
-         | 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 |
-
-       */
-
-       Tempo tempoA (120, 4.0);
-       map.replace_tempo (map.first_tempo(), tempoA, 0.0, 0, AudioTime);
-       Tempo tempoB (240, 4.0);
-       map.add_tempo (tempoB, 12.0 / tempoA.note_type(), 0, MusicTime);
-       Meter meterB (3, 8);
-       map.add_meter (meterB, BBT_Time (4, 1, 0), 0, MusicTime);
-
-       /* Now some tests */
-
-       /* Add 1 beat to 1|2 */
-       samplepos_t r = map.samplepos_plus_qn (24e3, Evoral::Beats(1));
-       CPPUNIT_ASSERT_EQUAL (samplepos_t (48e3), r);
-
-       /* Add 2 beats to 3|4 (over the tempo change) */
-       r = map.samplepos_plus_qn (264e3, Evoral::Beats(2));
-       CPPUNIT_ASSERT_EQUAL (samplepos_t (264e3 + 24e3 + 12e3), r);
-
-       /* Add 2.5 beats to 3|3|960 (over the tempo change) */
-       r = map.samplepos_plus_qn (264e3 - 12e3, Evoral::Beats(2.5));
-       CPPUNIT_ASSERT_EQUAL (samplepos_t (264e3 + 24e3 + 12e3), r);
-}
-
-/* Same as doubleTempoWithMeterTest () except use odd meter divisors
-   (which shouldn't affect anything, since we are just dealing with
-   beats)
-*/
-
-void
-FrameposPlusBeatsTest::doubleTempoWithComplexMeterTest ()
-{
-       int const sampling_rate = 48000;
-
-       TempoMap map (sampling_rate);
-       Meter meterA (3, 4);
-       map.replace_meter (map.first_meter(), meterA, BBT_Time (1, 1, 0), 0, AudioTime);
-
-       /*
-         120bpm at bar 1, 240bpm at bar 4
-
-         120bpm = 24e3 samples per beat
-         240bpm = 12e3 samples per beat
-       */
-
-
-       /*
-
-         120bpm                                    5/8                    240bpm
-         0 beats                                   9 quarter note beats   12 quarter note beats
-                                                   9 meter-based beat     15 meter-based beat
-         0 samples                                                         288e3 samples
-         0 pulses                                  |                      3 pulses
-         |             |             |             |                      |
-         | 1.1 1.2 1.3 | 2.1 2.2 2.3 | 3.1 3.2 3.3 |4.14.24.34.44.5|5.15.2^5.35.45.5|
-                                                   |
-                                                   4|1|0
-       */
-
-       Tempo tempoA (120, 4.0);
-       map.replace_tempo (map.first_tempo(), tempoA, 0.0, 0, AudioTime);
-       Tempo tempoB (240, 4.0);
-       map.add_tempo (tempoB, 12.0 / 4.0, 0, MusicTime);
-       Meter meterB (5, 8);
-       map.add_meter (meterB, BBT_Time (4, 1, 0), 0, MusicTime);
-       /* Now some tests */
-
-       /* Add 1 beat to 1|2 */
-       samplepos_t r = map.samplepos_plus_qn (24e3, Evoral::Beats(1));
-       CPPUNIT_ASSERT_EQUAL (samplepos_t (48e3), r);
-
-       /* Add 2 beats to 5|1 (over the tempo change) */
-       r = map.samplepos_plus_qn (264e3, Evoral::Beats(2));
-       CPPUNIT_ASSERT_EQUAL (samplepos_t (264e3 + 24e3 + 12e3), r);
-
-       /* Add 2.5 beats to 4|5 (over the tempo change) */
-       r = map.samplepos_plus_qn (264e3 - 12e3, Evoral::Beats(2.5));
-       CPPUNIT_ASSERT_EQUAL (samplepos_t (264e3 + 24e3 + 12e3), r);
-}
-
-
diff --git a/libs/ardour/test/framepos_plus_beats_test.h b/libs/ardour/test/framepos_plus_beats_test.h
deleted file mode 100644 (file)
index 8dfaaef..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-#include <sigc++/sigc++.h>
-#include <cppunit/TestFixture.h>
-#include <cppunit/extensions/HelperMacros.h>
-
-class FrameposPlusBeatsTest : public CppUnit::TestFixture
-{
-       CPPUNIT_TEST_SUITE (FrameposPlusBeatsTest);
-       CPPUNIT_TEST (singleTempoTest);
-       CPPUNIT_TEST (doubleTempoTest);
-       CPPUNIT_TEST (doubleTempoWithMeterTest);
-       CPPUNIT_TEST (doubleTempoWithComplexMeterTest);
-       CPPUNIT_TEST_SUITE_END ();
-
-public:
-       void setUp () {}
-       void tearDown () {}
-
-       void singleTempoTest ();
-       void doubleTempoTest ();
-       void doubleTempoWithMeterTest ();
-       void doubleTempoWithComplexMeterTest ();
-};
-
diff --git a/libs/ardour/test/framewalk_to_beats_test.cc b/libs/ardour/test/framewalk_to_beats_test.cc
deleted file mode 100644 (file)
index 3bf4505..0000000
+++ /dev/null
@@ -1,171 +0,0 @@
-#include "framewalk_to_beats_test.h"
-#include "ardour/tempo.h"
-#include "timecode/bbt_time.h"
-
-CPPUNIT_TEST_SUITE_REGISTRATION (FramewalkToBeatsTest);
-
-using namespace std;
-using namespace ARDOUR;
-using namespace Timecode;
-
-void
-FramewalkToBeatsTest::singleTempoTest ()
-{
-       int const sampling_rate = 48000;
-       int const bpm = 120;
-
-       double const samples_per_beat = (60 / double (bpm)) * double (sampling_rate);
-
-       TempoMap map (sampling_rate);
-       Tempo tempo (bpm, 4.0);
-       Meter meter (4, 4);
-
-       map.replace_meter (map.meter_section_at_sample (0), meter, BBT_Time (1, 1, 0), 0, AudioTime);
-       map.replace_tempo (map.tempo_section_at_sample (0), tempo, 0.0, 0, AudioTime);
-
-       /* Walk 1 beats-worth of samples from beat 3 */
-       double r = map.framewalk_to_qn (samples_per_beat * 2, samples_per_beat * 1).to_double();
-       CPPUNIT_ASSERT_EQUAL (1.0, r);
-
-       /* Walk 6 beats-worth of samples from beat 4 */
-       r = map.framewalk_to_qn (samples_per_beat * 3, samples_per_beat * 6).to_double();
-       CPPUNIT_ASSERT_EQUAL (6.0, r);
-
-       /* Walk 1.5 beats-worth of samples from beat 3 */
-       r = map.framewalk_to_qn (samples_per_beat * 2, samples_per_beat * 1.5).to_double();
-       CPPUNIT_ASSERT_EQUAL (1.5, r);
-
-       /* Walk 1.5 beats-worth of samples from beat 2.5 */
-       r = map.framewalk_to_qn (samples_per_beat * 2.5, samples_per_beat * 1.5).to_double();
-       CPPUNIT_ASSERT_EQUAL (1.5, r);
-}
-
-void
-FramewalkToBeatsTest::doubleTempoTest ()
-{
-       int const sampling_rate = 48000;
-
-       TempoMap map (sampling_rate);
-       Meter meter (4, 4);
-       map.replace_meter (map.meter_section_at_sample (0), meter, BBT_Time (1, 1, 0), 0, AudioTime);
-
-       /*
-         120bpm at bar 1, 240bpm at bar 4
-
-         120bpm = 24e3 samples per beat
-         240bpm = 12e3 samples per beat
-       */
-
-
-       /*
-
-         120bpm                                          240bpm
-         0 beats                                         12 beats
-         0 samples                                        288e3 samples
-         24e3 samples per beat                            12e3 samples per beat
-         0 pulses                                        4 pulses
-         |               |               |               |               |
-         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 5.1
-         0   1   2   3   4   5   6   7   8   9   10  11  12  13  14  15  16
-
-       */
-
-       Tempo tempoA (120);
-       map.replace_tempo (map.tempo_section_at_sample (0), tempoA, 0.0, 0, AudioTime);
-       Tempo tempoB (240);
-       map.add_tempo (tempoB, 12.0 / tempoB.note_type(), 0, MusicTime);
-
-       /* Now some tests */
-
-       /* Walk 1 beat from 1|2 */
-       double r = map.framewalk_to_qn (24e3, 24e3).to_double();
-       CPPUNIT_ASSERT_EQUAL (1.0, r);
-
-       /* Walk 2 beats from 3|3 to 4|1 (over the tempo change) */
-       r = map.framewalk_to_qn (240e3, (24e3 + 24e3)).to_double();
-       CPPUNIT_ASSERT_EQUAL (2.0, r);
-
-       /* Walk 2.5 beats from 3|3.5 to 4.2 (over the tempo change) */
-       r = map.framewalk_to_qn (264e3 - 12e3, (24e3 + 12e3 + 12e3)).to_double();
-       CPPUNIT_ASSERT_EQUAL (2.5, r);
-       /* Walk 3 beats from 3|4.5 to 4|3.5 (over the tempo change) */
-       r = map.framewalk_to_qn (264e3 - 12e3, (24e3 + 12e3 + 12e3 + 6e3)).to_double();
-       CPPUNIT_ASSERT_EQUAL (3.0, r);
-
-       /* Walk 3.5 beats from 3|4.5 to 4.4 (over the tempo change) */
-       r = map.framewalk_to_qn (264e3 - 12e3, (24e3 + 12e3 + 12e3 + 12e3)).to_double();
-       CPPUNIT_ASSERT_EQUAL (3.5, r);
-}
-
-void
-FramewalkToBeatsTest::tripleTempoTest ()
-{
-       int const sampling_rate = 48000;
-
-       TempoMap map (sampling_rate);
-       Meter meter (4, 4);
-       map.replace_meter (map.meter_section_at_sample (0), meter, BBT_Time (1, 1, 0), 0, AudioTime);
-
-       /*
-         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 samples          96e3 samples       144e3 samples
-         0 pulses          1 pulse           2 pulses
-         |                 |                 |                 |                 |
-         | 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, 4.0);
-       map.replace_tempo (map.tempo_section_at_sample (0), tempoA, 0.0, 0, AudioTime);
-       Tempo tempoB (240, 4.0);
-       map.add_tempo (tempoB, 4.0 / tempoB.note_type(), 0, MusicTime);
-       Tempo tempoC (160, 4.0);
-       map.add_tempo (tempoC, 8.0 / tempoB.note_type(), 0, MusicTime);
-
-       /* Walk from 1|3 to 4|1 */
-       double r = map.framewalk_to_qn (2 * 24e3, (2 * 24e3) + (4 * 12e3) + (4 * 18e3)).to_double();
-       CPPUNIT_ASSERT_EQUAL (10.0, r);
-}
-
-void
-FramewalkToBeatsTest::singleTempoMeterTest ()
-{
-       int const sampling_rate = 48000;
-       int const bpm = 120;
-
-       double const samples_per_beat = (60 / double (bpm)) * double (sampling_rate);
-
-       TempoMap map (sampling_rate);
-       Tempo tempo (bpm, 4.0);
-       Meter meter (7, 8);
-
-       map.replace_meter (map.meter_section_at_sample (0), meter, BBT_Time (1, 1, 0), 0, AudioTime);
-       map.replace_tempo (map.tempo_section_at_sample (0), tempo, 0.0, 0, AudioTime);
-
-       /* Walk 1 qn beats-worth of samples from beat 3 */
-       double r = map.framewalk_to_qn (samples_per_beat * 2, samples_per_beat * 1).to_double();
-       CPPUNIT_ASSERT_EQUAL (1.0, r);
-
-       /* Walk 6 qn beats-worth of samples from beat 4 */
-       r = map.framewalk_to_qn (samples_per_beat * 3, samples_per_beat * 6).to_double();
-       CPPUNIT_ASSERT_EQUAL (6.0, r);
-
-       /* Walk 1.5 qn beats-worth of samples from beat 3 */
-       r = map.framewalk_to_qn (samples_per_beat * 2, samples_per_beat * 1.5).to_double();
-       CPPUNIT_ASSERT_EQUAL (1.5, r);
-
-       /* Walk 1.5 qn beats-worth of samples from beat 2.5 */
-       r = map.framewalk_to_qn (samples_per_beat * 2.5, samples_per_beat * 1.5).to_double();
-       CPPUNIT_ASSERT_EQUAL (1.5, r);
-}
diff --git a/libs/ardour/test/framewalk_to_beats_test.h b/libs/ardour/test/framewalk_to_beats_test.h
deleted file mode 100644 (file)
index df02100..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-#include <sigc++/sigc++.h>
-#include <cppunit/TestFixture.h>
-#include <cppunit/extensions/HelperMacros.h>
-
-class FramewalkToBeatsTest : public CppUnit::TestFixture
-{
-       CPPUNIT_TEST_SUITE (FramewalkToBeatsTest);
-       CPPUNIT_TEST (singleTempoTest);
-       CPPUNIT_TEST (doubleTempoTest);
-       CPPUNIT_TEST (tripleTempoTest);
-       CPPUNIT_TEST (singleTempoMeterTest);
-       CPPUNIT_TEST_SUITE_END ();
-
-public:
-       void setUp () {}
-       void tearDown () {}
-
-       void singleTempoTest ();
-       void doubleTempoTest ();
-       void tripleTempoTest ();
-       void singleTempoMeterTest ();
-};
-
diff --git a/libs/ardour/test/samplepos_minus_beats_test.cc b/libs/ardour/test/samplepos_minus_beats_test.cc
new file mode 100644 (file)
index 0000000..5d2d95a
--- /dev/null
@@ -0,0 +1,141 @@
+#include "samplepos_minus_beats_test.h"
+#include "ardour/tempo.h"
+#include "timecode/bbt_time.h"
+
+CPPUNIT_TEST_SUITE_REGISTRATION (FrameposMinusBeatsTest);
+
+using namespace std;
+using namespace ARDOUR;
+using namespace Timecode;
+using namespace Evoral;
+
+/* Basic tests with no tempo / meter changes */
+void
+FrameposMinusBeatsTest::singleTempoTest ()
+{
+       int const sampling_rate = 48000;
+       int const bpm = 120;
+
+       double const samples_per_beat = (60 / double (bpm)) * double (sampling_rate);
+
+       TempoMap map (sampling_rate);
+       Tempo tempo (bpm);
+       Meter meter (4, 4);
+
+       map.replace_meter (map.first_meter(), meter, BBT_Time (1, 1, 0), (samplepos_t) 0, AudioTime);
+       map.replace_tempo (map.first_tempo(), tempo, 0.0, 0, TempoSection::Constant, AudioTime);
+
+       /* Subtract 1 beat from beat 3 of the first bar */
+       samplepos_t r = map.samplepos_minus_qn (samples_per_beat * 2, Beats(1));
+       CPPUNIT_ASSERT_EQUAL (r, samplepos_t (samples_per_beat * 1));
+
+       /* Subtract 4 beats from 3 beats in, to go beyond zero */
+       r = map.samplepos_minus_qn (samples_per_beat * 3, Beats(4));
+       CPPUNIT_ASSERT_EQUAL (r, samplepos_t (- samples_per_beat));
+}
+
+/* Test adding things that overlap a tempo change */
+void
+FrameposMinusBeatsTest::doubleTempoTest ()
+{
+       int const sampling_rate = 48000;
+
+       TempoMap map (sampling_rate);
+       Meter meter (4, 4);
+       map.replace_meter (map.first_meter(), meter, BBT_Time (1, 1, 0), (samplepos_t) 0, AudioTime);
+
+       /*
+         120bpm at bar 1, 240bpm at bar 4
+
+         120bpm = 24e3 samples per beat
+         240bpm = 12e3 samples per beat
+       */
+
+
+       /*
+
+         120bpm                                                240bpm
+         0 beats                                               12 beats
+         0 samples                                              288e3 samples
+         0 pulses                                              4 pulses
+         |                 |                 |                 |                 |
+         | 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.replace_tempo (map.first_tempo(), tempoA, 0.0, 0, TempoSection::Constant, AudioTime);
+       Tempo tempoB (240);
+       map.add_tempo (tempoB, 12.0 / tempoA.note_type(), 0, TempoSection::Constant, MusicTime);
+
+       /* Now some tests */
+
+       /* Subtract 1 beat from 1|2 */
+       samplepos_t r = map.samplepos_minus_qn (24e3, Beats(1));
+       CPPUNIT_ASSERT_EQUAL (r, samplepos_t (0));
+
+       /* Subtract 2 beats from 4|2 (over the tempo change) */
+       r = map.samplepos_minus_qn (288e3 + 12e3, Beats(2));
+       CPPUNIT_ASSERT_EQUAL (r, samplepos_t (288e3 - 24e3));
+
+       /* Subtract 2.5 beats from 4|2 (over the tempo change) */
+       r = map.samplepos_minus_qn (288e3 + 12e3, Beats(2.5));
+       CPPUNIT_ASSERT_EQUAL (r, samplepos_t (288e3 - 24e3 - 12e3));
+}
+
+/* Same as doubleTempoTest () except put a meter change at the same time as the
+   tempo change (which shouldn't affect anything, since we are just dealing with
+   beats)
+*/
+
+void
+FrameposMinusBeatsTest::doubleTempoWithMeterTest ()
+{
+       int const sampling_rate = 48000;
+
+       TempoMap map (sampling_rate);
+       Meter meterA (4, 4);
+       map.replace_meter (map.first_meter(), meterA, BBT_Time (1, 1, 0), (samplepos_t) 0, AudioTime);
+
+       /*
+         120bpm at bar 1, 240bpm at bar 4
+
+         120bpm = 24e3 samples per beat
+         240bpm = 12e3 samples per beat
+       */
+
+
+       /*
+
+         120bpm                                                240bpm
+         0 beats                                               12 beats
+         0 samples                                              288e3 samples
+         0 pulses                                              3 pulses
+         |                 |                 |                 |             |
+         | 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 |
+
+       */
+
+       Tempo tempoA (120);
+       map.replace_tempo (map.first_tempo(), tempoA, 0.0, 0, TempoSection::Constant, AudioTime);
+       Tempo tempoB (240);
+       map.add_tempo (tempoB, 12.0 / tempoA.note_type(), 0, TempoSection::Constant, MusicTime);
+       Meter meterB (3, 4);
+       map.add_meter (meterB, 12.0, BBT_Time (4, 1, 0), 0, MusicTime);
+
+       /* Now some tests */
+
+       /* Subtract 1 beat from 1|2 */
+       samplepos_t r = map.samplepos_minus_qn (24e3, Beats(1));
+       CPPUNIT_ASSERT_EQUAL (r, samplepos_t (0));
+
+       /* Subtract 2 beats from 4|2 (over the tempo change) */
+       r = map.samplepos_minus_qn (288e3 + 12e3, Beats(2));
+       CPPUNIT_ASSERT_EQUAL (r, samplepos_t (288e3 - 24e3));
+
+       /* Subtract 2.5 beats from 4|2 (over the tempo change) */
+       r = map.samplepos_minus_qn (288e3 + 12e3, Beats(2.5));
+       CPPUNIT_ASSERT_EQUAL (r, samplepos_t (288e3 - 24e3 - 12e3));
+}
+
+
diff --git a/libs/ardour/test/samplepos_minus_beats_test.h b/libs/ardour/test/samplepos_minus_beats_test.h
new file mode 100644 (file)
index 0000000..648ef71
--- /dev/null
@@ -0,0 +1,21 @@
+#include <sigc++/sigc++.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+class FrameposMinusBeatsTest : public CppUnit::TestFixture
+{
+       CPPUNIT_TEST_SUITE (FrameposMinusBeatsTest);
+       CPPUNIT_TEST (singleTempoTest);
+       CPPUNIT_TEST (doubleTempoTest);
+       CPPUNIT_TEST (doubleTempoWithMeterTest);
+       CPPUNIT_TEST_SUITE_END ();
+
+public:
+       void setUp () {}
+       void tearDown () {}
+
+       void singleTempoTest ();
+       void doubleTempoTest ();
+       void doubleTempoWithMeterTest ();
+};
+
diff --git a/libs/ardour/test/samplepos_plus_beats_test.cc b/libs/ardour/test/samplepos_plus_beats_test.cc
new file mode 100644 (file)
index 0000000..d567f46
--- /dev/null
@@ -0,0 +1,196 @@
+#include "samplepos_plus_beats_test.h"
+#include "ardour/tempo.h"
+#include "timecode/bbt_time.h"
+
+CPPUNIT_TEST_SUITE_REGISTRATION (FrameposPlusBeatsTest);
+
+using namespace std;
+using namespace ARDOUR;
+using namespace Timecode;
+
+/* Basic tests with no tempo / meter changes */
+void
+FrameposPlusBeatsTest::singleTempoTest ()
+{
+       int const sampling_rate = 48000;
+       int const bpm = 120;
+
+       double const samples_per_beat = (60 / double (bpm)) * double (sampling_rate);
+
+       TempoMap map (sampling_rate);
+       Tempo tempo (bpm, 4.0);
+       Meter meter (4, 4);
+
+       map.replace_meter (map.first_meter(), meter, BBT_Time (1, 1, 0), 0, AudioTime);
+       map.replace_tempo (map.first_tempo(), tempo, 0.0, 0, AudioTime);
+
+       /* Add 1 beat to beat 3 of the first bar */
+       samplepos_t r = map.samplepos_plus_qn (samples_per_beat * 2, Evoral::Beats(1));
+       CPPUNIT_ASSERT_EQUAL (samplepos_t (samples_per_beat * 3), r);
+
+       /* Add 4 beats to a -ve sample of 1 beat before zero */
+       r = map.samplepos_plus_qn (-samples_per_beat * 1, Evoral::Beats(4));
+       CPPUNIT_ASSERT_EQUAL (samplepos_t (samples_per_beat * 3), r);
+}
+
+/* Test adding things that overlap a tempo change */
+void
+FrameposPlusBeatsTest::doubleTempoTest ()
+{
+       int const sampling_rate = 48000;
+
+       TempoMap map (sampling_rate);
+       Meter meter (4, 4);
+       map.replace_meter (map.first_meter(), meter, BBT_Time (1, 1, 0), 0, AudioTime);
+
+       /*
+         120bpm at bar 1, 240bpm at bar 4
+
+         120bpm = 24e3 samples per beat
+         240bpm = 12e3 samples per beat
+       */
+
+
+       /*
+
+         120bpm                                                240bpm
+         0 beats                                               12 beats
+         0 samples                                              288e3 samples
+         0 pulses                                              3 pulses
+         |                 |                 |                 |                 |
+         | 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, 4.0);
+       map.replace_tempo (map.first_tempo(), tempoA, 0.0, 0, AudioTime);
+       Tempo tempoB (240, 4.0);
+       map.add_tempo (tempoB, 12.0 / tempoA.note_type(), 0, MusicTime);
+
+       /* Now some tests */
+
+       /* Add 1 beat to 1|2 */
+       samplepos_t r = map.samplepos_plus_qn (24e3, Evoral::Beats(1));
+       CPPUNIT_ASSERT_EQUAL (samplepos_t (48e3), r);
+
+       /* Add 2 beats to 3|4 (over the tempo change) */
+       r = map.samplepos_plus_qn (264e3, Evoral::Beats(2));
+       CPPUNIT_ASSERT_EQUAL (samplepos_t (264e3 + 24e3 + 12e3), r);
+
+       /* Add 2.5 beats to 3|3|960 (over the tempo change) */
+       r = map.samplepos_plus_qn (264e3 - 12e3, Evoral::Beats(2.5));
+       CPPUNIT_ASSERT_EQUAL (samplepos_t (264e3 + 24e3 + 12e3), r);
+}
+
+/* Same as doubleTempoTest () except put a meter change at the same time as the
+   tempo change (which shouldn't affect anything, since we are just dealing with
+   beats)
+*/
+
+void
+FrameposPlusBeatsTest::doubleTempoWithMeterTest ()
+{
+       int const sampling_rate = 48000;
+
+       TempoMap map (sampling_rate);
+       Meter meterA (4, 4);
+       map.replace_meter (map.first_meter(), meterA, BBT_Time (1, 1, 0), 0, AudioTime);
+
+       /*
+         120bpm at bar 1, 240bpm at bar 4
+
+         120bpm = 24e3 samples per beat
+         240bpm = 12e3 samples per beat
+       */
+
+
+       /*
+
+         120bpm                                                240bpm
+         0 beats                                               12 beats
+         0 samples                                              288e3 samples
+         0 pulses                                              3 pulses
+         |                 |                 |                 |             |
+         | 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 |
+
+       */
+
+       Tempo tempoA (120, 4.0);
+       map.replace_tempo (map.first_tempo(), tempoA, 0.0, 0, AudioTime);
+       Tempo tempoB (240, 4.0);
+       map.add_tempo (tempoB, 12.0 / tempoA.note_type(), 0, MusicTime);
+       Meter meterB (3, 8);
+       map.add_meter (meterB, BBT_Time (4, 1, 0), 0, MusicTime);
+
+       /* Now some tests */
+
+       /* Add 1 beat to 1|2 */
+       samplepos_t r = map.samplepos_plus_qn (24e3, Evoral::Beats(1));
+       CPPUNIT_ASSERT_EQUAL (samplepos_t (48e3), r);
+
+       /* Add 2 beats to 3|4 (over the tempo change) */
+       r = map.samplepos_plus_qn (264e3, Evoral::Beats(2));
+       CPPUNIT_ASSERT_EQUAL (samplepos_t (264e3 + 24e3 + 12e3), r);
+
+       /* Add 2.5 beats to 3|3|960 (over the tempo change) */
+       r = map.samplepos_plus_qn (264e3 - 12e3, Evoral::Beats(2.5));
+       CPPUNIT_ASSERT_EQUAL (samplepos_t (264e3 + 24e3 + 12e3), r);
+}
+
+/* Same as doubleTempoWithMeterTest () except use odd meter divisors
+   (which shouldn't affect anything, since we are just dealing with
+   beats)
+*/
+
+void
+FrameposPlusBeatsTest::doubleTempoWithComplexMeterTest ()
+{
+       int const sampling_rate = 48000;
+
+       TempoMap map (sampling_rate);
+       Meter meterA (3, 4);
+       map.replace_meter (map.first_meter(), meterA, BBT_Time (1, 1, 0), 0, AudioTime);
+
+       /*
+         120bpm at bar 1, 240bpm at bar 4
+
+         120bpm = 24e3 samples per beat
+         240bpm = 12e3 samples per beat
+       */
+
+
+       /*
+
+         120bpm                                    5/8                    240bpm
+         0 beats                                   9 quarter note beats   12 quarter note beats
+                                                   9 meter-based beat     15 meter-based beat
+         0 samples                                                         288e3 samples
+         0 pulses                                  |                      3 pulses
+         |             |             |             |                      |
+         | 1.1 1.2 1.3 | 2.1 2.2 2.3 | 3.1 3.2 3.3 |4.14.24.34.44.5|5.15.2^5.35.45.5|
+                                                   |
+                                                   4|1|0
+       */
+
+       Tempo tempoA (120, 4.0);
+       map.replace_tempo (map.first_tempo(), tempoA, 0.0, 0, AudioTime);
+       Tempo tempoB (240, 4.0);
+       map.add_tempo (tempoB, 12.0 / 4.0, 0, MusicTime);
+       Meter meterB (5, 8);
+       map.add_meter (meterB, BBT_Time (4, 1, 0), 0, MusicTime);
+       /* Now some tests */
+
+       /* Add 1 beat to 1|2 */
+       samplepos_t r = map.samplepos_plus_qn (24e3, Evoral::Beats(1));
+       CPPUNIT_ASSERT_EQUAL (samplepos_t (48e3), r);
+
+       /* Add 2 beats to 5|1 (over the tempo change) */
+       r = map.samplepos_plus_qn (264e3, Evoral::Beats(2));
+       CPPUNIT_ASSERT_EQUAL (samplepos_t (264e3 + 24e3 + 12e3), r);
+
+       /* Add 2.5 beats to 4|5 (over the tempo change) */
+       r = map.samplepos_plus_qn (264e3 - 12e3, Evoral::Beats(2.5));
+       CPPUNIT_ASSERT_EQUAL (samplepos_t (264e3 + 24e3 + 12e3), r);
+}
+
+
diff --git a/libs/ardour/test/samplepos_plus_beats_test.h b/libs/ardour/test/samplepos_plus_beats_test.h
new file mode 100644 (file)
index 0000000..8dfaaef
--- /dev/null
@@ -0,0 +1,23 @@
+#include <sigc++/sigc++.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+class FrameposPlusBeatsTest : public CppUnit::TestFixture
+{
+       CPPUNIT_TEST_SUITE (FrameposPlusBeatsTest);
+       CPPUNIT_TEST (singleTempoTest);
+       CPPUNIT_TEST (doubleTempoTest);
+       CPPUNIT_TEST (doubleTempoWithMeterTest);
+       CPPUNIT_TEST (doubleTempoWithComplexMeterTest);
+       CPPUNIT_TEST_SUITE_END ();
+
+public:
+       void setUp () {}
+       void tearDown () {}
+
+       void singleTempoTest ();
+       void doubleTempoTest ();
+       void doubleTempoWithMeterTest ();
+       void doubleTempoWithComplexMeterTest ();
+};
+
diff --git a/libs/ardour/test/samplewalk_to_beats_test.cc b/libs/ardour/test/samplewalk_to_beats_test.cc
new file mode 100644 (file)
index 0000000..3e396b2
--- /dev/null
@@ -0,0 +1,171 @@
+#include "samplewalk_to_beats_test.h"
+#include "ardour/tempo.h"
+#include "timecode/bbt_time.h"
+
+CPPUNIT_TEST_SUITE_REGISTRATION (FramewalkToBeatsTest);
+
+using namespace std;
+using namespace ARDOUR;
+using namespace Timecode;
+
+void
+FramewalkToBeatsTest::singleTempoTest ()
+{
+       int const sampling_rate = 48000;
+       int const bpm = 120;
+
+       double const samples_per_beat = (60 / double (bpm)) * double (sampling_rate);
+
+       TempoMap map (sampling_rate);
+       Tempo tempo (bpm, 4.0);
+       Meter meter (4, 4);
+
+       map.replace_meter (map.meter_section_at_sample (0), meter, BBT_Time (1, 1, 0), 0, AudioTime);
+       map.replace_tempo (map.tempo_section_at_sample (0), tempo, 0.0, 0, AudioTime);
+
+       /* Walk 1 beats-worth of samples from beat 3 */
+       double r = map.framewalk_to_qn (samples_per_beat * 2, samples_per_beat * 1).to_double();
+       CPPUNIT_ASSERT_EQUAL (1.0, r);
+
+       /* Walk 6 beats-worth of samples from beat 4 */
+       r = map.framewalk_to_qn (samples_per_beat * 3, samples_per_beat * 6).to_double();
+       CPPUNIT_ASSERT_EQUAL (6.0, r);
+
+       /* Walk 1.5 beats-worth of samples from beat 3 */
+       r = map.framewalk_to_qn (samples_per_beat * 2, samples_per_beat * 1.5).to_double();
+       CPPUNIT_ASSERT_EQUAL (1.5, r);
+
+       /* Walk 1.5 beats-worth of samples from beat 2.5 */
+       r = map.framewalk_to_qn (samples_per_beat * 2.5, samples_per_beat * 1.5).to_double();
+       CPPUNIT_ASSERT_EQUAL (1.5, r);
+}
+
+void
+FramewalkToBeatsTest::doubleTempoTest ()
+{
+       int const sampling_rate = 48000;
+
+       TempoMap map (sampling_rate);
+       Meter meter (4, 4);
+       map.replace_meter (map.meter_section_at_sample (0), meter, BBT_Time (1, 1, 0), 0, AudioTime);
+
+       /*
+         120bpm at bar 1, 240bpm at bar 4
+
+         120bpm = 24e3 samples per beat
+         240bpm = 12e3 samples per beat
+       */
+
+
+       /*
+
+         120bpm                                          240bpm
+         0 beats                                         12 beats
+         0 samples                                        288e3 samples
+         24e3 samples per beat                            12e3 samples per beat
+         0 pulses                                        4 pulses
+         |               |               |               |               |
+         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 5.1
+         0   1   2   3   4   5   6   7   8   9   10  11  12  13  14  15  16
+
+       */
+
+       Tempo tempoA (120);
+       map.replace_tempo (map.tempo_section_at_sample (0), tempoA, 0.0, 0, AudioTime);
+       Tempo tempoB (240);
+       map.add_tempo (tempoB, 12.0 / tempoB.note_type(), 0, MusicTime);
+
+       /* Now some tests */
+
+       /* Walk 1 beat from 1|2 */
+       double r = map.framewalk_to_qn (24e3, 24e3).to_double();
+       CPPUNIT_ASSERT_EQUAL (1.0, r);
+
+       /* Walk 2 beats from 3|3 to 4|1 (over the tempo change) */
+       r = map.framewalk_to_qn (240e3, (24e3 + 24e3)).to_double();
+       CPPUNIT_ASSERT_EQUAL (2.0, r);
+
+       /* Walk 2.5 beats from 3|3.5 to 4.2 (over the tempo change) */
+       r = map.framewalk_to_qn (264e3 - 12e3, (24e3 + 12e3 + 12e3)).to_double();
+       CPPUNIT_ASSERT_EQUAL (2.5, r);
+       /* Walk 3 beats from 3|4.5 to 4|3.5 (over the tempo change) */
+       r = map.framewalk_to_qn (264e3 - 12e3, (24e3 + 12e3 + 12e3 + 6e3)).to_double();
+       CPPUNIT_ASSERT_EQUAL (3.0, r);
+
+       /* Walk 3.5 beats from 3|4.5 to 4.4 (over the tempo change) */
+       r = map.framewalk_to_qn (264e3 - 12e3, (24e3 + 12e3 + 12e3 + 12e3)).to_double();
+       CPPUNIT_ASSERT_EQUAL (3.5, r);
+}
+
+void
+FramewalkToBeatsTest::tripleTempoTest ()
+{
+       int const sampling_rate = 48000;
+
+       TempoMap map (sampling_rate);
+       Meter meter (4, 4);
+       map.replace_meter (map.meter_section_at_sample (0), meter, BBT_Time (1, 1, 0), 0, AudioTime);
+
+       /*
+         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 samples          96e3 samples       144e3 samples
+         0 pulses          1 pulse           2 pulses
+         |                 |                 |                 |                 |
+         | 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, 4.0);
+       map.replace_tempo (map.tempo_section_at_sample (0), tempoA, 0.0, 0, AudioTime);
+       Tempo tempoB (240, 4.0);
+       map.add_tempo (tempoB, 4.0 / tempoB.note_type(), 0, MusicTime);
+       Tempo tempoC (160, 4.0);
+       map.add_tempo (tempoC, 8.0 / tempoB.note_type(), 0, MusicTime);
+
+       /* Walk from 1|3 to 4|1 */
+       double r = map.framewalk_to_qn (2 * 24e3, (2 * 24e3) + (4 * 12e3) + (4 * 18e3)).to_double();
+       CPPUNIT_ASSERT_EQUAL (10.0, r);
+}
+
+void
+FramewalkToBeatsTest::singleTempoMeterTest ()
+{
+       int const sampling_rate = 48000;
+       int const bpm = 120;
+
+       double const samples_per_beat = (60 / double (bpm)) * double (sampling_rate);
+
+       TempoMap map (sampling_rate);
+       Tempo tempo (bpm, 4.0);
+       Meter meter (7, 8);
+
+       map.replace_meter (map.meter_section_at_sample (0), meter, BBT_Time (1, 1, 0), 0, AudioTime);
+       map.replace_tempo (map.tempo_section_at_sample (0), tempo, 0.0, 0, AudioTime);
+
+       /* Walk 1 qn beats-worth of samples from beat 3 */
+       double r = map.framewalk_to_qn (samples_per_beat * 2, samples_per_beat * 1).to_double();
+       CPPUNIT_ASSERT_EQUAL (1.0, r);
+
+       /* Walk 6 qn beats-worth of samples from beat 4 */
+       r = map.framewalk_to_qn (samples_per_beat * 3, samples_per_beat * 6).to_double();
+       CPPUNIT_ASSERT_EQUAL (6.0, r);
+
+       /* Walk 1.5 qn beats-worth of samples from beat 3 */
+       r = map.framewalk_to_qn (samples_per_beat * 2, samples_per_beat * 1.5).to_double();
+       CPPUNIT_ASSERT_EQUAL (1.5, r);
+
+       /* Walk 1.5 qn beats-worth of samples from beat 2.5 */
+       r = map.framewalk_to_qn (samples_per_beat * 2.5, samples_per_beat * 1.5).to_double();
+       CPPUNIT_ASSERT_EQUAL (1.5, r);
+}
diff --git a/libs/ardour/test/samplewalk_to_beats_test.h b/libs/ardour/test/samplewalk_to_beats_test.h
new file mode 100644 (file)
index 0000000..df02100
--- /dev/null
@@ -0,0 +1,23 @@
+#include <sigc++/sigc++.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+class FramewalkToBeatsTest : public CppUnit::TestFixture
+{
+       CPPUNIT_TEST_SUITE (FramewalkToBeatsTest);
+       CPPUNIT_TEST (singleTempoTest);
+       CPPUNIT_TEST (doubleTempoTest);
+       CPPUNIT_TEST (tripleTempoTest);
+       CPPUNIT_TEST (singleTempoMeterTest);
+       CPPUNIT_TEST_SUITE_END ();
+
+public:
+       void setUp () {}
+       void tearDown () {}
+
+       void singleTempoTest ();
+       void doubleTempoTest ();
+       void tripleTempoTest ();
+       void singleTempoMeterTest ();
+};
+
index a3ff5e74ea93d25fea3fa99096232b66901f71ec..0d7b08e368d4b1b9327dbfc340ab183ab3e61198 100644 (file)
@@ -524,8 +524,8 @@ def build(bld):
             create_ardour_test_program(bld, obj.includes, 'lua_script', 'test_lua_script', ['test/lua_script_test.cc'])
             create_ardour_test_program(bld, obj.includes, 'midi_clock_slave', 'test_midi_clock_slave', ['test/midi_clock_slave_test.cc'])
             create_ardour_test_program(bld, obj.includes, 'resampled_source', 'test_resampled_source', ['test/resampled_source_test.cc'])
-            create_ardour_test_program(bld, obj.includes, 'framewalk_to_beats', 'test_framewalk_to_beats', ['test/framewalk_to_beats_test.cc'])
-            create_ardour_test_program(bld, obj.includes, 'framepos_plus_beats', 'test_framepos_plus_beats', ['test/framepos_plus_beats_test.cc'])
+            create_ardour_test_program(bld, obj.includes, 'samplewalk_to_beats', 'test_samplewalk_to_beats', ['test/samplewalk_to_beats_test.cc'])
+            create_ardour_test_program(bld, obj.includes, 'samplepos_plus_beats', 'test_samplepos_plus_beats', ['test/samplepos_plus_beats_test.cc'])
             create_ardour_test_program(bld, obj.includes, 'playlist_equivalent_regions', 'test_playlist_equivalent_regions', ['test/playlist_equivalent_regions_test.cc'])
             create_ardour_test_program(bld, obj.includes, 'playlist_layering', 'test_playlist_layering', ['test/playlist_layering_test.cc'])
             create_ardour_test_program(bld, obj.includes, 'plugins_test', 'test_plugins', ['test/plugins_test.cc'])
@@ -546,8 +546,8 @@ def build(bld):
             test/lua_script_test.cc
             test/midi_clock_slave_test.cc
             test/resampled_source_test.cc
-            test/framewalk_to_beats_test.cc
-            test/framepos_plus_beats_test.cc
+            test/samplewalk_to_beats_test.cc
+            test/samplepos_plus_beats_test.cc
             test/playlist_equivalent_regions_test.cc
             test/playlist_layering_test.cc
             test/plugins_test.cc