소스 검색

fix(Clefs): fix mid-measure clef added at wrong position (#954) because of forward/backup node.

fix #954 (together with 8b1d898750b524d2141eddcbe236173cc8705a16)

for now we don't add those clefs at all, because we would need to rework that
clefs are currently always saved for the currentStaffEntry.

actually using forward and backup nodes to position clefs (or for anything else)
is extremely bad MusicXML style,
and only seems to happen (for clefs) when exported by bad programs.

visual regression tests pass.
sschmid 4 년 전
부모
커밋
1a77ae8541
1개의 변경된 파일15개의 추가작업 그리고 3개의 파일을 삭제
  1. 15 3
      src/MusicalScore/ScoreIO/InstrumentReader.ts

+ 15 - 3
src/MusicalScore/ScoreIO/InstrumentReader.ts

@@ -141,8 +141,12 @@ export class InstrumentReader {
             currentMeasure.MeasureNumberXML = measureNumberXml;
         }
       }
+      let previousNode: IXmlElement; // needs a null check when accessed because of node index 0!
       for (let xmlNodeIndex: number = 0; xmlNodeIndex < xmlMeasureListArr.length; xmlNodeIndex++) {
         const xmlNode: IXmlElement = xmlMeasureListArr[xmlNodeIndex];
+        if (xmlNodeIndex > 0) {
+          previousNode = xmlMeasureListArr[xmlNodeIndex - 1];
+        }
         if (xmlNode.name === "print") {
           const newSystemAttr: IXmlAttribute = xmlNode.attribute("new-system");
           if (newSystemAttr?.value === "yes") {
@@ -438,7 +442,7 @@ export class InstrumentReader {
               throw new MusicSheetReadingException(errorMsg + this.instrument.Name);
             }
           }
-          this.addAbstractInstruction(xmlNode, octavePlusOne);
+          this.addAbstractInstruction(xmlNode, octavePlusOne, previousNode);
           if (currentFraction.Equals(new Fraction(0, 1)) &&
             this.isAttributesNodeAtBeginOfMeasure(this.xmlMeasureList[this.currentXmlMeasureIndex], xmlNode)) {
             this.saveAbstractInstructionList(this.instrument.Staves.length, true);
@@ -893,8 +897,16 @@ export class InstrumentReader {
           }
         }
 
-        const clefInstruction: ClefInstruction = new ClefInstruction(clefEnum, clefOctaveOffset, line);
-        this.abstractInstructions.push([staffNumber, clefInstruction]);
+        // TODO problem: in saveAbstractInstructionList, this is always saved in this.currentStaffEntry.
+        //   so when there's a <forward> or <backup> instruction in <attributes> (which is unfortunate encoding), this gets misplaced.
+        //   so for now we skip it.
+        const skipClefInstruction: boolean =
+          previousNode?.elements("forward").length > 0 ||
+          previousNode?.elements("backup").length > 0;
+        if (!skipClefInstruction) {
+          const clefInstruction: ClefInstruction = new ClefInstruction(clefEnum, clefOctaveOffset, line);
+          this.abstractInstructions.push([staffNumber, clefInstruction]);
+        }
       }
     }
     if (attrNode.element("key") !== undefined && this.instrument.MidiInstrumentId !== MidiInstrument.Percussion) {