<commit_before>$(function() {
  var settings = {
    soundPack: [],
    fadeInVal: 0,
    fadeOutVal: null,
    loopStatus: null,
    defVolume: .5,
    downbeatVol: 1,
    currentCol: 1,
    colInterval: 120,
    measures: 1,
    beats: 4,
    subdivision: 4,
    defaulCols: 16,
    totalCol: 16,
    selectedBoxes: {}
  };

//Setup
  createSoundPack();
  buildGrid();

  //Renders Tempo knob
  $(".knob").knob({
    'min': 1,
    'max': 240,
    'width': 100,
    'change': function (v) { setTempo('colInterval', v) },
    'release': function (v) { setTempo('colInterval', v) }
  });

//Event Handlers
  //Toggles selected class
  $('body').on('click', '.box', boxSelected);

  //Event listeners for toggling Start/Stop
    //Click button
   $(".toggle").click(function() {
     toggleClicked();
   });

    //Press spacebar
  $(window).keypress(function(e) {
    if (e.keyCode == 0 || e.keyCode == 32) {
      if ("activeElement" in document) {
      document.activeElement.blur();
      }
      toggleClicked();
    }
  });
 
  //Reset button
  $(".clear").click(function() {
    $(".box").removeClass("selected");
    for (var i in settings.selectedBoxes) {
      settings.selectedBoxes[i] = [];
    }
  });
    
  //Measures/Beats/Subdivision listeners
  $('.measures-container input').on('change', function() {
    settings.measures = $('input[name="measures"]:checked', '.measures-container').val(); 
    buildGrid();
  });

  $('.beats-container input').on('change', function() {
    settings.beats = $('input[name="beats"]:checked', '.beats-container').val(); 
    buildGrid();
  });

  $('.subdivision-container input').on('change', function() {
    settings.subdivision = $('input[name="subdivision"]:checked', '.subdivision-container').val(); 
    //console.log("Subdivision is now: "+settings.subdivision);
    buildGrid();
  });

  //Start button <-> Stop Button 
  function toggleClicked() {
    if ($('.toggle').html() == 'Start') {
      $('.toggle').html('Stop');
      settings.loopStatus = true;
      gridLoop();
    }
    else if ($('.toggle').html() == 'Stop') {
      $('.toggle').html('Start');
      settings.loopStatus = false;
    }
  }

//Functions

  //Dynamically create sound file references
  function createSoundPack() {
    for(var soundIndex = 1; soundIndex<=16; soundIndex++) {
      settings.soundPack[soundIndex-1] = new Howl({
        urls: ['media/'+soundIndex+'.ogg', 'media/'+soundIndex+'.mp3'],
        fadeIn: settings.fadeInVal,
        fadeOut: settings.fadeOutVal,
        volume: settings.defVolume,
      });
    }
  }

  //Dynamically build HTML grid
  function buildGrid() {
    var container = $(".grid");
    $(".grid").html("");
    settings.totalCol = settings.measures * settings.beats * settings.subdivision;
    //Loop through each row.
    for (var colIndex = 1; colIndex <= settings.totalCol; colIndex++) {
      //Create the skeleton for the row.
      var col = $("<div>", {
          "class": "col col-" + colIndex,
          "id": "col-"+colIndex
      });
      //Loop through each column
      for (var rowIndex = 1; rowIndex <= 16; rowIndex++) {
        //Create skeleton for the column.
        var row = $("<div>", {
            "class": "box row-"+rowIndex,
            "data-col": colIndex,
            "data-row": rowIndex,
        });
        //Append to the row div.
        col.append(row);
      }
      //Finally append this row to the container.
      container.append(col);

      if ((settings.selectedBoxes["col"+colIndex] != undefined) || (settings.selectedBoxes["col"+colIndex] != null)){
        console.log(settings.selectedBoxes["col"+colIndex]);
        populateColNotes(colIndex, settings.selectedBoxes["col"+colIndex]);
      } else {
        settings.selectedBoxes["col"+colIndex] = [];
      }
    }
    findDownbeat();
    console.log(settings.selectedBoxes);
  }

  function findDownbeat() {
    var markedColumns = $('.grid').find(".col");
    var measureMarkers = settings.beats * settings.subdivision;

    $(markedColumns).children().removeClass('downbeat downbeat-measure');
    for (var i = 0; i < markedColumns.length; i++ ) {
      if (i % settings.subdivision === 0) {
        $(markedColumns[i]).children().addClass('downbeat');
        //console.log(i + "downbeats");
      }
    }
    for (var j = 0; j < markedColumns.length; j++ ) {
      if (j % measureMarkers === 0) {
        //console.log(j + "measure beats");
        $(markedColumns[j]).children().addClass('downbeat-measure');<commit_msg>Fixed reset loop bug on build grid<commit_after>$(function() {
  var settings = {
    soundPack: [],
    fadeInVal: 0,
    fadeOutVal: null,
    loopStatus: null,
    defVolume: .5,
    downbeatVol: 1,
    currentCol: 1,
    colInterval: 120,
    measures: 1,
    beats: 4,
    subdivision: 4,
    defaulCols: 16,
    totalCol: 16,
    selectedBoxes: {}
  };

//Setup
  createSoundPack();
  buildGrid();

  //Renders Tempo knob
  $(".knob").knob({
    'min': 1,
    'max': 240,
    'width': 100,
    'change': function (v) { setTempo('colInterval', v) },
    'release': function (v) { setTempo('colInterval', v) }
  });

//Event Handlers
  //Toggles selected class
  $('body').on('click', '.box', boxSelected);

  //Event listeners for toggling Start/Stop
    //Click button
   $(".toggle").click(function() {
     toggleClicked();
   });

    //Press spacebar
  $(window).keypress(function(e) {
    if (e.keyCode == 0 || e.keyCode == 32) {
      if ("activeElement" in document) {
      document.activeElement.blur();
      }
      toggleClicked();
    }
  });
 
  //Reset button
  $(".clear").click(function() {
    $(".box").removeClass("selected");
    for (var i in settings.selectedBoxes) {
      settings.selectedBoxes[i] = [];
    }
  });
    
  //Measures/Beats/Subdivision listeners
  $('.measures-container input').on('change', function() {
    settings.measures = $('input[name="measures"]:checked', '.measures-container').val(); 
    buildGrid();
  });

  $('.beats-container input').on('change', function() {
    settings.beats = $('input[name="beats"]:checked', '.beats-container').val(); 
    buildGrid();
  });

  $('.subdivision-container input').on('change', function() {
    settings.subdivision = $('input[name="subdivision"]:checked', '.subdivision-container').val(); 
    //console.log("Subdivision is now: "+settings.subdivision);
    buildGrid();
  });

  //Start button <-> Stop Button 
  function toggleClicked() {
    if ($('.toggle').html() == 'Start') {
      $('.toggle').html('Stop');
      settings.loopStatus = true;
      gridLoop();
    }
    else if ($('.toggle').html() == 'Stop') {
      $('.toggle').html('Start');
      settings.loopStatus = false;
    }
  }

//Functions

  //Dynamically create sound file references
  function createSoundPack() {
    for(var soundIndex = 1; soundIndex<=16; soundIndex++) {
      settings.soundPack[soundIndex-1] = new Howl({
        urls: ['media/'+soundIndex+'.ogg', 'media/'+soundIndex+'.mp3'],
        fadeIn: settings.fadeInVal,
        fadeOut: settings.fadeOutVal,
        volume: settings.defVolume,
      });
    }
  }

  //Dynamically build HTML grid
  function buildGrid() {
    var container = $(".grid");
    $(".grid").html("");
    settings.totalCol = settings.measures * settings.beats * settings.subdivision;
    //Loop through each row.
    for (var colIndex = 1; colIndex <= settings.totalCol; colIndex++) {
      //Create the skeleton for the row.
      var col = $("<div>", {
          "class": "col col-" + colIndex,
          "id": "col-"+colIndex
      });
      //Loop through each column
      for (var rowIndex = 1; rowIndex <= 16; rowIndex++) {
        //Create skeleton for the column.
        var row = $("<div>", {
            "class": "box row-"+rowIndex,
            "data-col": colIndex,
            "data-row": rowIndex,
        });
        //Append to the row div.
        col.append(row);
      }
      //Finally append this row to the container.
      container.append(col);

      if ((settings.selectedBoxes["col"+colIndex] != undefined) || (settings.selectedBoxes["col"+colIndex] != null)){
        console.log(settings.selectedBoxes["col"+colIndex]);
        populateColNotes(colIndex, settings.selectedBoxes["col"+colIndex]);
      } else {
        settings.selectedBoxes["col"+colIndex] = [];
      }
    }
    settings.currentCol = 1;
    findDownbeat();
    console.log(settings.selectedBoxes);
  }

  function findDownbeat() {
    var markedColumns = $('.grid').find(".col");
    var measureMarkers = settings.beats * settings.subdivision;

    $(markedColumns).children().removeClass('downbeat downbeat-measure');
    for (var i = 0; i < markedColumns.length; i++ ) {
      if (i % settings.subdivision === 0) {
        $(markedColumns[i]).children().addClass('downbeat');
        //console.log(i + "downbeats");
      }
    }
    for (var j = 0; j < markedColumns.length; j++ ) {
      if (j % measureMarkers === 0) {
        //console.log(j + "measure beats");
        $(markedColumns[j]).children().addClass('downbeat-measure');
{'fraction_non_alphanumeric': 0.18289183222958058, 'fraction_numerical': 0.008278145695364239, 'mean_word_length': 2.727272727272727, 'pattern_counts': {'":': 10, '<': 19, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1500728', 'n_tokens_mistral': 2941, 'n_tokens_neox': 2777, 'n_words': 601}