<commit_before>class Convert {
    // example:
    // - "A4" | 440
    public static getFreq(pitch: string): number {
        return this._noteToFreq(this._keyToNote(pitch));
    }

    // copyright (c) 2014 <NAME> <<EMAIL>>
    // released under the MIT license
    // https://github.com/watilde/beeplay/blob/master/src/modules/nn.js
    //
    // example:
    // - "A4"  | 69
    // - "G#9" | "128 is not defined key at MIDI."
    private static _keyToNote(key: string): number {
        if (key === "") {
            return;
        }

        if (key.search(/^[cdefgabCDEFGAB]/) === -1) {
            throw new Error(key + " is invalid key name.");
        }

        var KEYS = [
        "c", "c#",
        "d", "d#",
        "e",
        "f", "f#",
        "g", "g#",
        "a", "a#",
        "b"
        ];
        var index = (key.indexOf("#") !== -1) ? 2 : 1;
        var keyName = key.substring(0, index).toLowerCase();
        var num = Number(key.substring(index)) + 1;
        var note = KEYS.indexOf(keyName) + 12 * num;

        if (note < 0 || note > 127) {
            throw new Error("'" + note + "'" + " is not defined key at MIDI.");
        }

        return note;
    }

    // ref:
    // example: 69 | 440
    private static _noteToFreq(note: number): number {
        if (typeof note !== "number") {
            throw new Error(note + " is not number.");
        }

        if (note < 0 || note > 127) {
            throw new Error(note + " is not defined key at MIDI.");
        }

        return 440 * Math.pow(Math.pow(2, (1 / 12)), note - 69);
    }
}

export = Convert;<commit_msg>[change] :art: code refactoring<commit_after>class Convert {
    private static KEYS: string[] = [
        "c", "c#",
        "d", "d#",
        "e",
        "f", "f#",
        "g", "g#",
        "a", "a#",
        "b"
    ];

    // example:
    // - "A4" | 440
    public static getFreq(pitch: string): number {
        return this._noteToFreq(this._keyToNote(pitch));
    }

    // copyright (c) 2014 <NAME> <<EMAIL>>
    // released under the MIT license
    // https://github.com/watilde/beeplay/blob/master/src/modules/nn.js
    //
    // example:
    // - "A4"  | 69
    // - "G#9" | "128 is not defined key at MIDI."
    private static _keyToNote(key: string): number {
        if (key === "") {
            return;
        }

        if (key.search(/^[cdefgabCDEFGAB]/) === -1) {
            throw new Error(key + " is invalid key name.");
        }

        var index = (key.indexOf("#") !== -1) ? 2 : 1;
        var keyName = key.substring(0, index).toLowerCase();
        var num = Number(key.substring(index)) + 1;
        var note = this.KEYS.indexOf(keyName) + 12 * num;

        this._isMIDIKey(note);

        return note;
    }

    // ref:
    // example: 69 | 440
    private static _noteToFreq(note: number): number {
        if (typeof note !== "number") {
            throw new Error(note + " is not number.");
        }

        this._isMIDIKey(note);

        return 440 * Math.pow(Math.pow(2, (1 / 12)), note - 69);
    }

    private static _isMIDIKey(note: number): void {
        if (note < 0 || note > 127) {
            throw new Error(note + " is not defined key at MIDI.");
        }
    }
}

export = Convert;
{'fraction_non_alphanumeric': 0.17229729729729729, 'fraction_numerical': 0.026412776412776413, 'mean_word_length': 1.665302782324059, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 2, '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': '4175860', 'n_tokens_mistral': 1171, 'n_tokens_neox': 1073, 'n_words': 284}