<commit_before>#!/usr/bin/env python
import RPi.GPIO as GPIO
import pygame
import time


FILENAME = 'mariachi.wav'


class TriggerPlayer(object):

    def __init__(self, filename, gpio_pin):
        # Setup player
        self.__gpio_pin = gpio_pin
        self.__playing = False
        # start mixer and load music
        pygame.mixer.init()
        pygame.mixer.music.load(filename)
        # Setup GPIO
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(gpio_pin, GPIO.IN)
        GPIO.add_event_detect(gpio_pin, GPIO.BOTH)
        GPIO.add_event_callback(gpio_pin, self.update_state)

    def is_playing(self):
        return self.__playing

    def play(self):
        self.__playing = True
        return pygame.mixer.music.play(-1)

    def stop(self):
        self.__playing = False
        return pygame.mixer.music.stop()

    def update_state(self, pin):
        if pin == self.__gpio_pin:
            time.sleep(1)
            input_ = GPIO.input(self.__gpio_pin)
            if input_ and not self.is_playing():
                self.play()
            elif not input_ and self.is_playing():
                self.stop()


if __name__ == '__main__':
    player = TriggerPlayer(FILENAME, 23)
    try:
        while True:
            GPIO.event_detected(23)
    except KeyboardInterrupt:
        GPIO.cleanup()<commit_msg>Reverse button and set correct initial state<commit_after>#!/usr/bin/env python
import RPi.GPIO as GPIO
import pygame
import time


FILENAME = 'mariachi.wav'


class TriggerPlayer(object):

    def __init__(self, filename, gpio_pin):
        # Setup player
        self.__gpio_pin = gpio_pin
        self.__playing = False
        # start mixer and load music
        pygame.mixer.init()
        pygame.mixer.music.load(filename)
        # Setup GPIO
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(gpio_pin, GPIO.IN)
        GPIO.add_event_detect(gpio_pin, GPIO.BOTH)
        GPIO.add_event_callback(gpio_pin, self.update_state)
        self.update_state(gpio_pin)

    def is_playing(self):
        return self.__playing

    def play(self):
        self.__playing = True
        return pygame.mixer.music.play(-1)

    def stop(self):
        self.__playing = False
        return pygame.mixer.music.stop()

    def update_state(self, pin):
        if pin == self.__gpio_pin:
            time.sleep(1)
            input_ = GPIO.input(self.__gpio_pin)
            if not input_ and not self.is_playing():
                self.play()
            elif input_ and self.is_playing():
                self.stop()


if __name__ == '__main__':
    player = TriggerPlayer(FILENAME, 23)
    try:
        while True:
            GPIO.event_detected(23)
    except KeyboardInterrupt:
        GPIO.cleanup()
{'fraction_non_alphanumeric': 0.09556938850238009, 'fraction_numerical': 0.004393994873672647, 'mean_word_length': 2.129438717067583, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3770382', 'n_tokens_mistral': 883, 'n_tokens_neox': 833, 'n_words': 186}