<commit_before>class @Keys
  constructor: (@canvas, @width, @height, @numNotes, @pubSub) ->
    @canvas.width = @width
    @canvas.height = @height
    @canvasContext = canvas.getContext '2d'
    @pubSub.on TouchController.TOUCH_START, @drawCurrentKey
    @pubSub.on TouchController.TOUCH_END, @clearKey
    @keys = []
    for i in [0..@numNotes]
      @keys[i] = 0

  drawCurrentKey: (message) =>
    @canvasContext.fillStyle = rgb2Color 255, 255, 255
    @applyCanvasFunction(message, 'fillRect')

  applyCanvasFunction: (message, func) =>
    yInc = @height / @numNotes
    y = message.pageY / @height
    noteNumber = Math.round(y * @numNotes)
    @keys[noteNumber] += 1
    startY = yInc * noteNumber
    @canvasContext[func] 0, startY, @width, yInc

  clearKey: (message) =>
    y = message.pageY / @height
    noteNumber = Math.round(y * @numNotes)
    numberOfTimesNotePressed = @keys[noteNumber]
    if numberOfTimesNotePressed == 0
      return
    numberOfTimesNotePressed -= 1
    if numberOfTimesNotePressed == 0
      @applyCanvasFunction(message, 'clearRect')
    @keys[noteNumber] = numberOfTimesNotePressed


<commit_msg>Best "keys" so far, but not perfect<commit_after>class @Keys
  constructor: (@canvas, @width, @height, @numNotes, @pubSub) ->
    @canvas.width = @width
    @canvas.height = @height
    @canvasContext = canvas.getContext '2d'
    @pubSub.on TouchController.TOUCH_START, @drawCurrentKey
    @pubSub.on TouchController.TOUCH_MOVE, @moveKey
    @pubSub.on TouchController.TOUCH_END, @clearKey
    @keys = []
    @ids = {}
    for i in [0..@numNotes]
      @keys[i] = 0

  _getNoteNumber: (message) ->
    y = message.pageY / @height
    return Math.round(y * @numNotes)

  drawCurrentKey: (message) =>
    noteNumber = @_getNoteNumber(message)
    oldNumber = @ids[message.identifier]
    unless oldNumber? and oldNumber == noteNumber
      @ids[message.identifier] = noteNumber
      @keys[noteNumber] += 1
    @canvasContext.fillStyle = rgb2Color 255, 255, 255
    @applyCanvasFunction(message, 'fillRect')

  applyCanvasFunction: (message, func) =>
    noteNumber = @_getNoteNumber(message)
    @_applyCanvasFunction(noteNumber, func)

  _applyCanvasFunction: (noteNumber, func) =>
    yInc = @height / @numNotes
    startY = yInc * noteNumber
    @canvasContext[func] 0, startY, @width, yInc

  clearKey: (message) =>
    noteNumber = @_getNoteNumber(message)
    oldNoteNumber = @ids[message.identifier]
    if oldNoteNumber? and oldNoteNumber != noteNumber
      @_clearKey(oldNoteNumber)
    @_clearKey(noteNumber)

  _clearKey: (noteNumber) ->
    numberOfTimesNotePressed = @keys[noteNumber]
    if numberOfTimesNotePressed == 0
      return
    numberOfTimesNotePressed -= 1
    if numberOfTimesNotePressed == 0
      @_applyCanvasFunction(noteNumber, 'clearRect')
    @keys[noteNumber] = numberOfTimesNotePressed

  moveKey: (message) =>
    noteNumber = @_getNoteNumber(message)
    oldNoteNumber = @ids[message.identifier]
    if oldNoteNumber? and oldNoteNumber != noteNumber
      @_clearKey(oldNoteNumber)
    @drawCurrentKey(message)


{'fraction_non_alphanumeric': 0.11694201490119857, 'fraction_numerical': 0.011661807580174927, 'mean_word_length': 3.75808936825886, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '5254090', 'n_tokens_mistral': 1052, 'n_tokens_neox': 995, 'n_words': 214}