-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsound.py
47 lines (37 loc) · 1.38 KB
/
sound.py
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
"""
Autor: Leandro Monteiro
Arquivo responsável pela classe de gerenciamento de som.
sound.py
"""
# Desabilita a mensagem de boas-vinas do pygame no console.
import os
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = '1'
import pygame
class SoundManager():
def __init__(self, parent):
self.parent = parent
pygame.init()
pygame.mixer.init()
pygame.mixer.set_num_channels(8)
self.pumpMixer = pygame.mixer.Channel(5)
self.waterMixer = pygame.mixer.Channel(6)
self.pumpSound = pygame.mixer.Sound('sounds/water_pump.wav')
self.waterSound = pygame.mixer.Sound('sounds/water_flowing.wav')
def SoundPlayback(self, key, state):
''' Toca ou para o som. '''
if key == 'rpm':
if state:
if not self.pumpMixer.get_busy():
self.pumpMixer.play(self.pumpSound, loops=-1)
else:
self.pumpMixer.stop()
elif key == 'abertura':
if state:
if not self.waterMixer.get_busy():
self.waterMixer.play(self.waterSound, loops=-1)
else:
self.waterMixer.stop()
def SoundVolume(self, volume):
''' Muda o volume. '''
self.pumpMixer.set_volume(volume / 5) # Barulho do motor é muito alto.
self.waterMixer.set_volume(volume)