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-63: Properly handle cue grace notes #8581

Merged
merged 1 commit into from
Jul 14, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion importexport/musicxml/exportxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3163,7 +3163,7 @@ static bool isSmallNote(const Note* const note)

static bool isCueNote(const Note* const note)
{
return (!note->chord()->isGrace()) && isSmallNote(note) && !note->play();
return isSmallNote(note) && !note->play();
}

//---------------------------------------------------------
Expand Down Expand Up @@ -3206,6 +3206,8 @@ static void writeTypeAndDots(XmlWriter& xml, const Note* const note)
// small notes are indicated by size=cue, but for grace and cue notes this is implicit
if (isSmallNote(note) && !isCueNote(note) && !note->chord()->isGrace())
xml.tag("type size=\"cue\"", s);
else if (isSmallNote(note) && !isCueNote(note) && note->chord()->isGrace())
xml.tag("type size=\"grace-cue\"", s);
else
xml.tag("type", s);
for (int ni = dots; ni > 0; ni--)
Expand Down
51 changes: 40 additions & 11 deletions importexport/musicxml/importmxmlpass2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1952,6 +1952,30 @@ static void markUserAccidentals(const int firstStaff,
}
}

//---------------------------------------------------------
// coerceGraceCue
//---------------------------------------------------------

/**
If the mainChord is small and/or silent, the grace note should likely
match this. Exporters tend to incorrectly omit <cue> or <type size="cue">
from grace notes.
*/

static void coerceGraceCue(Chord* mainChord, Chord* graceChord)
{
if (mainChord->small())
graceChord->setSmall(true);
bool anyPlays = false;
for (auto n : mainChord->notes()) {
anyPlays |= n->play();
}
if (!anyPlays) {
for (auto gn : graceChord->notes())
gn->setPlay(false);
}
}

//---------------------------------------------------------
// addGraceChordsAfter
//---------------------------------------------------------
Expand All @@ -1972,6 +1996,7 @@ static void addGraceChordsAfter(Chord* c, GraceChordList& gcl, int& gac)
gcl.removeFirst();
graceChord->toGraceAfter();
c->add(graceChord); // TODO check if same voice ?
coerceGraceCue(c, graceChord);
qDebug("addGraceChordsAfter chord %p grace after chord %p", c, graceChord);
}
gac--;
Expand Down Expand Up @@ -1999,6 +2024,7 @@ static void addGraceChordsBefore(Chord* c, GraceChordList& gcl)
}
}
c->add(gc); // TODO check if same voice ?
coerceGraceCue(c, gc);
}
gcl.clear();
}
Expand Down Expand Up @@ -4438,11 +4464,14 @@ NoteType graceNoteType(const TDuration duration, const bool slash)
*/

static Chord* createGraceChord(Score* score, const int track,
const TDuration duration, const bool slash)
const TDuration duration, const bool slash, const bool small)
{
Chord* c = new Chord(score);
c->setNoteType(graceNoteType(duration, slash));
c->setTrack(track);
// Chord is initialized with the smallness of its first note.
// If a non-small note is added later, this is handled in handleSmallness.
c->setSmall(small);
// note grace notes have no durations, use default fraction 0/1
setChordRestDuration(c, duration, Fraction());
return c;
Expand Down Expand Up @@ -4842,7 +4871,7 @@ Note* MusicXMLParserPass2::note(const QString& partId,
else if (_e.name() == "stem")
stem(stemDir, noStem);
else if (_e.name() == "type") {
small = _e.attributes().value("size") == "cue";
small = _e.attributes().value("size") == "cue" | _e.attributes().value("size") == "grace-cue";
Copy link
Contributor

@Jojo-Schmitz Jojo-Schmitz Jul 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes a compiler warning due to missing parentheses. Also I guess it should be || rather than |?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#8554 (for posterity)

type = _e.readElementText();
}
else if (_e.name() == "voice")
Expand Down Expand Up @@ -4954,7 +4983,7 @@ Note* MusicXMLParserPass2::note(const QString& partId,
// TODO: check if explicit stem direction should also be set for grace notes
// (the DOM parser does that, but seems to have no effect on the autotester)
if (!chord || gcl.isEmpty()) {
c = createGraceChord(_score, msTrack + msVoice, duration, graceSlash);
c = createGraceChord(_score, msTrack + msVoice, duration, graceSlash, small || cue);
// TODO FIX
// the setStaffMove() below results in identical behaviour as 2.0:
// grace note will be at the wrong staff with the wrong pitch,
Expand Down Expand Up @@ -5004,6 +5033,14 @@ Note* MusicXMLParserPass2::note(const QString& partId,
}
}
else {
handleSmallness(cue || small, note, c);
note->setPlay(!cue); // cue notes don't play
note->setHeadGroup(headGroup);
if (noteColor != QColor::Invalid)
note->setColor(noteColor);
setNoteHead(note, noteheadColor, noteheadParentheses, noteheadFilled);
note->setVisible(printObject); // TODO also set the stem to invisible

if (!grace) {
// regular note
// handle beam
Expand All @@ -5019,14 +5056,6 @@ Note* MusicXMLParserPass2::note(const QString& partId,
addGraceChordsBefore(c, gcl);
}

handleSmallness(cue || small, note, c);
note->setPlay(!cue); // cue notes don't play
note->setHeadGroup(headGroup);
if (noteColor != QColor::Invalid)
note->setColor(noteColor);
setNoteHead(note, noteheadColor, noteheadParentheses, noteheadFilled);
note->setVisible(printObject); // TODO also set the stem to invisible

if (velocity > 0) {
note->setVeloType(Note::ValueType::USER_VAL);
note->setVeloOffset(velocity);
Expand Down
Loading