Skip to content
Permalink
Browse files

fix #136406. add Tuplet::read in the compatibility code and add mtests.

  • Loading branch information...
lasconic committed Nov 9, 2016
1 parent 25c3d07 commit 3b7c0fedd43eefde61a0b592a9fb638392c7ae78
@@ -788,5 +788,18 @@ void TDuration::setType(DurationType t)
if (_val == DurationType::V_MEASURE)
_dots = 0;
}

//---------------------------------------------------------
// isValid
//---------------------------------------------------------

bool TDuration::isValid(Fraction f)
{
TDuration t;
t.setType(DurationType::V_LONG);
t.setDots(4);
t.truncateToFraction(f, 4);
return ((t.fraction() - f).numerator() == 0);
}
}

@@ -75,6 +75,7 @@ class TDuration {
void setDots(int v);
Fraction fraction() const;
QString durationTypeUserName() const;
static bool isValid(Fraction f);
};

std::vector<TDuration> toDurationList(Fraction l, bool useDots, int maxDots = 4, bool printRestRemains = true);
@@ -698,6 +698,42 @@ static void readClef(Clef* clef, XmlReader& e)
clef->setClefType(ClefType::G);
}

//---------------------------------------------------------
// readTuplet
//---------------------------------------------------------

static void readTuplet(Tuplet* tuplet, XmlReader& e)
{
int bl = -1;
tuplet->setId(e.intAttribute("id", 0));

while (e.readNextStartElement()) {
const QStringRef& tag(e.name());
if (tag == "subtype") // obsolete
e.skipCurrentElement();
else if (tag == "hasNumber") // obsolete even in 1.3
tuplet->setNumberType(e.readInt() ? Tuplet::NumberType::SHOW_NUMBER : Tuplet::NumberType::NO_TEXT);
else if (tag == "hasLine") { // obsolete even in 1.3
tuplet->setHasBracket(e.readInt());
tuplet->setBracketType(Tuplet::BracketType::AUTO_BRACKET);
}
else if (tag == "baseLen") // obsolete even in 1.3
bl = e.readInt();
else if (!tuplet->readProperties(e))
e.unknown();
}
Fraction r = (tuplet->ratio() == 1) ? tuplet->ratio() : tuplet->ratio().reduced();
Fraction f(r.denominator(), tuplet->baseLen().fraction().denominator());
tuplet->setDuration(f.reduced());
if (bl != -1) { // obsolete, even in 1.3
TDuration d;
d.setVal(bl);
tuplet->setBaseLen(d);
d.setVal(bl * tuplet->ratio().denominator());
tuplet->setDuration(d.fraction());
}
}

//---------------------------------------------------------
// readChord
//---------------------------------------------------------
@@ -1254,7 +1290,7 @@ static void readMeasure(Measure* m, int staffIdx, XmlReader& e)
tuplet->setTrack(e.track());
tuplet->setTick(e.tick());
tuplet->setParent(m);
tuplet->read(e);
readTuplet(tuplet, e);
e.addTuplet(tuplet);
}
else if (tag == "startRepeat") {
@@ -565,6 +565,22 @@ static void readNote(Note* note, XmlReader& e)
}
}

//---------------------------------------------------------
// readTuplet
//---------------------------------------------------------

static void readTuplet(Tuplet* tuplet, XmlReader& e)
{
tuplet->setId(e.intAttribute("id", 0));
while (e.readNextStartElement()) {
if (!tuplet->readProperties(e))
e.unknown();
}
Fraction r = (tuplet->ratio() == 1) ? tuplet->ratio() : tuplet->ratio().reduced();
Fraction f(r.denominator(), tuplet->baseLen().fraction().denominator());
tuplet->setDuration(f.reduced());
}

