Ardour  9.0-pre0-582-g084a23a80d
SequenceTest.h
Go to the documentation of this file.
1 #include <cassert>
2 #include <sigc++/sigc++.h>
3 #include <cppunit/TestFixture.h>
4 #include <cppunit/extensions/HelperMacros.h>
5 #include "temporal/beats.h"
6 #include "evoral/Sequence.h"
7 #include "evoral/TypeMap.h"
8 #include "evoral/EventSink.h"
9 #include "evoral/midi_events.h"
10 #include "evoral/Control.h"
11 
12 using namespace Evoral;
13 
14 class DummyTypeMap : public TypeMap {
15 public:
19  SYSEX
20  };
21 
23 
24  bool type_is_midi (uint32_t /*type*/) const { return true; }
25 
26  uint8_t parameter_midi_type(const Parameter& param) const {
27  switch (param.type()) {
28  case CONTROL: return MIDI_CMD_CONTROL;
29  case SYSEX: return MIDI_CMD_COMMON_SYSEX;
30  default: return 0;
31  };
32  }
33 
34  virtual ParameterType midi_parameter_type(const uint8_t* buf, uint32_t len) const {
35  switch (buf[0] & 0xF0) {
36  case MIDI_CMD_CONTROL: return CONTROL;
37  case MIDI_CMD_COMMON_SYSEX: return SYSEX;
38  case MIDI_CMD_NOTE_ON: return NOTE;
39  case MIDI_CMD_NOTE_OFF: return NOTE;
40  default: return 0;
41  }
42  }
43 
46  desc.upper = 127;
47  desc.rangesteps = 128;
48  return desc;
49  }
50 
51  std::string to_symbol(const Parameter& /*param*/) const { return "control"; }
52 };
53 
54 template<typename Time>
55 class MySequence : public Sequence<Time> {
56 public:
57  MySequence(DummyTypeMap&map) : Sequence<Time>(map) {}
58  MySequence(const MySequence& copy) : ControlSet(copy), Sequence<Time>(copy) {}
59 
60  virtual bool find_next_event(double start, double end, ControlEvent& ev, bool only_active) const { return false; }
61 
62  std::shared_ptr<Control> control_factory(const Parameter& param) {
64  desc.upper = 127;
65  desc.rangesteps = 128;
66  std::shared_ptr<ControlList> list(new ControlList(param, desc, Temporal::TimeDomainProvider (Temporal::BeatTime)));
67  return std::shared_ptr<Control>(new Control(param, desc, list));
68  }
69 };
70 
71 template<typename Time>
72 class TestSink : public EventSink<Time> {
73 public:
74  TestSink() : _last_event_time(Time::from_double (-1)) {}
75 
77  sigc::signal<uint32_t, Time, EventType, uint32_t, const uint8_t*> writing;
78 
79  virtual uint32_t write(Time time, EventType type, uint32_t size, const uint8_t* buf) {
80  //std::cerr << "last event time: " << _last_event_time << " time: " << time << std::endl;
81  uint32_t result = writing(time, type, size, buf);
82  _last_event_time = time;
83  return result;
84  }
85 
87  Time time, EventType /*type*/, uint32_t /*size*/, const uint8_t* /*buf*/) {
88  CPPUNIT_ASSERT(_last_event_time <= time);
89  return 0;
90  }
91 
92  Time last_event_time() const { return _last_event_time; }
93 
94 private:
96 };
97 
98 template<typename Time>
99 class CCTestSink : public EventSink<Time> {
100 public:
101  CCTestSink(uint32_t t) : cc_type(t) {}
102 
103  virtual uint32_t write(Time time, EventType type, uint32_t size, const uint8_t* buf) {
104  if (type == cc_type) {
105  CPPUNIT_ASSERT_EQUAL((uint32_t)3, size);
106  events.push_back(std::make_pair(time, buf[2]));
107  }
108  return size;
109  }
110 
111  typedef std::vector< std::pair<Time, uint8_t> > Events;
113  uint32_t cc_type;
114 };
115 
116 class SequenceTest : public CppUnit::TestFixture
117 {
119  CPPUNIT_TEST (createTest);
120  CPPUNIT_TEST (copyTest);
121  CPPUNIT_TEST (preserveEventOrderingTest);
122  CPPUNIT_TEST (iteratorSeekTest);
123  CPPUNIT_TEST (controlInterpolationTest);
125 
126 public:
128  typedef std::vector< std::shared_ptr< Note<Time> > > Notes;
129 
130  void setUp () {
131  type_map = new DummyTypeMap();
132  assert(type_map);
133  seq = new MySequence<Time>(*type_map);
134  assert(seq);
135 
136  for (int i = 0; i < 12; i++) {
137  test_notes.push_back(
138  std::shared_ptr<Note<Time> >(
139  new Note<Time>(0, Time::from_double(i * 100), Time::from_double(100), 64 + i, 64)));
140  }
141  }
142 
143  void tearDown () {
144  test_notes.clear();
145  delete seq;
146  delete type_map;
147  }
148 
149  void createTest ();
150  void copyTest ();
154 
155 private:
158 
160 };
CCTestSink(uint32_t t)
Definition: SequenceTest.h:101
Events events
Definition: SequenceTest.h:112
std::vector< std::pair< Time, uint8_t > > Events
Definition: SequenceTest.h:111
virtual uint32_t write(Time time, EventType type, uint32_t size, const uint8_t *buf)
Definition: SequenceTest.h:103
uint32_t cc_type
Definition: SequenceTest.h:113
std::string to_symbol(const Parameter &) const
Definition: SequenceTest.h:51
virtual ParameterType midi_parameter_type(const uint8_t *buf, uint32_t len) const
Definition: SequenceTest.h:34
uint8_t parameter_midi_type(const Parameter &param) const
Definition: SequenceTest.h:26
ParameterDescriptor descriptor(const Parameter &param) const
Definition: SequenceTest.h:44
bool type_is_midi(uint32_t) const
Definition: SequenceTest.h:24
ParameterType type() const
Definition: Parameter.h:49
virtual bool find_next_event(double start, double end, ControlEvent &ev, bool only_active) const
Definition: SequenceTest.h:60
std::shared_ptr< Control > control_factory(const Parameter &param)
Definition: SequenceTest.h:62
MySequence(const MySequence &copy)
Definition: SequenceTest.h:58
MySequence(DummyTypeMap &map)
Definition: SequenceTest.h:57
DummyTypeMap * type_map
Definition: SequenceTest.h:156
void controlInterpolationTest()
void iteratorSeekTest()
void preserveEventOrderingTest()
std::vector< std::shared_ptr< Note< Time > > > Notes
Definition: SequenceTest.h:128
void tearDown()
Definition: SequenceTest.h:143
CPPUNIT_TEST(createTest)
CPPUNIT_TEST(controlInterpolationTest)
CPPUNIT_TEST(copyTest)
Temporal::Beats Time
Definition: SequenceTest.h:127
CPPUNIT_TEST_SUITE_END()
MySequence< Time > * seq
Definition: SequenceTest.h:157
void createTest()
Notes test_notes
Definition: SequenceTest.h:159
CPPUNIT_TEST(preserveEventOrderingTest)
CPPUNIT_TEST_SUITE(SequenceTest)
void copyTest()
CPPUNIT_TEST(iteratorSeekTest)
uint32_t assertLastEventTimeEarlier(Time time, EventType, uint32_t, const uint8_t *)
Definition: SequenceTest.h:86
virtual uint32_t write(Time time, EventType type, uint32_t size, const uint8_t *buf)
Definition: SequenceTest.h:79
Time _last_event_time
Definition: SequenceTest.h:95
sigc::signal< uint32_t, Time, EventType, uint32_t, const uint8_t * > writing
return value, time, type, size, buffer
Definition: SequenceTest.h:77
Time last_event_time() const
Definition: SequenceTest.h:92
#define MIDI_CMD_NOTE_ON
Definition: midi_events.h:107
#define MIDI_CMD_COMMON_SYSEX
Definition: midi_events.h:113
#define MIDI_CMD_CONTROL
Definition: midi_events.h:109
#define MIDI_CMD_NOTE_OFF
Definition: midi_events.h:106
PBD::PropertyDescriptor< timepos_t > start
Definition: editor.h:86
uint32_t ParameterType
DebugBits ControlList
float upper
Maximum value (in Hz, for frequencies)
unsigned int rangesteps
number of steps, [min,max] (inclusive). <= 1 means continuous. == 2 only min, max....