Просмотр исходного кода

cherry-picked refactor/isGrace branches onto develop (isGrace branch was accidentally based on feature/expressions)
#56

sschmidTU 7 лет назад
Родитель
Сommit
ea521f9f0d

+ 1 - 1
src/MusicalScore/Graphical/AccidentalCalculator.ts

@@ -56,7 +56,7 @@ export class AccidentalCalculator {
         ) {
             this.currentAlterationsComparedToKeyInstructionList.splice(this.currentAlterationsComparedToKeyInstructionList.indexOf(pitchKey), 1);
             this.currentInMeasureNoteAlterationsDict.setValue(pitchKey, pitch.Accidental);
-            this.symbolFactory.addGraphicalAccidental(graphicalNote, pitch, grace, graceScalingFactor);
+            this.symbolFactory.addGraphicalAccidental(graphicalNote, pitch);
         }*/
 
         const isInCurrentAlterationsToKeyList: boolean = this.currentAlterationsComparedToKeyInstructionList.indexOf(pitchKey) >= 0;

+ 3 - 1
src/MusicalScore/Graphical/GraphicalVoiceEntry.ts

@@ -8,15 +8,17 @@ import { GraphicalStaffEntry } from "./GraphicalStaffEntry";
  * The graphical counterpart of a [[VoiceEntry]].
  */
 export class GraphicalVoiceEntry extends GraphicalObject {
-    constructor(parentVoiceEntry: VoiceEntry, parentStaffEntry: GraphicalStaffEntry) {
+    constructor(parentVoiceEntry: VoiceEntry, parentStaffEntry: GraphicalStaffEntry, isGrace: boolean = false) {
         super();
         this.parentVoiceEntry = parentVoiceEntry;
         this.parentStaffEntry = parentStaffEntry;
         this.PositionAndShape = new BoundingBox(this, parentStaffEntry ? parentStaffEntry.PositionAndShape : undefined);
         this.notes = [];
+        this.isGrace = isGrace;
     }
 
     public parentVoiceEntry: VoiceEntry;
     public parentStaffEntry: GraphicalStaffEntry;
     public notes: GraphicalNote[];
+    public isGrace: boolean;
 }

+ 8 - 9
src/MusicalScore/Graphical/MusicSheetCalculator.ts

@@ -288,7 +288,7 @@ export abstract class MusicSheetCalculator {
     }
 
     protected layoutVoiceEntry(voiceEntry: VoiceEntry, graphicalNotes: GraphicalNote[],
-                               graphicalStaffEntry: GraphicalStaffEntry, hasPitchedNote: boolean, isGraceStaffEntry: boolean): void {
+                               graphicalStaffEntry: GraphicalStaffEntry, hasPitchedNote: boolean): void {
         throw new Error("abstract, not implemented");
     }
 
@@ -907,7 +907,7 @@ export abstract class MusicSheetCalculator {
                                accidentalCalculator: AccidentalCalculator, openLyricWords: LyricWord[],
                                activeClef: ClefInstruction,
                                openTuplets: Tuplet[], openBeams: Beam[],
-                               octaveShiftValue: OctaveEnum, grace: boolean = false, linkedNotes: Note[] = undefined,
+                               octaveShiftValue: OctaveEnum, linkedNotes: Note[] = undefined,
                                sourceStaffEntry: SourceStaffEntry = undefined): OctaveEnum {
         this.calculateStemDirectionFromVoices(voiceEntry);
         const gve: GraphicalVoiceEntry = graphicalStaffEntry.findOrCreateGraphicalVoiceEntry(voiceEntry);
@@ -917,13 +917,13 @@ export abstract class MusicSheetCalculator {
                 continue;
             }
             let graphicalNote: GraphicalNote;
-            if (grace) {
+            if (voiceEntry.IsGrace) {
                 graphicalNote = MusicSheetCalculator.symbolFactory.createGraceNote(note, gve, activeClef, octaveShiftValue);
             } else {
                 graphicalNote = MusicSheetCalculator.symbolFactory.createNote(note, gve, activeClef, octaveShiftValue, undefined);
             }
             if (note.Pitch !== undefined) {
-                this.checkNoteForAccidental(graphicalNote, accidentalCalculator, activeClef, octaveShiftValue, grace);
+                this.checkNoteForAccidental(graphicalNote, accidentalCalculator, activeClef, octaveShiftValue);
             }
             this.resetYPositionForLeadSheet(graphicalNote.PositionAndShape);
             graphicalStaffEntry.addGraphicalNoteToListAtCorrectYPosition(gve, graphicalNote);
@@ -967,7 +967,7 @@ export abstract class MusicSheetCalculator {
                 this.handleVoiceEntry(
                     graceVoiceEntry, graceStaffEntry, accidentalCalculator, lyricWords,
                     activeClef, tuplets,
-                    beams, octaveShiftValue, true
+                    beams, octaveShiftValue
                 );
             }
         }
@@ -982,7 +982,6 @@ export abstract class MusicSheetCalculator {
     protected layoutVoiceEntries(graphicalStaffEntry: GraphicalStaffEntry): void {
         graphicalStaffEntry.PositionAndShape.RelativePosition = new PointF2D(0.0, 0.0);
         if (!this.leadSheet) {
-            const isGraceStaffEntry: boolean = graphicalStaffEntry.staffEntryParent !== undefined;
             for (const gve of graphicalStaffEntry.graphicalVoiceEntries) {
                 const graphicalNotes: GraphicalNote[] = gve.notes;
                 if (graphicalNotes.length === 0) {
@@ -990,7 +989,7 @@ export abstract class MusicSheetCalculator {
                 }
                 const voiceEntry: VoiceEntry = graphicalNotes[0].sourceNote.ParentVoiceEntry;
                 const hasPitchedNote: boolean = graphicalNotes[0].sourceNote.Pitch !== undefined;
-                this.layoutVoiceEntry(voiceEntry, graphicalNotes, graphicalStaffEntry, hasPitchedNote, isGraceStaffEntry);
+                this.layoutVoiceEntry(voiceEntry, graphicalNotes, graphicalStaffEntry, hasPitchedNote);
             }
         }
     }
@@ -1382,7 +1381,7 @@ export abstract class MusicSheetCalculator {
                         voiceEntry, graphicalStaffEntry,
                         accidentalCalculator, openLyricWords,
                         activeClefs[staffIndex], openTuplets,
-                        openBeams, octaveShiftValue, false, linkedNotes,
+                        openBeams, octaveShiftValue, linkedNotes,
                         sourceStaffEntry
                     );
                     this.handleVoiceEntryGraceNotes(
@@ -1447,7 +1446,7 @@ export abstract class MusicSheetCalculator {
     }
 
     private checkNoteForAccidental(graphicalNote: GraphicalNote, accidentalCalculator: AccidentalCalculator, activeClef: ClefInstruction,
-                                   octaveEnum: OctaveEnum, grace: boolean = false): void {
+                                   octaveEnum: OctaveEnum): void {
         let pitch: Pitch = graphicalNote.sourceNote.Pitch;
         const transpose: number = this.graphicalMusicSheet.ParentMusicSheet.Transpose;
         if (transpose !== 0 && graphicalNote.sourceNote.ParentStaffEntry.ParentStaff.ParentInstrument.MidiInstrumentId !== MidiInstrument.Percussion) {

+ 1 - 1
src/MusicalScore/Graphical/VexFlow/VexFlowGraphicalSymbolFactory.ts

@@ -80,7 +80,7 @@ export class VexFlowGraphicalSymbolFactory implements IGraphicalSymbolFactory {
     /**
      * Create an empty staffEntry which will be used for grace notes.
      * it will be linked to the given staffEntryParent, which is a staffEntry for normal notes.
-     * Grace notes are always given before (rarely also after) normal notes.
+     * Grace notes are almost always given before (rarely also after) normal notes.
      * @param staffEntryParent
      * @param measure
      * @returns {VexFlowStaffEntry}

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

@@ -149,10 +149,9 @@ export class VexFlowMusicSheetCalculator extends MusicSheetCalculator {
    * @param graphicalNotes
    * @param graphicalStaffEntry
    * @param hasPitchedNote
-   * @param isGraceStaffEntry
    */
   protected layoutVoiceEntry(voiceEntry: VoiceEntry, graphicalNotes: GraphicalNote[], graphicalStaffEntry: GraphicalStaffEntry,
-                             hasPitchedNote: boolean, isGraceStaffEntry: boolean): void {
+                             hasPitchedNote: boolean): void {
     return;
   }
 

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

@@ -588,7 +588,7 @@ export class VoiceGenerator {
     let graceVoiceEntry: VoiceEntry = undefined;
     if (!graceChord) {
       graceVoiceEntry = new VoiceEntry(
-        new Fraction(0, 1), this.currentVoiceEntry.ParentVoice, this.currentStaffEntry
+        new Fraction(0, 1), this.currentVoiceEntry.ParentVoice, this.currentStaffEntry, true
       );
       if (this.currentVoiceEntry.graceVoiceEntriesBefore === undefined) {
         this.currentVoiceEntry.graceVoiceEntriesBefore = [];

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

@@ -17,14 +17,16 @@ import Dictionary from "typescript-collections/dist/lib/Dictionary";
 export class VoiceEntry {
     /**
      *
-     * @param timestamp - The relative timestamp within the source measure.
+     * @param timestamp The relative timestamp within the source measure.
      * @param parentVoice
      * @param parentSourceStaffEntry
+     * @param isGrace States whether the VoiceEntry has (only) grace notes.
      */
-    constructor(timestamp: Fraction, parentVoice: Voice, parentSourceStaffEntry: SourceStaffEntry) {
+    constructor(timestamp: Fraction, parentVoice: Voice, parentSourceStaffEntry: SourceStaffEntry, isGrace: boolean = false) {
         this.timestamp = timestamp;
         this.parentVoice = parentVoice;
         this.parentSourceStaffEntry = parentSourceStaffEntry;
+        this.isGrace = isGrace;
     }
 
     public graceVoiceEntriesBefore: VoiceEntry[];
@@ -34,6 +36,7 @@ export class VoiceEntry {
     private parentSourceStaffEntry: SourceStaffEntry;
     private timestamp: Fraction;
     private notes: Note[] = [];
+    private isGrace: boolean;
     private articulations: ArticulationEnum[] = [];
     private technicalInstructions: TechnicalInstruction[] = [];
     private lyricsEntries: Dictionary<number, LyricsEntry> = new Dictionary<number, LyricsEntry>();
@@ -56,6 +59,12 @@ export class VoiceEntry {
     public get Notes(): Note[] {
         return this.notes;
     }
+    public get IsGrace(): boolean {
+        return this.isGrace;
+    }
+    public set IsGrace(value: boolean) {
+        this.isGrace = value;
+    }
     public get Articulations(): ArticulationEnum[] {
         return this.articulations;
     }