<commit_before>class @MIDI
  constructor: ->
    @_inputsDep = new Tracker.Dependency
    @_velocityDep = new Tracker.Dependency
    @_noteDep = new Tracker.Dependency

  start: ->
    if navigator.requestMIDIAccess
      navigator.requestMIDIAccess().then(_.bind(@_midiStarted, this), @_midiError)

  setKeyboard: (@_keyboard) ->

  _midiError: (error) ->
    console.log("MIDI not initialized: " + err.code)

  _midiStarted: (@_midiHandle) ->
    @_inputs = []
    entries = @_midiHandle.inputs.entries()
    while true
      entry = entries.next()
      unless entry.value?
        break
      @_inputs.push entry.value[1]
      entry.value[1].onmidimessage = _.bind(@_handleMidiMessage, this)
    @_inputsDep.changed()

  getInputs: ->
    @_inputsDep.depend()
    @_inputs

  setInput: (inputName) ->
    for input in @_inputs
      continue unless input.name == inputName
      input.onmidimessage = _.bind(@_handleMidiMessage, this)
      break

  _handleMidiMessage: (msg) ->
    channel = msg.data[0] & 0xf
    cmd = msg.data[0] >> 4

    #return if channel == 9 and cmd != 9

    @_velocity = msg.data[2]
    @_note = msg.data[1]
    if @_keyboard?
      switch cmd
        when 9
          @_keyboard.playNoteByMidiNumber(@_note)
        when 8
          @_keyboard.stopNoteByMidiNumber(@_note)

  getVelocity: ->
    @_velocityDep.depend()
    @_velocity

  getNote: ->
    @_noteDep.depend()
    @_note
<commit_msg>Count velocity 0 as note off<commit_after>class @MIDI
  constructor: ->
    @_inputsDep = new Tracker.Dependency
    @_velocityDep = new Tracker.Dependency
    @_noteDep = new Tracker.Dependency

  start: ->
    if navigator.requestMIDIAccess
      navigator.requestMIDIAccess().then(_.bind(@_midiStarted, this), @_midiError)

  setKeyboard: (@_keyboard) ->

  _midiError: (error) ->
    console.log("MIDI not initialized: " + err.code)

  _midiStarted: (@_midiHandle) ->
    @_inputs = []
    entries = @_midiHandle.inputs.entries()
    while true
      entry = entries.next()
      unless entry.value?
        break
      @_inputs.push entry.value[1]
      entry.value[1].onmidimessage = _.bind(@_handleMidiMessage, this)
    @_inputsDep.changed()

  getInputs: ->
    @_inputsDep.depend()
    @_inputs

  setInput: (inputName) ->
    for input in @_inputs
      continue unless input.name == inputName
      input.onmidimessage = _.bind(@_handleMidiMessage, this)
      break

  _handleMidiMessage: (msg) ->
    channel = msg.data[0] & 0xf
    cmd = msg.data[0] >> 4

    @_velocity = msg.data[2]
    @_note = msg.data[1]
    if @_velocity == 0
      # Count as note off event
      cmd = 8
    if @_keyboard?
      switch cmd
        when 9
          @_keyboard.playNoteByMidiNumber(@_note)
        when 8
          @_keyboard.stopNoteByMidiNumber(@_note)

  getVelocity: ->
    @_velocityDep.depend()
    @_velocity

  getNote: ->
    @_noteDep.depend()
    @_note

{'fraction_non_alphanumeric': 0.12146307798481712, 'fraction_numerical': 0.00862663906142167, 'mean_word_length': 2.6742712294043094, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '6879693', 'n_tokens_mistral': 1026, 'n_tokens_neox': 986, 'n_words': 200}