Skip to content

Commit

Permalink
Make direction boldness distinction more robust
Browse files Browse the repository at this point in the history
Rather than looking for <b> in the XML text, this commit pulls isBold
directly from the MusicXML, future-proofing the tempo text inference
from potential changes to MuseScore's internal XMLText representation.

Duplicate of musescore#8412, part 6
  • Loading branch information
iveshenry18 authored and Jojo-Schmitz committed Jul 22, 2021
1 parent 7e04c1e commit ce1254c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
17 changes: 9 additions & 8 deletions importexport/musicxml/importmxmlpass2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2610,7 +2610,7 @@ bool MusicXMLDelayedDirectionElement::isTempoOrphanCandidate() const
{
return _element->isStaffText()
&& _placement == "above"
&& toStaffText(_element)->xmlText().contains(QRegularExpression("^(<.*/>)*<b>.*</b>$"));
&& isBold();
}

//---------------------------------------------------------
Expand Down Expand Up @@ -2813,7 +2813,7 @@ void MusicXMLParserDirection::direction(const QString& partId,
else {
// Add element to score later, after collecting all the others and sorting by default-y
// This allows default-y to be at least respected by the order of elements
MusicXMLDelayedDirectionElement* delayedDirection = new MusicXMLDelayedDirectionElement(totalY(), t, track, wordsPlacement, measure, tick + _offset);
MusicXMLDelayedDirectionElement* delayedDirection = new MusicXMLDelayedDirectionElement(totalY(), t, track, wordsPlacement, measure, tick + _offset, _isBold);
delayedDirections.push_back(delayedDirection);
}
}
Expand Down Expand Up @@ -2860,15 +2860,15 @@ void MusicXMLParserDirection::direction(const QString& partId,

// Add element to score later, after collecting all the others and sorting by default-y
// This allows default-y to be at least respected by the order of elements
MusicXMLDelayedDirectionElement* delayedDirection = new MusicXMLDelayedDirectionElement(totalY(), dyn, track, dynamicsPlacement, measure, tick + _offset);
MusicXMLDelayedDirectionElement* delayedDirection = new MusicXMLDelayedDirectionElement(totalY(), dyn, track, dynamicsPlacement, measure, tick + _offset, _isBold);
delayedDirections.push_back(delayedDirection);
}

// handle the elems
foreach( auto elem, _elems) {
// Add element to score later, after collecting all the others and sorting by default-y
// This allows default-y to be at least respected by the order of elements
MusicXMLDelayedDirectionElement* delayedDirection = new MusicXMLDelayedDirectionElement(totalY(), elem, track, placement(), measure, tick + _offset);
MusicXMLDelayedDirectionElement* delayedDirection = new MusicXMLDelayedDirectionElement(totalY(), elem, track, placement(), measure, tick + _offset, _isBold);
delayedDirections.push_back(delayedDirection);
}

Expand Down Expand Up @@ -2946,6 +2946,7 @@ void MusicXMLParserDirection::directionType(QList<MusicXmlSpannerDesc>& starts,
_relativeY = relativeYCandidate;
_hasDefaultY |= hasDefaultYCandidate;
_hasRelativeY |= hasRelativeYCandidate;
_isBold &= _e.attributes().value("font-weight").toString() == "bold";
QString number = _e.attributes().value("number").toString();
int n = 0;
if (number != "") {
Expand Down Expand Up @@ -3319,7 +3320,7 @@ void MusicXMLInferredFingering::addToNotes(std::vector<Note*>& notes) const

MusicXMLDelayedDirectionElement* MusicXMLInferredFingering::toDelayedDirection()
{
auto dd = new MusicXMLDelayedDirectionElement(_totalY, _element, _track, _placement, _measure, _tick);
auto dd = new MusicXMLDelayedDirectionElement(_totalY, _element, _track, _placement, _measure, _tick, false);
return dd;
}

Expand Down Expand Up @@ -3375,7 +3376,7 @@ bool MusicXMLParserDirection::attemptTempoTextCoercion(const Fraction& tick)
_tpoSound = tempoVal / noteVal;
return true;
}
else if (placement() == "above" && _wordsText.contains(QRegularExpression("^(<.*/>)*<b>.*</b>$"))) {
else if (placement() == "above" && _isBold) {
if (tick == Fraction(0, 1)) return true;
for (auto tempoWord : tempoWords)
if (_wordsText.contains(tempoWord, Qt::CaseInsensitive))
Expand Down Expand Up @@ -5988,7 +5989,7 @@ void MusicXMLParserPass2::harmony(const QString& partId, Measure* measure, const
}
// Add element to score later, after collecting all the others and sorting by default-y
// This allows default-y to be at least respected by the order of elements
MusicXMLDelayedDirectionElement* delayedDirection = new MusicXMLDelayedDirectionElement(totalY, se, track, placement, measure, sTime + offset);
MusicXMLDelayedDirectionElement* delayedDirection = new MusicXMLDelayedDirectionElement(totalY, se, track, placement, measure, sTime + offset, false);
delayedDirections.push_back(delayedDirection);
}

Expand Down Expand Up @@ -7337,7 +7338,7 @@ MusicXMLParserDirection::MusicXMLParserDirection(QXmlStreamReader& e,
MusicXMLParserPass2& pass2,
MxmlLogger* logger)
: _e(e), _score(score), _pass1(pass1), _pass2(pass2), _logger(logger),
_hasDefaultY(false), _defaultY(0.0), _hasRelativeY(false), _relativeY(0.0),
_hasDefaultY(false), _defaultY(0.0), _hasRelativeY(false), _relativeY(0.0), _isBold(true),
_tpoMetro(0), _tpoSound(0), _offset(0, 1)
{
// nothing
Expand Down
9 changes: 6 additions & 3 deletions importexport/musicxml/importmxmlpass2.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ class MusicXMLParserDirection {
bool _hasRelativeY;
qreal _relativeY;
bool hasTotalY() const { return _hasRelativeY || _hasDefaultY; }
bool _isBold;
double _tpoMetro; // tempo according to metronome
double _tpoSound; // tempo according to sound
QList<Element*> _elems;
Expand Down Expand Up @@ -422,21 +423,22 @@ class MusicXMLParserDirection {
//---------------------------------------------------------
/**
Helper class to allow Direction elements to be sorted by _totalY
before being added to the score.
before being added to the score. TODO: merge into MusicXMLParserDirection.
*/

class MusicXMLDelayedDirectionElement {
public:
MusicXMLDelayedDirectionElement(qreal totalY, Element* element, int track,
QString placement, Measure* measure, Fraction tick) :
QString placement, Measure* measure, Fraction tick, bool isBold) :
_totalY(totalY), _element(element), _track(track), _placement(placement),
_measure(measure), _tick(tick) {}
_measure(measure), _tick(tick), _isBold(isBold) {}

qreal totalY() const { return _totalY; }
Element* element() { return _element; }
Fraction tick() const { return _tick; }

void addElem();
bool isBold() const { return _isBold; }
bool isTempoOrphanCandidate() const;

private:
Expand All @@ -446,6 +448,7 @@ class MusicXMLDelayedDirectionElement {
QString _placement;
Measure* _measure;
Fraction _tick;
bool _isBold;
};

//---------------------------------------------------------
Expand Down

0 comments on commit ce1254c

Please sign in to comment.