volume modifier
This commit is contained in:
parent
732a00d079
commit
a65355bf9f
|
@ -9,28 +9,27 @@ from Input import *
|
|||
class Audio(GameChild):
|
||||
|
||||
UP, DOWN = .1, -.1
|
||||
BASE_VOLUME = .8
|
||||
|
||||
def __init__(self, game):
|
||||
GameChild.__init__(self, game)
|
||||
self.original_volumes = {}
|
||||
self.volume = self.BASE_VOLUME
|
||||
if self.check_command_line("-mute"):
|
||||
self.set_volume(mute=True)
|
||||
self.volume = self.BASE_VOLUME
|
||||
self.subscribe(self.respond)
|
||||
|
||||
def set_volume(self, volume=None, increment=None, channels=None, mute=False):
|
||||
if not channels:
|
||||
channels = (Channel(ii) for ii in xrange(get_num_channels()))
|
||||
elif isinstance(channels, Channel):
|
||||
channels = [channels]
|
||||
for channel in channels:
|
||||
if mute:
|
||||
volume = 0
|
||||
elif increment:
|
||||
volume = channel.get_volume() + increment
|
||||
if volume > 1:
|
||||
volume = 1.0
|
||||
elif volume < 0:
|
||||
volume = 0
|
||||
channel.set_volume(volume)
|
||||
def set_volume(self, volume=None, increment=None, mute=False):
|
||||
if mute:
|
||||
self.volume = 0
|
||||
elif increment:
|
||||
self.volume += increment
|
||||
if self.volume > 1:
|
||||
self.volume = 1.0
|
||||
elif self.volume < 0:
|
||||
self.volume = 0
|
||||
else:
|
||||
self.volume = volume
|
||||
|
||||
def respond(self, event):
|
||||
compare = self.get_game().delegate.compare
|
||||
|
@ -40,3 +39,12 @@ class Audio(GameChild):
|
|||
self.set_volume(increment=self.UP)
|
||||
elif compare(event, "volume-down"):
|
||||
self.set_volume(increment=self.DOWN)
|
||||
|
||||
def update(self):
|
||||
for ii in xrange(get_num_channels()):
|
||||
channel = Channel(ii)
|
||||
sound = channel.get_sound()
|
||||
if sound is not None:
|
||||
if sound not in self.original_volumes.keys():
|
||||
self.original_volumes[sound] = sound.get_volume()
|
||||
sound.set_volume(self.original_volumes[sound] * self.volume)
|
||||
|
|
|
@ -54,6 +54,7 @@ class Game(GameChild):
|
|||
self.update()
|
||||
else:
|
||||
self.interpolator.gui.update()
|
||||
self.audio.update()
|
||||
if self.video_recorder.requested:
|
||||
self.video_recorder.update()
|
||||
|
||||
|
|
Loading…
Reference in New Issue