Selaa lähdekoodia

feat(NoteHeadShapes): add square, rectangle note head

demo: update OSMD Function Test NoteHeadShapes
(square, rectangle possible since Vexflow 1.2.87)

close #404
sschmidTU 6 vuotta sitten
vanhempi
commit
b6a15ef62a

+ 6 - 2
src/MusicalScore/Graphical/VexFlow/VexFlowConverter.ts

@@ -122,7 +122,7 @@ export class VexFlowConverter {
     /** returns the Vexflow code for a note head. Some are still unsupported, see Vexflow/tables.js */
     public static NoteHeadCode(noteHead: NoteHead): string {
         const codeStart: string = "/";
-        const codeFilled: string = noteHead.Filled ? "2" : "1";
+        const codeFilled: string = noteHead.Filled ? "2" : "1"; // filled/unfilled notehead code in most vexflow glyphs
         switch (noteHead.Shape) {
             case NoteHeadShape.NORMAL:
                 return "";
@@ -133,7 +133,11 @@ export class VexFlowConverter {
             case NoteHeadShape.X:
                 return codeStart + "X" + codeFilled;
             case NoteHeadShape.CIRCLEX:
-                return codeStart + "X3"; // circleX is "X3" in Vexflow for some reason
+                return codeStart + "X3";
+            case NoteHeadShape.RECTANGLE:
+                return codeStart + "R" + codeFilled;
+            case NoteHeadShape.SQUARE:
+                return codeStart + "S" + codeFilled;
             case NoteHeadShape.SLASH:
                 return ""; // slash is specified at end of duration string in Vexflow
             default:

+ 9 - 5
src/MusicalScore/VoiceData/NoteHead.ts

@@ -60,9 +60,13 @@ export class NoteHead {
      * Necessary because "circle-x" is not a valid enum member name.
      */
     public static ShapeTypeXmlToShape(shapeTypeXml: string): NoteHeadShape {
-        switch (shapeTypeXml) {
+        switch (shapeTypeXml.toLowerCase()) {
             case "normal":
                 return NoteHeadShape.NORMAL;
+            case "x":
+                return NoteHeadShape.X;
+            case "slash":
+                return NoteHeadShape.SLASH;
             case "diamond":
                 return NoteHeadShape.DIAMOND;
             case "square":
@@ -72,10 +76,8 @@ export class NoteHead {
             case "do":
             case "triangle":
                 return NoteHeadShape.TRIANGLE;
-            case "x":
-                return NoteHeadShape.X;
-            case "slash":
-                return NoteHeadShape.SLASH;
+            case "rectangle":
+                return NoteHeadShape.RECTANGLE;
             case "circle-x":
                 return NoteHeadShape.CIRCLEX;
             default:
@@ -90,9 +92,11 @@ export enum NoteHeadShape {
     CIRCLEX,
     DIAMOND,
     NORMAL,
+    RECTANGLE,
     SLASH,
     SQUARE,
     TRIANGLE,
     X,
     // TODO: Add the rest from https://usermanuals.musicxml.com/MusicXML/Content/ST-MusicXML-notehead-value.htm
+    // currently all Vexflow supported shapes present
 }

+ 113 - 62
test/data/OSMD_function_test_noteHeadShapes.musicxml

@@ -7,7 +7,7 @@
   <identification>
     <encoding>
       <software>MuseScore 2.3.2</software>
-      <encoding-date>2018-08-28</encoding-date>
+      <encoding-date>2018-10-11</encoding-date>
       <supports element="accidental" type="yes"/>
       <supports element="beam" type="yes"/>
       <supports element="print" attribute="new-page" type="yes" value="yes"/>
@@ -63,7 +63,7 @@
       <print>
         <system-layout>
           <system-margins>
-            <left-margin>-0.00</left-margin>
+            <left-margin>0.00</left-margin>
             <right-margin>0.00</right-margin>
             </system-margins>
           <top-system-distance>170.00</top-system-distance>
@@ -331,13 +331,13 @@
       <print new-system="yes">
         <system-layout>
           <system-margins>
-            <left-margin>-0.00</left-margin>
+            <left-margin>0.00</left-margin>
             <right-margin>0.00</right-margin>
             </system-margins>
           <system-distance>150.00</system-distance>
           </system-layout>
         </print>
-      <note default-x="49.08" default-y="-30.00">
+      <note default-x="49.07" default-y="-30.00">
         <pitch>
           <step>G</step>
           <octave>4</octave>
@@ -424,55 +424,17 @@
         <type>quarter</type>
         </note>
       </measure>
-    <measure number="12" width="1110.61">
+    <measure number="12" width="372.16">
       <print new-system="yes">
         <system-layout>
           <system-margins>
-            <left-margin>-0.00</left-margin>
+            <left-margin>0.00</left-margin>
             <right-margin>0.00</right-margin>
             </system-margins>
           <system-distance>150.00</system-distance>
           </system-layout>
         </print>
-      <note>
-        <rest/>
-        <duration>16</duration>
-        <voice>1</voice>
-        </note>
-      </measure>
-    <measure number="13" width="229.88">
-      <print new-system="yes">
-        <system-layout>
-          <system-margins>
-            <left-margin>-0.00</left-margin>
-            <right-margin>0.00</right-margin>
-            </system-margins>
-          <system-distance>150.00</system-distance>
-          </system-layout>
-        </print>
-      <note default-x="105.50" default-y="-15.00">
-        <pitch>
-          <step>C</step>
-          <octave>5</octave>
-          </pitch>
-        <duration>16</duration>
-        <voice>1</voice>
-        <type>whole</type>
-        <lyric number="1" default-x="11.65" default-y="-80.00">
-          <syllabic>single</syllabic>
-          <text>NotInVexFlow:</text>
-          </lyric>
-        </note>
-      </measure>
-    <measure number="14" width="80.05">
-      <note>
-        <rest/>
-        <duration>16</duration>
-        <voice>1</voice>
-        </note>
-      </measure>
-    <measure number="15" width="146.47">
-      <note default-x="49.95" default-y="-30.00">
+      <note default-x="87.03" default-y="-30.00">
         <pitch>
           <step>G</step>
           <octave>4</octave>
@@ -487,7 +449,7 @@
           </lyric>
         </note>
       </measure>
-    <measure number="16" width="183.27">
+    <measure number="13" width="377.89">
       <note default-x="33.79" default-y="-30.00">
         <pitch>
           <step>G</step>
@@ -497,13 +459,13 @@
         <voice>1</voice>
         <type>quarter</type>
         <stem>up</stem>
-        <notehead>la</notehead>
+        <notehead>square</notehead>
         <lyric number="1" default-x="6.58" default-y="-80.00">
           <syllabic>single</syllabic>
           <text>square</text>
           </lyric>
         </note>
-      <note default-x="71.24" default-y="-30.00">
+      <note default-x="121.40" default-y="-30.00">
         <pitch>
           <step>G</step>
           <octave>4</octave>
@@ -513,6 +475,10 @@
         <type>16th</type>
         <stem>up</stem>
         <notehead>la</notehead>
+        <lyric number="1" default-x="6.58" default-y="-80.00">
+          <syllabic>single</syllabic>
+          <text>La</text>
+          </lyric>
         </note>
       <note>
         <rest/>
@@ -526,7 +492,15 @@
         <voice>1</voice>
         <type>eighth</type>
         </note>
-      <note default-x="137.67" default-y="-30.00">
+      <note>
+        <rest/>
+        <duration>8</duration>
+        <voice>1</voice>
+        <type>half</type>
+        </note>
+      </measure>
+    <measure number="14" width="360.57">
+      <note default-x="48.28" default-y="-30.00">
         <pitch>
           <step>G</step>
           <octave>4</octave>
@@ -535,11 +509,56 @@
         <voice>1</voice>
         <type>half</type>
         <stem>up</stem>
-        <notehead>la</notehead>
+        <notehead>rectangle</notehead>
+        <lyric number="1" default-x="6.21" default-y="-80.00">
+          <syllabic>single</syllabic>
+          <text>Rectangle</text>
+          </lyric>
+        </note>
+      <note default-x="186.57" default-y="-30.00">
+        <pitch>
+          <step>G</step>
+          <octave>4</octave>
+          </pitch>
+        <duration>4</duration>
+        <voice>1</voice>
+        <type>quarter</type>
+        <stem>up</stem>
+        <notehead>rectangle</notehead>
+        </note>
+      <note>
+        <rest/>
+        <duration>4</duration>
+        <voice>1</voice>
+        <type>quarter</type>
         </note>
       </measure>
-    <measure number="17" width="129.19">
-      <note default-x="12.00" default-y="-30.00">
+    <measure number="15" width="247.84">
+      <print new-system="yes">
+        <system-layout>
+          <system-margins>
+            <left-margin>0.00</left-margin>
+            <right-margin>0.00</right-margin>
+            </system-margins>
+          <system-distance>150.00</system-distance>
+          </system-layout>
+        </print>
+      <note default-x="105.50" default-y="-15.00">
+        <pitch>
+          <step>C</step>
+          <octave>5</octave>
+          </pitch>
+        <duration>16</duration>
+        <voice>1</voice>
+        <type>whole</type>
+        <lyric number="1" default-x="11.65" default-y="-80.00">
+          <syllabic>single</syllabic>
+          <text>NotInVexFlow:</text>
+          </lyric>
+        </note>
+      </measure>
+    <measure number="16" width="248.46">
+      <note default-x="36.61" default-y="-30.00">
         <pitch>
           <step>G</step>
           <octave>4</octave>
@@ -553,7 +572,7 @@
           <text>slashed</text>
           </lyric>
         </note>
-      <note default-x="69.62" default-y="-30.00">
+      <note default-x="141.55" default-y="-30.00">
         <pitch>
           <step>G</step>
           <octave>4</octave>
@@ -562,13 +581,13 @@
         <voice>1</voice>
         <type>half</type>
         <stem>up</stem>
-        <lyric number="1" default-x="8.48" default-y="-80.00">
+        <lyric number="1" default-x="6.22" default-y="-80.00">
           <syllabic>single</syllabic>
-          <text>backslashed</text>
+          <text>backSlashed</text>
           </lyric>
         </note>
       </measure>
-    <measure number="18" width="115.13">
+    <measure number="17" width="133.09">
       <note default-x="26.11" default-y="-30.00">
         <pitch>
           <step>G</step>
@@ -580,10 +599,10 @@
         <stem>up</stem>
         <lyric number="1" default-x="6.22" default-y="-80.00">
           <syllabic>single</syllabic>
-          <text>invertedTriangle</text>
+          <text>none</text>
           </lyric>
         </note>
-      <note default-x="69.64" default-y="-30.00">
+      <note default-x="78.62" default-y="-30.00">
         <pitch>
           <step>G</step>
           <octave>4</octave>
@@ -594,7 +613,7 @@
         <stem>up</stem>
         </note>
       </measure>
-    <measure number="19" width="226.61">
+    <measure number="18" width="235.57">
       <note default-x="77.35" default-y="-30.00">
         <pitch>
           <step>G</step>
@@ -606,7 +625,7 @@
         <stem>up</stem>
         <lyric number="1" default-x="6.22" default-y="-80.00">
           <syllabic>single</syllabic>
-          <text>none</text>
+          <text>invertedTriangle</text>
           </lyric>
         </note>
       <note default-x="159.08" default-y="-30.00">
@@ -618,11 +637,43 @@
         <voice>1</voice>
         <type>half</type>
         <stem>up</stem>
-		<lyric number="1" default-x="8.48" default-y="-80.00">
+        </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>etc</text>
+          <text>none</text>
           </lyric>
         </note>
+      <note>
+        <rest/>
+        <duration>8</duration>
+        <voice>1</voice>
+        <type>half</type>
+        </note>
+      </measure>
+    <measure number="20" width="111.45">
+      <note default-x="14.97" default-y="-30.00">
+        <pitch>
+          <step>G</step>
+          <octave>4</octave>
+          </pitch>
+        <duration>16</duration>
+        <voice>1</voice>
+        <type>whole</type>
+        <lyric number="1" default-x="3.26" default-y="-80.00">
+          <syllabic>single</syllabic>
+          <text>etc</text>
+          </lyric>
         </note>
       <barline location="right">
         <bar-style>light-heavy</bar-style>