mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-05 03:15:07 -04:00
changes for new audio
This commit is contained in:
parent
fdaaef70c3
commit
c99ef1337b
@ -32,10 +32,10 @@ class SoundInterval(Interval):
|
|||||||
if duration == 0.0:
|
if duration == 0.0:
|
||||||
if self.wantSound:
|
if self.wantSound:
|
||||||
duration = self.sound.length()
|
duration = self.sound.length()
|
||||||
if (duration == 0):
|
if (duration == 0):
|
||||||
self.notify.warning('zero length duration!')
|
self.notify.warning('zero length duration!')
|
||||||
# MPG - hack for Miles bug
|
# MPG - hack for Miles bug
|
||||||
duration += 1.5
|
duration += 1.5
|
||||||
else:
|
else:
|
||||||
# This will screw up any intervals that base their
|
# This will screw up any intervals that base their
|
||||||
# time on the duration of this sound interval
|
# time on the duration of this sound interval
|
||||||
@ -61,7 +61,7 @@ class SoundInterval(Interval):
|
|||||||
# Update sound based on current time
|
# Update sound based on current time
|
||||||
if (t >= self.getDuration()):
|
if (t >= self.getDuration()):
|
||||||
# If end of sound reached or stop event received, stop sound
|
# If end of sound reached or stop event received, stop sound
|
||||||
AudioManager.stop(self.sound)
|
self.sound.stop()
|
||||||
self.ignore(self.stopEvent)
|
self.ignore(self.stopEvent)
|
||||||
elif (event == IVAL_INIT):
|
elif (event == IVAL_INIT):
|
||||||
# IVAL_INIT event, start new sound
|
# IVAL_INIT event, start new sound
|
||||||
@ -70,10 +70,12 @@ class SoundInterval(Interval):
|
|||||||
if (t < 0.1):
|
if (t < 0.1):
|
||||||
t = 0.0
|
t = 0.0
|
||||||
# Start sound
|
# Start sound
|
||||||
AudioManager.play(self.sound, t, self.loop)
|
self.sound.setTime(t)
|
||||||
|
self.sound.setLoop(self.loop)
|
||||||
|
self.sound.play()
|
||||||
# Accept event to kill sound
|
# Accept event to kill sound
|
||||||
self.acceptOnce(self.stopEvent,
|
self.acceptOnce(self.stopEvent,
|
||||||
lambda s = self: AudioManager.stop(s.sound))
|
lambda s = self: s.sound.stop())
|
||||||
# Print debug information
|
# Print debug information
|
||||||
self.notify.debug('updateFunc() - %s: t = %f' % (self.name, t))
|
self.notify.debug('updateFunc() - %s: t = %f' % (self.name, t))
|
||||||
|
|
||||||
|
@ -85,10 +85,10 @@ class Loader:
|
|||||||
return ModelPool.loadModel(modelPath)
|
return ModelPool.loadModel(modelPath)
|
||||||
|
|
||||||
def unloadModel(self, modelPath):
|
def unloadModel(self, modelPath):
|
||||||
"""unloadModel(self, string)
|
"""unloadModel(self, string)
|
||||||
"""
|
"""
|
||||||
Loader.notify.debug("Unloading model: %s" % (modelPath))
|
Loader.notify.debug("Unloading model: %s" % (modelPath))
|
||||||
ModelPool.releaseModel(modelPath)
|
ModelPool.releaseModel(modelPath)
|
||||||
|
|
||||||
# font loading funcs
|
# font loading funcs
|
||||||
def loadFont(self, modelPath, priority = 0):
|
def loadFont(self, modelPath, priority = 0):
|
||||||
@ -132,10 +132,10 @@ class Loader:
|
|||||||
return texture
|
return texture
|
||||||
|
|
||||||
def unloadTexture(self, texture):
|
def unloadTexture(self, texture):
|
||||||
"""unloadTexture(self, texture)
|
"""unloadTexture(self, texture)
|
||||||
"""
|
"""
|
||||||
Loader.notify.debug("Unloading texture: %s" % (texture) )
|
Loader.notify.debug("Unloading texture: %s" % (texture) )
|
||||||
TexturePool.releaseTexture(texture)
|
TexturePool.releaseTexture(texture)
|
||||||
|
|
||||||
# sound loading funcs
|
# sound loading funcs
|
||||||
def loadSound(self, soundPath):
|
def loadSound(self, soundPath):
|
||||||
@ -145,13 +145,13 @@ class Loader:
|
|||||||
Loader.notify.debug("Loading sound: %s" % (soundPath) )
|
Loader.notify.debug("Loading sound: %s" % (soundPath) )
|
||||||
if phaseChecker:
|
if phaseChecker:
|
||||||
phaseChecker(soundPath)
|
phaseChecker(soundPath)
|
||||||
sound = AudioPool.loadSound(soundPath)
|
sound = base.effectsAudioManager.getSound(soundPath)
|
||||||
return sound
|
return sound
|
||||||
|
|
||||||
def unloadSound(self, sound):
|
def unloadSound(self, sound):
|
||||||
"""unloadSound(self, sound)
|
"""unloadSound(self, sound)
|
||||||
"""
|
"""
|
||||||
if sound:
|
if sound:
|
||||||
Loader.notify.debug("Unloading sound: %s" % (sound) )
|
Loader.notify.debug("Unloading sound: %s" % (sound) )
|
||||||
AudioPool.releaseSound(sound)
|
del sound
|
||||||
|
|
||||||
|
@ -37,9 +37,10 @@ class ShowBase:
|
|||||||
self.wantTk = self.config.GetBool('want-tk', 0)
|
self.wantTk = self.config.GetBool('want-tk', 0)
|
||||||
self.wantAnySound = self.config.GetBool('want-sound', 1)
|
self.wantAnySound = self.config.GetBool('want-sound', 1)
|
||||||
if not self.wantAnySound:
|
if not self.wantAnySound:
|
||||||
AudioManager.setAllSoundActive(0)
|
self.effectsAudioManager.setActive(0)
|
||||||
self.wantSfx = AudioManager.getSfxActive()
|
self.musicAudioManager.setActive(0)
|
||||||
self.wantMusic = AudioManager.getMusicActive()
|
self.wantSfx = self.config.GetBool('audio-sfx-active', 1)
|
||||||
|
self.wantMusic = self.config.GetBool('audio-music-active', 1)
|
||||||
if not (self.wantSfx or self.wantMusic):
|
if not (self.wantSfx or self.wantMusic):
|
||||||
self.wantAnySound = None
|
self.wantAnySound = None
|
||||||
self.wantDIRECT = self.config.GetBool('want-directtools', 0)
|
self.wantDIRECT = self.config.GetBool('want-directtools', 0)
|
||||||
@ -275,61 +276,56 @@ class ShowBase:
|
|||||||
|
|
||||||
def createAudioManager(self):
|
def createAudioManager(self):
|
||||||
if self.wantAnySound:
|
if self.wantAnySound:
|
||||||
AudioManager.spawnUpdate()
|
self.effectsAudioManager = AudioManager.createAudioManager()
|
||||||
|
self.musicAudioManager = AudioManager.createAudioManager()
|
||||||
|
|
||||||
def loadSfx(self, name):
|
def loadSfx(self, name):
|
||||||
if (name and base.wantSfx):
|
if (name and base.wantSfx):
|
||||||
sound=loader.loadSound(name)
|
sound=self.effectsAudioManager.getSound(name)
|
||||||
if sound:
|
|
||||||
sound.setCategory(sound.EFFECT)
|
|
||||||
return sound
|
return sound
|
||||||
|
|
||||||
def loadMusic(self, name):
|
def loadMusic(self, name):
|
||||||
if (name and base.wantMusic):
|
if (name and base.wantMusic):
|
||||||
sound=loader.loadSound(name)
|
sound=self.musicAudioManager.getSound(name)
|
||||||
if sound:
|
|
||||||
sound.setCategory(sound.MUSIC)
|
|
||||||
return sound
|
return sound
|
||||||
|
|
||||||
def unloadSfx(self, sfx):
|
def unloadSfx(self, sfx):
|
||||||
if sfx:
|
if sfx:
|
||||||
loader.unloadSound(sfx)
|
del sfx
|
||||||
|
|
||||||
def unloadMusic(self, music):
|
def unloadMusic(self, music):
|
||||||
if music:
|
if music:
|
||||||
loader.unloadSound(music)
|
del music
|
||||||
|
|
||||||
def playSfx(self, sfx, looping = 0, interupt = 1, volume = None,
|
def playSfx(self, sfx, looping = 0, interupt = 1, volume = None,
|
||||||
time = 0.):
|
time = 0.):
|
||||||
if (sfx and base.wantSfx):
|
if (sfx and base.wantSfx):
|
||||||
if not interupt:
|
if volume != None:
|
||||||
if not (sfx.status() == AudioSound.PLAYING):
|
sfx.setVolume(volume)
|
||||||
AudioManager.play(sfx, time, looping)
|
if interupt or (sfx.status() != AudioSound.PLAYING):
|
||||||
else:
|
sfx.setTime(time)
|
||||||
AudioManager.play(sfx, time, looping)
|
sfx.setLoop(looping)
|
||||||
if volume:
|
sfx.play()
|
||||||
AudioManager.setVolume(sfx, volume)
|
|
||||||
|
|
||||||
def playMusic(self, music, looping = 0, interupt = 1, volume = None,
|
def playMusic(self, music, looping = 0, interupt = 1, volume = None,
|
||||||
restart = None, time = 0.):
|
restart = None, time = 0.):
|
||||||
if (music and base.wantMusic):
|
if (music and base.wantMusic):
|
||||||
if not interupt:
|
if interupt or (music.status() != AudioSound.PLAYING):
|
||||||
if not (music.status() == AudioSound.PLAYING):
|
music.setTime(time)
|
||||||
AudioManager.play(music, time, looping)
|
music.setLoop(looping)
|
||||||
else:
|
music.play()
|
||||||
AudioManager.play(music, time, looping)
|
if volume != None:
|
||||||
if volume:
|
music.setVolume(volume)
|
||||||
AudioManager.setVolume(music, volume)
|
|
||||||
if restart:
|
if restart:
|
||||||
restart[0].accept("restart-music", restart[1])
|
restart[0].accept("restart-music", restart[1])
|
||||||
|
|
||||||
def stopSfx(self, sfx):
|
def stopSfx(self, sfx):
|
||||||
if (sfx and base.wantSfx):
|
if (sfx and base.wantSfx):
|
||||||
AudioManager.stop(sfx)
|
sfx.stop()
|
||||||
|
|
||||||
def stopMusic(self, music, restart = None):
|
def stopMusic(self, music, restart = None):
|
||||||
if (music and base.wantMusic):
|
if (music and base.wantMusic):
|
||||||
AudioManager.stop(music)
|
music.stop()
|
||||||
if restart:
|
if restart:
|
||||||
restart[0].ignore("restart-music")
|
restart[0].ignore("restart-music")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user