Forráskód Böngészése

refactor: removed key signature reference in chord symbol container - we need to get the actual (possibly transposed) key signature directly when creating the chord text.

Matthias Uiberacker 5 éve
szülő
commit
b65703b317

+ 6 - 6
src/MusicalScore/Graphical/GraphicalChordSymbolContainer.ts

@@ -6,6 +6,7 @@ import {BoundingBox} from "./BoundingBox";
 import {GraphicalObject} from "./GraphicalObject";
 import {PointF2D} from "../../Common/DataObjects/PointF2D";
 import {EngravingRules} from "./EngravingRules";
+import { KeyInstruction } from "../VoiceData/Instructions/KeyInstruction";
 
 export class GraphicalChordSymbolContainer extends GraphicalObject {
     private chordSymbolContainer: ChordSymbolContainer;
@@ -13,11 +14,11 @@ export class GraphicalChordSymbolContainer extends GraphicalObject {
     private rules: EngravingRules;
 
     constructor(chordSymbolContainer: ChordSymbolContainer, parent: BoundingBox, textHeight: number,
-                transposeHalftones: number, rules: EngravingRules) {
+                keyInstruction: KeyInstruction, transposeHalftones: number, rules: EngravingRules) {
         super();
         this.chordSymbolContainer = chordSymbolContainer;
         this.boundingBox = new BoundingBox(this, parent);
-        this.calculateLabel(textHeight, transposeHalftones);
+        this.calculateLabel(textHeight, transposeHalftones, keyInstruction);
         this.rules = rules;
     }
     public get GetChordSymbolContainer(): ChordSymbolContainer {
@@ -26,10 +27,9 @@ export class GraphicalChordSymbolContainer extends GraphicalObject {
     public get GetGraphicalLabel(): GraphicalLabel {
         return this.graphicalLabel;
     }
-    private calculateLabel(textHeight: number, transposeHalftones: number): void {
-        const text: string = ChordSymbolContainer.calculateChordText(this.chordSymbolContainer, transposeHalftones);
-        const label: Label = new Label(text);
-        this.graphicalLabel = new GraphicalLabel(label, textHeight, TextAlignmentEnum.CenterBottom, this.rules, this.boundingBox);
+    private calculateLabel(textHeight: number, transposeHalftones: number, keyInstruction: KeyInstruction): void {
+        const text: string = ChordSymbolContainer.calculateChordText(this.chordSymbolContainer, transposeHalftones, keyInstruction);
+        this.graphicalLabel = new GraphicalLabel(new Label(text), textHeight, TextAlignmentEnum.CenterBottom, this.rules, this.boundingBox);
         this.graphicalLabel.PositionAndShape.RelativePosition = new PointF2D(0.0, 0.0);
     }
 }

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

@@ -2019,6 +2019,7 @@ export abstract class MusicSheetCalculator {
                     MusicSheetCalculator.symbolFactory.createChordSymbols(
                         sourceStaffEntry,
                         graphicalStaffEntry,
+                        accidentalCalculator.ActiveKeyInstruction,
                         this.graphicalMusicSheet.ParentMusicSheet.Transpose);
                 }
             }

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

@@ -27,6 +27,7 @@ import { VexFlowVoiceEntry } from "./VexFlowVoiceEntry";
 import { VexFlowConverter } from "./VexFlowConverter";
 import { VexFlowTabMeasure } from "./VexFlowTabMeasure";
 import { VexFlowStaffLine } from "./VexFlowStaffLine";
+import { KeyInstruction } from "../../VoiceData/Instructions/KeyInstruction";
 
 export class VexFlowGraphicalSymbolFactory implements IGraphicalSymbolFactory {
     /**
@@ -165,7 +166,10 @@ export class VexFlowGraphicalSymbolFactory implements IGraphicalSymbolFactory {
      * @param graphicalStaffEntry
      * @param transposeHalftones
      */
-    public createChordSymbols(sourceStaffEntry: SourceStaffEntry, graphicalStaffEntry: GraphicalStaffEntry, transposeHalftones: number): void {
+    public createChordSymbols(  sourceStaffEntry: SourceStaffEntry,
+                                graphicalStaffEntry: GraphicalStaffEntry,
+                                keyInstruction: KeyInstruction,
+                                transposeHalftones: number): void {
         const rules: EngravingRules = graphicalStaffEntry.parentMeasure.parentSourceMeasure.Rules;
         let xShift: number = 0;
         const chordSymbolSpacing: number = rules.ChordSymbolXSpacing;
@@ -174,6 +178,7 @@ export class VexFlowGraphicalSymbolFactory implements IGraphicalSymbolFactory {
               new GraphicalChordSymbolContainer(chordSymbolContainer,
                                                 graphicalStaffEntry.PositionAndShape,
                                                 rules.ChordSymbolTextHeight,
+                                                keyInstruction,
                                                 transposeHalftones,
                                                 graphicalStaffEntry.parentMeasure.parentSourceMeasure.Rules // TODO undefined sometimes
                                                 );

+ 2 - 0
src/MusicalScore/Interfaces/IGraphicalSymbolFactory.ts

@@ -15,6 +15,7 @@ import { TechnicalInstruction } from "../VoiceData/Instructions/TechnicalInstruc
 import { GraphicalVoiceEntry } from "../Graphical/GraphicalVoiceEntry";
 import { VoiceEntry } from "../VoiceData/VoiceEntry";
 import { EngravingRules } from "../Graphical/EngravingRules";
+import { KeyInstruction } from "../VoiceData";
 
 export interface IGraphicalSymbolFactory {
 
@@ -59,5 +60,6 @@ export interface IGraphicalSymbolFactory {
     createChordSymbols(
         sourceStaffEntry: SourceStaffEntry,
         graphicalStaffEntry: GraphicalStaffEntry,
+        keyInstruction: KeyInstruction,
         transposeHalftones: number): void;
 }

+ 1 - 1
src/MusicalScore/ScoreIO/MusicSymbolModules/ChordSymbolReader.ts

@@ -151,6 +151,6 @@ export class ChordSymbolReader {
 
             degree = new Degree(value, alter, text);
         }
-        return new ChordSymbolContainer(rootPitch, chordKind, bassPitch, degree, activeKey);
+        return new ChordSymbolContainer(rootPitch, chordKind, bassPitch, degree);
     }
 }

+ 4 - 17
src/MusicalScore/VoiceData/ChordSymbolContainer.ts

@@ -8,12 +8,10 @@ export class ChordSymbolContainer {
     private chordKind: ChordSymbolEnum;
     private bassPitch: Pitch;
     private degree: Degree;
-    private keyInstruction: KeyInstruction;
 
-    constructor(rootPitch: Pitch, chordKind: ChordSymbolEnum, bassPitch: Pitch, chordDegree: Degree, keyInstruction: KeyInstruction) {
+    constructor(rootPitch: Pitch, chordKind: ChordSymbolEnum, bassPitch: Pitch, chordDegree: Degree) {
         this.rootPitch = rootPitch;
         this.chordKind = chordKind;
-        this.keyInstruction = keyInstruction;
         this.bassPitch = bassPitch;
         this.degree = chordDegree;
     }
@@ -34,24 +32,13 @@ export class ChordSymbolContainer {
         return this.degree;
     }
 
-    public get KeyInstruction(): KeyInstruction {
-        return this.keyInstruction;
-    }
-
-    public static calculateChordText(chordSymbol: ChordSymbolContainer, transposeHalftones: number): string {
+    public static calculateChordText(chordSymbol: ChordSymbolContainer, transposeHalftones: number, keyInstruction: KeyInstruction): string {
         let transposedRootPitch: Pitch = chordSymbol.RootPitch;
 
-        // create a copy of the key instruction (for transposing it):
-        const transposedChordKey: KeyInstruction  = new KeyInstruction( chordSymbol.keyInstruction.Parent,
-                                                                        chordSymbol.keyInstruction.Key,
-                                                                        chordSymbol.keyInstruction.Mode);
         if (MusicSheetCalculator.transposeCalculator !== undefined) {
-            // first transpose the current key instruction
-            MusicSheetCalculator.transposeCalculator.transposeKey(transposedChordKey, transposeHalftones);
-            // then the pitch
             transposedRootPitch = MusicSheetCalculator.transposeCalculator.transposePitch(
                 chordSymbol.RootPitch,
-                transposedChordKey,
+                keyInstruction,
                 transposeHalftones
             );
         }
@@ -90,7 +77,7 @@ export class ChordSymbolContainer {
             if (MusicSheetCalculator.transposeCalculator !== undefined) {
                 transposedBassPitch = MusicSheetCalculator.transposeCalculator.transposePitch(
                     chordSymbol.BassPitch,
-                    transposedChordKey,
+                    keyInstruction,
                     transposeHalftones
                 );
             }