Browse Source

refactor(GraceNotes): move graceNoteSlash to VoiceEntry

start of the grace notes refactor, more changes coming.

part of #56
sschmidTU 7 years ago
parent
commit
6f361ae434

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

@@ -192,7 +192,7 @@ export class InstrumentReader {
           //log.info("currentStaffEntry", this.currentStaffEntry, this.currentMeasure.VerticalSourceStaffEntryContainers.length);
 
           if (!this.currentVoiceGenerator.hasVoiceEntry() || (!isChord && !isGraceNote && !lastNoteWasGrace) || (!lastNoteWasGrace && isGraceNote)) {
-            this.currentVoiceGenerator.createVoiceEntry(musicTimestamp, this.currentStaffEntry, !restNote);
+            this.currentVoiceGenerator.createVoiceEntry(musicTimestamp, this.currentStaffEntry, !restNote, isGraceNote);
           }
           if (!isGraceNote && !isChord) {
             previousFraction = currentFraction.clone();

+ 11 - 8
src/MusicalScore/ScoreIO/VoiceGenerator.ts

@@ -78,9 +78,10 @@ export class VoiceGenerator {
    * @param musicTimestamp
    * @param parentStaffEntry
    * @param addToVoice
+   * @param isGrace States whether the new VoiceEntry (only) has grace notes
    */
-  public createVoiceEntry(musicTimestamp: Fraction, parentStaffEntry: SourceStaffEntry, addToVoice: boolean): void {
-    this.currentVoiceEntry = new VoiceEntry(musicTimestamp.clone(), this.voice, parentStaffEntry);
+  public createVoiceEntry(musicTimestamp: Fraction, parentStaffEntry: SourceStaffEntry, addToVoice: boolean, isGrace: boolean = false): void {
+    this.currentVoiceEntry = new VoiceEntry(musicTimestamp.clone(), this.voice, parentStaffEntry, isGrace);
     if (addToVoice) {
       this.voice.VoiceEntries.push(this.currentVoiceEntry);
     }
@@ -413,7 +414,7 @@ export class VoiceGenerator {
       this.handleGraceNote(node, note);
     }
     if (node.elements("beam") && !chord) {
-      this.createBeam(node, note, graceNote);
+      this.createBeam(node, note);
     }
     return note;
   }
@@ -440,7 +441,7 @@ export class VoiceGenerator {
    * @param note
    * @param grace
    */
-  private createBeam(node: IXmlElement, note: Note, grace: boolean): void {
+  private createBeam(node: IXmlElement, note: Note): void {
     try {
       const beamNode: IXmlElement = node.element("beam");
       let beamAttr: IXmlAttribute = undefined;
@@ -453,7 +454,7 @@ export class VoiceGenerator {
         const currentBeamTag: string = mainBeamNode[0].value;
         if (beamNumber === 1 && mainBeamNode !== undefined) {
           if (currentBeamTag === "begin" && this.lastBeamTag !== currentBeamTag) {
-            if (grace) {
+            if (note.ParentVoiceEntry.IsGrace) {
               if (this.openGraceBeam !== undefined) {
                 this.handleOpenBeam();
               }
@@ -468,7 +469,7 @@ export class VoiceGenerator {
           this.lastBeamTag = currentBeamTag;
         }
         let sameVoiceEntry: boolean = false;
-        if (grace) {
+        if (note.ParentVoiceEntry.IsGrace) {
           if (this.openGraceBeam === undefined) {
             return;
           }
@@ -574,11 +575,13 @@ export class VoiceGenerator {
       }
     }
     const graceNode: IXmlElement = node.element("grace");
+    let graceNoteSlash: boolean = false;
+    // TODO overlap with InstrumentReader.readNextXmlMeasure, which also checks whether there's a grace node in XML
     if (graceNode !== undefined && graceNode.attributes()) {
       if (graceNode.attribute("slash")) {
         const slash: string = graceNode.attribute("slash").value;
         if (slash === "yes") {
-          note.GraceNoteSlash = true;
+          graceNoteSlash = true;
         }
       }
     }
@@ -588,7 +591,7 @@ export class VoiceGenerator {
     let graceVoiceEntry: VoiceEntry = undefined;
     if (!graceChord) {
       graceVoiceEntry = new VoiceEntry(
-        new Fraction(0, 1), this.currentVoiceEntry.ParentVoice, this.currentStaffEntry, true
+        new Fraction(0, 1), this.currentVoiceEntry.ParentVoice, this.currentStaffEntry, true, graceNoteSlash
       );
       if (this.currentVoiceEntry.graceVoiceEntriesBefore === undefined) {
         this.currentVoiceEntry.graceVoiceEntriesBefore = [];

+ 0 - 7
src/MusicalScore/VoiceData/Note.ts

@@ -42,15 +42,8 @@ export class Note {
     private tuplet: Tuplet;
     private tie: Tie;
     private slurs: Slur[] = [];
-    private graceNoteSlash: boolean = false;
     private playbackInstrumentId: string = undefined;
 
-    public get GraceNoteSlash(): boolean {
-        return this.graceNoteSlash;
-    }
-    public set GraceNoteSlash(value: boolean) {
-        this.graceNoteSlash = value;
-    }
     public get ParentVoiceEntry(): VoiceEntry {
         return this.voiceEntry;
     }

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

@@ -21,12 +21,15 @@ export class VoiceEntry {
      * @param parentVoice
      * @param parentSourceStaffEntry
      * @param isGrace States whether the VoiceEntry has (only) grace notes.
+     * @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) {
+    constructor(timestamp: Fraction, parentVoice: Voice, parentSourceStaffEntry: SourceStaffEntry,
+                isGrace: boolean = false, graceNoteSlash: boolean = false) {
         this.timestamp = timestamp;
         this.parentVoice = parentVoice;
         this.parentSourceStaffEntry = parentSourceStaffEntry;
         this.isGrace = isGrace;
+        this.graceNoteSlash = graceNoteSlash;
     }
 
     public graceVoiceEntriesBefore: VoiceEntry[];
@@ -37,6 +40,7 @@ export class VoiceEntry {
     private timestamp: Fraction;
     private notes: Note[] = [];
     private isGrace: boolean;
+    private graceNoteSlash: boolean;
     private articulations: ArticulationEnum[] = [];
     private technicalInstructions: TechnicalInstruction[] = [];
     private lyricsEntries: Dictionary<number, LyricsEntry> = new Dictionary<number, LyricsEntry>();
@@ -65,6 +69,12 @@ export class VoiceEntry {
     public set IsGrace(value: boolean) {
         this.isGrace = value;
     }
+    public get GraceNoteSlash(): boolean {
+        return this.graceNoteSlash;
+    }
+    public set GraceNoteSlash(value: boolean) {
+        this.graceNoteSlash = value;
+    }
     public get Articulations(): ArticulationEnum[] {
         return this.articulations;
     }