<commit_before>// VVVV.js -- Visual Web Client Programming
// (c) 2011 <NAME>
// VVVV.js is freely distributable under the MIT license.
// Additional authors of sub components are mentioned at the specific code locations.

/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 NODE: LFO (Animation)
 Author(s): <NAME>, sebl
 Original Node Author(s): VVVV Group
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/

VVVV.Nodes.LFO = function(id, graph) {
  this.constructor(id, "LFO (Animation)", graph);
  
  this.meta = {
    authors: ['<NAME>, sebl'],
    original_authors: ['VVVV Group'],
    credits: [],
    compatibility_issues: ['Not spreadable yet']
  };
  
  this.auto_evaluate = true;
  
  var PeriodIn = this.addInputPin('Period', [1.0], this);
  var PauseIn = this.addInputPin("Pause", [0], this);
  var ReverseIn = this.addInputPin("Reverse", [0], this);
  var ResetIn = this.addInputPin("Reset", [0], this);
  var PhaseIn = this.addInputPin("Phase", [0.0], this);
  
  var outputOut = this.addOutputPin("Output", [0.0], this);
  var CyclesOut = this.addOutputPin("Cycles", [0], this);
  
  var current = [];
  var cycles = [];
  
  var dt = new Date().getTime();
  var lastUpdate = new Date().getTime();

  this.evaluate = function() {
  
    var maxSize = this.getMaxInputSliceCount();
    
    dt = new Date().getTime()-lastUpdate;

    for (var i=0; i<maxSize; i++) {

      var period = PeriodIn.getValue(i % PeriodIn.values.length);
      var paused = PauseIn.getValue(i % PauseIn.values.length);
      var reverse = ReverseIn.getValue(i % ReverseIn.values.length);
      var reset = ResetIn.getValue(i % ResetIn.values.length);
      var phase = PhaseIn.getValue(i % PhaseIn.values.length);

      if (current[i]==undefined) current[i] = 0.0;
      if (cycles[i]==undefined) cycles[i] = 0.0;

      if (paused<=0 && period!=0 && isFinite(period)) {

        dv = (1/(period*1000)*dt);

        if (reverse>0){
          dv *= -1;
        }

        current[i] += dv;

        if (current[i]<0) {
          cycles[i] -= Math.ceil(-current[i]);
          current[i] = 1.0 + current[i];
        }

        if (current[i]>1){
          cycles[i] += Math.floor(current[i]);
        }
      }

      lastUpdate = new Date().getTime();

      if (reset>0){
        current[i] = 0.0;
      }

      if (paused<0.5) { 
        outputOut.setValue(i, (current[i]+phase)%1);
        CyclesOut.setValue(i, cycles[i]);
      }

      current[i] = current[i] %1;
    }
    outputOut.setSliceCount(maxSize);
    CyclesOut.setSliceCount(maxSize);<commit_msg>fixes bug in LFO where reset didn't work when paused<commit_after>// VVVV.js -- Visual Web Client Programming
// (c) 2011 <NAME>
// VVVV.js is freely distributable under the MIT license.
// Additional authors of sub components are mentioned at the specific code locations.

/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 NODE: LFO (Animation)
 Author(s): <NAME>, sebl
 Original Node Author(s): VVVV Group
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/

VVVV.Nodes.LFO = function(id, graph) {
  this.constructor(id, "LFO (Animation)", graph);
  
  this.meta = {
    authors: ['<NAME>, sebl'],
    original_authors: ['VVVV Group'],
    credits: [],
    compatibility_issues: ['Not spreadable yet']
  };
  
  this.auto_evaluate = true;
  
  var PeriodIn = this.addInputPin('Period', [1.0], this);
  var PauseIn = this.addInputPin("Pause", [0], this);
  var ReverseIn = this.addInputPin("Reverse", [0], this);
  var ResetIn = this.addInputPin("Reset", [0], this);
  var PhaseIn = this.addInputPin("Phase", [0.0], this);
  
  var outputOut = this.addOutputPin("Output", [0.0], this);
  var CyclesOut = this.addOutputPin("Cycles", [0], this);
  
  var current = [];
  var cycles = [];
  
  var dt = new Date().getTime();
  var lastUpdate = new Date().getTime();

  this.evaluate = function() {
  
    var maxSize = this.getMaxInputSliceCount();
    
    dt = new Date().getTime()-lastUpdate;

    for (var i=0; i<maxSize; i++) {

      var period = PeriodIn.getValue(i % PeriodIn.values.length);
      var paused = PauseIn.getValue(i % PauseIn.values.length);
      var reverse = ReverseIn.getValue(i % ReverseIn.values.length);
      var reset = ResetIn.getValue(i % ResetIn.values.length);
      var phase = PhaseIn.getValue(i % PhaseIn.values.length);

      if (current[i]==undefined) current[i] = 0.0;
      if (cycles[i]==undefined) cycles[i] = 0.0;

      if (paused<0.5 && period!=0 && isFinite(period)) {

        dv = (1/(period*1000)*dt);

        if (reverse>0){
          dv *= -1;
        }

        current[i] += dv;

        if (current[i]<0) {
          cycles[i] -= Math.ceil(-current[i]);
          current[i] = 1.0 + current[i];
        }

        if (current[i]>1){
          cycles[i] += Math.floor(current[i]);
        }
      }

      lastUpdate = new Date().getTime();

      if (reset>=0.5){
        current[i] = 0.0;
        cycles[i] = 0;
      }

      if (paused<0.5 || reset>=0.5) { 
        outputOut.setValue(i, (current[i]+phase)%1);
        CyclesOut.setValue(i, cycles[i]);
      }

      current[i] = current[i] %1;
    }
    outputOut.setSliceCount(maxSize);
    CyclesOut.setSliceCount(maxSize);
{'fraction_non_alphanumeric': 0.22478600669892074, 'fraction_numerical': 0.015444733903982136, 'mean_word_length': 2.9933135215453195, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 16, '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': '5753877', 'n_tokens_mistral': 1838, 'n_tokens_neox': 1731, 'n_words': 391}