Browse Source

feat(SourceMeasure): add reference to instance of engraving rules

Daniel Fürst 5 years ago
parent
commit
1361aca30e

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

@@ -18,7 +18,7 @@ export class GraphicalLyricEntry {
     constructor(lyricsEntry: LyricsEntry, graphicalStaffEntry: GraphicalStaffEntry, lyricsHeight: number, staffHeight: number) {
         this.lyricsEntry = lyricsEntry;
         this.graphicalStaffEntry = graphicalStaffEntry;
-        const lyricsTextAlignment: TextAlignmentEnum = graphicalStaffEntry.parentMeasure.parentMusicSystem.rules.LyricsAlignmentStandard;
+        const lyricsTextAlignment: TextAlignmentEnum = graphicalStaffEntry.parentMeasure.parentSourceMeasure.Rules.LyricsAlignmentStandard;
         // for small notes with long text, use center alignment
         // TODO use this, fix center+left alignment combination spacing
         if (lyricsEntry.Text.length >= 4

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

@@ -20,7 +20,7 @@ export class GraphicalVoiceEntry extends GraphicalObject {
         this.parentStaffEntry = parentStaffEntry;
         this.PositionAndShape = new BoundingBox(this, parentStaffEntry ? parentStaffEntry.PositionAndShape : undefined, true);
         this.notes = [];
-        this.rules = parentStaffEntry.parentMeasure.parentMusicSystem.rules;
+        this.rules = parentStaffEntry.parentMeasure.parentSourceMeasure.Rules;
     }
 
     public parentVoiceEntry: VoiceEntry;

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

@@ -166,7 +166,7 @@ export class VexFlowConverter {
         } */
         // VexFlow needs the notes ordered vertically in the other direction:
         const notes: GraphicalNote[] = gve.notes.reverse();
-        const rules: EngravingRules = gve.parentStaffEntry.parentMeasure.parentMusicSystem.rules;
+        const rules: EngravingRules = gve.parentStaffEntry.parentMeasure.parentSourceMeasure.Rules;
 
         const baseNote: GraphicalNote = notes[0];
         let keys: string[] = [];

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

@@ -156,7 +156,7 @@ export class VexFlowGraphicalSymbolFactory implements IGraphicalSymbolFactory {
      * @param transposeHalftones
      */
     public createChordSymbols(sourceStaffEntry: SourceStaffEntry, graphicalStaffEntry: GraphicalStaffEntry, transposeHalftones: number): void {
-        const rules: EngravingRules = graphicalStaffEntry.parentMeasure.parentMusicSystem.rules;
+        const rules: EngravingRules = graphicalStaffEntry.parentMeasure.parentSourceMeasure.Rules;
         let xShift: number = 0;
         const chordSymbolSpacing: number = rules.ChordSymbolXSpacing;
         for (const chordSymbolContainer of sourceStaffEntry.ChordContainers) {

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

@@ -39,7 +39,7 @@ export class VexFlowStaffEntry extends GraphicalStaffEntry {
                     // whole rest: length = measure length. (4/4 in a 4/4 time signature, 3/4 in a 3/4 time signature, 1/4 in a 1/4 time signature, etc.)
                     // see Note.isWholeRest(), which is currently not safe
                     this.PositionAndShape.RelativePosition.x +=
-                        this.staffEntryParent.parentMeasure.parentMusicSystem.rules.WholeRestXShiftVexflow - 0.1; // xShift from VexFlowConverter
+                        this.staffEntryParent.parentMeasure.parentSourceMeasure.Rules.WholeRestXShiftVexflow - 0.1; // xShift from VexFlowConverter
                     gve.PositionAndShape.BorderLeft = -0.7;
                     gve.PositionAndShape.BorderRight = 0.7;
                 }

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

@@ -146,7 +146,7 @@ export class MusicSheetReader /*implements IMusicSheetReader*/ {
             if (this.currentMeasure !== undefined && this.currentMeasure.endsPiece) {
                 sourceMeasureCounter = 0;
             }
-            this.currentMeasure = new SourceMeasure(this.completeNumberOfStaves);
+            this.currentMeasure = new SourceMeasure(this.completeNumberOfStaves, this.musicSheet.Rules);
             for (const instrumentReader of instrumentReaders) {
                 try {
                     couldReadMeasure = couldReadMeasure && instrumentReader.readNextXmlMeasure(this.currentMeasure, this.currentFraction, guitarPro);

+ 9 - 2
src/MusicalScore/VoiceData/SourceMeasure.ts

@@ -11,7 +11,7 @@ import {MultiTempoExpression} from "./Expressions/MultiTempoExpression";
 import {KeyInstruction} from "./Instructions/KeyInstruction";
 import {AbstractNotationInstruction} from "./Instructions/AbstractNotationInstruction";
 import {Repetition} from "../MusicSource/Repetition";
-import {GraphicalMeasure, SystemLinesEnum} from "../Graphical";
+import {GraphicalMeasure, SystemLinesEnum, EngravingRules} from "../Graphical";
 //import {BaseIdClass} from "../../Util/BaseIdClass"; // SourceMeasure originally extended BaseIdClass, but ids weren't used.
 
 /**
@@ -24,7 +24,7 @@ export class SourceMeasure {
      * so that existing objects can be referred to by staff index.
      * @param completeNumberOfStaves
      */
-    constructor(completeNumberOfStaves: number) {
+    constructor(completeNumberOfStaves: number, rules: EngravingRules) {
         this.completeNumberOfStaves = completeNumberOfStaves;
         this.implicitMeasure = false;
         this.breakSystemAfter = false;
@@ -33,6 +33,7 @@ export class SourceMeasure {
         this.endingBarStyleEnum = SystemLinesEnum.SingleThin;
         this.firstInstructionsStaffEntries = new Array(completeNumberOfStaves);
         this.lastInstructionsStaffEntries = new Array(completeNumberOfStaves);
+        this.rules = rules;
         this.TempoInBPM = 0;
         for (let i: number = 0; i < completeNumberOfStaves; i++) {
             this.graphicalMeasureErrors.push(false);
@@ -69,6 +70,7 @@ export class SourceMeasure {
     private lastInstructionsStaffEntries: SourceStaffEntry[];
     private firstRepetitionInstructions: RepetitionInstruction[] = [];
     private lastRepetitionInstructions: RepetitionInstruction[] = [];
+    private rules: EngravingRules;
     private tempoInBPM: number;
     private verticalMeasureList: GraphicalMeasure[]; // useful, see GraphicalMusicSheet.GetGraphicalFromSourceStaffEntry
 
@@ -171,6 +173,10 @@ export class SourceMeasure {
         return undefined;
     }
 
+    public get Rules(): EngravingRules {
+        return this.rules;
+    }
+
     public get VerticalMeasureList(): GraphicalMeasure[] {
         return this.verticalMeasureList;
     }
@@ -186,6 +192,7 @@ export class SourceMeasure {
     public set TempoInBPM(value: number) {
         this.tempoInBPM = value;
     }
+
     /**
      * Check at the given timestamp if a VerticalContainer exists, if not creates a new, timestamp-ordered one,
      * and at the given index, if a [[SourceStaffEntry]] exists, and if not, creates a new one.

+ 2 - 2
test/MusicalScore/Graphical/VexFlow/VexFlowMeasure_Test.ts

@@ -28,7 +28,7 @@ describe("VexFlow Measure", () => {
 
    it.skip("Simple Measure", (done: MochaDone) => {
       const sheet: MusicSheet = new MusicSheet();
-      const measure: SourceMeasure = new SourceMeasure(1);
+      const measure: SourceMeasure = new SourceMeasure(1, sheet.Rules);
       sheet.addMeasure(measure);
       const calc: MusicSheetCalculator = new VexFlowMusicSheetCalculator();
       const gms: GraphicalMusicSheet = new GraphicalMusicSheet(sheet, calc);
@@ -41,7 +41,7 @@ describe("VexFlow Measure", () => {
 
    it.skip("Empty Measure", (done: MochaDone) => {
       const sheet: MusicSheet = new MusicSheet();
-      const measure: SourceMeasure = new SourceMeasure(1);
+      const measure: SourceMeasure = new SourceMeasure(1, sheet.Rules);
       measure.FirstInstructionsStaffEntries[0] = new SourceStaffEntry(undefined, undefined);
       sheet.addMeasure(measure);
       const calc: MusicSheetCalculator = new VexFlowMusicSheetCalculator();