<commit_before>import React, {PropTypes, Component} from 'react';

class Oscillator extends Component {
  constructor(props, context) {
    super(props, context);
    this.osc = undefined;
    this.gain = undefined;
  }

  componentWillMount() {
    const {audioContext, oscillator, actions, decay, attack, sustain} = this.props;
    const now = audioContext.currentTime;
    this.osc = audioContext.createOscillator();
    this.gain = audioContext.createGain();
    this.osc.connect(this.gain);
    this.osc.frequency.value = oscillator.freq;
    this.gain.connect(audioContext.destination);
    this.osc.type = oscillator.type;
    this.osc.start(oscillator.start || 0);
    this.gain.gain.cancelScheduledValues(now);

    this.gain.gain.setValueAtTime(0, now);
    this.attackTime = now + attack;
    this.gain.gain.linearRampToValueAtTime(1, this.attackTime);
    this.gain.gain.linearRampToValueAtTime(sustain, this.attackTime + decay);
    if(oscillator.stop) {
      console.log('stop', oscillator.stop);
      actions.stopNote(oscillator.id, oscillator.stop);
    }

    this.osc.onended = () => {
      this.gain.disconnect();
      this.osc.disconnect();
    };
  }

  componentWillUnmount() {
    const {audioContext, release} = this.props;
    const now = audioContext.currentTime;
    // stop when attack has finished
    const stopTime = now > this.attackTime ? now : this.attackTime;
    this.gain.gain.cancelScheduledValues(0);
    this.gain.gain.setValueAtTime(this.gain.gain.value, now);
    this.gain.gain.linearRampToValueAtTime(0, now + release);
    this.osc.stop(now + release);
  }

  render() {
    return (
      <div className='hidden'>{this.props.oscillator.id}</div>
    );
  }
}

Oscillator.propTypes = {
  audioContext: PropTypes.object.isRequired,
  oscillator: PropTypes.object.isRequired,<commit_msg>prevent some of the annoying cracling & snapping<commit_after>import React, {PropTypes, Component} from 'react';

class Oscillator extends Component {
  constructor(props, context) {
    super(props, context);
    this.osc = undefined;
    this.gain = undefined;
  }

  componentWillMount() {
    const {audioContext, oscillator, actions, decay, attack, sustain} = this.props;
    const now = audioContext.currentTime;
    this.osc = audioContext.createOscillator();
    this.gain = audioContext.createGain();
    this.osc.connect(this.gain);
    this.osc.frequency.value = oscillator.freq;
    this.gain.connect(audioContext.destination);
    this.osc.type = oscillator.type;
    this.osc.start(oscillator.start || 0);
    this.gain.gain.cancelScheduledValues(now);

    this.gain.gain.setValueAtTime(0, now);
    this.attackTime = now + attack;
    this.gain.gain.linearRampToValueAtTime(1, this.attackTime);
    this.gain.gain.linearRampToValueAtTime(sustain, this.attackTime + decay);
    if(oscillator.stop) {
      console.log('stop', oscillator.stop);
      actions.stopNote(oscillator.id, oscillator.stop);
    }

    this.osc.onended = () => {
      this.gain.disconnect();
      this.osc.disconnect();
    };
  }

  componentWillUnmount() {
    const {audioContext, release} = this.props;
    const now = audioContext.currentTime;
    // stop when attack has finished
    const stopTime = now > this.attackTime ? now : this.attackTime;
    this.gain.gain.linearRampToValueAtTime(0, stopTime + release);
    this.osc.stop(stopTime + release);
  }

  render() {
    return (
      <div className='hidden'>{this.props.oscillator.id}</div>
    );
  }
}

Oscillator.propTypes = {
  audioContext: PropTypes.object.isRequired,
  oscillator: PropTypes.object.isRequired,
{'fraction_non_alphanumeric': 0.13117027176927343, 'fraction_numerical': 0.0024958402662229617, 'mean_word_length': 3.589058524173028, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '3850787', 'n_tokens_mistral': 1168, 'n_tokens_neox': 1138, 'n_words': 196}