<commit_before>'use strict';

function Drum(name, sample){
  this.name = name;
  this.sample = sample;//new Audio(sample);
  this.playTriggers = [];
  this.playTriggers.length = 16;
  this.playTriggers.fill(false);

}

function playDrum (drum) {
  new Audio(drum.sample).play();
}

var snare = new Drum('snare', 'Samples/snare-big.mp3');
var hihat = new Drum('hihat', 'Samples/hihat-808.mp3');
// playDrum(snare);
snare.playTriggers[1] = true;
snare.playTriggers[2] = true;
hihat.playTriggers[5] = true;
hihat.playTriggers[7] = true;
snare.playTriggers[9] = true;
snare.playTriggers[11] = true;
hihat.playTriggers[13] = true;
hihat.playTriggers[15] = true;

var interval = 4000/16;
setInterval(function() {playMeasure(snare);}, 4000);
setInterval(function() {playMeasure(hihat);}, 4000);


function playMeasure (drum){
  for (var i = 0; i < drum.playTriggers.length; i++){
    if (drum.playTriggers[i]){
      setTimeout(function() {playDrum(drum);}, i * interval);
      setTimeout(function() {console.log(drum.name);}, i * interval);
    }
  }
}<commit_msg>switched to playing each beat individually.<commit_after>'use strict';


var bpm = 10;
var currentBeat = 0;

function Drum(name, sample){
  this.name = name;
  this.sample = sample;
  this.playTriggers = new Array(16).fill(false);

}

Drum.prototype.playDrum = function(){
  new Audio(this.sample).play();
};

var snare = new Drum('snare', 'Samples/snare-big.mp3');
var hihat = new Drum('hihat', 'Samples/hihat-808.mp3');

var allDrums = [snare, hihat];

snare.playTriggers[1] = true;
snare.playTriggers[2] = true;
hihat.playTriggers[5] = true;
hihat.playTriggers[7] = true;
snare.playTriggers[9] = true;
snare.playTriggers[11] = true;
hihat.playTriggers[13] = true;
hihat.playTriggers[15] = true;


setInterval(playBeat, 6000 / bpm);

function playBeat(){
  for (var i = 0; i < allDrums.length; i++){
    if (allDrums[i].playTriggers[currentBeat]){
      allDrums[i].playDrum();
    }
  }
  currentBeat++;
  currentBeat %= 16;
}
{'fraction_non_alphanumeric': 0.17354124748490946, 'fraction_numerical': 0.0306841046277666, 'mean_word_length': 4.7485549132947975, 'pattern_counts': {'":': 0, '<': 5, '<?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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '837562', 'n_tokens_mistral': 811, 'n_tokens_neox': 775, 'n_words': 150}