2009-02-25 13:26:51 -05:00
|
|
|
#include <cassert>
|
|
|
|
#include <sigc++/sigc++.h>
|
2009-02-09 17:32:38 -05:00
|
|
|
#include <cppunit/TestFixture.h>
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "evoral/Sequence.hpp"
|
|
|
|
#include "evoral/TypeMap.hpp"
|
|
|
|
#include "evoral/EventSink.hpp"
|
|
|
|
#include "evoral/midi_events.h"
|
|
|
|
#include "evoral/Control.hpp"
|
2009-02-09 17:32:38 -05:00
|
|
|
|
|
|
|
using namespace Evoral;
|
|
|
|
|
|
|
|
class DummyTypeMap : public TypeMap {
|
|
|
|
public:
|
|
|
|
enum DummyEventType {
|
|
|
|
NOTE,
|
|
|
|
CONTROL,
|
|
|
|
SYSEX
|
|
|
|
};
|
2009-10-19 11:26:56 -04:00
|
|
|
|
2009-02-09 17:32:38 -05:00
|
|
|
~DummyTypeMap() {}
|
|
|
|
|
2009-10-22 22:53:47 -04:00
|
|
|
bool type_is_midi (uint32_t /*type*/) const { return true; }
|
2009-02-09 17:32:38 -05:00
|
|
|
|
|
|
|
uint8_t parameter_midi_type(const Parameter& param) const {
|
|
|
|
switch (param.type()) {
|
|
|
|
case CONTROL: return MIDI_CMD_CONTROL;
|
|
|
|
case SYSEX: return MIDI_CMD_COMMON_SYSEX;
|
|
|
|
default: return 0;
|
2009-10-19 11:26:56 -04:00
|
|
|
};
|
2009-02-09 17:32:38 -05:00
|
|
|
}
|
2009-10-19 11:26:56 -04:00
|
|
|
|
2009-02-09 17:32:38 -05:00
|
|
|
uint32_t midi_event_type(uint8_t status) const {
|
|
|
|
status &= 0xf0;
|
|
|
|
switch (status) {
|
|
|
|
case MIDI_CMD_CONTROL: return CONTROL;
|
2009-10-19 11:26:56 -04:00
|
|
|
case MIDI_CMD_COMMON_SYSEX: return SYSEX;
|
2009-02-09 17:32:38 -05:00
|
|
|
default: return 0;
|
|
|
|
};
|
|
|
|
}
|
2009-10-19 11:26:56 -04:00
|
|
|
|
2014-12-02 23:30:16 -05:00
|
|
|
ParameterDescriptor descriptor(const Parameter& param) const {
|
|
|
|
return ParameterDescriptor();
|
|
|
|
}
|
|
|
|
|
2009-10-22 22:53:47 -04:00
|
|
|
std::string to_symbol(const Parameter& /*param*/) const { return "control"; }
|
2009-02-09 17:32:38 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
template<typename Time>
|
|
|
|
class MySequence : public Sequence<Time> {
|
|
|
|
public:
|
2009-10-19 11:23:42 -04:00
|
|
|
MySequence(DummyTypeMap&map) : Sequence<Time>(map) {}
|
2009-10-19 11:26:56 -04:00
|
|
|
|
2009-02-09 17:32:38 -05:00
|
|
|
boost::shared_ptr<Control> control_factory(const Parameter& param) {
|
2014-12-02 23:30:16 -05:00
|
|
|
const Evoral::ParameterDescriptor desc;
|
|
|
|
boost::shared_ptr<ControlList> list(new ControlList(param, desc));
|
|
|
|
return boost::shared_ptr<Control>(new Control(param, desc, list));
|
2009-02-09 17:32:38 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename Time>
|
|
|
|
class TestSink : public EventSink<Time> {
|
|
|
|
public:
|
|
|
|
TestSink() : _last_event_time(-1) {}
|
2009-10-19 11:26:56 -04:00
|
|
|
|
2009-02-09 17:32:38 -05:00
|
|
|
/// return value, time, type, size, buffer
|
|
|
|
sigc::signal<uint32_t, Time, EventType, uint32_t, const uint8_t*> writing;
|
2009-10-19 11:26:56 -04:00
|
|
|
|
2009-02-09 17:32:38 -05:00
|
|
|
virtual uint32_t write(Time time, EventType type, uint32_t size, const uint8_t* buf) {
|
2009-02-11 15:20:41 -05:00
|
|
|
//std::cerr << "last event time: " << _last_event_time << " time: " << time << std::endl;
|
2009-02-09 17:32:38 -05:00
|
|
|
uint32_t result = writing(time, type, size, buf);
|
|
|
|
_last_event_time = time;
|
|
|
|
return result;
|
|
|
|
}
|
2009-10-19 11:26:56 -04:00
|
|
|
|
|
|
|
uint32_t assertLastEventTimeEarlier(
|
|
|
|
Time time, EventType /*type*/, uint32_t /*size*/, const uint8_t* /*buf*/) {
|
|
|
|
CPPUNIT_ASSERT(_last_event_time <= time);
|
2009-02-09 17:32:38 -05:00
|
|
|
return 0;
|
2009-10-19 11:26:56 -04:00
|
|
|
}
|
|
|
|
|
2009-02-09 17:32:38 -05:00
|
|
|
Time last_event_time() const { return _last_event_time; }
|
2009-10-19 11:26:56 -04:00
|
|
|
|
2009-02-09 17:32:38 -05:00
|
|
|
private:
|
|
|
|
Time _last_event_time;
|
|
|
|
};
|
|
|
|
|
2009-10-23 00:24:20 -04:00
|
|
|
template<typename Time>
|
|
|
|
class CCTestSink : public EventSink<Time> {
|
|
|
|
public:
|
|
|
|
CCTestSink(uint32_t t) : cc_type(t) {}
|
|
|
|
|
|
|
|
virtual uint32_t write(Time time, EventType type, uint32_t size, const uint8_t* buf) {
|
|
|
|
if (type == cc_type) {
|
|
|
|
CPPUNIT_ASSERT(size == 3);
|
2012-03-29 21:21:08 -04:00
|
|
|
events.push_back(std::make_pair(time, buf[2]));
|
2009-10-23 00:24:20 -04:00
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef std::vector< std::pair<Time, uint8_t> > Events;
|
|
|
|
Events events;
|
|
|
|
uint32_t cc_type;
|
|
|
|
};
|
|
|
|
|
2009-02-09 17:32:38 -05:00
|
|
|
class SequenceTest : public CppUnit::TestFixture
|
|
|
|
{
|
2009-10-19 11:26:56 -04:00
|
|
|
CPPUNIT_TEST_SUITE (SequenceTest);
|
|
|
|
CPPUNIT_TEST (createTest);
|
|
|
|
CPPUNIT_TEST (preserveEventOrderingTest);
|
2009-10-19 12:09:20 -04:00
|
|
|
CPPUNIT_TEST (iteratorSeekTest);
|
2009-10-23 00:24:20 -04:00
|
|
|
CPPUNIT_TEST (controlInterpolationTest);
|
2009-10-19 11:26:56 -04:00
|
|
|
CPPUNIT_TEST_SUITE_END ();
|
|
|
|
|
|
|
|
public:
|
2014-11-22 04:05:42 -05:00
|
|
|
typedef MusicalTime Time;
|
2009-10-22 22:53:47 -04:00
|
|
|
typedef std::vector< boost::shared_ptr< Note<Time> > > Notes;
|
2009-10-19 11:26:56 -04:00
|
|
|
|
2009-10-19 12:09:20 -04:00
|
|
|
void setUp () {
|
2009-10-19 11:26:56 -04:00
|
|
|
type_map = new DummyTypeMap();
|
|
|
|
assert(type_map);
|
|
|
|
seq = new MySequence<Time>(*type_map);
|
|
|
|
assert(seq);
|
|
|
|
|
|
|
|
for (int i = 0; i < 12; i++) {
|
2014-11-22 04:05:42 -05:00
|
|
|
test_notes.push_back(
|
|
|
|
boost::shared_ptr<Note<Time> >(
|
|
|
|
new Note<Time>(0, MusicalTime(i * 100), MusicalTime(100), 64 + i, 64)));
|
2009-10-19 11:26:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-19 12:09:20 -04:00
|
|
|
void tearDown () {
|
2009-10-19 11:26:56 -04:00
|
|
|
test_notes.clear();
|
|
|
|
delete seq;
|
|
|
|
delete type_map;
|
|
|
|
}
|
|
|
|
|
2009-10-19 12:09:20 -04:00
|
|
|
void createTest ();
|
|
|
|
void preserveEventOrderingTest ();
|
|
|
|
void iteratorSeekTest ();
|
2009-10-23 00:24:20 -04:00
|
|
|
void controlInterpolationTest ();
|
2009-10-19 11:26:56 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
DummyTypeMap* type_map;
|
|
|
|
MySequence<Time>* seq;
|
|
|
|
|
|
|
|
Notes test_notes;
|
2009-02-09 17:32:38 -05:00
|
|
|
};
|