2012-05-26 14:49:10 +02:00
|
|
|
//=============================================================================
|
|
|
|
// MuseScore
|
|
|
|
// Music Composition & Notation
|
|
|
|
//
|
2013-04-25 21:37:19 +02:00
|
|
|
// Copyright (C) 2012-2013 Werner Schweer
|
2012-05-26 14:49:10 +02:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License version 2
|
|
|
|
// as published by the Free Software Foundation and appearing in
|
|
|
|
// the file LICENCE.GPL
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
#include <QtTest/QtTest>
|
2012-06-04 10:05:18 +02:00
|
|
|
#include "config.h"
|
2012-05-26 14:49:10 +02:00
|
|
|
#include "libmscore/score.h"
|
|
|
|
#include "libmscore/note.h"
|
|
|
|
#include "libmscore/chord.h"
|
|
|
|
#include "libmscore/instrtemplate.h"
|
|
|
|
#include "omr/omr.h"
|
|
|
|
#include "testutils.h"
|
|
|
|
#include "mscore/preferences.h"
|
|
|
|
#include "libmscore/page.h"
|
2013-04-03 12:49:55 +02:00
|
|
|
#include "synthesizer/msynthesizer.h"
|
2012-12-10 09:15:50 +01:00
|
|
|
#include "mscore/musescoreCore.h"
|
|
|
|
#include "mscore/shortcut.h"
|
2012-05-26 14:49:10 +02:00
|
|
|
|
2013-05-13 20:24:03 +02:00
|
|
|
namespace Ms {
|
|
|
|
|
2012-06-04 10:05:18 +02:00
|
|
|
#ifdef OMR
|
2012-10-01 10:31:55 +02:00
|
|
|
extern Score::FileError importPdf(Score*, const QString&);
|
2012-06-04 10:05:18 +02:00
|
|
|
#endif
|
2013-03-28 11:09:31 +01:00
|
|
|
|
2013-05-07 13:36:21 +02:00
|
|
|
extern Score::FileError importBB(Score*, const QString&);
|
2013-04-25 21:37:19 +02:00
|
|
|
extern Score::FileError importCapella(Score*, const QString&);
|
|
|
|
extern Score::FileError importCapXml(Score*, const QString&);
|
2012-10-13 13:47:57 +02:00
|
|
|
extern Score::FileError importCompressedMusicXml(Score*, const QString&);
|
2012-10-01 10:31:55 +02:00
|
|
|
extern Score::FileError importMusicXml(Score*, const QString&);
|
2012-09-27 21:34:36 +02:00
|
|
|
extern bool saveXml(Score*, const QString&);
|
2012-05-26 14:49:10 +02:00
|
|
|
bool debugMode = false;
|
|
|
|
bool noGui = true;
|
|
|
|
QString revision;
|
2013-02-06 17:43:43 +01:00
|
|
|
bool enableTestMode;
|
2012-05-26 14:49:10 +02:00
|
|
|
|
|
|
|
Score* score;
|
2012-12-10 09:15:50 +01:00
|
|
|
MuseScoreCore* mscoreCore;
|
2013-03-28 11:09:31 +01:00
|
|
|
MasterSynthesizer* synti;
|
2012-12-10 09:15:50 +01:00
|
|
|
QString dataPath;
|
|
|
|
QIcon* icons[0];
|
|
|
|
Shortcut Shortcut::sc[1] = { Shortcut() };
|
2012-05-26 14:49:10 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// Preferences
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
Preferences preferences;
|
|
|
|
Preferences::Preferences()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// writeReadElement
|
|
|
|
// writes and element and reads it back
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
Element* MTest::writeReadElement(Element* element)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// write element
|
|
|
|
//
|
|
|
|
QBuffer buffer;
|
|
|
|
buffer.open(QIODevice::WriteOnly);
|
|
|
|
Xml xml(&buffer);
|
|
|
|
xml.header();
|
|
|
|
element->write(xml);
|
|
|
|
buffer.close();
|
|
|
|
|
|
|
|
//
|
|
|
|
// read element
|
|
|
|
//
|
2012-09-13 18:37:29 +02:00
|
|
|
// printf("===read <%s>===\n", element->name());
|
|
|
|
// printf("%s\n", buffer.buffer().data());
|
2012-05-26 14:49:10 +02:00
|
|
|
|
2013-01-11 18:10:18 +01:00
|
|
|
XmlReader e(buffer.buffer());
|
2013-01-17 12:56:14 +01:00
|
|
|
e.readNextStartElement();
|
|
|
|
QString tag(e.name().toString());
|
|
|
|
// printf("read tag %s\n", qPrintable(tag));
|
2013-01-18 14:46:49 +01:00
|
|
|
element = Element::name2Element(e.name(), score);
|
2012-05-26 14:49:10 +02:00
|
|
|
element->read(e);
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// MTest
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
MTest::MTest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// readScore
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
Score* MTest::readScore(const QString& name)
|
|
|
|
{
|
|
|
|
QString path = root + "/" + name;
|
|
|
|
return readCreatedScore(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// readCreatedScore
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
Score* MTest::readCreatedScore(const QString& name)
|
|
|
|
{
|
|
|
|
Score* score = new Score(mscore->baseStyle());
|
|
|
|
score->setName(name);
|
2013-03-28 11:09:31 +01:00
|
|
|
MScore::testMode = true;
|
2012-05-26 14:49:10 +02:00
|
|
|
QString csl = score->fileInfo()->suffix().toLower();
|
|
|
|
|
2012-10-01 10:31:55 +02:00
|
|
|
Score::FileError rv;
|
2013-04-25 21:37:19 +02:00
|
|
|
if (csl == "cap")
|
|
|
|
rv = importCapella(score, name);
|
|
|
|
else if (csl == "capx")
|
|
|
|
rv = importCapXml(score, name);
|
2013-05-07 13:36:21 +02:00
|
|
|
else if (csl == "sgu")
|
|
|
|
rv = importBB(score, name);
|
2013-04-25 21:37:19 +02:00
|
|
|
else if (csl == "mscz" || csl == "mscx")
|
2012-10-01 10:31:55 +02:00
|
|
|
rv = score->loadMsc(name, false);
|
2012-10-13 13:47:57 +02:00
|
|
|
else if (csl == "mxl")
|
|
|
|
rv = importCompressedMusicXml(score, name);
|
2012-06-04 10:05:18 +02:00
|
|
|
#ifdef OMR
|
2012-05-26 14:49:10 +02:00
|
|
|
else if (csl == "pdf")
|
|
|
|
rv = importPdf(score, name);
|
2012-06-04 10:05:18 +02:00
|
|
|
#endif
|
2012-09-27 21:34:36 +02:00
|
|
|
else if (csl == "xml")
|
|
|
|
rv = importMusicXml(score, name);
|
2012-10-01 10:31:55 +02:00
|
|
|
else
|
|
|
|
rv = Score::FILE_UNKNOWN_TYPE;
|
|
|
|
|
|
|
|
if (rv != Score::FILE_NO_ERROR) {
|
2012-05-26 14:49:10 +02:00
|
|
|
QWARN(qPrintable(QString("readScore: cannot load <%1> type <%2>\n").arg(name).arg(csl)));
|
|
|
|
delete score;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return score;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// saveScore
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
bool MTest::saveScore(Score* score, const QString& name)
|
|
|
|
{
|
|
|
|
QFileInfo fi(name);
|
2013-03-28 11:09:31 +01:00
|
|
|
MScore::testMode = true;
|
2012-05-26 14:49:10 +02:00
|
|
|
return score->saveFile(fi);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
2012-09-27 21:34:36 +02:00
|
|
|
// compareFiles
|
2012-05-26 14:49:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2012-09-27 21:34:36 +02:00
|
|
|
bool MTest::compareFiles(const QString& saveName, const QString& compareWith)
|
2012-05-26 14:49:10 +02:00
|
|
|
{
|
|
|
|
QString cmd = "diff";
|
|
|
|
QStringList args;
|
|
|
|
args.append(saveName);
|
|
|
|
args.append(root + "/" + compareWith);
|
2013-05-16 12:48:23 +02:00
|
|
|
QProcess p;
|
|
|
|
p.start(cmd, args);
|
|
|
|
if (!p.waitForFinished())
|
|
|
|
return false;
|
|
|
|
if (p.exitCode()) {
|
|
|
|
QByteArray ba = p.readAll();
|
|
|
|
qDebug("%s", qPrintable(ba));
|
|
|
|
qDebug(" <diff %s %s failed", qPrintable(saveName),
|
|
|
|
qPrintable(QString(root + "/" + compareWith)));
|
2012-05-26 14:49:10 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-09-27 21:34:36 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// saveCompareScore
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
bool MTest::saveCompareScore(Score* score, const QString& saveName, const QString& compareWith)
|
|
|
|
{
|
|
|
|
saveScore(score, saveName);
|
|
|
|
return compareFiles(saveName, compareWith);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// saveCompareMusicXMLScore
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
bool MTest::saveCompareMusicXmlScore(Score* score, const QString& saveName, const QString& compareWith)
|
|
|
|
{
|
|
|
|
saveMusicXml(score, saveName);
|
|
|
|
return compareFiles(saveName, compareWith);
|
|
|
|
}
|
|
|
|
|
2012-05-26 14:49:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// savePdf
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
bool MTest::savePdf(Score* cs, const QString& saveName)
|
|
|
|
{
|
|
|
|
QPrinter printerDev(QPrinter::HighResolution);
|
|
|
|
const PageFormat* pf = cs->pageFormat();
|
|
|
|
printerDev.setPaperSize(pf->size(), QPrinter::Inch);
|
|
|
|
|
|
|
|
printerDev.setCreator("MuseScore Version: " VERSION);
|
|
|
|
printerDev.setFullPage(true);
|
|
|
|
printerDev.setColorMode(QPrinter::Color);
|
|
|
|
printerDev.setDocName(cs->name());
|
|
|
|
printerDev.setDoubleSidedPrinting(pf->twosided());
|
|
|
|
printerDev.setOutputFormat(QPrinter::PdfFormat);
|
|
|
|
|
|
|
|
printerDev.setOutputFileName(saveName);
|
|
|
|
QPainter p(&printerDev);
|
|
|
|
p.setRenderHint(QPainter::Antialiasing, true);
|
|
|
|
p.setRenderHint(QPainter::TextAntialiasing, true);
|
|
|
|
double mag = printerDev.logicalDpiX() / MScore::DPI;
|
|
|
|
p.scale(mag, mag);
|
|
|
|
|
|
|
|
const QList<Page*> pl = cs->pages();
|
|
|
|
int pages = pl.size();
|
|
|
|
int offset = cs->pageNumberOffset();
|
|
|
|
int fromPage = printerDev.fromPage() - 1 - offset;
|
|
|
|
int toPage = printerDev.toPage() - 1 - offset;
|
|
|
|
if (fromPage < 0)
|
|
|
|
fromPage = 0;
|
|
|
|
if ((toPage < 0) || (toPage >= pages))
|
|
|
|
toPage = pages - 1;
|
|
|
|
|
|
|
|
for (int copy = 0; copy < printerDev.numCopies(); ++copy) {
|
|
|
|
bool firstPage = true;
|
|
|
|
for (int n = fromPage; n <= toPage; ++n) {
|
|
|
|
if (!firstPage)
|
|
|
|
printerDev.newPage();
|
|
|
|
firstPage = false;
|
|
|
|
|
|
|
|
cs->print(&p, n);
|
|
|
|
if ((copy + 1) < printerDev.numCopies())
|
|
|
|
printerDev.newPage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p.end();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-09-27 21:34:36 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// saveMusicXml
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
bool MTest::saveMusicXml(Score* score, const QString& saveName)
|
|
|
|
{
|
|
|
|
return saveXml(score, saveName);
|
|
|
|
}
|
|
|
|
|
2012-05-26 14:49:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// initMTest
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void MTest::initMTest()
|
|
|
|
{
|
|
|
|
MScore::DPI = 120;
|
|
|
|
MScore::PDPI = 120;
|
|
|
|
MScore::DPMM = MScore::DPI / INCH;
|
|
|
|
|
2013-03-28 11:09:31 +01:00
|
|
|
synti = new MasterSynthesizer();
|
2012-05-26 14:49:10 +02:00
|
|
|
mscore = new MScore;
|
|
|
|
mscore->init();
|
2013-05-27 01:45:18 +02:00
|
|
|
preferences.shortestNote = MScore::division / 4; // midi quantization: 1/16
|
2012-05-26 14:49:10 +02:00
|
|
|
|
|
|
|
root = TESTROOT "/mtest";
|
|
|
|
loadInstrumentTemplates(":/instruments.xml");
|
2012-09-14 10:09:06 +02:00
|
|
|
score = readScore("/test.mscx");
|
2012-05-26 14:49:10 +02:00
|
|
|
}
|
2013-05-13 20:24:03 +02:00
|
|
|
}
|
2012-05-26 14:49:10 +02:00
|
|
|
|