Skip to content

Commit

Permalink
Update and extend subtitle inference cases
Browse files Browse the repository at this point in the history
This commit extends the cases covered by inferred subtitles. Also, it
extends this functionality to apply to Titles—some titles are multi-
line, where the second line is really a subtitle. This commit adds a
function to infer these, extract them from the title, and add them
as the subtitle.
  • Loading branch information
iveshenry18 committed Jul 22, 2021
1 parent 114e449 commit 6c6b752
Show file tree
Hide file tree
Showing 12 changed files with 516 additions and 10 deletions.
37 changes: 37 additions & 0 deletions importexport/musicxml/importmxmlpass1.cpp
Expand Up @@ -667,6 +667,37 @@ static bool mustAddWordToVbox(const QString& creditType)
}

//---------------------------------------------------------
// isLikelySubtitleText
//---------------------------------------------------------

bool isLikelySubtitleText(const QString& text, const bool caseInsensitive = true)
{
QRegularExpression::PatternOption caseOption = caseInsensitive ? QRegularExpression::CaseInsensitiveOption : QRegularExpression::NoPatternOption;
return (text.trimmed().contains(QRegularExpression("^[Ff]rom\\s+(?!$)", caseOption))
|| text.trimmed().contains(QRegularExpression("^Theme from\\s+(?!$)", caseOption))
|| text.trimmed().contains(QRegularExpression("(Op\\.?\\s?\\d+)\\s?(No\\.?\\s?\\d+)?", caseOption))
|| text.trimmed().contains(QRegularExpression("^\\(.*[Ff]rom\\s.*\\)$", caseOption)));
}

//---------------------------------------------------------
// inferSubTitleFromTitle
//---------------------------------------------------------

// Extracts a likely subtitle from the title string
// Returns the inferred subtitle

static QString inferSubTitleFromTitle(const QString& title)
{
QString inferredSubTitle = "";
for (auto line : title.split(QRegularExpression("\\n"))) {
if (isLikelySubtitleText(line, true)) {
inferredSubTitle = line;
break;
}
}
return inferredSubTitle;
}
//---------------------------------------------------------
// addCreditWords
//---------------------------------------------------------

Expand Down Expand Up @@ -732,6 +763,7 @@ static void createDefaultHeader(Score* const score)
{
QString strTitle;
QString strSubTitle;
QString inferredStrSubTitle;
QString strComposer;
QString strPoet;
QString strTranslator;
Expand All @@ -740,12 +772,17 @@ static void createDefaultHeader(Score* const score)
strTitle = score->metaTag("movementTitle");
if (strTitle.isEmpty())
strTitle = score->metaTag("workTitle");
inferredStrSubTitle = inferSubTitleFromTitle(strTitle);
}
if (!(score->metaTag("movementNumber").isEmpty() && score->metaTag("workNumber").isEmpty())) {
strSubTitle = score->metaTag("movementNumber");
if (strSubTitle.isEmpty())
strSubTitle = score->metaTag("workNumber");
}
else if (!inferredStrSubTitle.isEmpty()) {
strSubTitle = inferredStrSubTitle;
strTitle.replace(inferredStrSubTitle, "");
}
QString metaComposer = score->metaTag("composer");
QString metaPoet = score->metaTag("poet");
QString metaTranslator = score->metaTag("translator");
Expand Down
1 change: 1 addition & 0 deletions importexport/musicxml/importmxmlpass1.h
Expand Up @@ -104,6 +104,7 @@ using MxmlTupletStates = std::map<QString, MxmlTupletState>;

void determineTupletFractionAndFullDuration(const Fraction duration, Fraction& fraction, Fraction& fullDuration);
Fraction missingTupletDuration(const Fraction duration);
bool isLikelySubtitleText(const QString& text, const bool caseInsensitive);


