diff --git a/host.py b/host.py old mode 100644 new mode 100755 index 846c974..dbb943a --- a/host.py +++ b/host.py @@ -29,38 +29,70 @@ MAPPING = [ SPATH = "sounds/" +play_again_at = time.time() + def logmesohard(name): + return s = socket.socket() s.connect(('10.8.1.1', 2003)) - s.sendall('hackerspace.soundboard.{} 1'.format(name.replace('.', '_'_))) + s.sendall('hackerspace.soundboard.{} 1'.format(name.replace('.', '_'))) s.close() -class SimpleSound: - def __init__(self, path): - self.path = path - def create(self): - print("Loading {}".format(self.path)) - self.s = pygame.mixer.Sound(SPATH + self.path) - def play(self): - print("Playing {}".format(self.path)) - logmesohard(self.path) - self.s.play() - return self.s.get_length() * 0.5 + print("Playing {}".format(name)) -class RandomSound: +class Sound: def __init__(self, paths): self.paths = paths def create(self): print("Loading {}".format(", ".join(self.paths))) self.sounds = [(pygame.mixer.Sound(SPATH + p), p) for p in self.paths] + +class SimpleSound(Sound): + def __init__(self, path): + super(SimpleSound,self).__init__([path,]) + + def play(self): + logmesohard(self.paths[0]) + # loonquawl is an idiot + sound = self.sounds[0][0] + sound.play() + return sound.get_length() * 0.5 + +class RandomSound(Sound): def play(self): s, path = random.choice(self.sounds) - logmesohard(self.paths[0]) - print("Playing {}".format(path)) + logmesohard(self.path) print(s) s.play() return s.get_length() * 0.5 +class ListSound(Sound): + def __init__(self, paths): + self._state = self._getsound() + super().__init__(paths) + + def _getsound(self): + last_sound = None + delay = 3 + index = 0 + while True: + if last_sound is None or last_sound + delay < time.time(): + index = 0 + last_sound = time.time() + else: + index += 1 + if index >= len(self.sounds): + index = 0 + last_sound = time.time() + sound = self.sounds[index] + yield sound[0], sound[1] + + def play(self): + s, path = next(self._state) + print(s) + s.play() + return s.get_length() * 0.75 + SOUNDS = [ SimpleSound("nope.wav"), SimpleSound("yesyes.wav"), @@ -70,15 +102,13 @@ SOUNDS = [ SimpleSound("trombone.wav"), RandomSound(["whip.wav", "whip2.wav", "whip4.wav"]), SimpleSound("finishim.wav"), - SimpleSound("wtfboom.wav"), +# SimpleSound("wtfboom.wav"), # We all hate it anyway. + ListSound(["dayum1.wav", "dayum2.wav", "dayum3.wav"]), SimpleSound("noooooooo.wav"), SimpleSound("fanfare.wav"), SimpleSound("dundundun.wav"), ] -play_again_at = time.time() - - if __name__ == "__main__": # are we a fucking rpi? f = open("/proc/cpuinfo", "r") @@ -94,6 +124,11 @@ if __name__ == "__main__": for s in SOUNDS: s.create() pygame.joystick.init() + + if pygame.joystick.get_count() == 0: + print("You don't have any joysticks.") + exit() + j = pygame.joystick.Joystick(0) j.init() print("Ready!") @@ -102,8 +137,10 @@ if __name__ == "__main__": pygame.event.pump() for event in pygame.event.get(): if event.type == JOYBUTTONDOWN: + print("JOYBUTTONDOWN") n = MAPPING.index(event.button) if n < len(SOUNDS) and time.time() >= play_again_at: - play_again_at = time.time() + SOUNDS[n].play() + play_again_at = time.time() + SOUNDS[n].play() + + time.sleep(0.01) - time.sleep(0.1) diff --git a/sounds/dayum1.wav b/sounds/dayum1.wav new file mode 100644 index 0000000..bcb9910 Binary files /dev/null and b/sounds/dayum1.wav differ diff --git a/sounds/dayum2.wav b/sounds/dayum2.wav new file mode 100644 index 0000000..334924c Binary files /dev/null and b/sounds/dayum2.wav differ diff --git a/sounds/dayum3.wav b/sounds/dayum3.wav new file mode 100644 index 0000000..855c51c Binary files /dev/null and b/sounds/dayum3.wav differ