summaryrefslogtreecommitdiff
path: root/libs/ardour/test
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2019-09-05 14:52:08 +0200
committerRobin Gareus <robin@gareus.org>2019-09-05 14:52:08 +0200
commit01c5aa34c69cebf2816f5ea42bccbdd9b80145d0 (patch)
treefef1d32787a6749d7d1bcbeda65359ee1571f1cb /libs/ardour/test
parent5dfb729155e19960e99ca973947bdbb680e6630f (diff)
Update MClk unit-test - new transportmaster API
Diffstat (limited to 'libs/ardour/test')
-rw-r--r--libs/ardour/test/midi_clock_slave_test.cc45
-rw-r--r--libs/ardour/test/midi_clock_slave_test.h100
-rw-r--r--libs/ardour/test/midi_clock_test.cc49
-rw-r--r--libs/ardour/test/midi_clock_test.h49
4 files changed, 98 insertions, 145 deletions
diff --git a/libs/ardour/test/midi_clock_slave_test.cc b/libs/ardour/test/midi_clock_slave_test.cc
deleted file mode 100644
index 93262483f1..0000000000
--- a/libs/ardour/test/midi_clock_slave_test.cc
+++ /dev/null
@@ -1,45 +0,0 @@
-#include <sigc++/sigc++.h>
-#include "midi_clock_slave_test.h"
-
-using namespace std;
-using namespace ARDOUR;
-
-CPPUNIT_TEST_SUITE_REGISTRATION( MIDIClock_SlaveTest );
-
-void
-MIDIClock_SlaveTest::testStepResponse ()
-{
- double speed = 1.0;
- samplepos_t position = 0;
-
- MIDI::Parser* parser = 0;
-
- TestSlaveSessionProxy *sess = (TestSlaveSessionProxy *) session;
- samplecnt_t period_size = 4096;
- sess->set_period_size (period_size);
-
- bandwidth = 1.0 / 60.0;
-
- samplepos_t start_time = 1000000;
- start (*parser, start_time);
-
- update_midi_clock (*parser, start_time);
-
- for (samplecnt_t i = 1; i<= 100 * period_size; i++) {
- // simulate jitter
- samplecnt_t input_delta = samplecnt_t (one_ppqn_in_samples + 0.1 * (double(g_random_int()) / double (RAND_MAX)) * one_ppqn_in_samples);
-
- if (i % input_delta == 0) {
- update_midi_clock (*parser, start_time + i);
- }
-
- if (i % period_size == 0) {
- sess->next_period ();
- speed_and_position (speed, position);
- sess->request_transport_speed (speed);
- }
- }
-
-}
-
-
diff --git a/libs/ardour/test/midi_clock_slave_test.h b/libs/ardour/test/midi_clock_slave_test.h
deleted file mode 100644
index c7062a6e3e..0000000000
--- a/libs/ardour/test/midi_clock_slave_test.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Copyright (C) 2010-2012 Carl Hetherington <carl@carlh.net>
- * Copyright (C) 2010 Hans Baier <hansfbaier@googlemail.com>
- * Copyright (C) 2015-2016 Robin Gareus <robin@gareus.org>
- * Copyright (C) 2015-2017 Nick Mainsbridge <mainsbridge@gmail.com>
- * Copyright (C) 2015-2018 Paul Davis <paul@linuxaudiosystems.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include <cassert>
-#include <stdint.h>
-#include <cppunit/TestFixture.h>
-#include <cppunit/extensions/HelperMacros.h>
-
-#include "ardour/tempo.h"
-#include "ardour/transport_master.h"
-
-namespace ARDOUR {
-
-class TestSlaveSessionProxy : public ISlaveSessionProxy {
- #define FRAME_RATE 44100
- samplecnt_t _period_size;
-
- double transport_speed;
- samplepos_t _transport_sample;
- samplepos_t _sample_time;
- TempoMap *_tempo_map;
-
- Tempo tempo;
- Meter meter;
-
- public:
- TestSlaveSessionProxy() :
- transport_speed (1.0),
- _transport_sample (0),
- _sample_time (1000000),
- _tempo_map (0),
- tempo (120, 4.0),
- meter (4.0, 4.0)
- {
- _tempo_map = new TempoMap (FRAME_RATE);
- _tempo_map->add_tempo (tempo, 0.0, 0, AudioTime);
- _tempo_map->add_meter (meter, Timecode::BBT_Time(1, 1, 0), 0, AudioTime);
- }
-
- // Controlling the mock object
- void set_period_size (samplecnt_t a_size) { _period_size = a_size; }
- samplecnt_t period_size () const { return _period_size; }
- void next_period () {
- _transport_sample += double(_period_size) * double(transport_speed);
- _sample_time += _period_size;
- }
-
- // Implementation
- TempoMap& tempo_map () const { return *_tempo_map; }
- samplecnt_t sample_rate () const { return FRAME_RATE; }
- samplepos_t audible_sample () const { return _transport_sample; }
- samplepos_t transport_sample () const { return _transport_sample; }
- pframes_t samples_since_cycle_start () const { return 0; }
- samplepos_t sample_time () const { return _sample_time; }
-
- void request_locate (samplepos_t sample, bool with_roll = false) {
- _transport_sample = sample;
- }
-
- void request_transport_speed (const double speed) { transport_speed = speed; }
-};
-
-class MIDIClock_SlaveTest : public CppUnit::TestFixture, ARDOUR::MIDIClock_Slave
-{
- CPPUNIT_TEST_SUITE(MIDIClock_SlaveTest);
- CPPUNIT_TEST(testStepResponse);
- CPPUNIT_TEST_SUITE_END();
-
- public:
- MIDIClock_SlaveTest () : MIDIClock_Slave (new TestSlaveSessionProxy) {}
-
- void setUp() {
- }
-
- void tearDown() {
- }
-
- void testStepResponse();
-};
-
-} // namespace ARDOUR
diff --git a/libs/ardour/test/midi_clock_test.cc b/libs/ardour/test/midi_clock_test.cc
new file mode 100644
index 0000000000..fdccf56ab5
--- /dev/null
+++ b/libs/ardour/test/midi_clock_test.cc
@@ -0,0 +1,49 @@
+#include <sigc++/sigc++.h>
+#include "midi_clock_test.h"
+
+using namespace std;
+using namespace ARDOUR;
+
+CPPUNIT_TEST_SUITE_REGISTRATION(MIDIClock_Test);
+
+void
+MclkTestMaster::testStepResponse ()
+{
+ double speed = 1.0;
+ samplepos_t position = 0;
+ MIDI::Parser* parser = 0;
+
+ samplecnt_t period_size = 4096;
+ samplepos_t start_time = 1000000;
+
+ start (*parser, start_time);
+
+ update_midi_clock (*parser, start_time);
+
+ for (samplecnt_t i = 1; i <= 100 * period_size; i++) {
+ /* simulate jitter */
+ samplecnt_t input_delta = samplecnt_t (one_ppqn_in_samples + 0.1 * (double(g_random_int()) / double (RAND_MAX)) * one_ppqn_in_samples);
+
+ if (i % input_delta == 0) {
+ update_midi_clock (*parser, start_time + i);
+ }
+
+ if (i % period_size == 0) {
+ samplepos_t most_recent;
+ samplepos_t when;
+ speed_and_position (speed, position, most_recent, when, start_time + i);
+ // TODO CPPUNIT_ASSERT_EQUAL ?!
+ }
+ }
+}
+
+void MIDIClock_Test::run_test ()
+{
+ /* Note: A running engine is required to construct
+ * ARDOUR::MIDIClock_TransportMaster
+ */
+ MclkTestMaster* m = new MclkTestMaster;
+ m->set_session (_session);
+ m->testStepResponse ();
+ delete m;
+}
diff --git a/libs/ardour/test/midi_clock_test.h b/libs/ardour/test/midi_clock_test.h
new file mode 100644
index 0000000000..09dd048046
--- /dev/null
+++ b/libs/ardour/test/midi_clock_test.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2015-2019 Robin Gareus <robin@gareus.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <cassert>
+#include <stdint.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include "ardour/tempo.h"
+#include "ardour/transport_master.h"
+
+#include "test_needing_session.h"
+
+namespace ARDOUR {
+
+class MclkTestMaster : public ARDOUR::MIDIClock_TransportMaster
+{
+
+public:
+ MclkTestMaster () : MIDIClock_TransportMaster ("MClk-test", 24) {}
+ void testStepResponse ();
+};
+
+class MIDIClock_Test : public TestNeedingSession
+{
+ CPPUNIT_TEST_SUITE(MIDIClock_Test);
+ CPPUNIT_TEST(run_test);
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ void run_test ();
+};
+
+} // namespace ARDOUR