Skip to content

Commit

Permalink
ENG-91: fix barline and brace spanning > 2 staves
Browse files Browse the repository at this point in the history
Previously, barlines would only span to 2 staves, even if the part had
more staves. This commit changes that so all but the bottom staff has
barLineSpan set to true if in the same part or group.

This commit also ensures that multi-staff parts have braces by default,
even if they are part of a group that doesn't have a bracket or brace.

Also, this commit adds a small condition that prevents redundant
brackets (which are sometimes exported by Dolet) from being imported.

In the above fixes, many tests had to be tweaked to account for changes
in the underlying data which mostly don't effect presentation.
  • Loading branch information
iveshenry18 committed Aug 5, 2021
1 parent adfbc11 commit c5af641
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 42 deletions.
53 changes: 43 additions & 10 deletions importexport/musicxml/importmxmlpass1.cpp
Expand Up @@ -1046,6 +1046,26 @@ static bool allStaffGroupsIdentical(Part const* const p)
return true;
}

//---------------------------------------------------------
// isRedundantBracket
//---------------------------------------------------------

/**
Return true if there is already an existing bracket
with the same type and span.
This prevents double brackets, which are sometimes exported
by Dolet.
*/

static bool isRedundantBracket(Staff const* const staff, const BracketType bracketType, const int span)
{
for (auto bracket : staff->brackets()) {
if (bracket->bracketType() == bracketType && bracket->bracketSpan() == span)
return true;
}
return false;
}