//---------------------------------------------------------
// readChord
//---------------------------------------------------------
@@ -1166,7 +1182,7 @@ static void readMeasure(Measure* m, int staffIdx, XmlReader& e)
tuplet->setTrack(e.track());
tuplet->setTick(e.tick());
tuplet->setParent(m);
tuplet->read(e);
readTuplet(tuplet, e);
e.addTuplet(tuplet);
}
else if (tag == "startRepeat") {
@@ -651,61 +651,51 @@ void Tuplet::write(Xml& xml) const

void Tuplet::read(XmlReader& e)
{
int bl = -1;
_id = e.intAttribute("id", 0);

while (e.readNextStartElement()) {
const QStringRef& tag(e.name());

if (tag == "direction")
readProperty(e, P_ID::DIRECTION);
else if (tag == "numberType")
_numberType = NumberType(e.readInt());
else if (tag == "bracketType")
_bracketType = BracketType(e.readInt());
else if (tag == "normalNotes")
_ratio.setDenominator(e.readInt());
else if (tag == "actualNotes")
_ratio.setNumerator(e.readInt());
else if (tag == "p1")
_p1 = e.readPoint();
else if (tag == "p2")
_p2 = e.readPoint();
else if (tag == "baseNote")
_baseLen = TDuration(e.readElementText());
else if (tag == "Number") {
_number = new Text(score());
_number->setParent(this);
_number->read(e);
_number->setTextStyleType(TextStyleType::TUPLET);
_number->setVisible(visible()); //?? override saved property
_number->setTrack(track());
}
else if (tag == "subtype") // obsolete
e.skipCurrentElement();
else if (tag == "hasNumber") // obsolete
_numberType = e.readInt() ? NumberType::SHOW_NUMBER : NumberType::NO_TEXT;
else if (tag == "hasLine") { // obsolete
_hasBracket = e.readInt();
_bracketType = BracketType::AUTO_BRACKET;
}
else if (tag == "baseLen") // obsolete
bl = e.readInt();
else if (!DurationElement::readProperties(e))
if (readProperties(e))
;
else
e.unknown();
}
// Fraction f(_ratio.reduced().denominator(), _baseLen.fraction().denominator());
Fraction f(_ratio.denominator(), _baseLen.fraction().denominator());
setDuration(f.reduced());
if (bl != -1) { // obsolete
TDuration d;
d.setVal(bl);
_baseLen = d;
// qDebug("Tuplet base len %d/%d", d.fraction().numerator(), d.fraction().denominator());
// qDebug(" %s dots %d, %d/%d", qPrintable(d.name()), d.dots(), _ratio.numerator(), _ratio.denominator());
d.setVal(bl * _ratio.denominator());
setDuration(d.fraction());
}

//---------------------------------------------------------
// readProperties
//---------------------------------------------------------

bool Tuplet::readProperties(XmlReader& e)
{
const QStringRef& tag(e.name());
if (tag == "direction")
readProperty(e, P_ID::DIRECTION);
else if (tag == "numberType")
_numberType = NumberType(e.readInt());
else if (tag == "bracketType")
_bracketType = BracketType(e.readInt());
else if (tag == "normalNotes")
_ratio.setDenominator(e.readInt());
else if (tag == "actualNotes")
_ratio.setNumerator(e.readInt());
else if (tag == "p1")
_p1 = e.readPoint();
else if (tag == "p2")
_p2 = e.readPoint();
else if (tag == "baseNote")
_baseLen = TDuration(e.readElementText());
else if (tag == "Number") {
_number = new Text(score());
_number->setParent(this);
_number->read(e);
_number->setTextStyleType(TextStyleType::TUPLET);
_number->setVisible(visible()); //?? override saved property
_number->setTrack(track());
}
else if (!DurationElement::readProperties(e))
return false;
return true;
}

//---------------------------------------------------------
@@ -92,6 +92,7 @@ class Tuplet : public DurationElement {
void setNumberType(NumberType val) { _numberType = val; }
void setBracketType(BracketType val) { _bracketType = val; }
bool hasBracket() const { return _hasBracket; }
void setHasBracket(bool b) { _hasBracket = b; }

Fraction ratio() const { return _ratio; }
void setRatio(const Fraction& r) { _ratio = r; }
@@ -105,6 +106,7 @@ class Tuplet : public DurationElement {

virtual void read(XmlReader&) override;
virtual void write(Xml&) const override;
virtual bool readProperties(XmlReader&) override;

virtual void reset() override;

@@ -100,18 +100,21 @@ Tuplet* MuseScore::tupletDialog()
tuplet->setTrack(cr->track());
tuplet->setTick(cr->tick());
td.setupTuplet(tuplet);
// tuplet->setRatio(tuplet->ratio().reduced());
Fraction f1(cr->duration());
tuplet->setDuration(f1);
Fraction f = f1 * tuplet->ratio();
Fraction f = f1 * Fraction(1, tuplet->ratio().denominator());
f.reduce();

qDebug("len %s ratio %s base %s",
qPrintable(f1.print()),
qPrintable(tuplet->ratio().print()),
qPrintable(f.print()));

tuplet->setBaseLen(Fraction(1, f.denominator()));
Fraction fbl(1, f.denominator());
if (TDuration::isValid(fbl))
tuplet->setBaseLen(fbl);
else
tuplet->setBaseLen(TDuration::DurationType::V_INVALID);

if (tuplet->baseLen() == TDuration::DurationType::V_INVALID) {
QMessageBox::warning(0,
@@ -73,6 +73,7 @@ void TestCompat114::compat_data()
QTest::newRow("text_scaling") << "text_scaling";
QTest::newRow("markers") << "markers";
QTest::newRow("drumset") << "drumset";
QTest::newRow("tuplets") << "tuplets";
}

//---------------------------------------------------------

0 comments on commit 3b7c0fe

Please sign in to comment.
You can’t perform that action at this time.