2009-02-09 17:32:38 -05:00
|
|
|
#include "SequenceTest.hpp"
|
2009-10-23 00:24:20 -04:00
|
|
|
#include "evoral/MIDIParameters.hpp"
|
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;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
uint8_t buffer[2];
|
|
|
|
Event<Time>* event = new Event<Time>(
|
|
|
|
DummyTypeMap::CONTROL, (*i)->on_event().time(), 3, buffer, true
|
|
|
|
);
|
2009-10-19 11:26:56 -04:00
|
|
|
|
2009-02-09 17:32:38 -05:00
|
|
|
event->buffer()[0] = MIDI_CMD_CONTROL;
|
2010-07-24 20:39:04 -04:00
|
|
|
event->buffer()[1] = event->time() / 1000;
|
|
|
|
event->buffer()[2] = event->time() / 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
|
|
|
}
|
|
|
|
|
|
|
|
bool on = true;
|
|
|
|
for (Sequence<Time>::const_iterator i = seq->begin(600); i != seq->end(); ++i) {
|
|
|
|
if (on) {
|
|
|
|
CPPUNIT_ASSERT(((MIDIEvent<Time>&)*i).is_note_on());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(i->time(), Time((num_notes + 6) * 100));
|
|
|
|
++num_notes;
|
|
|
|
on = false;
|
|
|
|
} else {
|
|
|
|
CPPUNIT_ASSERT(((MIDIEvent<Time>&)*i).is_note_off());
|
|
|
|
on = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(num_notes, size_t(6));
|
|
|
|
}
|
2009-10-23 00:24:20 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
SequenceTest::controlInterpolationTest ()
|
|
|
|
{
|
|
|
|
seq->clear();
|
|
|
|
|
|
|
|
for (Notes::const_iterator i = test_notes.begin(); i != test_notes.end(); ++i) {
|
|
|
|
seq->notes().insert(*i);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
boost::shared_ptr<Control> c = seq->control(MIDI::ContinuousController(cc_type, 1, 1), true);
|
|
|
|
CPPUNIT_ASSERT(c);
|
|
|
|
|
|
|
|
double min, max, normal;
|
|
|
|
MIDI::controller_range(min, max, normal);
|
|
|
|
|
|
|
|
// Make a ramp like /\ from min to max and back to min
|
2010-07-27 20:42:43 -04:00
|
|
|
c->set_double(min, true, 0);
|
|
|
|
c->set_double(max, true, delay);
|
|
|
|
c->set_double(min, true, 2*delay);
|
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());
|
|
|
|
}
|
|
|
|
CPPUNIT_ASSERT(sink.events.size() == 3);
|
|
|
|
CPPUNIT_ASSERT(sink.events[0].first == 0);
|
|
|
|
CPPUNIT_ASSERT(sink.events[0].second == 0);
|
|
|
|
CPPUNIT_ASSERT(sink.events[1].first == 1000);
|
|
|
|
CPPUNIT_ASSERT(sink.events[1].second == 127);
|
|
|
|
CPPUNIT_ASSERT(sink.events[2].first == 2000);
|
|
|
|
CPPUNIT_ASSERT(sink.events[2].second == 0);
|
|
|
|
sink.events.clear();
|
|
|
|
CPPUNIT_ASSERT(sink.events.size() == 0);
|
|
|
|
|
|
|
|
// 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());
|
|
|
|
}
|
|
|
|
CPPUNIT_ASSERT(sink.events.size() == 128 * 2 - 1);
|
|
|
|
Time last_time = 0;
|
|
|
|
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) {
|
|
|
|
CPPUNIT_ASSERT(i->second == last_value + 1);
|
|
|
|
} else {
|
|
|
|
CPPUNIT_ASSERT(i->second == last_value - 1);
|
|
|
|
}
|
|
|
|
last_time = i->first;
|
|
|
|
last_value = i->second;
|
|
|
|
}
|
|
|
|
}
|