<commit_before>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
}
<commit_msg>fix(ChordSymbols): add 5 for power chord (e.g. C5, C plus fifth) (#760)<commit_after>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:
                text += "5";
                break;
            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
}

{'fraction_non_alphanumeric': 0.08232246651503665, 'fraction_numerical': 0.006696992671215567, 'mean_word_length': 1.5149348585954878, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2396826', 'n_tokens_mistral': 4489, 'n_tokens_neox': 4160, 'n_words': 828}