Pārlūkot izejas kodu

feat(Accidentals): can display triple sharps/flats, quarter tones

add Accidentals test to demo

closes #215, part of #284
sschmidTU 7 gadi atpakaļ
vecāks
revīzija
024b95e1f9

+ 1 - 0
demo/index.js

@@ -25,6 +25,7 @@ import { OpenSheetMusicDisplay } from '../src/OpenSheetMusicDisplay/OpenSheetMus
             "OSMD Function Test - All": "OSMD_function_test_all.xml",
             "OSMD Function Test - Grace Notes": "OSMD_function_test_GraceNotes.xml",
             "OSMD Function Test - Ornaments": "OSMD_function_test_Ornaments.xml",
+            "OSMD Function Test - Accidentals": "OSMD_function_test_accidentals.musicxml",
             "L. Actor - Prelude (Sample)": "ActorPreludeSample.xml",
             "Anonymous - Saltarello": "Saltarello.mxl",
             "C. Debussy - Mandoline": "Debussy_Mandoline.xml",

+ 5 - 1
src/Common/DataObjects/Pitch.ts

@@ -10,12 +10,16 @@ export enum NoteEnum {
 }
 
 export enum AccidentalEnum {
+    TRIPLEFLAT = -3,
     DOUBLEFLAT = -2,
     FLAT = -1,
     NONE = 0,
     SHARP = 1,
     DOUBLESHARP = 2,
-    NATURAL = 3
+    TRIPLESHARP = 3,
+    NATURAL = 4,
+    QUARTERTONESHARP = 0.5,
+    QUARTERTONEFLAT = -0.5
 }
 
 // This class represents a musical note. The middle A (440 Hz) lies in the octave with the value 1.

+ 12 - 0
src/MusicalScore/Graphical/VexFlow/VexFlowConverter.ts

@@ -131,9 +131,21 @@ export class VexFlowConverter {
             case AccidentalEnum.DOUBLESHARP:
                 acc = "##";
                 break;
+            case AccidentalEnum.TRIPLESHARP:
+                acc = "++";
+                break;
             case AccidentalEnum.DOUBLEFLAT:
                 acc = "bb";
                 break;
+            case AccidentalEnum.TRIPLEFLAT:
+                acc = "bbs"; // there is no "bbb" in VexFlow yet, unfortunately.
+                break;
+            case AccidentalEnum.QUARTERTONESHARP:
+                acc = "+";
+                break;
+            case AccidentalEnum.QUARTERTONEFLAT:
+                acc = "d";
+                break;
             default:
         }
         return acc;

+ 10 - 1
src/MusicalScore/ScoreIO/MusicSymbolModules/ArticulationReader.ts

@@ -13,13 +13,22 @@ export class ArticulationReader {
         return AccidentalEnum.NATURAL;
       case "sharp":
         return AccidentalEnum.SHARP;
-      case "sharp-sharp":
       case "double-sharp":
+      case "sharp-sharp":
         return AccidentalEnum.DOUBLESHARP;
+      case "triple-sharp":
+        return AccidentalEnum.TRIPLESHARP;
       case "flat":
         return AccidentalEnum.FLAT;
+      case "double-flat":
       case "flat-flat":
         return AccidentalEnum.DOUBLEFLAT;
+      case "triple-flat":
+        return AccidentalEnum.TRIPLEFLAT;
+      case "quarter-sharp":
+        return AccidentalEnum.QUARTERTONESHARP;
+      case "quarter-flat":
+        return AccidentalEnum.QUARTERTONEFLAT;
       default:
         return AccidentalEnum.NONE;
     }

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

