Quellcode durchsuchen

refactor: NoteHead -> Notehead

demo sample: rename NoteHeadShapes to Notehead Shapes, remove second bar of "none" noteheads
sschmidTU vor 6 Jahren
Ursprung
Commit
d48aefa3a9

+ 1 - 1
demo/index.js

@@ -29,7 +29,7 @@ import { OpenSheetMusicDisplay } from '../src/OpenSheetMusicDisplay/OpenSheetMus
         "OSMD Function Test - Expressions": "OSMD_function_test_expressions.musicxml",
         "OSMD Function Test - Expressions Overlap": "OSMD_function_test_expressions_overlap.musicxml",
         "OSMD Function Test - Grace Notes": "OSMD_function_test_GraceNotes.xml",
-        "OSMD Function Test - NoteHeadShapes": "OSMD_function_test_noteHeadShapes.musicxml",
+        "OSMD Function Test - Notehead Shapes": "OSMD_function_test_noteheadShapes.musicxml",
         "OSMD Function Test - Ornaments": "OSMD_function_test_Ornaments.xml",
         "Schubert, F. - An Die Musik": "Schubert_An_die_Musik.xml",
         "Actor, L. - Prelude (Sample)": "ActorPreludeSample.xml",

+ 9 - 9
src/MusicalScore/Graphical/VexFlow/VexFlowConverter.ts

@@ -20,7 +20,7 @@ import { ArticulationEnum, StemDirectionType } from "../../VoiceData/VoiceEntry"
 import { SystemLinePosition } from "../SystemLinePosition";
 import { GraphicalVoiceEntry } from "../GraphicalVoiceEntry";
 import { OrnamentEnum, OrnamentContainer } from "../../VoiceData/OrnamentContainer";
-import { NoteHead, NoteHeadShape } from "../../VoiceData/NoteHead";
+import { Notehead, NoteHeadShape } from "../../VoiceData/Notehead";
 import { unitInPixels } from "./VexFlowMusicSheetDrawer";
 import { EngravingRules } from "../EngravingRules";
 
