<commit_before>import angular from 'angular';
import Firebase from 'firebase';

const template = `
<div>
  <div style="position: absolute; left: 10px; bottom: 10px;">
    <md-button class="md-fab" ng-click="main.play()">
      <md-icon>play_arrow</md-icon>
    </md-button>
  </div>
  <div style="position: absolute; left: 10px; top: 500px;">
    <md-button class="md-fab" ng-click="main.noteon()">
      <md-icon>add</md-icon>
    </md-button>
    <md-button class="md-fab" ng-click="main.noteoff()">
      <md-icon>remove</md-icon>
    </md-button>
  </div>

  <visualizer style="position: absolute; left: 0; top: 0; right: 0; height: 500px;"></visualizer>
  <grid grid="main.grid" style="position: absolute; left: 100px; top: 500px; right: 0; bottom: 10px;"></grid>
</div>
`;

class MainController {
  constructor($scope, $window, numRow, numCol, grid) {
    this.$scope = $scope;
    this.$window = $window;
    this.numRow = numRow;
    this.numCol = numCol;
    this.playing = false;
    this.grid = grid;
  }

  play() {
    if (!this.playing) {
      this.playing = true;
      this.startTime = new Date();
      const tick = () => {<commit_msg>broadcasting noteon and noteoff<commit_after>import angular from 'angular';
import Firebase from 'firebase';

const template = `
<div>
  <div style="position: absolute; left: 10px; bottom: 10px;">
    <md-button class="md-fab" ng-click="main.play()">
      <md-icon>play_arrow</md-icon>
    </md-button>
  </div>
  <div style="position: absolute; left: 10px; top: 500px;">
    <md-button class="md-fab" ng-click="main.noteon()">
      <md-icon>add</md-icon>
    </md-button>
    <md-button class="md-fab" ng-click="main.noteoff()">
      <md-icon>remove</md-icon>
    </md-button>
  </div>

  <visualizer style="position: absolute; left: 0; top: 0; right: 0; height: 500px;"></visualizer>
  <grid grid="main.grid" style="position: absolute; left: 100px; top: 500px; right: 0; bottom: 10px;"></grid>
</div>
`;

class MainController {
  constructor($scope, $window, numRow, numCol, grid) {
    this.$scope = $scope;
    this.$window = $window;
    this.numRow = numRow;
    this.numCol = numCol;
    this.playing = false;
    this.grid = grid;

    let lastTick = -1;
    $scope.$on('tick', (e, tick) => {
      const colIndex = (time) => Math.floor(time / 125),
        i0 = colIndex(lastTick),
        i = colIndex(tick);
      if (i !== i0) {
        const enter = [],
          exit = [];
        if (i === 0) {
          const col = grid[i];
          for (let j = 0; j < numRow; ++j) {
            if (col[j].mask) {
              enter.push(j);
            }
          }
        } else if (i >= numCol) {
          const col0 = grid[i - 1];
          for (let j = 0; j < numRow; ++j) {
            if (col0[j].mask) {
              exit.push(j);
            }
          }
        } else {
          const col0 = grid[i - 1],
            col = grid[i];
          for (let j = 0; j < numRow; ++j) {
            if (col[j].mask && !col0[j].mask) {
              enter.push(j);
            }
            if (!col[j].mask && col0[j].mask) {
              exit.push(j);
            }
          }
        }

        if (enter.length > 0) {
          $scope.$broadcast('note-on', {
            colIndex: i,
            notes: enter.map((j) => {
                return {
                  rowIndex: j,
                  velocity: Math.floor(Math.random() * 128),
                  channel: Math.floor(Math.random() * 16)
                };
              })
          });
        }
        if (exit.length > 0) {
          $scope.$broadcast('note-off', {
            colIndex: i,
            notes: exit.map((j) => {
                return {
                  rowIndex: j
                };
              })
          });
        }

      }
      lastTick = tick;
    });
  }

  play() {
    if (!this.playing) {
      this.playing = true;
      this.startTime = new Date();
      const tick = () => {
{'fraction_non_alphanumeric': 0.17498100785008863, 'fraction_numerical': 0.01823246391491517, 'mean_word_length': 1.843772498200144, 'pattern_counts': {'":': 0, '<': 50, '<?xml version=': 0, '>': 56, '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': '1840597', 'n_tokens_mistral': 1412, 'n_tokens_neox': 1311, 'n_words': 300}