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>
|
2019-09-05 08:08:31 -04:00
|
|
|
#include "temporal/beats.h"
|
2019-10-25 15:13:51 -04:00
|
|
|
#include "evoral/Sequence.h"
|
|
|
|
#include "evoral/TypeMap.h"
|
|
|
|
#include "evoral/EventSink.h"
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "evoral/midi_events.h"
|
2019-10-25 15:13:51 -04:00
|
|
|
#include "evoral/Control.h"
|
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
|
|
|
|
2016-11-07 05:14:55 -05:00
|
|
|
virtual ParameterType midi_parameter_type(const uint8_t* buf, uint32_t len) const {
|
|
|
|
switch (buf[0] & 0xF0) {
|
|
|
|
case MIDI_CMD_CONTROL: return CONTROL;
|
|
|
|
case MIDI_CMD_COMMON_SYSEX: return SYSEX;
|
|
|
|
case MIDI_CMD_NOTE_ON: return NOTE;
|
|
|
|
case MIDI_CMD_NOTE_OFF: return NOTE;
|
|
|
|
default: return 0;
|
|
|
|
}
|
2009-02-09 17:32:38 -05:00
|
|
|
}
|
2009-10-19 11:26:56 -04:00
|
|
|
|
2014-12-02 23:30:16 -05:00
|
|
|
ParameterDescriptor descriptor(const Parameter& param) const {
|
2019-09-05 16:37:06 -04:00
|
|
|
Evoral::ParameterDescriptor desc;
|
|
|
|
desc.upper = 127;
|
|
|
|
desc.rangesteps = 128;
|
|
|
|
return desc;
|
2014-12-02 23:30:16 -05:00
|
|
|
}
|
|
|
|
|
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) {}
|
2016-12-04 15:17:08 -05:00
|
|
|
MySequence(const MySequence& copy) : ControlSet(copy), Sequence<Time>(copy) {}
|
2009-10-19 11:26:56 -04:00
|
|
|
|
2015-10-07 04:42:28 -04:00
|
|
|
virtual bool find_next_event(double start, double end, ControlEvent& ev, bool only_active) const { return false; }
|
|
|
|
|
2009-02-09 17:32:38 -05:00
|
|
|
boost::shared_ptr<Control> control_factory(const Parameter& param) {
|
2019-09-05 16:37:06 -04:00
|
|
|
Evoral::ParameterDescriptor desc;
|
|
|
|
desc.upper = 127;
|
|
|
|
desc.rangesteps = 128;
|
2022-09-29 22:04:48 -04:00
|
|
|
boost::shared_ptr<ControlList> list(new ControlList(param, desc, Temporal::BeatTime));
|
2014-12-02 23:30:16 -05:00
|
|
|
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:
|
2022-09-29 22:04:48 -04:00
|
|
|
TestSink() : _last_event_time(Time::from_double (-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) {
|
2016-12-03 15:49:13 -05:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint32_t)3, size);
|
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);
|
2016-12-04 15:17:08 -05:00
|
|
|
CPPUNIT_TEST (copyTest);
|
2009-10-19 11:26:56 -04:00
|
|
|
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:
|
2019-09-05 08:08:31 -04:00
|
|
|
typedef Temporal::Beats 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> >(
|
2022-09-29 22:04:48 -04:00
|
|
|
new Note<Time>(0, Time::from_double(i * 100), Time::from_double(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 ();
|
2016-12-04 15:17:08 -05:00
|
|
|
void copyTest ();
|
2009-10-19 12:09:20 -04:00
|
|
|
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
|
|
|
};
|