@@ -111,19 +111,19 @@ export class VexFlowConverter {
         const acc: string = VexFlowConverter.accidental(pitch.Accidental);
         // The octave seems to need a shift of three FIXME?
         const octave: number = pitch.Octave - note.Clef().OctaveOffset + 3;
-        const noteHead: NoteHead = note.sourceNote.NoteHead;
-        let noteHeadCode: string = "";
-        if (noteHead !== undefined) {
-            noteHeadCode = this.NoteHeadCode(noteHead);
+        const notehead: Notehead = note.sourceNote.NoteHead;
+        let noteheadCode: string = "";
+        if (notehead !== undefined) {
+            noteheadCode = this.NoteHeadCode(notehead);
         }
-        return [fund + "n/" + octave + noteHeadCode, acc, note.Clef()];
+        return [fund + "n/" + octave + noteheadCode, acc, note.Clef()];
     }
 
     /** returns the Vexflow code for a note head. Some are still unsupported, see Vexflow/tables.js */
-    public static NoteHeadCode(noteHead: NoteHead): string {
+    public static NoteHeadCode(notehead: Notehead): string {
         const codeStart: string = "/";
-        const codeFilled: string = noteHead.Filled ? "2" : "1"; // filled/unfilled notehead code in most vexflow glyphs
-        switch (noteHead.Shape) {
+        const codeFilled: string = notehead.Filled ? "2" : "1"; // filled/unfilled notehead code in most vexflow glyphs
+        switch (notehead.Shape) {
             case NoteHeadShape.NORMAL:
                 return "";
             case NoteHeadShape.DIAMOND:

+ 9 - 9
src/MusicalScore/ScoreIO/VoiceGenerator.ts

@@ -25,7 +25,7 @@ import { IXmlAttribute } from "../../Common/FileIO/Xml";
 import { CollectionUtil } from "../../Util/CollectionUtil";
 import { ArticulationReader } from "./MusicSymbolModules/ArticulationReader";
 import { SlurReader } from "./MusicSymbolModules/SlurReader";
-import { NoteHead } from "../VoiceData/NoteHead";
+import { Notehead } from "../VoiceData/Notehead";
 import { Arpeggio, ArpeggioType } from "../VoiceData/Arpeggio";
 
 export class VoiceGenerator {
@@ -331,8 +331,8 @@ export class VoiceGenerator {
     let noteStep: NoteEnum = NoteEnum.C;
     let noteOctave: number = 0;
     let playbackInstrumentId: string = undefined;
-    let noteHeadShapeXml: string = undefined;
-    let noteHeadFilledXml: boolean = undefined; // if undefined, the final filled parameter will be calculated from duration
+    let noteheadShapeXml: string = undefined;
+    let noteheadFilledXml: boolean = undefined; // if undefined, the final filled parameter will be calculated from duration
 
     const xmlnodeElementsArr: IXmlElement[] = node.elements();
     for (let idx: number = 0, len: number = xmlnodeElementsArr.length; idx < len; ++idx) {
@@ -342,8 +342,8 @@ export class VoiceGenerator {
           const noteElementsArr: IXmlElement[] = noteElement.elements();
           for (let idx2: number = 0, len2: number = noteElementsArr.length; idx2 < len2; ++idx2) {
             const pitchElement: IXmlElement = noteElementsArr[idx2];
-            noteHeadShapeXml = undefined; // reinitialize for each pitch
-            noteHeadFilledXml = undefined;
+            noteheadShapeXml = undefined; // reinitialize for each pitch
+            noteheadFilledXml = undefined;
             try {
               if (pitchElement.name === "step") {
                 noteStep = NoteEnum[pitchElement.value];
@@ -402,9 +402,9 @@ export class VoiceGenerator {
             playbackInstrumentId = noteElement.firstAttribute.value;
           }
         } else if (noteElement.name === "notehead") {
-          noteHeadShapeXml = noteElement.value;
+          noteheadShapeXml = noteElement.value;
           if (noteElement.attribute("filled") !== null) {
-            noteHeadFilledXml = noteElement.attribute("filled").value === "yes";
+            noteheadFilledXml = noteElement.attribute("filled").value === "yes";
           }
         }
       } catch (ex) {
@@ -421,8 +421,8 @@ export class VoiceGenerator {
     note.StemDirectionXml = stemDirectionXml; // maybe unnecessary, also in VoiceEntry
     note.NoteheadColorXml = noteheadColorXml;
     note.PlaybackInstrumentId = playbackInstrumentId;
-    if (noteHeadShapeXml !== undefined && noteHeadShapeXml !== "normal") {
-      note.NoteHead = new NoteHead(note, noteHeadShapeXml, noteHeadFilledXml);
+    if (noteheadShapeXml !== undefined && noteheadShapeXml !== "normal") {
+      note.NoteHead = new Notehead(note, noteheadShapeXml, noteheadFilledXml);
     } // if normal, leave note head undefined to save processing/runtime
     this.currentVoiceEntry.Notes.push(note);
     this.currentVoiceEntry.StemDirectionXml = stemDirectionXml;

+ 6 - 6
src/MusicalScore/VoiceData/Note.ts

@@ -8,7 +8,7 @@ import {Tie} from "./Tie";
 import {Staff} from "./Staff";
 import {Slur} from "./Expressions/ContinuousExpressions/Slur";
 import {NoteState} from "../Graphical/DrawingEnums";
-import {NoteHead} from "./NoteHead";
+import {Notehead} from "./Notehead";
 import {Arpeggio} from "./Arpeggio";
 
 /**
@@ -45,7 +45,7 @@ export class Note {
     private tie: Tie;
     private slurs: Slur[] = [];
     private playbackInstrumentId: string = undefined;
-    private noteHead: NoteHead = undefined;
+    private notehead: Notehead = undefined;
     /** States whether the note should be displayed. False if xmlNode.attribute("print-object").value = "no". */
     private printObject: boolean = true;
     /** The Arpeggio this note is part of. */
@@ -112,11 +112,11 @@ export class Note {
     public set PlaybackInstrumentId(value: string) {
         this.playbackInstrumentId = value;
     }
-    public set NoteHead(value: NoteHead) {
-        this.noteHead = value;
+    public set NoteHead(value: Notehead) {
+        this.notehead = value;
     }
-    public get NoteHead(): NoteHead {
-        return this.noteHead;
+    public get NoteHead(): Notehead {
+        return this.notehead;
     }
     public get PrintObject(): boolean {
         return this.printObject;

+ 3 - 3
src/MusicalScore/VoiceData/NoteHead.ts

@@ -4,7 +4,7 @@ import * as log from "loglevel";
 /**
  * A note head with shape and fill information belonging to a [[Note]].
  */
-export class NoteHead {
+export class Notehead {
     /**
      * @param sourceNote
      * @param shapeTypeXml The shape type given from XML.
@@ -30,13 +30,13 @@ export class NoteHead {
      *                           If undefined, this.sourceNote should not be undefined.
      */
     public setShapeFromXml(shapeTypeXml: string, filledXmlAttribute: boolean = undefined): void {
-        this.shape = NoteHead.ShapeTypeXmlToShape(shapeTypeXml);
+        this.shape = Notehead.ShapeTypeXmlToShape(shapeTypeXml);
 
         let filled: boolean = filledXmlAttribute;
         if (filled === undefined) {
             if (this.sourceNote === undefined) {
                 // this should not happen. Either filledXmlAttribute or sourceNote should be defined.
-                log.warn("noteHead: sourceNote and filledXmlAttribute undefined.");
+                log.warn("notehead: sourceNote and filledXmlAttribute undefined.");
                 filled = true;
             } else {
                 filled = this.sourceNote.Length.Denominator > 2;

+ 1 - 23
test/data/OSMD_function_test_noteHeadShapes.musicxml → test/data/OSMD_function_test_noteheadShapes.musicxml

@@ -639,29 +639,7 @@
         <stem>up</stem>
         </note>
       </measure>
-    <measure number="19" width="134.20">
-      <note default-x="26.11" default-y="-30.00">
-        <pitch>
-          <step>G</step>
-          <octave>4</octave>
-          </pitch>
-        <duration>8</duration>
-        <voice>1</voice>
-        <type>half</type>
-        <stem>up</stem>
-        <lyric number="1" default-x="6.22" default-y="-80.00">
-          <syllabic>single</syllabic>
-          <text>none</text>
-          </lyric>
-        </note>
-      <note>
-        <rest/>
-        <duration>8</duration>
-        <voice>1</voice>
-        <type>half</type>
-        </note>
-      </measure>
-    <measure number="20" width="111.45">
+    <measure number="19" width="111.45">
       <note default-x="14.97" default-y="-30.00">
         <pitch>
           <step>G</step>