Daaaayum!
parent
e089f4d0e3
commit
6496fbd7a8
|
@ -29,38 +29,70 @@ MAPPING = [
|
||||||
|
|
||||||
SPATH = "sounds/"
|
SPATH = "sounds/"
|
||||||
|
|
||||||
|
play_again_at = time.time()
|
||||||
|
|
||||||
def logmesohard(name):
|
def logmesohard(name):
|
||||||
|
return
|
||||||
s = socket.socket()
|
s = socket.socket()
|
||||||
s.connect(('10.8.1.1', 2003))
|
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()
|
s.close()
|
||||||
|
|
||||||
class SimpleSound:
|
print("Playing {}".format(name))
|
||||||
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
|
|
||||||
|
|
||||||
class RandomSound:
|
class Sound:
|
||||||
def __init__(self, paths):
|
def __init__(self, paths):
|
||||||
self.paths = paths
|
self.paths = paths
|
||||||
def create(self):
|
def create(self):
|
||||||
print("Loading {}".format(", ".join(self.paths)))
|
print("Loading {}".format(", ".join(self.paths)))
|
||||||
self.sounds = [(pygame.mixer.Sound(SPATH + p), p) for p in 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):
|
def play(self):
|
||||||
s, path = random.choice(self.sounds)
|
s, path = random.choice(self.sounds)
|
||||||
logmesohard(self.paths[0])
|
logmesohard(self.path)
|
||||||
print("Playing {}".format(path))
|
|
||||||
print(s)
|
print(s)
|
||||||
s.play()
|
s.play()
|
||||||
return s.get_length() * 0.5
|
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 = [
|
SOUNDS = [
|
||||||
SimpleSound("nope.wav"),
|
SimpleSound("nope.wav"),
|
||||||
SimpleSound("yesyes.wav"),
|
SimpleSound("yesyes.wav"),
|
||||||
|
@ -70,15 +102,13 @@ SOUNDS = [
|
||||||
SimpleSound("trombone.wav"),
|
SimpleSound("trombone.wav"),
|
||||||
RandomSound(["whip.wav", "whip2.wav", "whip4.wav"]),
|
RandomSound(["whip.wav", "whip2.wav", "whip4.wav"]),
|
||||||
SimpleSound("finishim.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("noooooooo.wav"),
|
||||||
SimpleSound("fanfare.wav"),
|
SimpleSound("fanfare.wav"),
|
||||||
SimpleSound("dundundun.wav"),
|
SimpleSound("dundundun.wav"),
|
||||||
]
|
]
|
||||||
|
|
||||||
play_again_at = time.time()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# are we a fucking rpi?
|
# are we a fucking rpi?
|
||||||
f = open("/proc/cpuinfo", "r")
|
f = open("/proc/cpuinfo", "r")
|
||||||
|
@ -94,6 +124,11 @@ if __name__ == "__main__":
|
||||||
for s in SOUNDS:
|
for s in SOUNDS:
|
||||||
s.create()
|
s.create()
|
||||||
pygame.joystick.init()
|
pygame.joystick.init()
|
||||||
|
|
||||||
|
if pygame.joystick.get_count() == 0:
|
||||||
|
print("You don't have any joysticks.")
|
||||||
|
exit()
|
||||||
|
|
||||||
j = pygame.joystick.Joystick(0)
|
j = pygame.joystick.Joystick(0)
|
||||||
j.init()
|
j.init()
|
||||||
print("Ready!")
|
print("Ready!")
|
||||||
|
@ -102,8 +137,10 @@ if __name__ == "__main__":
|
||||||
pygame.event.pump()
|
pygame.event.pump()
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == JOYBUTTONDOWN:
|
if event.type == JOYBUTTONDOWN:
|
||||||
|
print("JOYBUTTONDOWN")
|
||||||
n = MAPPING.index(event.button)
|
n = MAPPING.index(event.button)
|
||||||
if n < len(SOUNDS) and time.time() >= play_again_at:
|
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)
|
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue