<commit_before>var ui = require('./ui');
var socket = require('../socket');
var stairway = require('./stairway');
var index = 0;
var playing = false;

function update(type, value) {
  socket.emit('update', {
    type: type,
    value: value
  });
}

function setHarmonicBase(value) {
  update('harmonic', value);
}

function noise(value) {
  update('noise', value);
}

function modulation(value) {
  update('modulation', value);
}

function volume(value) {
  update('volume', value);
}

function next() {
  if (index >= global.sequence.length) {
    index = 0;
  }
  setHarmonicBase(global.sequence[index]);
  index++;
}

function play(sequence) {
  if (sequence) {
    global.sequence = sequence;
  }
  next();
  if ((index <= global.sequence.length - 1 || global.repeat) && playing) {
    window.setTimeout(play, global.interval);
  }
  else {
    if (playing) {
      playing = ui.togglePlay();
    }
    if (index = global.sequence.length - 1) {
      index = 0;
    }
  }
}

function clickPlay() {
  playing = ui.togglePlay()
  if(playing) {
    play();
  }
}

function clickMute() {
  var muted = ui.toggleMute();
  volume(!muted);
}

function clickRepeat() {
  global.repeat = ui.toggleRepeat();
}

function newSequence(e) {
  var notes = e.srcElement.value.split(' ');
  notes = notes.reduce(function (prev, cur) {
    var num = Number(cur);
    if (num) {
      prev.push(num);
    }
    else if (cur) {
      prev.push(cur);
    }
    return prev;
  }, []);
  global.sequence = notes;
}

function updateInterval(e) {
  var newInterval = Number(e.srcElement.value);
  if (newInterval) {
    global.interval = newInterval;
  }
}

function updateModulation(e) {
  if (e.keyCode === 13) {
    modulation(Number(e.srcElement.value));
  }
}

ui.noiseElem.onclick = function ( ) { noise() };
ui.muteElem.onclick = clickMute;
ui.playElem.onclick = clickPlay;
ui.repeatElem.onclick = clickRepeat;
ui.sequenceElem.oninput = newSequence;
ui.intervalElem.oninput = updateInterval;
ui.modulateElem.onkeypress = updateModulation;

global.note = global.freq = setHarmonicBase;
global.play = play;
global.sequence = stairway;
global.stairway = stairway;
global.repeat = false;
global.interval = 500;<commit_msg>tweaks to gepetto<commit_after>var ui = require('./ui');
var socket = require('../socket');
var stairway = require('./stairway');
var index = 0;
var playing = false;

function update(type, value) {
  socket.emit('update', {
    type: type,
    value: value
  });
}

function setHarmonicBase(value) {
  update('harmonic', value);
}

function noise(value) {
  update('noise', value);
}

function modulation(value) {
  update('modulation', value);
}

function volume(value) {
  update('volume', value);
}

function next() {
  if (index >= global.sequence.length) {
    index = 0;
  }
  setHarmonicBase(global.sequence[index]);
  index++;
}

function play(sequence) {
  if (sequence) {
    global.sequence = sequence;
  }
  next();
  if ((index <= global.sequence.length - 1 || global.repeat) && playing) {
    window.setTimeout(play, global.interval);
  }
  else {
    if (playing) {
      playing = ui.togglePlay();
    }
    if (index = global.sequence.length - 1) {
      index = 0;
    }
  }
}

function clickPlay() {
  playing = ui.togglePlay()
  if(playing) {
    play();
  }
}

function clickMute() {
  var muted = ui.toggleMute();
  volume(!muted);
}

function clickRepeat() {
  global.repeat = ui.toggleRepeat();
}

function newSequence(e) {
  if(e.keyCode === 13) {
    var notes = e.srcElement.value.split(' ');
    notes = notes.reduce(function (prev, cur) {
      var num = Number(cur);
      if (num) {
        prev.push(num);
      }
      else if (cur) {
        prev.push(cur);
      }
      return prev;
    }, []);
    global.sequence = notes;
    if (!playing) {
      setHarmonicBase(sequence[index]);
    }
  }
}

function updateInterval(e) {
  if (e.keyCode === 13) {
    var newInterval = Number(e.srcElement.value);
    if (newInterval) {
      global.interval = newInterval;
    }
  }
}

function updateModulation(e) {
  if (e.keyCode === 13) {
    modulation(Number(e.srcElement.value));
  }
}

ui.noiseElem.onclick = function ( ) { noise() };
ui.muteElem.onclick = clickMute;
ui.playElem.onclick = clickPlay;
ui.repeatElem.onclick = clickRepeat;
ui.sequenceElem.onkeypress = newSequence;
ui.intervalElem.onkeypress = updateInterval;
ui.modulateElem.onkeypress = updateModulation;

global.note = global.freq = setHarmonicBase;
global.play = play;
global.sequence = stairway;
global.stairway = stairway;
global.repeat = false;
global.interval = 500;
{'fraction_non_alphanumeric': 0.15730828053310028, 'fraction_numerical': 0.005243609351103343, 'mean_word_length': 3.355851569933397, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3997190', 'n_tokens_mistral': 1603, 'n_tokens_neox': 1565, 'n_words': 321}