<commit_before>// Copyright (c) 2015 <NAME>
// Copyright (c) 2018 <NAME>
// Copyright (c) 2018 <NAME>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the The GNU Affero General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// You should have received a copy of the GNU Affero General Public
// License along with this library; if not, write to the Free Software
// Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA

function MusicKeyboard() {
    var synth = new Tone.Synth().toMaster();

    const BUTTONDIVWIDTH = 295;  // 5 buttons
    const DRUMNAMEWIDTH = 50;
    const OUTERWINDOWWIDTH = 128;
    const INNERWINDOWWIDTH = 50;
    const BUTTONSIZE = 53;
    const ICONSIZE = 32;

    this.noteNames = [];
    this.octaves = [];

    var keyboard = document.getElementById('keyboard');
    var keyboardHolder = document.getElementById('keyboardHolder2');
    var firstOctave = document.getElementById('firstOctave');
    var firstNote = document.getElementById('firstNote');
    var secondOctave = document.getElementById('secondOctave');
    var secondNote = document.getElementById('secondNote');
    var whiteKeys = document.getElementById('white');
    var blackKeys = document.getElementById('black');

    var whiteNoteEnums = ['C','D','E','F','G','A','B'];
    var blackNoteEnums = ['C' + SHARP + '/D' + FLAT, 'D' + SHARP + '/E' + FLAT, null, 'F' + SHARP + '/G' + FLAT, 'G' + SHARP + '/A' + FLAT, 'A' + SHARP + '/B' + FLAT, null];

    var selected = [];
    var selected1 = [];

    this.processClick = function(i) {
        var temp1 = this.noteNames[i];
        if (temp1 === 'hertz') {
            var temp2 = this.octaves[i];
        } else if (temp1 in FIXEDSOLFEGE1) {
            var temp2 = FIXEDSOLFEGE1[temp1].replace(SHARP, '#').replace(FLAT, 'b') + this.octaves[i];
        } else {
            var temp2 = temp1.replace(SHARP, '#').replace(FLAT, 'b') + this.octaves[i];
        }

        selected1.push(temp2);
        synth.triggerAttackRelease(temp2, '8n');
    };

    this.loadHandler = function(element, i) {
        var that = this;
        element.onclick = function() {
            that.processClick(i);
        };
    };

    this.init = function(logo) {
        this._logo = logo; 

        var w = window.innerWidth;
        this._cellScale = w / 1200;
        var iconSize = ICONSIZE * this._cellScale;

        var canvas = docById('myCanvas');

        // Position the widget and make it visible.
        var mkbDiv = docById('mkbDiv');
        mkbDiv.style.visibility = 'visible';
        mkbDiv.setAttribute('draggable', 'true');
        mkbDiv.style.left = '200px';
        mkbDiv.style.top = '150px';

        // The buttons
        var mkbButtonsDiv = docById('mkbButtonsDiv');
        mkbButtonsDiv.style.display = 'inline';
        mkbButtonsDiv.style.visibility = 'visible';
        mkbButtonsDiv.style.width = BUTTONDIVWIDTH;
        mkbButtonsDiv.innerHTML = '<table cellpadding="0px" id="mkbButtonTable"></table>';

        var myNode = document.getElementById('myrow');
        myNode.innerHTML = '';
        var myNode = document.getElementById('myrow2');
        myNode.innerHTML = '';
        selected = [];
        selected1 = [];

        var buttonTable1 = docById('mkbButtonTable');
        var header1 = buttonTable1.createTHead();
        var row1 = header1.insertRow(0);

        // For the button callbacks
        var that = this;
        if (this.noteNames.length === 0) {
            // document.getElementById('keyboardHolder').style.display = 'block';
            for (var i = 0; i < PITCHES3.length; i++) {
                this.noteNames.push(PITCHES3[i]);
                this.octaves.push(4);
                if (i === 4) {
                    this.noteNames.push(null); // missing black key
                    this.octaves.push(4);
                }
            }

            this.noteNames.push(PITCHES3[0]);
            this.octaves.push(5);
        } // else {
            document.getElementById('keyboardHolder2').style.display = 'block';
            var idContainer = [];

            for (var p = 0; p < this.noteNames.length; p++){
                if (this.noteNames[p] === null) {
                    var parenttbl2 = document.getElementById('myrow2');
                    var newel2 = document.createElement('td');
                    var elementid2 = document.getElementsByTagName('td').length
                    
                    newel2.setAttribute('id',elementid2);
                    idContainer.push(elementid2);
                    newel2.innerHTML = '';
                    newel2.style.visibility = 'hidden';
                    parenttbl2.appendChild(newel2);
                } else if (this.noteNames[p] === 'hertz') {
                    var parenttbl = document.getElementById('myrow');
                    var newel = document.createElement('td');
                    var elementid = document.getElementsByTagName('td').length

                    newel.setAttribute('id',elementid);
                    idContainer.push(elementid);
                    newel.innerHTML = this.octaves[p];
                    parenttbl.appendChild(newel);
                } else if (this.noteNames[p].indexOf(SHARP) !== -1 || this.noteNames[p].indexOf('#') !== -1) {
                    var parenttbl2 = document.getElementById('myrow2');
                    var newel2 = document.createElement('td');
                    var elementid2 = document.getElementsByTagName('td').length

                    newel2.setAttribute('id',elementid2);
                    idContainer.push(elementid2);
                    newel2.innerHTML = this.noteNames[p] + this.octaves[p];
                    parenttbl2.appendChild(newel2);
                } else if (this.noteNames[p].indexOf(FLAT) !== -1 || this.noteNames[p].indexOf('b') !== -1) {
                    var parenttbl2 = document.getElementById('myrow2');
                    var newel2 = document.createElement('td');
                    var elementid2 = document.getElementsByTagName('td').length

                    newel2.setAttribute('id',elementid2);
                    idContainer.push(elementid2);
                    newel2.innerHTML = this.noteNames[p] + this.octaves[p];
                    parenttbl2.appendChild(newel2);
                } else {
                    var parenttbl = document.getElementById('myrow');
                    var newel = document.createElement('td');
                    var elementid = document.getElementsByTagName('td').length

                    newel.setAttribute('id',elementid);
                    idContainer.push(elementid);
                    newel.innerHTML = this.noteNames[p] + this.octaves[p];
                    parenttbl.appendChild(newel);
                }
            }

            for (var i = 0; i < idContainer.length; i++) {
                this.loadHandler(document.getElementById(idContainer[i]), i);
            }
        // }

        var cell = this._addButton(row1, 'play-button.svg', ICONSIZE, _('play'));

        cell.onclick = function() {
            that._logo.setTurtleDelay(0);
            if (selected.length > 0 ) {
                for (var q = 0; q < selected.length; q++) {
                    var zx = selected[q];
                    var res = zx.replace(SHARP, '#').replace(FLAT, 'b');

                    synth.triggerAttackRelease(res, '8n');
                    sleep(500);
                }
            } else {
                for (var q = 0; q < selected1.length; q++) {
                    var zx = selected1[q];
                    var res = zx.replace(SHARP, '#').replace(FLAT, 'b');

                    synth.triggerAttackRelease(res, '8n');
                    sleep(500);
                }<commit_msg>fix i18n of solfege<commit_after>// Copyright (c) 2015 <NAME>
// Copyright (c) 2018 <NAME>
// Copyright (c) 2018 <NAME>ender
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the The GNU Affero General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// You should have received a copy of the GNU Affero General Public
// License along with this library; if not, write to the Free Software
// Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA

function MusicKeyboard() {
    var synth = new Tone.Synth().toMaster();

    const BUTTONDIVWIDTH = 295;  // 5 buttons
    const DRUMNAMEWIDTH = 50;
    const OUTERWINDOWWIDTH = 128;
    const INNERWINDOWWIDTH = 50;
    const BUTTONSIZE = 53;
    const ICONSIZE = 32;

    this.noteNames = [];
    this.octaves = [];

    var keyboard = document.getElementById('keyboard');
    var keyboardHolder = document.getElementById('keyboardHolder2');
    var firstOctave = document.getElementById('firstOctave');
    var firstNote = document.getElementById('firstNote');
    var secondOctave = document.getElementById('secondOctave');
    var secondNote = document.getElementById('secondNote');
    var whiteKeys = document.getElementById('white');
    var blackKeys = document.getElementById('black');

    var whiteNoteEnums = ['C','D','E','F','G','A','B'];
    var blackNoteEnums = ['C' + SHARP + '/D' + FLAT, 'D' + SHARP + '/E' + FLAT, null, 'F' + SHARP + '/G' + FLAT, 'G' + SHARP + '/A' + FLAT, 'A' + SHARP + '/B' + FLAT, null];

    var selected = [];
    var selected1 = [];

    this.processClick = function(i) {
        var temp1 = this.noteNames[i];
        if (temp1 === 'hertz') {
            var temp2 = this.octaves[i];
        } else if (temp1 in FIXEDSOLFEGE1) {
            var temp2 = FIXEDSOLFEGE1[temp1].replace(SHARP, '#').replace(FLAT, 'b') + this.octaves[i];
        } else {
            var temp2 = temp1.replace(SHARP, '#').replace(FLAT, 'b') + this.octaves[i];
        }

        selected1.push(temp2);
        synth.triggerAttackRelease(temp2, '8n');
    };

    this.loadHandler = function(element, i) {
        var that = this;
        element.onclick = function() {
            that.processClick(i);
        };
    };

    this.init = function(logo) {
        this._logo = logo; 

        var w = window.innerWidth;
        this._cellScale = w / 1200;
        var iconSize = ICONSIZE * this._cellScale;

        var canvas = docById('myCanvas');

        // Position the widget and make it visible.
        var mkbDiv = docById('mkbDiv');
        mkbDiv.style.visibility = 'visible';
        mkbDiv.setAttribute('draggable', 'true');
        mkbDiv.style.left = '200px';
        mkbDiv.style.top = '150px';

        // The buttons
        var mkbButtonsDiv = docById('mkbButtonsDiv');
        mkbButtonsDiv.style.display = 'inline';
        mkbButtonsDiv.style.visibility = 'visible';
        mkbButtonsDiv.style.width = BUTTONDIVWIDTH;
        mkbButtonsDiv.innerHTML = '<table cellpadding="0px" id="mkbButtonTable"></table>';

        var myNode = document.getElementById('myrow');
        myNode.innerHTML = '';
        var myNode = document.getElementById('myrow2');
        myNode.innerHTML = '';
        selected = [];
        selected1 = [];

        var buttonTable1 = docById('mkbButtonTable');
        var header1 = buttonTable1.createTHead();
        var row1 = header1.insertRow(0);

        // For the button callbacks
        var that = this;
        if (this.noteNames.length === 0) {
            // document.getElementById('keyboardHolder').style.display = 'block';
            for (var i = 0; i < PITCHES3.length; i++) {
                this.noteNames.push(PITCHES3[i]);
                this.octaves.push(4);
                if (i === 4) {
                    this.noteNames.push(null); // missing black key
                    this.octaves.push(4);
                }
            }

            this.noteNames.push(PITCHES3[0]);
            this.octaves.push(5);
        } // else {
            document.getElementById('keyboardHolder2').style.display = 'block';
            var idContainer = [];

            for (var p = 0; p < this.noteNames.length; p++){
                if (this.noteNames[p] === null) {
                    var parenttbl2 = document.getElementById('myrow2');
                    var newel2 = document.createElement('td');
                    var elementid2 = document.getElementsByTagName('td').length
                    
                    newel2.setAttribute('id',elementid2);
                    idContainer.push(elementid2);
                    newel2.innerHTML = '';
                    newel2.style.visibility = 'hidden';
                    parenttbl2.appendChild(newel2);
                } else if (this.noteNames[p] === 'hertz') {
                    var parenttbl = document.getElementById('myrow');
                    var newel = document.createElement('td');
                    var elementid = document.getElementsByTagName('td').length

                    newel.setAttribute('id',elementid);
                    idContainer.push(elementid);
                    newel.innerHTML = this.octaves[p];
                    parenttbl.appendChild(newel);
                } else if (this.noteNames[p].indexOf(SHARP) !== -1 || this.noteNames[p].indexOf('#') !== -1) {
                    var parenttbl2 = document.getElementById('myrow2');
                    var newel2 = document.createElement('td');
                    var elementid2 = document.getElementsByTagName('td').length

                    newel2.setAttribute('id',elementid2);
                    idContainer.push(elementid2);
                    var nname = this.noteNames[p].replace(SHARP, '').replace('#', '');
                    if (SOLFEGENAMES.indexOf(nname) !== -1) {
                        newel2.innerHTML = i18nSolfege(nname) + SHARP + this.octaves[p];
                    } else {
                        newel2.innerHTML = this.noteNames[p] + this.octaves[p];
                    }
                    parenttbl2.appendChild(newel2);
                } else if (this.noteNames[p].indexOf(FLAT) !== -1 || this.noteNames[p].indexOf('b') !== -1) {
                    var parenttbl2 = document.getElementById('myrow2');
                    var newel2 = document.createElement('td');
                    var elementid2 = document.getElementsByTagName('td').length

                    newel2.setAttribute('id',elementid2);
                    idContainer.push(elementid2);
                    var nname = this.noteNames[p].replace(FLAT, '').replace('b', '');
                    if (SOLFEGENAMES.indexOf(nname) !== -1) {
                        newel2.innerHTML = i18nSolfege(nname) + FLAT + this.octaves[p];
                    } else {
                        newel2.innerHTML = this.noteNames[p] + this.octaves[p];
                    }
                    parenttbl2.appendChild(newel2);
                } else {
                    var parenttbl = document.getElementById('myrow');
                    var newel = document.createElement('td');
                    var elementid = document.getElementsByTagName('td').length

                    newel.setAttribute('id',elementid);
                    idContainer.push(elementid);
                    if (SOLFEGENAMES.indexOf(this.noteNames[p]) !== -1) {
                        newel.innerHTML = i18nSolfege(this.noteNames[p]) + this.octaves[p];
                    } else {
                        newel.innerHTML = this.noteNames[p] + this.octaves[p];
                    }
                    parenttbl.appendChild(newel);
                }
            }

            for (var i = 0; i < idContainer.length; i++) {
                this.loadHandler(document.getElementById(idContainer[i]), i);
            }
        // }

        var cell = this._addButton(row1, 'play-button.svg', ICONSIZE, _('play'));

        cell.onclick = function() {
            that._logo.setTurtleDelay(0);
            if (selected.length > 0 ) {
                for (var q = 0; q < selected.length; q++) {
                    var zx = selected[q];
                    var res = zx.replace(SHARP, '#').replace(FLAT, 'b');

                    synth.triggerAttackRelease(res, '8n');
                    sleep(500);
                }
            } else {
                for (var q = 0; q < selected1.length; q++) {
                    var zx = selected1[q];
                    var res = zx.replace(SHARP, '#').replace(FLAT, 'b');

                    synth.triggerAttackRelease(res, '8n');
                    sleep(500);
                }
{'fraction_non_alphanumeric': 0.13110709987966307, 'fraction_numerical': 0.017629362214199758, 'mean_word_length': 1.815210027100271, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 15, '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': '1047104', 'n_tokens_mistral': 4885, 'n_tokens_neox': 4533, 'n_words': 990}