Initial commit. Code kind of works.

master
q3k 2013-07-14 17:45:54 +02:00
commit d91a4ddd8f
18 changed files with 83 additions and 0 deletions

83
host.py Normal file
View File

@ -0,0 +1,83 @@
#!/usr/bin/env python3
import sys
import time
import random
import pygame
from pygame.locals import *
# "we'll fix it in post!"
MAPPING = [
8,
7,
6,
5,
1,
2,
3,
4,
9,
10,
11,
0
]
SPATH = "/mnt/nas/Projects/soundboard/sounds/"
class SimpleSound:
def __init__(self, path):
self.path = path
def create(self):
self.s = pygame.mixer.Sound(SPATH + self.path)
def play(self):
self.s.play()
return self.s.get_length() * 0.5
class RandomSound:
def __init__(self, paths):
self.paths = paths
def create(self):
self.sounds = [pygame.mixer.Sound(SPATH + p) for p in self.paths]
def play(self):
s = random.choice(self.sounds)
print(s)
s.play()
return s.get_length() * 0.5
SOUNDS = [
SimpleSound("nope.wav"),
SimpleSound("yesyes.wav"),
SimpleSound("ba-dum-tish.wav"),
SimpleSound("crickets.wav"),
SimpleSound("wind.wav"),
SimpleSound("trombone.wav"),
RandomSound(["whip.wav", "whip2.wav", "whip4.wav"]),
SimpleSound("finishim.wav"),
SimpleSound("wtfboom.wav"),
SimpleSound("noooooooo.wav"),
SimpleSound("fanfare.wav"),
SimpleSound("dundundun.wav"),
]
play_again_at = time.time()
if __name__ == "__main__":
pygame.init()
for s in SOUNDS:
s.create()
pygame.joystick.init()
j = pygame.joystick.Joystick(0)
j.init()
while True:
pygame.event.pump()
for event in pygame.event.get():
if event.type == JOYBUTTONDOWN:
n = MAPPING.index(event.button)
if n < len(SOUNDS) and time.time() >= play_again_at:
play_again_at = time.time() + SOUNDS[n].play()
time.sleep(0.1)

BIN
sounds/ba-dum-tish.wav Normal file

Binary file not shown.

BIN
sounds/crickets.wav Executable file

Binary file not shown.

BIN
sounds/dundundun.wav Executable file

Binary file not shown.

BIN
sounds/fanfare.wav Executable file

Binary file not shown.

BIN
sounds/fight.wav Executable file

Binary file not shown.

BIN
sounds/finishim.wav Executable file

Binary file not shown.

BIN
sounds/noooooooo.wav Executable file

Binary file not shown.

BIN
sounds/nope.wav Executable file

Binary file not shown.

BIN
sounds/partyalarm.wav Executable file

Binary file not shown.

BIN
sounds/trombone.wav Executable file

Binary file not shown.

BIN
sounds/whip.wav Executable file

Binary file not shown.

BIN
sounds/whip2.wav Executable file

Binary file not shown.

BIN
sounds/whip3.wav Executable file

Binary file not shown.

BIN
sounds/whip4.wav Executable file

Binary file not shown.

BIN
sounds/wind.wav Executable file

Binary file not shown.

BIN
sounds/wtfboom.wav Executable file

Binary file not shown.

BIN
sounds/yesyes.wav Executable file

Binary file not shown.