Skip to content

Commit 337d2d4

Browse files
authored
Merge pull request #33925 from miiizen/33912-percNoteParen
[4.7] Sort percussion notes before reading chord parentheses
2 parents 1b48550 + 9be1352 commit 337d2d4

5 files changed

Lines changed: 38 additions & 28 deletions

File tree

src/engraving/dom/chord.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,34 +1131,6 @@ bool Chord::underBeam() const
11311131
return false;
11321132
}
11331133

1134-
//---------------------------------------------------------
1135-
// updatePercussionNotes
1136-
//---------------------------------------------------------
1137-
1138-
static void updatePercussionNotes(Chord* c, const Drumset* drumset)
1139-
{
1140-
TRACEFUNC;
1141-
for (Chord* ch : c->graceNotes()) {
1142-
updatePercussionNotes(ch, drumset);
1143-
}
1144-
std::vector<Note*> lnotes(c->notes()); // we need a copy!
1145-
for (Note* note : lnotes) {
1146-
if (!drumset) {
1147-
note->setLine(0);
1148-
} else {
1149-
int pitch = note->pitch();
1150-
if (!drumset->isValid(pitch)) {
1151-
note->setLine(0);
1152-
//! NOTE May be called too often
1153-
//LOGW("unmapped drum note %d", pitch);
1154-
} else if (!note->fixed()) {
1155-
note->undoChangeProperty(Pid::HEAD_GROUP, drumset->noteHead(pitch));
1156-
note->setLine(drumset->line(pitch));
1157-
}
1158-
}
1159-
}
1160-
}
1161-
11621134
//---------------------------------------------------------
11631135
// cmdUpdateNotes
11641136
//---------------------------------------------------------

src/engraving/dom/utils.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1971,4 +1971,28 @@ bool noteIsBefore(const Note* n1, const Note* n2)
19711971

19721972
return false;
19731973
}
1974+
1975+
void updatePercussionNotes(Chord* c, const Drumset* drumset)
1976+
{
1977+
TRACEFUNC;
1978+
for (Chord* ch : c->graceNotes()) {
1979+
updatePercussionNotes(ch, drumset);
1980+
}
1981+
std::vector<Note*> lnotes(c->notes()); // we need a copy!
1982+
for (Note* note : lnotes) {
1983+
if (!drumset) {
1984+
note->setLine(0);
1985+
} else {
1986+
int pitch = note->pitch();
1987+
if (!drumset->isValid(pitch)) {
1988+
note->setLine(0);
1989+
//! NOTE May be called too often
1990+
//LOGW("unmapped drum note %d", pitch);
1991+
} else if (!note->fixed()) {
1992+
note->undoChangeProperty(Pid::HEAD_GROUP, drumset->noteHead(pitch));
1993+
note->setLine(drumset->line(pitch));
1994+
}
1995+
}
1996+
}
1997+
}
19741998
}

src/engraving/dom/utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
namespace mu::engraving {
3232
class Chord;
3333
class ChordRest;
34+
class Drumset;
3435
class EngravingItem;
3536
class KeySig;
3637
class Lyrics;
@@ -133,4 +134,5 @@ extern std::vector<EngravingItem*> filterTargetElements(const Selection& sel, En
133134

134135
extern Lyrics* searchNextLyrics(Segment* s, staff_idx_t staffIdx, int verse, PlacementV p);
135136
extern bool noteIsBefore(const Note* n1, const Note* n2);
137+
extern void updatePercussionNotes(Chord* c, const Drumset* drumset);
136138
} // namespace mu::engraving

src/engraving/rw/read460/tread.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3836,6 +3836,18 @@ void TRead::lineBreakFromTag(String& str)
38363836

38373837
void TRead::readNoteParenGroup(Chord* ch, XmlReader& e, ReadContext& ctx)
38383838
{
3839+
StaffGroup staffGroup = ctx.staff(ch->staffIdx())->staffTypeForElement(ch)->group();
3840+
if (staffGroup == StaffGroup::PERCUSSION) {
3841+
// We should have read all notes by now. They need to be sorted for percussion staves
3842+
const Instrument* instrument = ch->part()->instrument(ch->tick());
3843+
const Drumset* drumset = instrument->drumset();
3844+
if (!drumset) {
3845+
LOGW("no drumset");
3846+
}
3847+
updatePercussionNotes(ch, drumset);
3848+
ch->sortNotes();
3849+
}
3850+
38393851
Parenthesis* leftParen = nullptr;
38403852
Parenthesis* rightParen = nullptr;
38413853
std::vector<Note*> notes;

vtest/scores/paren-chords-4.mscz

23.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)