//---------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions importexport/musicxml/importmxmlpass2.cpp
Expand Up @@ -2778,7 +2778,7 @@ void MusicXMLParserDirection::direction(const QString& partId,
hideRedundantHeaderText(inferredText, {"lyricist", "composer", "poet"});
}
}
else if (isLikelySource(tick)) {
else if (isLikelySubtitle(tick)) {
Text* inferredText = addTextToHeader(Tid::SUBTITLE);
if (inferredText) {
_pass2.setHasInferredHeaderText(true);
Expand Down Expand Up @@ -3263,16 +3263,16 @@ bool MusicXMLParserDirection::isLikelyFingering() const
}

//---------------------------------------------------------
// isLikelySource
// isLikelySubtitle
//---------------------------------------------------------

bool MusicXMLParserDirection::isLikelySource(const Fraction& tick) const
bool MusicXMLParserDirection::isLikelySubtitle(const Fraction& tick) const
{
return (tick + _offset < Fraction(5, 1)) // Only early in the piece
&& _rehearsalText == ""
&& _metroText == ""
&& _tpoSound < 0.1
&& _wordsText.contains(QRegularExpression("^\\s*[Ff]rom\\s+(?!$)"));
&& isLikelySubtitleText(_wordsText, false);
}

//---------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion importexport/musicxml/importmxmlpass2.h
Expand Up @@ -412,7 +412,7 @@ class MusicXMLParserDirection {
bool isLikelyFingering() const;
bool isLikelyCredit(const Fraction& tick) const;
bool isLyricBracket() const;
bool isLikelySource(const Fraction& tick) const;
bool isLikelySubtitle(const Fraction& tick) const;
bool isLikelyLegallyDownloaded(const Fraction& tick) const;
Text* addTextToHeader(const Tid tid);
void hideRedundantHeaderText(const Text* inferredText, const std::vector<QString> metaTags);
Expand Down
Binary file removed mtest/musicxml/io/testInferredCredits.pdf
Binary file not shown.
Binary file added mtest/musicxml/io/testInferredCredits1.pdf
Binary file not shown.
Expand Up @@ -2,7 +2,7 @@
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 3.1 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise version="3.1">
<work>
<work-title>Inferred Credits</work-title>
<work-title>Inferred Credits 1</work-title>
</work>
<identification>
<creator type="composer">Henry Ives</creator>
Expand Down Expand Up @@ -43,7 +43,7 @@
</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 Credits</credit-words>
<credit-words default-x="600" default-y="1611.86" justify="center" valign="top" font-size="22">Inferred Credits 1</credit-words>
</credit>
<part-list>
<score-part id="P1">
Expand Down
Expand Up @@ -51,7 +51,7 @@
the video game: a tone poem</metaTag>
<metaTag name="translator"></metaTag>
<metaTag name="workNumber"></metaTag>
<metaTag name="workTitle">Inferred Credits</metaTag>
<metaTag name="workTitle">Inferred Credits 1</metaTag>
<Part>
<Staff id="1">
<StaffType group="pitched">
Expand Down Expand Up @@ -121,7 +121,7 @@ the video game: a tone poem</metaTag>
<height>13.821</height>
<Text>
<style>Title</style>
<text><font size="22"/>Inferred Credits</text>
<text><font size="22"/>Inferred Credits 1</text>
</Text>
<Text>
<style>Composer</style>
Expand Down
Binary file added mtest/musicxml/io/testInferredCredits2.pdf
Binary file not shown.
214 changes: 214 additions & 0 deletions mtest/musicxml/io/testInferredCredits2.xml
@@ -0,0 +1,214 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 3.1 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise version="3.1">
<work>
<work-title>Inferred Credits 2
from MUSESCORE: the musical: a tone poem
</work-title>
</work>
<identification>
<creator type="composer">Henry Ives</creator>
<creator type='lyricist'>Henry Ives</creator>
<encoding>
<software>MuseScore 0.7.0</software>
<encoding-date>2007-09-10</encoding-date>
<supports element="accidental" type="yes"/>
<supports element="beam" type="yes"/>
<supports element="print" attribute="new-page" type="no"/>
<supports element="print" attribute="new-system" type="no"/>
<supports element="stem" type="yes"/>
</encoding>
</identification>
<defaults>
<scaling>
<millimeters>7</millimeters>
<tenths>40</tenths>
</scaling>
<page-layout>
<page-height>1697.14</page-height>
<page-width>1200</page-width>
<page-margins type="even">
<left-margin>85.7143</left-margin>
<right-margin>85.7143</right-margin>
<top-margin>85.7143</top-margin>
<bottom-margin>85.7143</bottom-margin>
</page-margins>
<page-margins type="odd">
<left-margin>85.7143</left-margin>
<right-margin>85.7143</right-margin>
<top-margin>85.7143</top-margin>
<bottom-margin>85.7143</bottom-margin>
</page-margins>
</page-layout>
<word-font font-family="Edwin" font-size="10"/>
<lyric-font font-family="Edwin" font-size="10"/>
</defaults>
<part-list>
<score-part id="P1">
<part-name>Piano</part-name>
<part-abbreviation>Pno.</part-abbreviation>
<score-instrument id="P1-I1">
<instrument-name>Piano</instrument-name>
</score-instrument>
<midi-device id="P1-I1" port="1"></midi-device>
<midi-instrument id="P1-I1">
<midi-channel>1</midi-channel>
<midi-program>1</midi-program>
<volume>78.7402</volume>
<pan>0</pan>
</midi-instrument>
</score-part>
</part-list>
<part id="P1">
<measure number="1" width="288.37">
<print>
<system-layout>
<system-margins>
<left-margin>50.00</left-margin>
<right-margin>0.00</right-margin>
</system-margins>
<top-system-distance>170.00</top-system-distance>
</system-layout>
</print>
<attributes>
<divisions>2</divisions>
<key>
<fifths>0</fifths>
</key>
<time>
<beats>4</beats>
<beat-type>4</beat-type>
</time>
<clef>
<sign>G</sign>
<line>2</line>
</clef>
</attributes>
<direction placement="above">
<direction-type>
<words default-y="34.66" relative-y="10.00">Words &amp; Music by Henry Ives (and ampersands)
</words>
<words>
</words>
<words></words>
</direction-type>
</direction>
<direction placement="above">
<direction-type>
<words default-y="34.66" relative-y="10.00">Lyrics to be sung by candlelight
(and this not to be inferred)</words>
</direction-type>
</direction>
<note default-x="73.72" default-y="-15.00">
<pitch>
<step>C</step>
<octave>5</octave>
</pitch>
<duration>1</duration>
<voice>1</voice>
<type>eighth</type>
<stem>down</stem>
<beam number="1">begin</beam>
<lyric number="1" default-x="6.50" default-y="-44.91" relative-y="-30.00">
<syllabic>begin</syllabic>
<text>ha</text>
</lyric>
</note>
<direction placement="above">
<direction-type>
<words default-y="34.66" relative-y="10.00">
Op.1 No.43
</words>
</direction-type>
</direction>
<note default-x="110.42" default-y="-15.00">
<pitch>
<step>C</step>
<octave>5</octave>
</pitch>
<duration>1</duration>
<voice>1</voice>
<type>eighth</type>
<stem>down</stem>
<beam number="1">end</beam>
<lyric number="1" default-x="6.50" default-y="-44.91" relative-y="-30.00">
<syllabic>end</syllabic>
<text>ha</text>
</lyric>
</note>
<note>
<rest/>
<duration>2</duration>
<voice>1</voice>
<type>quarter</type>
</note>
<note>
<rest/>
<duration>4</duration>
<voice>1</voice>
<type>half</type>
</note>
</measure>
<measure number="2" width="203.70">
<note default-x="26.30" default-y="-45.00">
<pitch>
<step>D</step>
<octave>4</octave>
</pitch>
<duration>2</duration>
<voice>1</voice>
<type>quarter</type>
<stem>up</stem>
<lyric number="1" default-x="8.72" default-y="-44.91" relative-y="-30.00">
<syllabic>single</syllabic>
<text>nice.</text>
</lyric>
</note>
<note>
<rest/>
<duration>2</duration>
<voice>1</voice>
<type>quarter</type>
</note>
<note>
<rest/>
<duration>4</duration>
<voice>1</voice>
<type>half</type>
</note>
</measure>
<measure number="3" width="161.62">
<note>
<rest measure="yes"/>
<duration>8</duration>
<voice>1</voice>
</note>
<direction placement='above'>
<direction-type>
<words>This music has been legally downloaded.
Do not photocopy.</words>
<words>
</words>
</direction-type>
<staff>1</staff>
</direction>
</measure>
<measure number="4" width="161.62">
<note>
<rest measure="yes"/>
<duration>8</duration>
<voice>1</voice>
</note>
</measure>
<measure number="5" width="163.26">
<note>
<rest measure="yes"/>
<duration>8</duration>
<voice>1</voice>
</note>
<barline location="right">
<bar-style>light-heavy</bar-style>
</barline>
</measure>
</part>
</score-partwise>

0 comments on commit 6c6b752

Please sign in to comment.