//---------------------------------------------------------
// scorePartwise
//---------------------------------------------------------
Expand Down Expand Up @@ -1110,34 +1130,47 @@ void MusicXMLParserPass1::scorePartwise()
const QList<Part*>& il = _score->parts();
for (size_t i = 0; i < partGroupList.size(); i++) {
MusicXmlPartGroup* pg = partGroupList[i];
// add part to set
if (pg->span == 1)
partSet << il.at(pg->start);
// determine span in staves
// and span all barlines except last if applicable
int stavesSpan = 0;
for (int j = 0; j < pg->span; j++)
stavesSpan += il.at(pg->start + j)->nstaves();
for (int j = 0; j < pg->span; j++) {
Part* spannedPart = il.at(pg->start + j);
stavesSpan += spannedPart->nstaves();

if (pg->barlineSpan) {
for (auto spannedStaff : *(spannedPart->staves())) {
if ((j == pg->span - 1) && (spannedStaff == spannedPart->staves()->back()))
// Very last staff of group,
continue;
else
spannedStaff->setBarLineSpan(true);
}
}
}
// add bracket and set the span
// TODO: use group-symbol default-x to determine horizontal order of brackets
Staff* staff = il.at(pg->start)->staff(0);
if (pg->type != BracketType::NO_BRACKET) {
if (pg->type != BracketType::NO_BRACKET && !isRedundantBracket(staff, pg->type, stavesSpan)) {
staff->setBracketType(pg->column, pg->type);
staff->setBracketSpan(pg->column, stavesSpan);
// add part to set (skip implicit bracket later)
if (pg->span == 1)
partSet << il.at(pg->start);
}
if (pg->barlineSpan)
staff->setBarLineSpan(pg->span);
}

// handle the implicit brackets:
// multi-staff parts w/o explicit brackets get a brace
foreach(Part const* const p, il) {
for (Part const* const p : il) {
if (p->nstaves() > 1 && !partSet.contains(p)) {
const int column = p->staff(0)->bracketLevels() + 1;
p->staff(0)->setBracketType(column, BracketType::BRACE);
p->staff(0)->setBracketSpan(column, p->nstaves());
if (allStaffGroupsIdentical(p)) {
// span only if the same types
p->staff(0)->setBarLineSpan(p->nstaves());
for (auto spannedStaff : *(p->staves()))
if (spannedStaff != p->staves()->back()) // not last staff
spannedStaff->setBarLineSpan(true);
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions mtest/musicxml/io/testBackupRoundingError_ref.mscx
Expand Up @@ -29,7 +29,7 @@
</StaffType>
<hideWhenEmpty>3</hideWhenEmpty>
<bracket type="1" span="2" col="1"/>
<barLineSpan>2</barLineSpan>
<barLineSpan>1</barLineSpan>
</Staff>
<Staff id="2">
<StaffType group="pitched">
Expand Down Expand Up @@ -900,7 +900,6 @@
</Chord>
<endTuplet/>
<BarLine>
<span>1</span>
<visible>0</visible>
</BarLine>
</voice>
Expand Down Expand Up @@ -1306,7 +1305,6 @@
<endTuplet/>
<BarLine>
<subtype>end</subtype>
<span>1</span>
</BarLine>
</voice>
</Measure>
Expand Down Expand Up @@ -1758,6 +1756,7 @@
<Pedal>
<endHookType>1</endHookType>
<beginText>&lt;sym&gt;keyboardPedalPed&lt;/sym&gt;</beginText>
<continueText>(&lt;sym&gt;keyboardPedalPed&lt;/sym&gt;)</continueText>
</Pedal>
<next>
<location>
Expand Down
6 changes: 1 addition & 5 deletions mtest/musicxml/io/testBarlinesGrandStaff_ref.mscx
Expand Up @@ -29,7 +29,7 @@
</StaffType>
<hideWhenEmpty>3</hideWhenEmpty>
<bracket type="1" span="2" col="1"/>
<barLineSpan>2</barLineSpan>
<barLineSpan>1</barLineSpan>
</Staff>
<Staff id="2">
<StaffType group="pitched">
Expand Down Expand Up @@ -192,7 +192,6 @@
</Rest>
<BarLine>
<subtype>dotted</subtype>
<span>1</span>
</BarLine>
</voice>
</Measure>
Expand Down Expand Up @@ -220,7 +219,6 @@
</Rest>
<BarLine>
<subtype>double</subtype>
<span>1</span>
</BarLine>
</voice>
</Measure>
Expand Down Expand Up @@ -298,7 +296,6 @@
</Rest>
<BarLine>
<subtype>double</subtype>
<span>1</span>
</BarLine>
</voice>
</Measure>
Expand Down Expand Up @@ -390,7 +387,6 @@
</Rest>
<BarLine>
<subtype>end</subtype>
<span>1</span>
</BarLine>
</voice>
</Measure>
Expand Down
Binary file added mtest/musicxml/io/testExcessHiddenStaves.pdf
Binary file not shown.
11 changes: 9 additions & 2 deletions mtest/musicxml/io/testExcessHiddenStaves_ref.mscx
Expand Up @@ -57,49 +57,57 @@
<name>stdNormal</name>
</StaffType>
<bracket type="1" span="10" col="1"/>
<barLineSpan>10</barLineSpan>
<barLineSpan>1</barLineSpan>
</Staff>
<Staff id="2">
<StaffType group="pitched">
<name>stdNormal</name>
</StaffType>
<barLineSpan>1</barLineSpan>
</Staff>
<Staff id="3">
<StaffType group="pitched">
<name>stdNormal</name>
</StaffType>
<barLineSpan>1</barLineSpan>
</Staff>
<Staff id="4">
<StaffType group="pitched">
<name>stdNormal</name>
</StaffType>
<barLineSpan>1</barLineSpan>
</Staff>
<Staff id="5">
<StaffType group="pitched">
<name>stdNormal</name>
</StaffType>
<barLineSpan>1</barLineSpan>
</Staff>
<Staff id="6">
<StaffType group="pitched">
<name>stdNormal</name>
</StaffType>
<barLineSpan>1</barLineSpan>
</Staff>
<Staff id="7">
<StaffType group="pitched">
<name>stdNormal</name>
</StaffType>
<barLineSpan>1</barLineSpan>
</Staff>
<Staff id="8">
<StaffType group="pitched">
<name>stdNormal</name>
<mag>0.75</mag>
</StaffType>
<barLineSpan>1</barLineSpan>
</Staff>
<Staff id="9">
<StaffType group="pitched">
<name>stdNormal</name>
</StaffType>
<hideWhenEmpty>3</hideWhenEmpty>
<barLineSpan>1</barLineSpan>
</Staff>
<Staff id="10">
<StaffType group="pitched">
Expand Down Expand Up @@ -368,7 +376,6 @@
</Rest>
<BarLine>
<subtype>end</subtype>
<span>1</span>
</BarLine>
</voice>
</Measure>
Expand Down
3 changes: 1 addition & 2 deletions mtest/musicxml/io/testNegativeOffset_ref.mscx
Expand Up @@ -58,7 +58,7 @@
</StaffType>
<hideWhenEmpty>3</hideWhenEmpty>
<bracket type="1" span="2" col="1"/>
<barLineSpan>2</barLineSpan>
<barLineSpan>1</barLineSpan>
</Staff>
<Staff id="2">
<StaffType group="pitched">
Expand Down Expand Up @@ -333,7 +333,6 @@
</Rest>
<BarLine>
<subtype>end</subtype>
<span>1</span>
</BarLine>
</voice>
</Measure>
Expand Down
3 changes: 1 addition & 2 deletions mtest/musicxml/io/testPartNames_ref.mscx
Expand Up @@ -59,7 +59,7 @@
</StaffType>
<hideWhenEmpty>3</hideWhenEmpty>
<bracket type="1" span="2" col="1"/>
<barLineSpan>2</barLineSpan>
<barLineSpan>1</barLineSpan>
</Staff>
<Staff id="2">
<StaffType group="pitched">
Expand Down Expand Up @@ -591,7 +591,6 @@
</Rest>
<BarLine>
<subtype>end</subtype>
<span>1</span>
</BarLine>
</voice>
</Measure>
Expand Down
3 changes: 1 addition & 2 deletions mtest/musicxml/io/testStaffEmptiness_ref.mscx
Expand Up @@ -58,7 +58,7 @@
</StaffType>
<hideWhenEmpty>3</hideWhenEmpty>
<bracket type="1" span="2" col="1"/>
<barLineSpan>2</barLineSpan>
<barLineSpan>1</barLineSpan>
</Staff>
<Staff id="2">
<StaffType group="pitched">
Expand Down Expand Up @@ -944,7 +944,6 @@
</Rest>
<BarLine>
<subtype>end</subtype>
<span>1</span>
</BarLine>
</voice>
</Measure>
Expand Down
4 changes: 0 additions & 4 deletions mtest/musicxml/io/testSystemBrackets1.xml
Expand Up @@ -114,9 +114,6 @@
</midi-instrument>
</score-part>
<part-group type="stop" number="1"/>
<part-group type="start" number="1">
<group-symbol>none</group-symbol>
</part-group>
<score-part id="P7">
<part-name>Piano</part-name>
<part-abbreviation>Pno.</part-abbreviation>
Expand All @@ -131,7 +128,6 @@
<pan>0</pan>
</midi-instrument>
</score-part>
<part-group type="stop" number="1"/>
<part-group type="start" number="1">
<group-symbol>square</group-symbol>
</part-group>
Expand Down
8 changes: 4 additions & 4 deletions mtest/musicxml/io/testSystemBrackets3_ref.mscx
Expand Up @@ -29,7 +29,6 @@
</StaffType>
<hideWhenEmpty>3</hideWhenEmpty>
<bracket type="0" span="1" col="0"/>
<barLineSpan>1</barLineSpan>
</Staff>
<trackName>Backing
Vocals</trackName>
Expand Down Expand Up @@ -99,7 +98,7 @@ Vocals</longName>
<hideWhenEmpty>3</hideWhenEmpty>
<bracket type="0" span="6" col="0"/>
<bracket type="1" span="2" col="1"/>
<barLineSpan>2</barLineSpan>
<barLineSpan>1</barLineSpan>
</Staff>
<Staff id="3">
<StaffType group="tablature">
Expand All @@ -124,6 +123,7 @@ Vocals</longName>
<useNumbers>1</useNumbers>
</StaffType>
<hideWhenEmpty>3</hideWhenEmpty>
<barLineSpan>1</barLineSpan>
</Staff>
<trackName>Electric
Guitar 1</trackName>
Expand Down Expand Up @@ -253,6 +253,7 @@ Gtr. 1</shortName>
<useNumbers>1</useNumbers>
</StaffType>
<hideWhenEmpty>3</hideWhenEmpty>
<barLineSpan>1</barLineSpan>
</Staff>
<trackName>Electric
Guitar 2</trackName>
Expand Down Expand Up @@ -356,6 +357,7 @@ Gtr. 2</shortName>
<name>stdNormal</name>
</StaffType>
<hideWhenEmpty>3</hideWhenEmpty>
<bracket type="1" span="2" col="1"/>
<barLineSpan>1</barLineSpan>
</Staff>
<Staff id="7">
Expand Down Expand Up @@ -563,7 +565,6 @@ Gtr.</shortName>
</Rest>
<BarLine>
<subtype>end</subtype>
<span>0</span>
</BarLine>
</voice>
</Measure>
Expand All @@ -585,7 +586,6 @@ Gtr.</shortName>
</Rest>
<BarLine>
<subtype>end</subtype>
<span>1</span>
</BarLine>
</voice>
</Measure>
Expand Down
3 changes: 1 addition & 2 deletions mtest/musicxml/io/testTempoTextSpace1_ref.mscx
Expand Up @@ -58,7 +58,7 @@
</StaffType>
<hideWhenEmpty>3</hideWhenEmpty>
<bracket type="1" span="2" col="1"/>
<barLineSpan>2</barLineSpan>
<barLineSpan>1</barLineSpan>
</Staff>
<Staff id="2">
<StaffType group="pitched">
Expand Down Expand Up @@ -415,7 +415,6 @@
</Rest>
<BarLine>
<subtype>end</subtype>
<span>1</span>
</BarLine>
</voice>
</Measure>
Expand Down
3 changes: 1 addition & 2 deletions mtest/musicxml/io/testTempoTextSpace2_ref.mscx
Expand Up @@ -58,7 +58,7 @@
</StaffType>
<hideWhenEmpty>3</hideWhenEmpty>
<bracket type="1" span="2" col="1"/>
<barLineSpan>2</barLineSpan>
<barLineSpan>1</barLineSpan>
</Staff>
<Staff id="2">
<StaffType group="pitched">
Expand Down Expand Up @@ -415,7 +415,6 @@
</Rest>
<BarLine>
<subtype>end</subtype>
<span>1</span>
</BarLine>
</voice>
</Measure>
Expand Down

0 comments on commit c5af641

Please sign in to comment.