From 01c5aa34c69cebf2816f5ea42bccbdd9b80145d0 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Thu, 5 Sep 2019 14:52:08 +0200 Subject: Update MClk unit-test - new transportmaster API --- libs/ardour/test/midi_clock_slave_test.cc | 45 -------------- libs/ardour/test/midi_clock_slave_test.h | 100 ------------------------------ libs/ardour/test/midi_clock_test.cc | 49 +++++++++++++++ libs/ardour/test/midi_clock_test.h | 49 +++++++++++++++ libs/ardour/wscript | 4 +- 5 files changed, 100 insertions(+), 147 deletions(-) delete mode 100644 libs/ardour/test/midi_clock_slave_test.cc delete mode 100644 libs/ardour/test/midi_clock_slave_test.h create mode 100644 libs/ardour/test/midi_clock_test.cc create mode 100644 libs/ardour/test/midi_clock_test.h 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 -#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 - * Copyright (C) 2010 Hans Baier - * Copyright (C) 2015-2016 Robin Gareus - * Copyright (C) 2015-2017 Nick Mainsbridge - * Copyright (C) 2015-2018 Paul Davis - * - * 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 -#include -#include -#include - -#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 +#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 + * + * 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 +#include +#include +#include + +#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 diff --git a/libs/ardour/wscript b/libs/ardour/wscript index d3e55320ca..c952d6aa0c 100644 --- a/libs/ardour/wscript +++ b/libs/ardour/wscript @@ -521,7 +521,7 @@ def build(bld): create_ardour_test_program(bld, obj.includes, 'bbt', 'test_bbt', ['test/bbt_test.cc']) create_ardour_test_program(bld, obj.includes, 'tempo', 'test_tempo', ['test/tempo_test.cc']) 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, 'midi_clock', 'test_midi_clock', ['test/midi_clock_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, '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']) @@ -542,7 +542,7 @@ def build(bld): test/dsp_load_calculator_test.cc test/tempo_test.cc test/lua_script_test.cc - test/midi_clock_slave_test.cc + test/midi_clock_test.cc test/resampled_source_test.cc test/samplewalk_to_beats_test.cc test/samplepos_plus_beats_test.cc -- cgit v1.2.3