Skip to content

Commit

Permalink
ENG-57: Remove preliminary chord charts
Browse files Browse the repository at this point in the history
Some PVG scores begin with a list of all chord charts for the piece.
These usually translate incorrectly to MusicXML; therefore, this commit
adds code to detect and remove these. In porting to master, perhaps this
code can be controlled with an import setting.

Duplicate of musescore#8530
  • Loading branch information
iveshenry18 authored and Jojo-Schmitz committed Sep 2, 2021
1 parent 80fe1c3 commit 6cea1a0
Show file tree
Hide file tree
Showing 6 changed files with 2,581 additions and 0 deletions.
54 changes: 54 additions & 0 deletions importexport/musicxml/importmxmlpass2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,59 @@ static void resetTuplets(Tuplets& tuplets)
}

//---------------------------------------------------------
// cleanFretDiagrams
//---------------------------------------------------------
/**
PVG scores sometimes display fretboards for all chords at
the beginning. These often fail to translate correctly to
MusicXML, so we delete them here.
*/

static void cleanFretDiagrams(Measure* measure)
{
if (measure->no() > 0)
return;
// Case 1: Dummy hidden first measure with all fretboards attached
bool isDummyMeasure = toMeasureBase(measure)->lineBreak();
for (Segment* s = measure->first(SegmentType::ChordRest); s; s = s->next(SegmentType::ChordRest)) {
if (!isDummyMeasure) break;
for (Element* e : s->elist()) {
if (e && e->isChord() && e->visible()) {
isDummyMeasure = false;
break;
}
}
}
if (isDummyMeasure) {
for (Segment* s = measure->first(SegmentType::ChordRest); s; s = s->next(SegmentType::ChordRest)) {
for (Element* e : s->annotations()) {
if (e->isFretDiagram()) {
s->remove(e);
delete e;
}
}
}
}

// Case 2: All the fretboards attached to first beat
Segment* firstBeat = measure->first(SegmentType::ChordRest);
QList<FretDiagram*> beat1FretDiagrams;
int fretDiagramsTrack = -1;
for (Element* e : firstBeat->annotations()) {
if (e->isFretDiagram()
&& (fretDiagramsTrack == e->track() || fretDiagramsTrack == -1)) {
beat1FretDiagrams.append(toFretDiagram(e));
fretDiagramsTrack = e->track();
}
}
if (beat1FretDiagrams.length() > 1 && fretDiagramsTrack != -1) {
for (FretDiagram* fd : beat1FretDiagrams) {
firstBeat->remove(fd);
delete fd;
}
}
}
//---------------------------------------------------------
// initPartState
//---------------------------------------------------------

Expand Down Expand Up @@ -1629,6 +1682,7 @@ void MusicXMLParserPass2::scorePartwise()
lm->setEndBarLineType(BarLineType::NORMAL, 0);

_score->connectArpeggios();
cleanFretDiagrams(_score->firstMeasure());
}

//---------------------------------------------------------
Expand Down
Loading

0 comments on commit 6cea1a0

Please sign in to comment.