فهرست منبع

fix: improved chord symbol text output and fixed transposing code.

Matthias Uiberacker 5 سال پیش
والد
کامیت
de2ef57c27
1فایلهای تغییر یافته به همراه34 افزوده شده و 19 حذف شده
  1. 34 19
      src/MusicalScore/VoiceData/ChordSymbolContainer.ts

+ 34 - 19
src/MusicalScore/VoiceData/ChordSymbolContainer.ts

@@ -40,48 +40,63 @@ export class ChordSymbolContainer {
 
     public static calculateChordText(chordSymbol: ChordSymbolContainer, transposeHalftones: number): 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,
-                chordSymbol.KeyInstruction,
+                transposedChordKey,
                 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,
+                    transposedChordKey,
+                    transposeHalftones
+                );
             }
+            text += "/";
+            text += Pitch.getNoteEnumString(transposedBassPitch.FundamentalNote);
+            text += this.getTextForAccidental(transposedBassPitch.Accidental);
         }
         return text;
     }