Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MU3 Backend] ENG-5: Infer Credits #8413

Merged
merged 2 commits into from Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions importexport/musicxml/importmxmlpass1.cpp
Expand Up @@ -639,7 +639,7 @@ static Tid tidForCreditWords(const CreditWords* const word, std::vector<const Cr
// createAndAddVBoxForCreditWords
//---------------------------------------------------------

static VBox* createAndAddVBoxForCreditWords(Score* const score, const int miny = 0, const int maxy = 75)
VBox* MusicXMLParserPass1::createAndAddVBoxForCreditWords(Score* const score, const int miny, const int maxy)
{
auto vbox = new VBox(score);
qreal vboxHeight = 10; // default height in tenths
Expand Down Expand Up @@ -716,7 +716,7 @@ static VBox* addCreditWords(Score* const score, const CreditWordsList& crWords,
const auto tid = (pageNr == 1 && top) ? tidForCreditWords(w, words, pageSize.width()) : Tid::DEFAULT;
double yoffs = (maxy - w->defaultY) * score->spatium() / 10;
if (!vbox)
vbox = createAndAddVBoxForCreditWords(score, miny, maxy);
vbox = MusicXMLParserPass1::createAndAddVBoxForCreditWords(score, miny, maxy);
addText2(vbox, score, w->words, tid, align, yoffs);
}
}
Expand Down Expand Up @@ -754,7 +754,7 @@ static void createDefaultHeader(Score* const score)
if (!metaPoet.isEmpty()) strPoet = metaPoet;
if (!metaTranslator.isEmpty()) strTranslator = metaTranslator;

const auto vbox = createAndAddVBoxForCreditWords(score);
const auto vbox = MusicXMLParserPass1::createAndAddVBoxForCreditWords(score);
addText(vbox, score, strTitle.toHtmlEscaped(), Tid::TITLE);
addText(vbox, score, strSubTitle.toHtmlEscaped(), Tid::SUBTITLE);
addText(vbox, score, strComposer.toHtmlEscaped(), Tid::COMPOSER);
Expand Down
1 change: 1 addition & 0 deletions importexport/musicxml/importmxmlpass1.h
Expand Up @@ -166,6 +166,7 @@ class MusicXMLParserPass1 {
int octaveShift(const QString& id, const int staff, const Fraction f) const;
const CreditWordsList& credits() const { return _credits; }
bool hasBeamingInfo() const { return _hasBeamingInfo; }
static VBox* createAndAddVBoxForCreditWords(Score* const score, const int miny = 0, const int maxy = 75);

private:
// functions
Expand Down
27 changes: 26 additions & 1 deletion importexport/musicxml/importmxmlpass2.cpp
Expand Up @@ -22,6 +22,7 @@

#include "libmscore/arpeggio.h"
#include "libmscore/accidental.h"
#include "libmscore/box.h"
#include "libmscore/breath.h"
#include "libmscore/chord.h"
#include "libmscore/chordline.h"
Expand Down Expand Up @@ -71,6 +72,7 @@
#include "importmxmlnoteduration.h"
#include "importmxmlnotepitch.h"
#include "importmxmlpass2.h"
#include "importmxmlpass1.h"
#include "musicxmlfonthandler.h"
#include "musicxmlsupport.h"

Expand Down Expand Up @@ -2504,7 +2506,17 @@ void MusicXMLParserDirection::direction(const QString& partId,
// qPrintable(_wordsText), qPrintable(_rehearsalText), qPrintable(_metroText), _tpoSound);

// create text if any text was found
if (_wordsText != "" || _rehearsalText != "" || _metroText != "") {
if (isLikelyCredit(tick)) {
Text* t = new Text(_score, Tid::COMPOSER);
t->setXmlText(_wordsText.trimmed());
auto firstMeasure = _score->measures()->first();
VBox* vbox = firstMeasure->isVBox() ? toVBox(firstMeasure) : MusicXMLParserPass1::createAndAddVBoxForCreditWords(_score);
t->layout();
vbox->layout();
vbox->setBoxHeight(vbox->boxHeight() + Spatium(t->height()/_score->spatium())/2); // add some height
vbox->add(t);
}
else if (_wordsText != "" || _rehearsalText != "" || _metroText != "") {
TextBase* t = 0;
if (_tpoSound > 0.1) {
// to prevent duplicates, only create a TempoText if none is present yet
Expand Down Expand Up @@ -2888,6 +2900,19 @@ bool MusicXMLParserDirection::isLikelyFingering() const
&& _tpoSound < 0.1;
}

//---------------------------------------------------------
// isLikelyCredit
//---------------------------------------------------------

bool MusicXMLParserDirection::isLikelyCredit(const Fraction& tick) const
{
return (tick + _offset < Fraction(5, 1)) // Only early in the piece
&& _rehearsalText == ""
&& _metroText == ""
&& _tpoSound < 0.1
&& _wordsText.contains(QRegularExpression("^\\s*((Words|Music|Lyrics).*)*by\\s+([A-Z][a-zA-Zö'’-]+\\s[A-Z][a-zA-Zös'’-]+.*)+"));
}

//---------------------------------------------------------
// MusicXMLInferredFingering
//---------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions importexport/musicxml/importmxmlpass2.h
Expand Up @@ -400,6 +400,7 @@ class MusicXMLParserDirection {
void dynamics();
void handleRepeats(Measure* measure, const int track);
bool isLikelyFingering() const;
bool isLikelyCredit(const Fraction& tick) const;
void skipLogCurrElem();
};

Expand Down
Binary file added mtest/musicxml/io/testInferredCredits.pdf
Binary file not shown.
197 changes: 197 additions & 0 deletions mtest/musicxml/io/testInferredCredits.xml
@@ -0,0 +1,197 @@
<?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</work-title>
</work>
<identification>
<creator type="composer">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>
<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>
<credit page="1">
<credit-type>subtitle</credit-type>
<credit-words default-x="600" default-y="1554.28" justify="center" valign="top" font-size="16">MuseScore Testcase</credit-words>
</credit>
<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 and Music by Henry Ives
</words>
<words>
</words>
<words></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>
<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>
</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>