<commit_before>//cutting edge...
cracked.urnFactory = function (max) {

    var arr = [];
    while(arr.length < max){
        var r = Math.floor(Math.random() * max);
        if(arr.indexOf(r) === -1) arr.push(r);
    }

    return function() {
        return cracked.array_next(arr);
    };

};

//array of midi note numbers from midi controller.
var pad_array = [
    36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,
    58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
    80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,
    100,101,103,105,107,108,110,112,113,115,117
];

//var pad_array1 = [36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51];
//var pad_array2 = [52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67];
//var pad_array3 = [68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83];
//var pad_array4 = [84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99];

//CHANGE THIS TO POINT TO A DIRECTORY OF WAVS OR MP3S.
//array of sound files.
var snd_arr = __.ls("</ABSOLUTE/PATH/TO/FOLDER/OF/SAMPLES>");

//init on page load
var noteMap = {},
        r = __.random;

var speed = 1,
    speed_offset = 0.1;

function ranPan() {
  return (__.random(1,200)-100)/100;
}  

var urn = __.urnFactory(snd_arr.length);

//create a sampler for each tile / pad on the midi controller
pad_array.forEach(function(el,i,arr){

    let path = snd_arr[urn()];

    let selector = "pad_"+ el;

    //sampler->overdrive->gain->panner
    __().sampler({
        id:selector,
        path:path
    }).overdrive({
        id:selector+"_od"
    }).gain({
        id:selector+"_g"
    }).panner(ranPan());

});

//connect all the gains to the dac
__("panner").dac();

//initialize midi
__.midi_init(function(){

    //note on handler
    __.midi_noteon(function(data){

        var selector = "pad_"+data[1];

        //grab the data for that note
        var note_data = noteMap[selector];

        //stop the sampler (in case it's running), trigger the note on, then set the playback speed,
        __("#"+selector).stop().start().speed(speed);

        //ramp low pass freq and low pass q
        __("#"+selector+"_lp").ramp(note_data.lp_ramp[0],note_data.lp_ramp[1],"frequency",note_data.lp_ramp[2]).q(note_data.lp_q);

        //set delay and feedback values for delay 2
        __("#"+selector+"_d2").time(note_data.delay2_delay).feedback(note_data.delay2_feedback);

        __("#"+selector+"_g").volume(note_data.velocity);

        //set distortion level for overdrive
        __("#"+selector+"_od").drive(note_data.overdrive);

    });

    //midi controller messages- hardcoded for my setup
    __.midi_control(function(data){
        speed = (__.scale(data[2],0,127,50,100,"log")/100);
        //change the playback speed of all the samplers
        __("sampler").speed(speed-speed_offset);
    });

});

//run on page load- make the data for each note
pad_array.forEach(function(el,i,arr){
    var selector = "pad_"+ el;
    noteMap[selector]={
        pitch:r(100,10000)/1000,
        velocity:r(100,5000)/100,
        lp_ramp:[r(100,1000),(r(10,100)),r(0,100)],
        lp_q:r(5,100),
        overdrive:r(0,1000)/300,
        delay2_delay:r(0,100)/1000,
        delay2_feedback:r(0,100)/100
    };
});
<commit_msg>Update SAMPLER_CLEANER.js<commit_after>//cutting edge...
cracked.urnFactory = function (max) {

    var arr = [];
    while(arr.length < max){
        var r = Math.floor(Math.random() * max);
        if(arr.indexOf(r) === -1) arr.push(r);
    }

    return function() {
        return cracked.array_next(arr);
    };

};

//array of midi note numbers from midi controller.
var pad_array = [
    36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,
    58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
    80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,
    100,101,103,105,107,108,110,112,113,115,117
];

//var pad_array1 = [36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51];
//var pad_array2 = [52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67];
//var pad_array3 = [68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83];
//var pad_array4 = [84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99];

//CHANGE THIS TO POINT TO A DIRECTORY OF WAVS OR MP3S.
//array of sound files.
var snd_arr = __.ls("</ABSOLUTE/PATH/TO/FOLDER/OF/SAMPLES>");

//init on page load
var noteMap = {},
        r = __.random;

var speed = 1,
    speed_offset = 0.1;

function ranPan() {
  return (__.random(1,200)-100)/100;
}  

var urn = __.urnFactory(snd_arr.length);

//create a sampler for each tile / pad on the midi controller
pad_array.forEach(function(el,i,arr){

    let path = snd_arr[urn()];

    let selector = "pad_"+ el;

    //sampler->overdrive->gain->panner
    __().sampler({
        id:selector,
        path:path
    }).overdrive({
        id:selector+"_od"
    }).gain({
        id:selector+"_g"
    }).panner(ranPan());

});

//connect all the gains to the dac
__("panner").dac();

//initialize midi
__.midi_init(function(){

    //note on handler
    __.midi_noteon(function(data){

        var selector = "pad_"+data[1];

        //grab the data for that note
        var note_data = noteMap[selector];

        //stop the sampler (in case it's running), trigger the note on, then set the playback speed,
        __("#"+selector).stop().start().speed(speed);

        //ramp low pass freq and low pass q
        __("#"+selector+"_lp").ramp(note_data.lp_ramp[0],note_data.lp_ramp[1],"frequency",note_data.lp_ramp[2]).q(note_data.lp_q);

        //set delay and feedback values for delay 2
        __("#"+selector+"_d2").time(note_data.delay2_delay).feedback(note_data.delay2_feedback);

        __("#"+selector+"_g").volume(note_data.velocity);

        //set distortion level for overdrive
        __("#"+selector+"_od").drive(note_data.overdrive);

    });

    //midi controller messages- hardcoded for my setup
    __.midi_control(function(data){
        speed = (__.scale(data[2],0,127,50,100,"log")/100);
        //change the playback speed of all the samplers
        __("sampler").speed(speed-speed_offset);
    });

});

//run on page load- make the data for each note
pad_array.forEach(function(el,i,arr){
    var selector = "pad_"+ el;
    noteMap[selector]={
        pitch:r(100,10000)/1000,
        velocity:r(100,5000)/100,
        lp_ramp:[r(100,1000),(r(10,100)),r(0,100)],
        lp_q:r(5,100),
        overdrive:r(0,1000)/300,
        delay2_delay:r(0,100)/1000,
        delay2_feedback:r(0,100)/100
    };
});
{'fraction_non_alphanumeric': 0.18605008449838684, 'fraction_numerical': 0.1216776770625288, 'mean_word_length': 3.3055555555555554, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '794180', 'n_tokens_mistral': 2982, 'n_tokens_neox': 2504, 'n_words': 447}