Exemplo n.º 1
0
void MidiTest::testMMCGoto()
{
	PhMidiInput midiIn;
	PhMidiOutput midiOut;

	int tcCount = 0;
	PhTime time = 0;
	PhTimeCodeType tcType = PhTimeCodeType25;

	connect(&midiIn, &PhMidiInput::timeCodeReceived, [&](int h, int m, int s, int f, PhTimeCodeType type) {
	            tcCount++;
	            tcType = type;
	            time = PhTimeCode::timeFromHhMmSsFf(h, m, s, f, tcType);
			});

	QVERIFY(midiIn.open("testMMCGoto"));
	QVERIFY(midiOut.open("testMMCGoto"));

	QCOMPARE(tcCount, 0);
	QCOMPARE(tcType, PhTimeCodeType25);

	midiOut.sendMMCGoto(2, 3, 4, 5, PhTimeCodeType24);
	QThread::msleep(10);

	QCOMPARE(tcCount, 1);
	QCOMPARE(tcType, PhTimeCodeType24);
	QCOMPARE(t2s(time, tcType), QString("02:03:04:05"));
}
Exemplo n.º 2
0
void makeLexDic(JKArgs& args)
{
	if(!args.is_set("src")||!args.is_set("tar")||!args.is_set("align"))
		usage();
	string srcfilename=args.value("src");
	string tarfilename=args.value("tar");
	string alignfilename=args.value("align");
	string s2tDicName="s2t.lex";
	string t2sDicName="t2s.lex";
	string weightFilename="";
	if(args.is_set("w"))weightFilename=args.value("w");
	if(args.is_set("s2t"))
		s2tDicName=args.value("s2t");
	if(args.is_set("t2s"))
		t2sDicName=args.value("t2s");

	ofstream s2t(s2tDicName.c_str());
	ofstream t2s(t2sDicName.c_str());
	Dic<double> s2tLexDic;
	Dic<double> t2sLexDic;
	makeLexDic(srcfilename,tarfilename,alignfilename,weightFilename,s2tLexDic,t2sLexDic);
	s2tLexDic.print(s2t);
	t2sLexDic.print(t2s);
	s2t.close();
	t2s.close();
}
Exemplo n.º 3
0
void MidiTest::testMTCReader()
{
	//
	// Initialize the midi timecode reader:
	//

	PhMidiTimeCodeReader mtcReader(PhTimeCodeType25);
	PhMidiOutput midiOut;

	PhTimeCodeType tcType = PhTimeCodeType25;
	int tcTypeCalled = 0;
	connect(&mtcReader, &PhMidiTimeCodeReader::timeCodeTypeChanged, [&](PhTimeCodeType type) {
	            tcType = type;
	            tcTypeCalled++;
			});

	QVERIFY(mtcReader.open("testMTCReader"));
	QVERIFY(midiOut.open("testMTCReader"));

	midiOut.sendFullTC(1, 0, 0, 0, PhTimeCodeType24);
	QThread::msleep(10);
	QCOMPARE(tcTypeCalled, 1);
	QCOMPARE(tcType, PhTimeCodeType24);
	QCOMPARE(mtcReader.timeCodeType(), PhTimeCodeType24);
	QCOMPARE(t2s(mtcReader.clock()->time(), PhTimeCodeType24), QString("01:00:00:00"));

	//
	// Any quarter frame message should trigger play mode
	//

	midiOut.sendQFTC(0x02); // Send frame low digit
	QThread::msleep(10);

	QCOMPARE(t2s(mtcReader.clock()->time(), PhTimeCodeType24), QString("01:00:00:00"));
	QVERIFY(PhTestTools::compareFloats(mtcReader.clock()->rate(), 1));

	// Test basic playback behaviour

	midiOut.sendQFTC(0x10); // Send frame high digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x20); // Send second low digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x30); // Send second high digit
	QThread::msleep(10);

	// Since 4 quarter frame message have elapsed the frame increment by one
	QCOMPARE(t2s(mtcReader.clock()->time(), PhTimeCodeType24), QString("01:00:00:01"));

	midiOut.sendQFTC(0x40); // Send minute low digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x50); // Send minute high digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x61); // Send hour low digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x70); // Send hour high digit and 24 fps info
	QThread::msleep(10);

	QCOMPARE(t2s(mtcReader.clock()->time(), PhTimeCodeType24), QString("01:00:00:02"));

	// Send 8 quarter frame message from another timecode (23:40:19:20)

	midiOut.sendQFTC(0x06); // Send frame low digit (6 because we start the next frame transmission)
	QThread::msleep(10);
	midiOut.sendQFTC(0x11); // Send frame high digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x23); // Send second low digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x31); // Send second high digit
	QThread::msleep(10);
	QCOMPARE(t2s(mtcReader.clock()->time(), PhTimeCodeType24), QString("01:00:00:03"));
	midiOut.sendQFTC(0x48); // Send minute low digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x52); // Send minute high digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x67); // Send hour low digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x71); // Send hour high digit and 24 fps info
	QThread::msleep(10);
	QCOMPARE(t2s(mtcReader.clock()->time(), PhTimeCodeType24), QString("23:40:19:22"));

	// Send the next 8 quarter frame message to check passing seconds

	midiOut.sendQFTC(0x00); // Send frame low digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x10); // Send frame high digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x24); // Send second low digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x31); // Send second high digit
	QThread::msleep(10);
	QCOMPARE(t2s(mtcReader.clock()->time(), PhTimeCodeType24), QString("23:40:19:23"));
	midiOut.sendQFTC(0x48); // Send minute low digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x52); // Send minute high digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x67); // Send hour low digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x71); // Send hour high digit and 24 fps info
	QThread::msleep(10);

	QCOMPARE(t2s(mtcReader.clock()->time(), PhTimeCodeType24), QString("23:40:20:00"));

	// Test passing minutes (from 10:03:59:20 to 10:04:00:00)

	midiOut.sendQFTC(0x06); // Send frame low digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x11); // Send frame high digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x2b); // Send second low digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x33); // Send second high digit
	QThread::msleep(10);
	QCOMPARE(t2s(mtcReader.clock()->time(), PhTimeCodeType24), QString("23:40:20:01"));
	midiOut.sendQFTC(0x43); // Send minute low digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x50); // Send minute high digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x6a); // Send hour low digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x70); // Send hour high digit and 24 fps info
	QThread::msleep(10);
	QCOMPARE(t2s(mtcReader.clock()->time(), PhTimeCodeType24), QString("10:03:59:22"));
	midiOut.sendQFTC(0x00); // Send frame low digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x10); // Send frame high digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x20); // Send second low digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x30); // Send second high digit
	QThread::msleep(10);
	QCOMPARE(t2s(mtcReader.clock()->time(), PhTimeCodeType24), QString("10:03:59:23"));
	midiOut.sendQFTC(0x44); // Send minute low digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x50); // Send minute high digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x6a); // Send hour low digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x70); // Send hour high digit and 24 fps info
	QThread::msleep(10);
	QCOMPARE(t2s(mtcReader.clock()->time(), PhTimeCodeType24), QString("10:04:00:00"));
	midiOut.sendQFTC(0x02); // Send frame low digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x10); // Send frame high digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x20); // Send second low digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x30); // Send second high digit
	QThread::msleep(10);
	QCOMPARE(t2s(mtcReader.clock()->time(), PhTimeCodeType24), QString("10:04:00:01"));
	midiOut.sendQFTC(0x44); // Send minute low digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x50); // Send minute high digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x6a); // Send hour low digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x70); // Send hour high digit and 24 fps info
	QThread::msleep(10);
	QCOMPARE(t2s(mtcReader.clock()->time(), PhTimeCodeType24), QString("10:04:00:02"));

	// Switch to 25 fps timecode
	QCOMPARE(tcTypeCalled, 1);
	QCOMPARE(tcType, PhTimeCodeType24);

	midiOut.sendQFTC(0x04); // Send frame low digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x10); // Send frame high digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x20); // Send second low digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x30); // Send second high digit
	QThread::msleep(10);
	QCOMPARE(t2s(mtcReader.clock()->time(), PhTimeCodeType24), QString("10:04:00:03"));
	midiOut.sendQFTC(0x44); // Send minute low digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x50); // Send minute high digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x6a); // Send hour low digit
	QThread::msleep(10);
	midiOut.sendQFTC(0x72); // Send hour high digit and 25fps info
	QThread::msleep(10);

	QCOMPARE(tcTypeCalled, 2);
	QCOMPARE(tcType, PhTimeCodeType25);
	QCOMPARE(mtcReader.timeCodeType(), PhTimeCodeType25);
	QCOMPARE(t2s(mtcReader.clock()->time(), PhTimeCodeType25), QString("10:04:00:04"));

	// Stop sending quarter frame MTC message should stop the reader after one frame:
#warning /// @todo QThread::msleep block the pause detector timer and QTest::qWait crashes...
//	QThread::msleep(30);
//	QVERIFY(PhTestTools::compareFloats(mtcReader.clock()->rate(), 1));
//	QThread::msleep(200);
//	QVERIFY(PhTestTools::compareFloats(mtcReader.clock()->rate(), 0));

}