@@ -320,7 +320,7 @@ export class VoiceGenerator {
                   throw new MusicSheetReadingException(errorMsg, undefined);
                 }
               } else if (pitchElement.name === "alter") {
-                noteAlter = parseInt(pitchElement.value, 10);
+                noteAlter = parseFloat(pitchElement.value);
                 if (isNaN(noteAlter)) {
                   const errorMsg: string = ITextTranslation.translateText(
                     "ReaderErrorMessages/NoteAlterationError", "Invalid alteration while reading note."
@@ -328,7 +328,15 @@ export class VoiceGenerator {
                   this.musicSheet.SheetErrors.pushMeasureError(errorMsg);
                   throw new MusicSheetReadingException(errorMsg, undefined);
                 }
-
+                if (noteAlter === 0.5) {
+                  noteAlter = AccidentalEnum.QUARTERTONESHARP;
+                } else if (noteAlter === -0.5) {
+                  noteAlter = AccidentalEnum.QUARTERTONEFLAT;
+                } else if (noteAlter === 3) {
+                  noteAlter = AccidentalEnum.TRIPLESHARP;
+                } else if (noteAlter === -3) {
+                  noteAlter = AccidentalEnum.TRIPLEFLAT;
+                }
               } else if (pitchElement.name === "octave") {
                 noteOctave = parseInt(pitchElement.value, 10);
                 if (isNaN(noteOctave)) {

+ 305 - 0
test/data/OSMD_function_test_accidentals.musicxml

@@ -0,0 +1,305 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 3.1 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
+<score-partwise version="3.1">
+  <work>
+    <work-title>OSMD Function Test - Accidentals</work-title>
+    </work>
+  <identification>
+    <creator type="composer">OSMD</creator>
+    <encoding>
+      <software>MuseScore 2.3.1</software>
+      <encoding-date>2018-07-20</encoding-date>
+      <supports element="accidental" type="yes"/>
+      <supports element="beam" type="yes"/>
+      <supports element="print" attribute="new-page" type="yes" value="yes"/>
+      <supports element="print" attribute="new-system" type="yes" value="yes"/>
+      <supports element="stem" type="yes"/>
+      </encoding>
+    </identification>
+  <defaults>
+    <scaling>
+      <millimeters>7.05556</millimeters>
+      <tenths>40</tenths>
+      </scaling>
+    <page-layout>
+      <page-height>1584</page-height>
+      <page-width>1224</page-width>
+      <page-margins type="even">
+        <left-margin>56.6929</left-margin>
+        <right-margin>56.6929</right-margin>
+        <top-margin>56.6929</top-margin>
+        <bottom-margin>113.386</bottom-margin>
+        </page-margins>
+      <page-margins type="odd">
+        <left-margin>56.6929</left-margin>
+        <right-margin>56.6929</right-margin>
+        <top-margin>56.6929</top-margin>
+        <bottom-margin>113.386</bottom-margin>
+        </page-margins>
+      </page-layout>
+    <word-font font-family="FreeSerif" font-size="10"/>
+    <lyric-font font-family="FreeSerif" font-size="11"/>
+    </defaults>
+  <credit page="1">
+    <credit-words default-x="612" default-y="1527.31" justify="center" valign="top" font-size="24">OSMD Function Test - Accidentals</credit-words>
+    </credit>
+  <part-list>
+    <score-part id="P1">
+      <part-name>Piano</part-name>
+      <part-abbreviation>Pno.</part-abbreviation>
+      <score-instrument id="P1-I1">
+        <instrument-name>Piano</instrument-name>
+        </score-instrument>
+      <midi-device id="P1-I1" port="1"></midi-device>
+      <midi-instrument id="P1-I1">
+        <midi-channel>1</midi-channel>
+        <midi-program>1</midi-program>
+        <volume>78.7402</volume>
+        <pan>0</pan>
+        </midi-instrument>
+      </score-part>
+    </part-list>
+  <part id="P1">
+    <measure number="1" width="242.89">
+      <print>
+        <system-layout>
+          <system-margins>
+            <left-margin>0.00</left-margin>
+            <right-margin>0.00</right-margin>
+            </system-margins>
+          <top-system-distance>170.00</top-system-distance>
+          </system-layout>
+        </print>
+      <attributes>
+        <divisions>1</divisions>
+        <key>
+          <fifths>0</fifths>
+          </key>
+        <time>
+          <beats>4</beats>
+          <beat-type>4</beat-type>
+          </time>
+        <clef>
+          <sign>G</sign>
+          <line>2</line>
+          </clef>
+        </attributes>
+      <note default-x="84.60" default-y="-50.00">
+        <pitch>
+          <step>C</step>
+          <alter>1</alter>
+          <octave>4</octave>
+          </pitch>
+        <duration>2</duration>
+        <voice>1</voice>
+        <type>half</type>
+        <accidental>sharp</accidental>
+        <stem>up</stem>
+        <lyric number="1" default-x="6.22" default-y="-80.00">
+          <syllabic>single</syllabic>
+          <text>Sharp</text>
+          </lyric>
+        </note>
+      <note>
+        <rest/>
+        <duration>2</duration>
+        <voice>1</voice>
+        <type>half</type>
+        </note>
+      </measure>
+    <measure number="2" width="243.57">
+      <note default-x="53.36" default-y="-40.00">
+        <pitch>
+          <step>E</step>
+          <alter>2</alter>
+          <octave>4</octave>
+          </pitch>
+        <duration>2</duration>
+        <voice>1</voice>
+        <type>half</type>
+        <accidental>double-sharp</accidental>
+        <stem>up</stem>
+        <lyric number="1" default-x="6.22" default-y="-80.00">
+          <syllabic>single</syllabic>
+          <text>DoubleSharp</text>
+          </lyric>
+        </note>
+      <note>
+        <rest/>
+        <duration>2</duration>
+        <voice>1</voice>
+        <type>half</type>
+        </note>
+      </measure>
+    <measure number="3" width="233.19">
+      <note default-x="48.17" default-y="-30.00">
+        <pitch>
+	  <alter>3</alter>
+          <step>G</step>
+          <octave>4</octave>
+          </pitch>
+        <duration>2</duration>
+        <voice>1</voice>
+        <type>half</type>
+        <accidental>triple-sharp</accidental>
+        <stem>up</stem>
+        <lyric number="1" default-x="6.22" default-y="-80.00">
+          <syllabic>single</syllabic>
+          <text>TripleSharp</text>
+          </lyric>
+        </note>
+      <note>
+        <rest/>
+        <duration>2</duration>
+        <voice>1</voice>
+        <type>half</type>
+        </note>
+      </measure>
+    <measure number="4" width="247.09">
+      <note default-x="55.12" default-y="-30.00">
+        <pitch>
+          <step>G</step>
+          <alter>0.5</alter>
+          <octave>4</octave>
+          </pitch>
+        <duration>2</duration>
+        <voice>1</voice>
+        <type>half</type>
+        <accidental>quarter-sharp</accidental>
+        <stem>up</stem>
+        <lyric number="1" default-x="6.22" default-y="-80.00">
+          <syllabic>single</syllabic>
+          <text>QuarterSharp</text>
+          </lyric>
+        </note>
+      <note>
+        <rest/>
+        <duration>2</duration>
+        <voice>1</voice>
+        <type>half</type>
+        </note>
+      </measure>
+    <measure number="5" width="143.87">
+      <note>
+        <rest/>
+        <duration>4</duration>
+        <voice>1</voice>
+        </note>
+      </measure>
+    <measure number="6" width="228.26">
+      <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="64.34" default-y="-50.00">
+        <pitch>
+          <step>C</step>
+          <alter>-1</alter>
+          <octave>4</octave>
+          </pitch>
+        <duration>2</duration>
+        <voice>1</voice>
+        <type>half</type>
+        <accidental>flat</accidental>
+        <stem>up</stem>
+        <lyric number="1" default-x="6.22" default-y="-80.00">
+          <syllabic>single</syllabic>
+          <text>Flat</text>
+          </lyric>
+        </note>
+      <note>
+        <rest/>
+        <duration>2</duration>
+        <voice>1</voice>
+        <type>half</type>
+        </note>
+      </measure>
+    <measure number="7" width="240.76">
+      <note default-x="44.92" default-y="-40.00">
+        <pitch>
+          <step>E</step>
+          <alter>-2</alter>
+          <octave>4</octave>
+          </pitch>
+        <duration>2</duration>
+        <voice>1</voice>
+        <type>half</type>
+        <accidental>flat-flat</accidental>
+        <stem>up</stem>
+        <lyric number="1" default-x="6.22" default-y="-80.00">
+          <syllabic>single</syllabic>
+          <text>DoubleFlat</text>
+          </lyric>
+        </note>
+      <note>
+        <rest/>
+        <duration>2</duration>
+        <voice>1</voice>
+        <type>half</type>
+        </note>
+      </measure>
+    <measure number="8" width="230.38">
+      <note default-x="39.73" default-y="-30.00">
+        <pitch>
+	  <alter>-3</alter>
+          <step>G</step>
+          <octave>4</octave>
+          </pitch>
+        <duration>2</duration>
+        <voice>1</voice>
+        <type>half</type>
+        <accidental>triple-flat</accidental>
+        <stem>up</stem>
+        <lyric number="1" default-x="6.22" default-y="-80.00">
+          <syllabic>single</syllabic>
+          <text>TripleFlat</text>
+          </lyric>
+        </note>
+      <note>
+        <rest/>
+        <duration>2</duration>
+        <voice>1</voice>
+        <type>half</type>
+        </note>
+      </measure>
+    <measure number="9" width="244.28">
+      <note default-x="46.68" default-y="-30.00">
+        <pitch>
+          <step>G</step>
+          <alter>-0.5</alter>
+          <octave>4</octave>
+          </pitch>
+        <duration>2</duration>
+        <voice>1</voice>
+        <type>half</type>
+        <accidental>quarter-flat</accidental>
+        <stem>up</stem>
+        <lyric number="1" default-x="6.22" default-y="-80.00">
+          <syllabic>single</syllabic>
+          <text>QuarterFlat</text>
+          </lyric>
+        </note>
+      <note>
+        <rest/>
+        <duration>2</duration>
+        <voice>1</voice>
+        <type>half</type>
+        </note>
+      </measure>
+    <measure number="10" width="166.94">
+      <note>
+        <rest/>
+        <duration>4</duration>
+        <voice>1</voice>
+        </note>
+      <barline location="right">
+        <bar-style>light-heavy</bar-style>
+        </barline>
+      </measure>
+    </part>
+  </score-partwise>