2009-02-09 17:32:38 -05:00
|
|
|
#include "SMFTest.hpp"
|
2009-02-10 18:58:02 -05:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( SMFTest );
|
|
|
|
|
2009-02-12 18:28:51 -05:00
|
|
|
void
|
|
|
|
SMFTest::createNewFileTest ()
|
|
|
|
{
|
2009-02-14 20:32:41 -05:00
|
|
|
TestSMF smf;
|
2009-02-14 15:52:15 -05:00
|
|
|
smf.create("NewFile.mid");
|
2009-02-12 18:28:51 -05:00
|
|
|
smf.close();
|
2009-02-14 15:52:15 -05:00
|
|
|
CPPUNIT_ASSERT(access("NewFile.mid", R_OK) == 0);
|
2009-02-12 18:28:51 -05:00
|
|
|
unlink(smf.path().c_str());
|
|
|
|
}
|
|
|
|
|
2009-02-10 18:58:02 -05:00
|
|
|
void
|
|
|
|
SMFTest::takeFiveTest ()
|
|
|
|
{
|
2009-02-14 20:32:41 -05:00
|
|
|
TestSMF smf;
|
2009-02-10 18:58:02 -05:00
|
|
|
smf.open("./test/testdata/TakeFive.mid");
|
|
|
|
CPPUNIT_ASSERT(!smf.is_empty());
|
2009-10-19 11:26:56 -04:00
|
|
|
|
2009-02-10 18:58:02 -05:00
|
|
|
seq->start_write();
|
|
|
|
smf.seek_to_start();
|
|
|
|
|
|
|
|
uint64_t time = 0; /* in SMF ticks */
|
|
|
|
Evoral::Event<double> ev;
|
2009-10-19 11:26:56 -04:00
|
|
|
|
2009-02-10 18:58:02 -05:00
|
|
|
const double frames_per_beat = 100.0;
|
2009-10-19 11:26:56 -04:00
|
|
|
|
2009-02-10 18:58:02 -05:00
|
|
|
uint32_t delta_t = 0;
|
|
|
|
uint32_t size = 0;
|
|
|
|
uint8_t* buf = NULL;
|
|
|
|
int ret;
|
|
|
|
while ((ret = smf.read_event(&delta_t, &size, &buf)) >= 0) {
|
|
|
|
ev.set(buf, size, 0.0);
|
|
|
|
time += delta_t;
|
2009-10-19 11:26:56 -04:00
|
|
|
|
2009-02-10 18:58:02 -05:00
|
|
|
if (ret > 0) { // didn't skip (meta) event
|
2009-02-11 15:20:41 -05:00
|
|
|
//cerr << "read smf event type " << hex << int(buf[0]) << endl;
|
2009-02-10 18:58:02 -05:00
|
|
|
// make ev.time absolute time in frames
|
2011-11-12 22:54:29 -05:00
|
|
|
ev.set_time(time * frames_per_beat / (double)smf.ppqn());
|
2009-02-10 18:58:02 -05:00
|
|
|
ev.set_event_type(type_map->midi_event_type(buf[0]));
|
2010-07-24 20:39:04 -04:00
|
|
|
seq->append(ev, next_event_id ());
|
2009-02-10 18:58:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-31 09:58:26 -04:00
|
|
|
seq->end_write (Sequence<Time>::Relax, false);
|
2009-02-10 18:58:02 -05:00
|
|
|
CPPUNIT_ASSERT(!seq->empty());
|
|
|
|
}
|