浏览代码

Merge pull request #750 from opensheetmusicdisplay/fix/ChordSymbols

Merge branch Fix/chord symbols
Simon 5 年之前
父节点
当前提交
66f020a3c1

+ 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);
     }
 }

+ 29 - 27
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,54 +32,58 @@ 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;
+
         if (MusicSheetCalculator.transposeCalculator !== undefined) {
             transposedRootPitch = MusicSheetCalculator.transposeCalculator.transposePitch(
                 chordSymbol.RootPitch,
-                chordSymbol.KeyInstruction,
+                keyInstruction,
                 transposeHalftones
             );
         }
+        // main Note
         let text: string = Pitch.getNoteEnumString(transposedRootPitch.FundamentalNote);
+        // main alteration
         if (transposedRootPitch.Accidental !== AccidentalEnum.NONE) {
             text += this.getTextForAccidental(transposedRootPitch.Accidental);
         }
+        // chord kind text
         text += ChordSymbolContainer.getTextFromChordKindEnum(chordSymbol.ChordKind);
-        if (chordSymbol.BassPitch !== undefined) {
-            let transposedBassPitch: Pitch = chordSymbol.BassPitch;
-            if (MusicSheetCalculator.transposeCalculator !== undefined) {
-                transposedBassPitch = MusicSheetCalculator.transposeCalculator.transposePitch(
-                    chordSymbol.BassPitch,
-                    chordSymbol.KeyInstruction,
-                    transposeHalftones
-                );
-            }
-            text += "/";
-            text += Pitch.getNoteEnumString(transposedBassPitch.FundamentalNote);
-            text += this.getTextForAccidental(transposedBassPitch.Accidental);
-        }
+        // degree
         if (chordSymbol.ChordDegree !== undefined) {
             switch (chordSymbol.ChordDegree.text) {
                 case ChordDegreeText.add:
                     text += "add";
+                    text += chordSymbol.ChordDegree.value.toString();
                     break;
                 case ChordDegreeText.alter:
-                    text += "alt";
+                    if (chordSymbol.ChordDegree.alteration !== AccidentalEnum.NONE) {
+                        text += this.getTextForAccidental(chordSymbol.ChordDegree.alteration);
+                    }
+                    text += chordSymbol.ChordDegree.value.toString();
                     break;
                 case ChordDegreeText.subtract:
-                    text += "sub";
+                    text += "(omit";
+                    text += chordSymbol.ChordDegree.value.toString();
+                    text += ")";
                     break;
                 default:
             }
-            text += chordSymbol.ChordDegree.value;
-            if (chordSymbol.ChordDegree.alteration !== AccidentalEnum.NONE) {
-                text += ChordSymbolContainer.getTextForAccidental(chordSymbol.ChordDegree.alteration);
+        }
+        // bass
+        if (chordSymbol.BassPitch !== undefined) {
+            let transposedBassPitch: Pitch = chordSymbol.BassPitch;
+            if (MusicSheetCalculator.transposeCalculator !== undefined) {
+                transposedBassPitch = MusicSheetCalculator.transposeCalculator.transposePitch(
+                    chordSymbol.BassPitch,
+                    keyInstruction,
+                    transposeHalftones
+                );
             }
+            text += "/";
+            text += Pitch.getNoteEnumString(transposedBassPitch.FundamentalNote);
+            text += this.getTextForAccidental(transposedBassPitch.Accidental);
         }
         return text;
     }