123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- import {Pitch} from "../../Common/DataObjects/Pitch";
- import {KeyInstruction} from "./Instructions/KeyInstruction";
- import {MusicSheetCalculator} from "../Graphical/MusicSheetCalculator";
- import {AccidentalEnum} from "../../Common/DataObjects/Pitch";
- export class ChordSymbolContainer {
- private rootPitch: Pitch;
- private chordKind: ChordSymbolEnum;
- private bassPitch: Pitch;
- private degree: Degree;
- constructor(rootPitch: Pitch, chordKind: ChordSymbolEnum, bassPitch: Pitch, chordDegree: Degree) {
- this.rootPitch = rootPitch;
- this.chordKind = chordKind;
- this.bassPitch = bassPitch;
- this.degree = chordDegree;
- }
- public get RootPitch(): Pitch {
- return this.rootPitch;
- }
- public get ChordKind(): ChordSymbolEnum {
- return this.chordKind;
- }
- public get BassPitch(): Pitch {
- return this.bassPitch;
- }
- public get ChordDegree(): Degree {
- return this.degree;
- }
- 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,
- 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);
- // degree
- if (chordSymbol.ChordDegree !== undefined) {
- switch (chordSymbol.ChordDegree.text) {
- case ChordDegreeText.add:
- text += "add";
- text += chordSymbol.ChordDegree.value.toString();
- break;
- case ChordDegreeText.alter:
- if (chordSymbol.ChordDegree.alteration !== AccidentalEnum.NONE) {
- text += this.getTextForAccidental(chordSymbol.ChordDegree.alteration);
- }
- text += chordSymbol.ChordDegree.value.toString();
- break;
- case ChordDegreeText.subtract:
- text += "(omit";
- text += chordSymbol.ChordDegree.value.toString();
- text += ")";
- break;
- default:
- }
- }
- // 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;
- }
- private static getTextForAccidental(alteration: AccidentalEnum): string {
- let text: string = "";
- switch (alteration) {
- case AccidentalEnum.DOUBLEFLAT:
- text += "bb";
- break;
- case AccidentalEnum.FLAT:
- text += "b";
- break;
- case AccidentalEnum.SHARP:
- text += "#";
- break;
- case AccidentalEnum.DOUBLESHARP:
- text += "x";
- break;
- default:
- }
- return text;
- }
- private static getTextFromChordKindEnum(kind: ChordSymbolEnum): string {
- let text: string = "";
- switch (kind) {
- case ChordSymbolEnum.major:
- break;
- case ChordSymbolEnum.minor:
- text += "m";
- break;
- case ChordSymbolEnum.augmented:
- text += "aug";
- break;
- case ChordSymbolEnum.diminished:
- text += "dim";
- break;
- case ChordSymbolEnum.dominant:
- text += "7";
- break;
- case ChordSymbolEnum.majorseventh:
- text += "maj7";
- break;
- case ChordSymbolEnum.minorseventh:
- text += "m7";
- break;
- case ChordSymbolEnum.diminishedseventh:
- text += "dim7";
- break;
- case ChordSymbolEnum.augmentedseventh:
- text += "aug7";
- break;
- case ChordSymbolEnum.halfdiminished:
- text += "m7b5";
- break;
- case ChordSymbolEnum.majorminor:
- text += "";
- break;
- case ChordSymbolEnum.majorsixth:
- text += "maj6";
- break;
- case ChordSymbolEnum.minorsixth:
- text += "m6";
- break;
- case ChordSymbolEnum.dominantninth:
- text += "9";
- break;
- case ChordSymbolEnum.majorninth:
- text += "maj9";
- break;
- case ChordSymbolEnum.minorninth:
- text += "m9";
- break;
- case ChordSymbolEnum.dominant11th:
- text += "11";
- break;
- case ChordSymbolEnum.major11th:
- text += "maj11";
- break;
- case ChordSymbolEnum.minor11th:
- text += "m11";
- break;
- case ChordSymbolEnum.dominant13th:
- text += "13";
- break;
- case ChordSymbolEnum.major13th:
- text += "maj13";
- break;
- case ChordSymbolEnum.minor13th:
- text += "m13";
- break;
- case ChordSymbolEnum.suspendedsecond:
- text += "sus2";
- break;
- case ChordSymbolEnum.suspendedfourth:
- text += "sus4";
- break;
- case ChordSymbolEnum.Neapolitan:
- case ChordSymbolEnum.Italian:
- case ChordSymbolEnum.French:
- case ChordSymbolEnum.German:
- case ChordSymbolEnum.pedal:
- case ChordSymbolEnum.power:
- case ChordSymbolEnum.Tristan:
- break;
- default:
- break;
- }
- return text;
- }
- }
- export class Degree {
- constructor(value: number, alteration: AccidentalEnum, text: ChordDegreeText) {
- this.value = value;
- this.alteration = alteration;
- this.text = text;
- }
- public value: number;
- public alteration: AccidentalEnum;
- public text: ChordDegreeText;
- }
- export enum ChordDegreeText {
- add,
- alter,
- subtract
- }
- export enum ChordSymbolEnum {
- major,
- minor,
- augmented,
- diminished,
- dominant,
- majorseventh,
- minorseventh,
- diminishedseventh,
- augmentedseventh,
- halfdiminished,
- majorminor,
- majorsixth,
- minorsixth,
- dominantninth,
- majorninth,
- minorninth,
- dominant11th,
- major11th,
- minor11th,
- dominant13th,
- major13th,
- minor13th,
- suspendedsecond,
- suspendedfourth,
- Neapolitan,
- Italian,
- French,
- German,
- pedal,
- power,
- Tristan
- }
|