Daaaayum!

master
Mateusz Zalega 2013-10-19 20:27:19 +02:00 committed by Sergiusz 'q3k' Bazański
parent e089f4d0e3
commit 6496fbd7a8
4 changed files with 58 additions and 21 deletions

79
host.py Normal file → Executable file
View File

@ -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)

BIN
sounds/dayum1.wav Normal file

Binary file not shown.

BIN
sounds/dayum2.wav Normal file

Binary file not shown.

BIN
sounds/dayum3.wav Normal file

Binary file not shown.