Selaa lähdekoodia

feat(GraceNotes): add grace slur (boolean)

part of #293
sschmidTU 7 vuotta sitten
vanhempi
commit
2525e92aed

+ 4 - 4
src/MusicalScore/Graphical/VexFlow/VexFlowMeasure.ts

@@ -577,13 +577,13 @@ export class VexFlowMeasure extends GraphicalMeasure {
     public graphicalMeasureCreatedCalculations(): void {
         for (const graphicalStaffEntry of this.staffEntries as VexFlowStaffEntry[]) {
             // create vex flow Stave Notes:
-            let graceNotesSlur: boolean = false;
+            let graceSlur: boolean = false;
             let graceGVoiceEntriesBefore: GraphicalVoiceEntry[] = [];
             for (const gve of graphicalStaffEntry.graphicalVoiceEntries) {
                 if (gve.parentVoiceEntry.IsGrace) {
                     graceGVoiceEntriesBefore.push(gve);
-                    if (!graceNotesSlur) {
-                        graceNotesSlur = gve.parentVoiceEntry.hasSlur();
+                    if (!graceSlur) {
+                        graceSlur = gve.parentVoiceEntry.GraceSlur;
                     }
                     continue;
                 }
@@ -593,7 +593,7 @@ export class VexFlowMeasure extends GraphicalMeasure {
                     for (let i: number = 0; i < graceGVoiceEntriesBefore.length; i++) {
                         graceNotes.push(VexFlowConverter.StaveNote(graceGVoiceEntriesBefore[i]));
                     }
-                    const graceNoteGroup: Vex.Flow.GraceNoteGroup = new Vex.Flow.GraceNoteGroup(graceNotes, graceNotesSlur);
+                    const graceNoteGroup: Vex.Flow.GraceNoteGroup = new Vex.Flow.GraceNoteGroup(graceNotes, graceSlur);
                     (gve as VexFlowVoiceEntry).vfStaveNote.addModifier(0, graceNoteGroup.beamNotes());
                     graceGVoiceEntriesBefore = [];
                 }

+ 0 - 1
src/MusicalScore/Graphical/VexFlow/VexFlowMusicSheetCalculator.ts

@@ -92,7 +92,6 @@ export class VexFlowMusicSheetCalculator extends MusicSheetCalculator {
             if (mvoices.hasOwnProperty(voiceID)) {
                 voices.push(mvoices[voiceID]);
                 allVoices.push(mvoices[voiceID]);
-
             }
         }
         if (voices.length === 0) {

+ 11 - 1
src/MusicalScore/ScoreIO/InstrumentReader.ts

@@ -182,6 +182,7 @@ export class InstrumentReader {
 
           const isGraceNote: boolean = xmlNode.element("grace") !== undefined || noteDivisions === 0 || isChord && lastNoteWasGrace;
           let graceNoteSlash: boolean = false;
+          let graceSlur: boolean = false;
           if (isGraceNote) {
             const graceNode: IXmlElement = xmlNode.element("grace");
             if (graceNode && graceNode.attributes()) {
@@ -194,6 +195,14 @@ export class InstrumentReader {
             }
 
             noteDuration = this.getNoteDurationFromTypeNode(xmlNode);
+
+            const notationNode: IXmlElement = xmlNode.element("notations");
+            if (notationNode !== undefined) {
+              if (notationNode.element("slur") !== undefined) {
+                graceSlur = true;
+                // grace slurs could be non-binary, but VexFlow.GraceNoteGroup modifier system is currently only boolean for slurs.
+              }
+            }
           }
 
           let musicTimestamp: Fraction = currentFraction.clone();
@@ -213,7 +222,8 @@ export class InstrumentReader {
             || (isGraceNote && !isChord)
             || (!isGraceNote && lastNoteWasGrace)
           ) {
-            this.currentVoiceGenerator.createVoiceEntry(musicTimestamp, this.currentStaffEntry, !restNote && !isGraceNote, isGraceNote, graceNoteSlash);
+            this.currentVoiceGenerator.createVoiceEntry(musicTimestamp, this.currentStaffEntry, !restNote && !isGraceNote,
+                                                        isGraceNote, graceNoteSlash, graceSlur);
           }
           if (!isGraceNote && !isChord) {
             previousFraction = currentFraction.clone();

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

@@ -80,8 +80,8 @@ export class VoiceGenerator {
    * @param isGrace States whether the new VoiceEntry (only) has grace notes
    */
   public createVoiceEntry(musicTimestamp: Fraction, parentStaffEntry: SourceStaffEntry, addToVoice: boolean,
-                          isGrace: boolean = false, graceNoteSlash: boolean = false): void {
-    this.currentVoiceEntry = new VoiceEntry(musicTimestamp.clone(), this.voice, parentStaffEntry, isGrace);
+                          isGrace: boolean = false, graceNoteSlash: boolean = false, graceSlur: boolean = false): void {
+    this.currentVoiceEntry = new VoiceEntry(musicTimestamp.clone(), this.voice, parentStaffEntry, isGrace, graceNoteSlash, graceSlur);
     if (addToVoice) {
       this.voice.VoiceEntries.push(this.currentVoiceEntry);
     }

+ 9 - 1
src/MusicalScore/VoiceData/VoiceEntry.ts

@@ -24,12 +24,13 @@ export class VoiceEntry {
      * @param graceNoteSlash States whether the grace note(s) have a slash (Acciaccatura, played before the beat)
      */
     constructor(timestamp: Fraction, parentVoice: Voice, parentSourceStaffEntry: SourceStaffEntry,
-                isGrace: boolean = false, graceNoteSlash: boolean = false) {
+                isGrace: boolean = false, graceNoteSlash: boolean = false, graceSlur: boolean = false) {
         this.timestamp = timestamp;
         this.parentVoice = parentVoice;
         this.parentSourceStaffEntry = parentSourceStaffEntry;
         this.isGrace = isGrace;
         this.graceNoteSlash = graceNoteSlash;
+        this.graceSlur = graceSlur;
     }
 
     private parentVoice: Voice;
@@ -38,6 +39,7 @@ export class VoiceEntry {
     private notes: Note[] = [];
     private isGrace: boolean;
     private graceNoteSlash: boolean;
+    private graceSlur: boolean; // TODO grace slur system could be refined to be non-binary
     private articulations: ArticulationEnum[] = [];
     private technicalInstructions: TechnicalInstruction[] = [];
     private lyricsEntries: Dictionary<number, LyricsEntry> = new Dictionary<number, LyricsEntry>();
@@ -72,6 +74,12 @@ export class VoiceEntry {
     public set GraceNoteSlash(value: boolean) {
         this.graceNoteSlash = value;
     }
+    public get GraceSlur(): boolean {
+        return this.graceSlur;
+    }
+    public set GraceSlur(value: boolean) {
+        this.graceSlur = value;
+    }
     public get Articulations(): ArticulationEnum[] {
         return this.articulations;
     }