2020-01-16 14:58:28 -05:00
|
|
|
#include "SequenceTest.h"
|
2009-02-09 17:32:38 -05:00
|
|
|
#include <cassert>
|
|
|
|
|
2009-02-11 15:20:41 -05:00
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(SequenceTest);
|
2009-02-09 17:32:38 -05:00
|
|
|
|
|
|
|
using namespace std;
|
2014-11-22 04:05:42 -05:00
|
|
|
using namespace Evoral;
|
2009-02-09 17:32:38 -05:00
|
|
|
|
2009-10-19 11:26:56 -04:00
|
|
|
void
|
2009-10-19 12:09:20 -04:00
|
|
|
SequenceTest::createTest ()
|
2009-02-09 17:32:38 -05:00
|
|
|
{
|
2009-02-11 15:20:41 -05:00
|
|
|
CPPUNIT_ASSERT_EQUAL(size_t(0), seq->sysexes().size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(size_t(0), seq->notes().size());
|
|
|
|
CPPUNIT_ASSERT(seq->notes().begin() == seq->notes().end());
|
2009-02-09 17:32:38 -05:00
|
|
|
}
|
|
|
|
|
2016-12-04 15:17:08 -05:00
|
|
|
void
|
|
|
|
SequenceTest::copyTest ()
|
|
|
|
{
|
|
|
|
DummyTypeMap map;
|
|
|
|
MySequence<Time> a(map);
|
|
|
|
for (Notes::const_iterator i = test_notes.begin(); i != test_notes.end(); ++i) {
|
|
|
|
a.notes().insert(*i);
|
|
|
|
}
|
|
|
|
|
|
|
|
MySequence<Time> b(a);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(b.notes().size(), a.notes().size());
|
|
|
|
}
|
2009-02-09 17:32:38 -05:00
|
|
|
|
2009-10-19 11:26:56 -04:00
|
|
|
void
|
2009-10-19 12:09:20 -04:00
|
|
|
SequenceTest::preserveEventOrderingTest ()
|
2009-02-09 17:32:38 -05:00
|
|
|
{
|
2009-02-11 15:20:41 -05:00
|
|
|
vector< boost::shared_ptr< Event<Time> > > inserted_events;
|
2009-10-19 11:26:56 -04:00
|
|
|
|
2009-02-09 17:32:38 -05:00
|
|
|
seq->start_write();
|
2009-10-19 11:26:56 -04:00
|
|
|
|
2009-02-09 17:32:38 -05:00
|
|
|
for (Notes::const_iterator i = test_notes.begin(); i != test_notes.end(); ++i) {
|
2014-04-07 14:27:56 -04:00
|
|
|
uint8_t buffer[3];
|
2009-02-09 17:32:38 -05:00
|
|
|
Event<Time>* event = new Event<Time>(
|
2016-11-07 05:14:55 -05:00
|
|
|
(Evoral::EventType)DummyTypeMap::CONTROL, (*i)->on_event().time(), 3, buffer, true
|
2009-02-09 17:32:38 -05:00
|
|
|
);
|
2009-10-19 11:26:56 -04:00
|
|
|
|
2009-02-09 17:32:38 -05:00
|
|
|
event->buffer()[0] = MIDI_CMD_CONTROL;
|
2014-11-24 10:10:50 -05:00
|
|
|
event->buffer()[1] = event->time().to_double() / 1000;
|
|
|
|
event->buffer()[2] = event->time().to_double() / 1000;
|
2009-10-19 11:26:56 -04:00
|
|
|
|
2009-02-09 17:32:38 -05:00
|
|
|
boost::shared_ptr<Event<Time> > event_ptr(event);
|
|
|
|
|
2010-07-24 20:39:04 -04:00
|
|
|
seq->append((*i)->on_event(), next_event_id ());
|
2009-02-09 17:32:38 -05:00
|
|
|
inserted_events.push_back(
|
|
|
|
boost::shared_ptr<Event<Time> >(
|
|
|
|
new Event<Time>((*i)->on_event(), true)
|
|
|
|
));
|
2009-10-19 11:26:56 -04:00
|
|
|
|
2010-07-24 20:39:04 -04:00
|
|
|
seq->append(*event_ptr, next_event_id ());
|
2009-02-09 17:32:38 -05:00
|
|
|
inserted_events.push_back(event_ptr);
|
2009-10-19 11:26:56 -04:00
|
|
|
|
2010-07-24 20:39:04 -04:00
|
|
|
seq->append((*i)->off_event(), next_event_id ());
|
2009-02-09 17:32:38 -05:00
|
|
|
inserted_events.push_back(
|
|
|
|
boost::shared_ptr<Event<Time> >(
|
|
|
|
new Event<Time>((*i)->off_event(), true)
|
|
|
|
));
|
|
|
|
}
|
2009-10-19 11:26:56 -04:00
|
|
|
|
2011-07-31 09:58:26 -04:00
|
|
|
seq->end_write (Sequence<Time>::Relax);
|
2009-02-09 17:32:38 -05:00
|
|
|
|
|
|
|
TestSink<Time> sink;
|
2009-02-11 15:20:41 -05:00
|
|
|
sink.writing.connect(sigc::mem_fun(&sink, &TestSink<Time>::assertLastEventTimeEarlier));
|
2009-02-09 17:32:38 -05:00
|
|
|
|
2009-02-14 20:24:26 -05:00
|
|
|
|
|
|
|
for (MySequence<Time>::const_iterator i = seq->begin(); i != seq->end(); ++i) {
|
|
|
|
sink.write(i->time(), i->event_type(), i->size(), i->buffer());
|
|
|
|
}
|
2009-10-19 11:26:56 -04:00
|
|
|
|
2009-02-09 17:32:38 -05:00
|
|
|
CPPUNIT_ASSERT_EQUAL(size_t(12), test_notes.size());
|
|
|
|
}
|
2009-02-14 20:24:26 -05:00
|
|
|
|
2009-10-19 12:09:20 -04:00
|
|
|
void
|
|
|
|
SequenceTest::iteratorSeekTest ()
|
|
|
|
{
|
|
|
|
size_t num_notes = 0;
|
|
|
|
|
|
|
|
seq->clear();
|
|
|
|
|
|
|
|
for (Notes::const_iterator i = test_notes.begin(); i != test_notes.end(); ++i) {
|
2009-10-19 12:14:55 -04:00
|
|
|
seq->notes().insert(*i);
|
2009-10-19 12:09:20 -04:00
|
|
|
}
|
|
|
|
|
2016-12-04 15:17:08 -05:00
|
|
|
// Iterate over all notes
|
2009-10-19 12:09:20 -04:00
|
|
|
bool on = true;
|
2019-09-05 08:08:31 -04:00
|
|
|
for (Sequence<Time>::const_iterator i = seq->begin(Time(600)); i != seq->end(); ++i) {
|
2009-10-19 12:09:20 -04:00
|
|
|
if (on) {
|
2016-11-07 05:14:55 -05:00
|
|
|
CPPUNIT_ASSERT(i->is_note_on());
|
2009-10-19 12:09:20 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL(i->time(), Time((num_notes + 6) * 100));
|
|
|
|
++num_notes;
|
|
|
|
on = false;
|
|
|
|
} else {
|
2016-11-07 05:14:55 -05:00
|
|
|
CPPUNIT_ASSERT(i->is_note_off());
|
2009-10-19 12:09:20 -04:00
|
|
|
on = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-04 15:17:08 -05:00
|
|
|
CPPUNIT_ASSERT_EQUAL(size_t(6), num_notes);
|
|
|
|
|
|
|
|
// Test invalidation
|
|
|
|
Sequence<Time>::const_iterator i = seq->begin(Time(600));
|
|
|
|
std::set< boost::weak_ptr< Note<Time> > > active_notes;
|
|
|
|
i.invalidate(&active_notes);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, active_notes.size());
|
|
|
|
|
|
|
|
// Test resuming after invalidation
|
|
|
|
i = seq->begin(Time(601), false, std::set<Evoral::Parameter>(), &active_notes);
|
|
|
|
CPPUNIT_ASSERT(i->is_note_off());
|
|
|
|
on = false;
|
|
|
|
num_notes = 1;
|
|
|
|
for (; i != seq->end(); ++i) {
|
|
|
|
if (on) {
|
|
|
|
CPPUNIT_ASSERT(i->is_note_on());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(Time((num_notes + 6) * 100), i->time());
|
|
|
|
++num_notes;
|
|
|
|
on = false;
|
|
|
|
} else {
|
|
|
|
CPPUNIT_ASSERT(i->is_note_off());
|
|
|
|
on = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(size_t(6), num_notes);
|
|
|
|
|
|
|
|
// Test equality of copied iterators
|
|
|
|
i = seq->begin();
|
|
|
|
++i;
|
|
|
|
Sequence<Time>::const_iterator j = i;
|
|
|
|
CPPUNIT_ASSERT(i == j);
|
2009-10-19 12:09:20 -04:00
|
|
|
}
|
2009-10-23 00:24:20 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
SequenceTest::controlInterpolationTest ()
|
|
|
|
{
|
|
|
|
seq->clear();
|
|
|
|
|
2010-07-27 20:42:43 -04:00
|
|
|
static const uint64_t delay = 1000;
|
|
|
|
static const uint32_t cc_type = 1;
|
2009-10-23 00:24:20 -04:00
|
|
|
|
2014-11-30 23:14:03 -05:00
|
|
|
boost::shared_ptr<Control> c = seq->control(Parameter(cc_type, 1, 1), true);
|
2009-10-23 00:24:20 -04:00
|
|
|
CPPUNIT_ASSERT(c);
|
|
|
|
|
2014-11-30 23:14:03 -05:00
|
|
|
double min = 0.0;
|
|
|
|
double max = 127.0;
|
2009-10-23 00:24:20 -04:00
|
|
|
|
|
|
|
// Make a ramp like /\ from min to max and back to min
|
2012-07-14 11:42:10 -04:00
|
|
|
c->set_double(min, 0, true);
|
|
|
|
c->set_double(max, delay, true);
|
|
|
|
c->set_double(min, 2*delay, true);
|
2009-10-23 00:24:20 -04:00
|
|
|
|
|
|
|
CCTestSink<Time> sink(cc_type);
|
|
|
|
|
|
|
|
// Test discrete (lack of) interpolation
|
|
|
|
c->list()->set_interpolation(ControlList::Discrete);
|
|
|
|
for (MySequence<Time>::const_iterator i = seq->begin(); i != seq->end(); ++i) {
|
|
|
|
sink.write(i->time(), i->event_type(), i->size(), i->buffer());
|
|
|
|
}
|
2016-12-03 15:49:13 -05:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, sink.events.size());
|
2019-09-05 08:08:31 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL(Time(0), sink.events[0].first);
|
2016-12-03 15:49:13 -05:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint8_t)0, sink.events[0].second);
|
2019-09-05 08:08:31 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL(Time(1000), sink.events[1].first);
|
2016-12-03 15:49:13 -05:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint8_t)127, sink.events[1].second);
|
2019-09-05 08:08:31 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL(Time(2000), sink.events[2].first);
|
2016-12-03 15:49:13 -05:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint8_t)0, sink.events[2].second);
|
2009-10-23 00:24:20 -04:00
|
|
|
sink.events.clear();
|
2016-12-03 15:49:13 -05:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, sink.events.size());
|
2009-10-23 00:24:20 -04:00
|
|
|
|
|
|
|
// Test linear interpolation
|
|
|
|
c->list()->set_interpolation(ControlList::Linear);
|
|
|
|
for (MySequence<Time>::const_iterator i = seq->begin(); i != seq->end(); ++i) {
|
|
|
|
sink.write(i->time(), i->event_type(), i->size(), i->buffer());
|
|
|
|
}
|
2016-12-03 15:49:13 -05:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)(128 * 2 - 1), sink.events.size());
|
2014-11-22 04:05:42 -05:00
|
|
|
Time last_time(0);
|
2009-10-23 00:24:20 -04:00
|
|
|
int16_t last_value = -1;
|
|
|
|
bool ascending = true;
|
|
|
|
for (CCTestSink<Time>::Events::const_iterator i = sink.events.begin();
|
|
|
|
i != sink.events.end(); ++i) {
|
|
|
|
CPPUNIT_ASSERT(last_time == 0 || i->first > last_time);
|
|
|
|
if (last_value == 127) {
|
|
|
|
ascending = false;
|
|
|
|
}
|
|
|
|
if (ascending) {
|
2016-12-03 15:49:13 -05:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int)i->second, last_value + 1);
|
2009-10-23 00:24:20 -04:00
|
|
|
} else {
|
2016-12-03 15:49:13 -05:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int)i->second, last_value - 1);
|
2009-10-23 00:24:20 -04:00
|
|
|
}
|
|
|
|
last_time = i->first;
|
|
|
|
last_value = i->second;
|
|
|
|
}
|
|
|
|
}
|