<commit_before>#! /bin/python

import os
import time
os.environ["SDL_VIDEODRIVER"] = "dummy"

from evdev import InputDevice, categorize, ecodes

import pygame

if __name__ == '__main__':

  # Need to pre-init the mixer or the delay between start() and the
  # sound is large, approx. 400ms.
  # See: http://stackoverflow.com/questions/18273722/pygame-sound-delay
  pygame.mixer.pre_init(44100, -16, 2, 1024)

  pygame.init();
  pygame.display.set_mode((1,1))

  dev = InputDevice('/dev/input/by-id/usb-JoyLabz_Makey_Makey_v1.20aa_50000000-event-kbd')

  # Don't need any params since we called pre_ini().
  pygame.mixer.init()

  touchStateMap = {
    1: "press",
    2: "hold",
    0: "release"
  }

  # Ten notes for ten inputs from the MakeyMakey.
  c4 = pygame.mixer.Sound('audio-files/C4-261.63.wav')
  d4 = pygame.mixer.Sound('audio-files/D4-293.66.wav')
  e4 = pygame.mixer.Sound('audio-files/E4-329.63.wav')
  f4 = pygame.mixer.Sound('audio-files/F4-349.23.wav')
  g4 = pygame.mixer.Sound('audio-files/G4-392.0.wav')
  a4 = pygame.mixer.Sound('audio-files/A4-440.0.wav')
  b4 = pygame.mixer.Sound('audio-files/B4-493.88.wav')
  c5= pygame.mixer.Sound('audio-files/C5-523.25.wav')
  d5= pygame.mixer.Sound('audio-files/D5-587.33.wav')
  e5= pygame.mixer.Sound('audio-files/E5-659.26.wav')

  # Map between input codes and the notes to play.
  noteMap = {
    ecodes.KEY_UP: c4,
    ecodes.KEY_RIGHT: d4,
    ecodes.KEY_DOWN: e4,
    ecodes.KEY_LEFT: f4,
    ecodes.KEY_W: g4,
    ecodes.KEY_A: a4,
    ecodes.KEY_S: b4,
    ecodes.KEY_D: c5,
    ecodes.KEY_F: d5,
    ecodes.KEY_G: e5,
  }

  for event in dev.read_loop():
    if event.type == ecodes.EV_KEY:
      if 0<=event.value and event.value<=2:
        touchState = touchStateMap[event.value]

      note = noteMap[event.code]

      if not(note == None):
        if touchState == 'press':
          note.play()
        elif touchState == 'release':
          note.stop()
    <commit_msg>Added piano mode sounds and logic.<commit_after>#! /bin/python

import os
import time
os.environ["SDL_VIDEODRIVER"] = "dummy"

from evdev import InputDevice, categorize, ecodes

import pygame

if __name__ == '__main__':

  # Need to pre-init the mixer or the delay between start() and the
  # sound is large, approx. 400ms.
  # See: http://stackoverflow.com/questions/18273722/pygame-sound-delay
  pygame.mixer.pre_init(44100, -16, 2, 1024)

  pygame.init();
  pygame.display.set_mode((1,1))

  dev = InputDevice('/dev/input/by-id/usb-JoyLabz_Makey_Makey_v1.20aa_50000000-event-kbd')

  # Don't need any params since we called pre_ini().
  pygame.mixer.init()

  touchStateMap = {
    1: "press",
    2: "hold",
    0: "release"
  }

  # Ten notes for ten inputs from the MakeyMakey.
  organNotes = [
    pygame.mixer.Sound('audio-files/C4-261.63.wav'),
    pygame.mixer.Sound('audio-files/D4-293.66.wav'),
    pygame.mixer.Sound('audio-files/E4-329.63.wav'),
    pygame.mixer.Sound('audio-files/F4-349.23.wav'),
    pygame.mixer.Sound('audio-files/G4-392.0.wav'),
    pygame.mixer.Sound('audio-files/A4-440.0.wav'),
    pygame.mixer.Sound('audio-files/B4-493.88.wav'),
    pygame.mixer.Sound('audio-files/C5-523.25.wav'),
    pygame.mixer.Sound('audio-files/D5-587.33.wav'),
    pygame.mixer.Sound('audio-files/E5-659.26.wav'),
  ]

  pianoNotes = [
    pygame.mixer.Sound('audio-files/net_C3.wav'),
    pygame.mixer.Sound('audio-files/net_D3.wav'),
    pygame.mixer.Sound('audio-files/net_E3.wav'),
    pygame.mixer.Sound('audio-files/net_F3.wav'),
    pygame.mixer.Sound('audio-files/net_G3.wav'),
    pygame.mixer.Sound('audio-files/net_A3.wav'),
    pygame.mixer.Sound('audio-files/net_B3.wav'),
    pygame.mixer.Sound('audio-files/net_C4.wav'),
    pygame.mixer.Sound('audio-files/net_D4.wav'),
    pygame.mixer.Sound('audio-files/net_E4.wav'),
  ]

  mode = "piano"
  notes = pianoNotes

  # Map between input codes and the notes to play.
  noteMap = {
    ecodes.KEY_UP: notes[0],
    ecodes.KEY_RIGHT: notes[1],
    ecodes.KEY_DOWN: notes[2],
    ecodes.KEY_LEFT: notes[3],
    ecodes.KEY_W: notes[4],
    ecodes.KEY_A: notes[5],
    ecodes.KEY_S: notes[6],
    ecodes.KEY_D: notes[7],
    ecodes.KEY_F: notes[8],
    ecodes.KEY_G: notes[9],
  }

  for event in dev.read_loop():
    if event.type == ecodes.EV_KEY:
      if 0<=event.value and event.value<=2:
        touchState = touchStateMap[event.value]

      note = noteMap[event.code]

      if not(note == None):
        if touchState=='press':
          note.stop()
          note.play()
        elif touchState=='release' and mode=='organ':
          note.stop()
    
{'fraction_non_alphanumeric': 0.16041848299912817, 'fraction_numerical': 0.05187445510026155, 'mean_word_length': 3.104651162790698, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '429766', 'n_tokens_mistral': 1951, 'n_tokens_neox': 1845, 'n_words': 304}