-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsoundboard2.py
More file actions
147 lines (135 loc) · 4.93 KB
/
Copy pathsoundboard2.py
File metadata and controls
147 lines (135 loc) · 4.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
"""Test script for using pygame to read in ds4 controller
with ds4drv running as a daemon
DS4 controller axis maps:
X 1
Square 0
O 2
Triangle 3
R1 5
L1 4
R2 7 and axis 4
L2 axis 3 and button 6
R stick button 11
L stick button 10
Options 9
Share 8
D pad hat
Click 13
PS 12
L stick L/R axis 0 (L -1 R 1)
L stick up/down axis 1 (up -1 down 1)
R stick L/R axis 2 (L -1 R 1)
R stick up/down axis 5 (up -1 down 1)
"""
import os
import pygame
import pygame.mixer
from time import sleep
import sys
pygame.mixer.init(48000, -16, 1, 1024)
sndA = pygame.mixer.Sound("Obey.wav")
sndB = pygame.mixer.Sound("youwillbeexterminated!.wav")
sndC = pygame.mixer.Sound("annihilate.wav")
sndD = pygame.mixer.Sound("Emrgncy.wav")
sndE = pygame.mixer.Sound("R2D2.wav")
sndF = pygame.mixer.Sound("Tardis.wav")
sndG = pygame.mixer.Sound("Theme.wav")
sndH = pygame.mixer.Sound("Intruder.wav")
soundChannelA = pygame.mixer.Channel(0)
soundChannelB = pygame.mixer.Channel(1)
soundChannelC = pygame.mixer.Channel(2)
soundChannelD = pygame.mixer.Channel(3)
soundChannelE = pygame.mixer.Channel(4)
soundChannelF = pygame.mixer.Channel(5)
soundChannelF = pygame.mixer.Channel(6)
soundChannelF = pygame.mixer.Channel(7)
print ("Soundboard loaded")
#os.system("espeak -p 1 -v english-us 'Soundboard loaded'")
global DS4 #create global variable
def Dualshock4Init():
global DS4
# Setup pygame and wait for the joystick to become available
pygame.init()
print 'Waiting for joystick... (press CTRL+C to abort)'
while True:
try:
try:
pygame.joystick.init()
# Attempt to setup the joystick
if pygame.joystick.get_count() < 1:
Print("No joystick attached")
pygame.joystick.quit()
sleep(0.1)
else:
# We have a joystick, attempt to initialise it!
DS4 = pygame.joystick.Joystick(0)
break
except pygame.error:
print("Failed to connect to the joystick")
pygame.joystick.quit()
sleep(0.1)
except KeyboardInterrupt:
# CTRL+C exit, give up
print '\nUser aborted'
sys.exit()
print 'Joystick found'
DS4.init()
def soundboard():
global DS4
print ('Press CTRL+C to quit')
if not DS4.get_init():
print("re-initializing controller")
DS4.init()
elif DS4.get_init():
print("DS4 Initialized")
else:
print("WTF?")
while True:
try:
pygame.event.get()
LSLR = DS4.get_axis(0) #Left stick left right (-1 left, 1 right)
LSUD = DS4.get_axis(1) #Left stick up down (-1 up, 1 down)
RSLR = DS4.get_axis(2) #Right stick left right (-1 left, 1 right)
RSUD = DS4.get_axis(5) #Left stick up down (-1 up, 1 down)
R2 = DS4.get_axis(4) # R2 (-1 unpressed, 1 completely pressed)
L2 = DS4.get_axis(3) # L2 (-1 unpressed, 1 completely pressed)
Triangle =DS4.get_button(3)
Circle = DS4.get_button(2)
Square = DS4.get_button(0)
X = DS4.get_button(1)
L1 = DS4.get_button(4)
R1 = DS4.get_button(5)
L3 = DS4.get_button(10) #button under L stick
R3 = DS4.get_button(11) #button under R stick
PS = DS4.get_button(12)
Share = DS4.get_button(8)
Options = DS4.get_button(9)
#Dpad1 = DS4.get_hat(0)
#Dpad2 = DS4.get_hat(0)
#Code for soundboard
if Triangle and not pygame.mixer.get_busy(): #checks to see if button is pressed and sound is already playing or not
soundChannelA.play(sndA)
print("Playing sndA!")
elif Triangle and pygame.mixer.get_busy(): #if sound is playing, then dont play sound
print("Waiting for sndA to finish!")
if Circle and not pygame.mixer.get_busy():
soundChannelB.play(sndB)
print("Playing sndB!")
elif Circle and pygame.mixer.get_busy():
print("Waiting for sndB to finish!")
if Square and not pygame.mixer.get_busy():
soundChannelC.play(sndC)
print("Playing sndC!")
elif Square and pygame.mixer.get_busy():
print("Waiting for sndC to finish!")
if X and not pygame.mixer.get_busy():
soundChannelD.play(sndD)
print("Playing sndD!")
elif X and pygame.mixer.get_busy():
print("Waiting for sndD to finish!")
sleep(0.1) #limit the frequency to 10Hz
except KeyboardInterrupt:
print("Stopping...")
pygame.quit()
Dualshock4Init()
soundboard()