Skip to content

Commit

Permalink
ENG-55: Infer more tempo text
Browse files Browse the repository at this point in the history
This now adds inferencing based on common tempo text words such as "rit"
and "accel". In the case that one of these is inferenced, the underlying
tempo remains the same.

Duplicate of musescore#8412, part 3
  • Loading branch information
iveshenry18 authored and Jojo-Schmitz committed May 12, 2022
1 parent 92ce02e commit f274992
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
18 changes: 13 additions & 5 deletions importexport/musicxml/importmxmlpass2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2745,7 +2745,7 @@ void MusicXMLParserDirection::direction(const QString& partId,
}
else if (_wordsText != "" || _rehearsalText != "" || _metroText != "") {
TextBase* t = 0;
if (_tpoSound > 0.1 || isLikelyTempoText()) {
if (_tpoSound > 0.1 || attemptTempoTextCoercion()) {
// to prevent duplicates, only create a TempoText if none is present yet
if (hasTempoTextAtTick(_score->tempomap(), tick.ticks())) {
_logger->logError(QString("duplicate tempo at tick %1").arg(tick.ticks()), &_e);
Expand All @@ -2763,9 +2763,12 @@ void MusicXMLParserDirection::direction(const QString& partId,
if (_tpoSound > 0.1) {
_tpoSound /= 60;
((TempoText*) t)->setTempo(_tpoSound);
((TempoText*) t)->setFollowText(true);
_score->setTempo(tick, _tpoSound);
}
else {
((TempoText*) t)->setTempo(_score->tempo(tick)); // Maintain tempo (somewhat hacky)
}
((TempoText*) t)->setFollowText(true);
}
}
else if (_wordsText != "" || _metroText != "") {
Expand Down Expand Up @@ -3359,22 +3362,27 @@ double MusicXMLParserDirection::convertTextToNotes()
}

//---------------------------------------------------------
// isLikelyTempoText
// attemptTempoTextCoercion
//---------------------------------------------------------
/**
Infers if a direction is likely tempo text, possibly changing
the _wordsText to the appropriate note symbol and inferring the _tpoSound.
*/

bool MusicXMLParserDirection::isLikelyTempoText()
bool MusicXMLParserDirection::attemptTempoTextCoercion()
{
if (_tpoSound < 0.1 && _wordsText.contains(QRegularExpression("[yxeqhwW.]+\\s*=\\s*\\d+"))) {
QList<QString> tempoWords{"rit", "rall", "accel", "tempo", "allegr", "poco", "molto", "piu", "meno", "mosso", "rubato"};
if (_wordsText.contains(QRegularExpression("[yxeqhwW.]+\\s*=\\s*\\d+"))) {
QRegularExpression tempoValRegex("=\\s*(?<tempo>\\d+)");
double tempoVal = tempoValRegex.match(_wordsText).captured("tempo").toDouble();
double noteVal = convertTextToNotes() * 60.0;
_tpoSound = tempoVal / noteVal;
return true;
}
else if (placement() == "above" && _wordsText.contains("<b>"))
for (auto tempoWord : tempoWords)
if (_wordsText.contains(tempoWord, Qt::CaseInsensitive))
return true;
return false;
}

Expand Down
1 change: 1 addition & 0 deletions importexport/musicxml/importmxmlpass2.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ class MusicXMLParserDirection {
void textToDynamic(QString& text) const;
bool directionToDynamic();
bool isLikelyTempoText();
bool attemptTempoTextCoercion();
double convertTextToNotes();
void skipLogCurrElem();
};
Expand Down
11 changes: 8 additions & 3 deletions mtest/musicxml/io/testInferredTempoText.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@
</defaults>
<credit page="1">
<credit-type>title</credit-type>
<credit-words default-x="600" default-y="1611.86" justify="center" valign="top" font-size="22">Inferred Tempo Text</credit-words>
<credit-words default-x="600" default-y="1612.29" justify="center" valign="top" font-size="22">Inferred Tempo Text</credit-words>
</credit>
<credit page="1">
<credit-type>subtitle</credit-type>
<credit-words default-x="600" default-y="1554.72" justify="center" valign="top" font-size="16">MuseScore Testcase</credit-words>
<credit-words default-x="600" default-y="1555.15" justify="center" valign="top" font-size="16">MuseScore Testcase</credit-words>
</credit>
<credit page="1">
<credit-type>composer</credit-type>
<credit-words default-x="1114.29" default-y="1511.86" justify="right" valign="top">Henry Ives</credit-words>
<credit-words default-x="1114.29" default-y="1512.29" justify="right" valign="top">Henry Ives</credit-words>
</credit>
<part-list>
<score-part id="P1">
Expand Down Expand Up @@ -726,6 +726,11 @@
<type>eighth</type>
<stem>down</stem>
</note>
<direction placement="above">
<direction-type>
<words default-y="5.60" relative-y="10.00" font-weight="bold">rit.</words>
</direction-type>
</direction>
<note default-x="63.84" default-y="-10.00">
<pitch>
<step>D</step>
Expand Down
11 changes: 8 additions & 3 deletions mtest/musicxml/io/testInferredTempoText_ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,18 @@
<height>12.5</height>
<Text>
<style>Title</style>
<offset x="0" y="-0.1505"/>
<offset x="0" y="-0.05075"/>
<text><font size="22"/>Inferred Tempo Text</text>
</Text>
<Text>
<style>Subtitle</style>
<offset x="0" y="9.849"/>
<offset x="0" y="9.94875"/>
<text><font size="16"/>MuseScore Testcase</text>
</Text>
<Text>
<style>Composer</style>
<align>right,top</align>
<offset x="0" y="17.3495"/>
<offset x="0" y="17.4493"/>
<text>Henry Ives</text>
</Text>
</VBox>
Expand Down Expand Up @@ -578,6 +578,11 @@
<tpc>17</tpc>
</Note>
</Chord>
<Tempo>
<tempo>3</tempo>
<followText>1</followText>
<text><b>rit.</b></text>
</Tempo>
<Chord>
<BeamMode>mid</BeamMode>
<durationType>eighth</durationType>
Expand Down

0 comments on commit f274992

Please sign in to comment.