浏览代码

fix(noteheadshape): add color attribute null check

sschmidTU 6 年之前
父节点
当前提交
3d8da1e03a
共有 2 个文件被更改,包括 9 次插入8 次删除
  1. 8 6
      src/MusicalScore/ScoreIO/InstrumentReader.ts
  2. 1 2
      src/MusicalScore/ScoreIO/VoiceGenerator.ts

+ 8 - 6
src/MusicalScore/ScoreIO/InstrumentReader.ts

@@ -267,17 +267,19 @@ export class InstrumentReader {
           const noteheadNode: IXmlElement = xmlNode.element("notehead");
           if (noteheadNode) {
             const colorAttr: Attr = noteheadNode.attribute("color");
-            const colorValue: string = colorAttr.value;
-            if (colorValue.length === 7) { // #RGB hexa
-              noteheadColorXml = colorValue;
-            } else if (colorValue.length === 9) { // #ARGB hexa, first part alpha channel
-              noteheadColorXml = colorValue.substr(2);
+            if (colorAttr) {
+              const colorValue: string = colorAttr.value;
+              if (colorValue.length === 7) { // #RGB hexa
+                noteheadColorXml = colorValue;
+              } else if (colorValue.length === 9) { // #ARGB hexa, first part alpha channel
+                noteheadColorXml = colorValue.substr(2);
+              }
             }
           }
 
           let noteColorXml: string;
           const noteColorAttr: Attr = xmlNode.attribute("color");
-          if (noteColorAttr) {
+          if (noteColorAttr) { // can be undefined
             const noteColorValue: string = noteColorAttr.value;
             if (noteColorValue.length === 7) { // #RGB hexa
               noteColorXml = noteColorValue;

+ 1 - 2
src/MusicalScore/ScoreIO/VoiceGenerator.ts

@@ -401,8 +401,7 @@ export class VoiceGenerator {
           if (noteElement.firstAttribute !== undefined) {
             playbackInstrumentId = noteElement.firstAttribute.value;
           }
-        }
-        if (noteElement.name === "notehead") {
+        } else if (noteElement.name === "notehead") {
           noteHeadShapeXml = noteElement.value;
           if (noteElement.attribute("filled") !== null) {
             noteHeadFilledXml = noteElement.attribute("filled").value === "yes";