<commit_before>// I have no idea what I'm doing . gif
// Starting to figure it out though yipee

var myles = myles || {};

(function ($) {
    myles.midiToFreq = function(m){
        return Math.pow(2, ((m-69)/12))*440;
    };
    myles.piano = function (container){
        var that = {};
        that.container = $(container);
        that.svg = that.container.svg()
        that.keys = {
            white: [60,62,64,65,67,69,71],
            black: [61,63,66,68,70]
        };
        // console.log(that.keys);
        that.noteOn = function(note){
            // Flocking Related 
            var freq = myles.midiToFreq(note[0].id);
            that.synth.input("carrier.freq", freq);
            that.synth.input("asr.gate", 1.0);
            // UI related
            note.css('fill', 'yellow');
        };
        that.noteOff = function(note){
            // Flocking Related
            that.synth.input("asr.gate", 0.0);
            // UI Related
            if($.inArray(parseInt(note[0].id), that.keys.white) != -1){
                note.css('fill', 'white');
            }
            else{
                note.css('fill', 'black');
            }
        };
        that.bindEvents = function(){
            var lastPressed = {};
            that.isPressed = false;
            that.notes = that.container.find(".note");
            that.notes.each(function(i,note){
                note = $(note);
                note.hover(function(){
                    if(that.isPressed){
                        that.noteOff(lastPressed);
                        that.noteOn(note);
                        lastPressed = note;
                    }
                });
                note.mousedown(function(){
                    lastPressed = note;
                    that.isPressed = true;
                    that.noteOn(note);
                });
                note.mouseup(function(){
                    that.isPressed = false;
                    that.noteOff(note);
                });
            });
        };
        that.init = function(){
            that.synth = flock.synth({
                id: "carrier",
                ugen: "flock.ugen.sinOsc",
                freq: 440,
                mul: {
                    id: "asr",
                    ugen: "flock.ugen.env.simpleASR",
                    attack: 0.25,
                    sustain: 0.6,
                    release: 0.5
                }
            });
            that.bindEvents();
            flock.enviro.shared.play();
        };
        that.init();
        return that;
    };
})(jQuery);<commit_msg>Added support for keyboards(very rough, in desperate need of refactoring)<commit_after>// I have no idea what I'm doing . gif
// Starting to figure it out though yipee

var myles = myles || {};

(function ($) {
    myles.midiToFreq = function(m){
        return Math.pow(2, ((m-69)/12))*440;
    };
    myles.piano = function (container){
        var that = {};
        that.container = $(container);
        that.svg = that.container.svg()
        that.keys = {
            white: [60,62,64,65,67,69,71],
            black: [61,63,66,68,70]
        };
        that.keyCodes = {
            "65": 60,
            "87": 61,
            "83": 62,
            "69": 63,
            "68": 64,
            "70": 65,
            "84": 66,
            "71": 67,
            "89": 68,
            "72": 69,
            "85": 70,
            "74": 71
        };
        that.noteOn = function(note){
            // Flocking Related 
            var freq = myles.midiToFreq(note[0].id);
            that.synth.input("carrier.freq", freq);
            that.synth.input("asr.gate", 1.0);
            // UI related
            note.css('fill', 'yellow');
        };
        that.noteOff = function(note){
            // Flocking Related
            that.synth.input("asr.gate", 0.0);
            // UI Related
            if($.inArray(parseInt(note[0].id), that.keys.white) != -1){
                note.css('fill', 'white');
            }
            else{
                note.css('fill', 'black');
            }
        };
        that.bindEvents = function(){
            var lastPressed = {};
            var isPressed = false;
            $(document).keydown(function(e){
                var note = that.container.find("#"+that.keyCodes[e.keyCode]+".note");
                that.noteOn(note);
             });
             $(document).keyup(function(e){
                 var note = that.container.find("#"+that.keyCodes[e.keyCode]+".note");
                 that.noteOff(note);
             });
            that.notes = that.container.find(".note");
            that.notes.each(function(i,note){
                note = $(note);
                note.mousedown(function(){
                    lastPressed = note;
                    isPressed = true;
                    that.noteOn(note);
                });
                note.mouseup(function(){
                    isPressed = false;
                    that.noteOff(note);
                    lastPressed = {}
                });
                note.hover(function(){
                    if(isPressed){
                        that.noteOff(lastPressed);
                        that.noteOn(note);
                        lastPressed = note;
                    }
                });
                
            });
        };
        that.init = function(){
            that.synth = flock.synth({
                id: "carrier",
                ugen: "flock.ugen.sinOsc",
                freq: 440,
                mul: {
                    id: "asr",
                    ugen: "flock.ugen.env.simpleASR",
                    attack: 0.25,
                    sustain: 0.6,
                    release: 0.5
                }
            });
            that.bindEvents();
            flock.enviro.shared.play();
        };
        that.init();
        return that;
    };
})(jQuery);
{'fraction_non_alphanumeric': 0.14073824372155738, 'fraction_numerical': 0.024608124051913028, 'mean_word_length': 1.0842992623814542, 'pattern_counts': {'":': 12, '<': 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': '5120451', 'n_tokens_mistral': 1791, 'n_tokens_neox': 1622, 'n_words': 294}