Bläddra i källkod

fix GraphicalNoteFromNote not working (#660, 659)

sschmid 4 år sedan
förälder
incheckning
2fa82b29c5

+ 1 - 0
src/MusicalScore/Graphical/EngravingRules.ts

@@ -565,6 +565,7 @@ export class EngravingRules {
         this.SpacingBetweenTextLines = 0;
 
         this.NoteToGraphicalNoteMap = new Dictionary<number, GraphicalNote>();
+        this.NoteToGraphicalNoteMapObjectCount = 0;
 
         // this.populateDictionaries(); // these values aren't used currently
         try {

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

@@ -15,7 +15,7 @@ import { EngravingRules } from "./EngravingRules";
  * The graphical counterpart of a [[Note]]
  */
 export class GraphicalNote extends GraphicalObject {
-    constructor(note: Note, parent: GraphicalVoiceEntry, graphicalNoteLength: Fraction = undefined) {
+    constructor(note: Note, parent: GraphicalVoiceEntry, rules: EngravingRules, graphicalNoteLength: Fraction = undefined) {
         super();
         this.sourceNote = note;
         this.parentVoiceEntry = parent;
@@ -27,6 +27,8 @@ export class GraphicalNote extends GraphicalObject {
         }
 
         this.numberOfDots = this.calculateNumberOfNeededDots(this.graphicalNoteLength);
+        this.rules = rules;
+        this.rules.addGraphicalNoteToNoteMap(note, this);
     }
 
     public sourceNote: Note;

+ 1 - 0
src/MusicalScore/Graphical/MusicSheetCalculator.ts

@@ -114,6 +114,7 @@ export abstract class MusicSheetCalculator {
     public initialize(graphicalMusicSheet: GraphicalMusicSheet): void {
         this.graphicalMusicSheet = graphicalMusicSheet;
         this.rules = graphicalMusicSheet.ParentMusicSheet.Rules;
+        this.rules.clearMusicSheetObjects();
         this.prepareGraphicalMusicSheet();
         //this.calculate();
     }

+ 1 - 3
src/MusicalScore/Graphical/VexFlow/VexFlowGraphicalNote.ts

@@ -17,10 +17,9 @@ export class VexFlowGraphicalNote extends GraphicalNote {
     constructor(note: Note, parent: GraphicalVoiceEntry, activeClef: ClefInstruction,
                 octaveShift: OctaveEnum = OctaveEnum.NONE, rules: EngravingRules,
                 graphicalNoteLength: Fraction = undefined) {
-        super(note, parent, graphicalNoteLength);
+        super(note, parent, rules, graphicalNoteLength);
         this.clef = activeClef;
         this.octaveShift = octaveShift;
-        this.rules = rules;
         if (note.Pitch) {
             // TODO: Maybe shift to Transpose function when available
             const drawPitch: Pitch = note.isRest() ? note.Pitch : OctaveShift.getPitchFromOctaveShift(note.Pitch, octaveShift);
@@ -36,7 +35,6 @@ export class VexFlowGraphicalNote extends GraphicalNote {
     public vfnote: [Vex.Flow.StemmableNote, number];
     // The current clef
     private clef: ClefInstruction;
-    public rules: EngravingRules;
 
     /**
      * Update the pitch of this note. Necessary in order to display accidentals correctly.

+ 0 - 1
src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.ts

@@ -191,7 +191,6 @@ export class OpenSheetMusicDisplay {
         this.drawer?.clear(); // clear canvas before setting width
         // this.graphic.GetCalculator.clearSystemsAndMeasures(); // maybe?
         // this.graphic.GetCalculator.clearRecreatedObjects();
-        this.rules.clearObjects();
 
         // Set page width
         let width: number = this.container.offsetWidth;