Initial commit. Code kind of works.
commit
d91a4ddd8f
|
@ -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)
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue