<commit_before>var MidiInput = function() {
  this.init = function(visualizer) {
    this.visualizer = visualizer;

    if (navigator.requestMIDIAccess) {
        navigator.requestMIDIAccess().then(onMidiSuccess.bind(this), onMidiReject);
    } else {
      console.log('No MIDI support: navigator.requestMIDIAccess is not defined');
    }
  };

  function onMidiReject(err) {
    console.log('MIDI init error: ' + err);
  }

  function onMidiSuccess(midi) {
    if (midi.inputs.size > 0) {
      // Get first MIDI device
      var input = midi.inputs.values().next().value;
      console.log('MIDI device found: ' + input.name);

      // Set MIDI message handler
      input.onmidimessage = messageHandler.bind(this);
    } else {
      console.log('No MIDI input devices available');
    }
  }

  function messageHandler(event) {
    var data = {
      status: event.data[0] & 0xf0,
      data: [
        event.data[1],
        event.data[2]
      ]
    };

    handleInput(data);
  }

  function handleInput(data) {
    // Note on event
    if (data.status === 144) {
      var note = data.data[0];
      var velocity = data.data[1];
      console.log('Note on: ' + note + ', ' + velocity);

    // Control change event
    } else if (data.status === 176) {
      var index = data.data[0];
      var value = data.data[1];
      console.log('Control change: ' + index + ', ' + value);
    }
  }
};<commit_msg>Refactor note on and control change handling to separate functions<commit_after>var MidiInput = function() {
  this.init = function(visualizer) {
    this.visualizer = visualizer;

    if (navigator.requestMIDIAccess) {
        navigator.requestMIDIAccess().then(onMidiSuccess.bind(this), onMidiReject);
    } else {
      console.log('No MIDI support: navigator.requestMIDIAccess is not defined');
    }
  };

  function onMidiReject(err) {
    console.log('MIDI init error: ' + err);
  }

  function onMidiSuccess(midi) {
    if (midi.inputs.size > 0) {
      // Get first MIDI device
      var input = midi.inputs.values().next().value;
      console.log('MIDI device found: ' + input.name);

      // Set MIDI message handler
      input.onmidimessage = messageHandler.bind(this);
    } else {
      console.log('No MIDI input devices available');
    }
  }

  function messageHandler(event) {
    var message = {
      status: event.data[0] & 0xf0,
      data: [
        event.data[1],
        event.data[2]
      ]
    };

    // Note on event
    if (message.status === 144) {
      handleNoteOn(message.data[0], message.data[1]);

    // Control change event
    } else if (message.status === 176) {
      handleControlChange(message.data[0], message.data[1]);
    }
  }

  function handleNoteOn(note, velocity) {
    console.log('Note on: ' + note + ', ' + velocity);
  }

  function handleControlChange(index, value) {
    console.log('Control change: ' + index + ', ' + value);
  }
};
{'fraction_non_alphanumeric': 0.14000687994496044, 'fraction_numerical': 0.011007911936704506, 'mean_word_length': 2.5901234567901232, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6562841', 'n_tokens_mistral': 981, 'n_tokens_neox': 935, 'n_words': 202}