removed want-sound, use 'audio-library-name null' instead

This commit is contained in:
Dave Schuyler 2002-01-09 03:06:49 +00:00
parent a885fa007a
commit 8ba7c32af2
5 changed files with 72 additions and 120 deletions

View File

@ -87,26 +87,24 @@ class DirectButton(DirectFrame):
apply(self['command'], self['extraArgs']) apply(self['command'], self['extraArgs'])
def setClickSound(self): def setClickSound(self):
if base.wantSfx: clickSound = self['clickSound']
clickSound = self['clickSound'] # Clear out sounds
# Clear out sounds self.guiItem.clearSound(B1PRESS + self.guiId)
self.guiItem.clearSound(B1PRESS + self.guiId) self.guiItem.clearSound(B2PRESS + self.guiId)
self.guiItem.clearSound(B2PRESS + self.guiId) self.guiItem.clearSound(B3PRESS + self.guiId)
self.guiItem.clearSound(B3PRESS + self.guiId) if clickSound:
if clickSound: if LMB in self['commandButtons']:
if LMB in self['commandButtons']: self.guiItem.setSound(B1PRESS + self.guiId, clickSound)
self.guiItem.setSound(B1PRESS + self.guiId, clickSound) if MMB in self['commandButtons']:
if MMB in self['commandButtons']: self.guiItem.setSound(B2PRESS + self.guiId, clickSound)
self.guiItem.setSound(B2PRESS + self.guiId, clickSound) if RMB in self['commandButtons']:
if RMB in self['commandButtons']: self.guiItem.setSound(B3PRESS + self.guiId, clickSound)
self.guiItem.setSound(B3PRESS + self.guiId, clickSound)
def setRolloverSound(self): def setRolloverSound(self):
if base.wantSfx: rolloverSound = self['rolloverSound']
rolloverSound = self['rolloverSound'] if rolloverSound:
if rolloverSound: self.guiItem.setSound(ENTER + self.guiId, rolloverSound)
self.guiItem.setSound(ENTER + self.guiId, rolloverSound) else:
else: self.guiItem.clearSound(ENTER + self.guiId)
self.guiItem.clearSound(ENTER + self.guiId)

View File

@ -109,20 +109,18 @@ class DirectEntry(DirectFrame):
PGEntry.setBackgroundFocus(self.guiItem, self['backgroundFocus']) PGEntry.setBackgroundFocus(self.guiItem, self['backgroundFocus'])
def setRolloverSound(self): def setRolloverSound(self):
if base.wantSfx: rolloverSound = self['rolloverSound']
rolloverSound = self['rolloverSound'] if rolloverSound:
if rolloverSound: self.guiItem.setSound(ENTER + self.guiId, rolloverSound)
self.guiItem.setSound(ENTER + self.guiId, rolloverSound) else:
else: self.guiItem.clearSound(ENTER + self.guiId)
self.guiItem.clearSound(ENTER + self.guiId)
def setClickSound(self): def setClickSound(self):
if base.wantSfx: clickSound = self['clickSound']
clickSound = self['clickSound'] if clickSound:
if clickSound: self.guiItem.setSound(ACCEPT + self.guiId, clickSound)
self.guiItem.setSound(ACCEPT + self.guiId, clickSound) else:
else: self.guiItem.clearSound(ACCEPT + self.guiId)
self.guiItem.clearSound(ACCEPT + self.guiId)
def commandFunc(self, event): def commandFunc(self, event):
if self['command']: if self['command']:

View File

@ -76,8 +76,6 @@ panel = None
def getDefaultRolloverSound(): def getDefaultRolloverSound():
global defaultRolloverSound global defaultRolloverSound
if not base.wantSfx:
return None
if defaultRolloverSound == None: if defaultRolloverSound == None:
defaultRolloverSound = base.loadSfx( defaultRolloverSound = base.loadSfx(
"phase_3/audio/sfx/GUI_rollover.mp3") "phase_3/audio/sfx/GUI_rollover.mp3")
@ -85,8 +83,6 @@ def getDefaultRolloverSound():
def getDefaultClickSound(): def getDefaultClickSound():
global defaultClickSound global defaultClickSound
if not base.wantSfx:
return None
if defaultClickSound == None: if defaultClickSound == None:
defaultClickSound = base.loadSfx( defaultClickSound = base.loadSfx(
"phase_3/audio/sfx/GUI_create_toon_fwd.mp3") "phase_3/audio/sfx/GUI_create_toon_fwd.mp3")

View File

@ -28,24 +28,16 @@ class SoundInterval(Interval):
self.sound = sound self.sound = sound
self.loop = loop self.loop = loop
self.volume = volume self.volume = volume
self.wantSound = base.wantSfx
# If no duration given use sound's duration as interval's duration # If no duration given use sound's duration as interval's duration
if duration == 0.0: if duration == 0.0 and self.sound != None:
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 # DCR - hack for Miles bug - adding 1.5 seconds caused
# DCR - hack for Miles bug - adding 1.5 seconds caused # problems for MG_neg_buzzer.wav
# problems for MG_neg_buzzer.wav duration += min(duration * 2.4, 1.5)
duration += min(duration * 2.4, 1.5)
else:
# This will screw up any intervals that base their
# time on the duration of this sound interval
print ('SoundInterval: Warning, want-sound #f,'+
' zero sound duration assumed')
duration = 0.0
# Generate unique name if necessary # Generate unique name if necessary
if (name == None): if (name == None):
name = id name = id
@ -53,15 +45,12 @@ class SoundInterval(Interval):
Interval.__init__(self, name, duration) Interval.__init__(self, name, duration)
# Update stopEvent # Update stopEvent
self.stopEvent = id + '_stopEvent' self.stopEvent = id + '_stopEvent'
if self.wantSound: self.stopEventList = [self.stopEvent]
self.stopEventList = [self.stopEvent]
def updateFunc(self, t, event = IVAL_NONE): def updateFunc(self, t, event = IVAL_NONE):
""" updateFunc(t, event) """ updateFunc(t, event)
Go to time t Go to time t
""" """
if not self.wantSound:
return
# 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

View File

@ -39,18 +39,14 @@ class ShowBase:
# Store dconfig variables # Store dconfig variables
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.sfxActive = self.config.GetBool('audio-sfx-active', 1)
self.wantSfx = self.config.GetBool('audio-sfx-active', 1) self.musicActive = self.config.GetBool('audio-music-active', 1)
self.wantMusic = self.config.GetBool('audio-music-active', 1)
self.wantFog = self.config.GetBool('want-fog', 1) self.wantFog = self.config.GetBool('want-fog', 1)
self.screenshotExtension = self.config.GetString('screenshot-extension', 'jpg') self.screenshotExtension = self.config.GetString('screenshot-extension', 'jpg')
if not (self.wantSfx or self.wantMusic):
self.wantAnySound = None
if not self.wantAnySound:
self.wantSfx = None
self.wantMusic = None
self.musicManager = None self.musicManager = None
self.musicManagerIsValid = None
self.sfxManager = None self.sfxManager = None
self.sfxManagerIsValid = None
self.wantDIRECT = self.config.GetBool('want-directtools', 0) self.wantDIRECT = self.config.GetBool('want-directtools', 0)
self.wantStats = self.config.GetBool('want-stats', 0) self.wantStats = self.config.GetBool('want-stats', 0)
@ -319,29 +315,28 @@ class ShowBase:
PStatClient.connect() PStatClient.connect()
def createAudioManager(self): def createAudioManager(self):
if self.wantSfx: self.sfxManager = AudioManager.createAudioManager()
self.sfxManager = AudioManager.createAudioManager() self.sfxManagerIsValid=self.sfxManager!=None \
if not self.sfxManager.isValid(): and self.sfxManager.isValid()
self.wantSfx=None
if self.wantMusic: self.musicManager = AudioManager.createAudioManager()
self.musicManager = AudioManager.createAudioManager() self.musicManagerIsValid=self.musicManager!=None \
and self.musicManager.isValid()
if self.musicManagerIsValid:
# Turn down the music globally # Turn down the music globally
# Eventually we may want to control this in the options page # Eventually we may want to control this in the options page
self.musicManager.setVolume(0.7) self.musicManager.setVolume(0.7)
if not self.musicManager.isValid():
self.wantMusic=None
self.wantAnySound = (self.wantSfx or self.wantMusic)
def loadSfx(self, name): def loadSfx(self, name):
if (name and base.wantSfx): if (name):
sound=self.sfxManager.getSound(name) sound=self.sfxManager.getSound(name)
if sound == None: if sound == None:
self.notify.warning("Could not load sound file %s." % name) self.notify.warning("Could not load sound file %s." % name)
return sound return sound
def loadMusic(self, name): def loadMusic(self, name):
if (name and base.wantMusic): if (name):
sound=self.musicManager.getSound(name) sound=self.musicManager.getSound(name)
if sound == None: if sound == None:
self.notify.warning("Could not load music file %s." % name) self.notify.warning("Could not load music file %s." % name)
@ -356,8 +351,8 @@ class ShowBase:
del 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:
if volume != None: if volume != None:
sfx.setVolume(volume) sfx.setVolume(volume)
if interupt or (sfx.status() != AudioSound.PLAYING): if interupt or (sfx.status() != AudioSound.PLAYING):
@ -366,8 +361,8 @@ class ShowBase:
sfx.play() sfx.play()
def playMusic(self, music, looping = 0, interupt = 1, volume = None, def playMusic(self, music, looping = 0, interupt = 1, volume = None,
time = 0.0): time = 0.0):
if (music and base.wantMusic): if music:
if volume != None: if volume != None:
music.setVolume(volume) music.setVolume(volume)
if interupt or (music.status() != AudioSound.PLAYING): if interupt or (music.status() != AudioSound.PLAYING):
@ -376,11 +371,11 @@ class ShowBase:
music.play() music.play()
def stopSfx(self, sfx): def stopSfx(self, sfx):
if (sfx and base.wantSfx): if sfx:
sfx.stop() sfx.stop()
def stopMusic(self, music): def stopMusic(self, music):
if (music and base.wantMusic): if music:
music.stop() music.stop()
def dataloop(self, state): def dataloop(self, state):
@ -702,64 +697,40 @@ class ShowBase:
# these are meant to be called in response to a user request # these are meant to be called in response to a user request
def EnableMusic(self, bEnableMusic): def EnableMusic(self, bEnableMusic):
self.wantMusic = bEnableMusic
self.wantAnySound = (self.wantSfx or self.wantMusic)
if (self.wantMusic and self.musicManager == None):
self.createAudioManager()
if not self.wantMusic:
# Oops, it didn't work.
self.notify.warning("Unable to toggle music on.")
return 0
# dont setActive(1) if no audiofocus # dont setActive(1) if no audiofocus
if(not (self.wantMusic and not self.AppHasAudioFocus)): if self.AppHasAudioFocus and self.musicManagerIsValid:
self.musicManager.setActive(self.wantMusic) self.musicManager.setActive(bEnableMusic)
self.musicActive = bEnableMusic
if(self.wantMusic): if bEnableMusic:
self.notify.debug("Enabling music") self.notify.debug("Enabling music")
else: else:
self.notify.debug("Disabling music") self.notify.debug("Disabling music")
return 1
def EnableSoundEffects(self, bEnableSoundEffects): def EnableSoundEffects(self, bEnableSoundEffects):
self.wantSfx = bEnableSoundEffects
self.wantAnySound = (self.wantSfx or self.wantMusic)
if (self.wantSfx and self.sfxManager == None):
self.createAudioManager()
if not self.wantSfx:
# Oops, it didn't work.
self.notify.warning("Unable to toggle sound effects on.")
return 0
# dont setActive(1) if no audiofocus # dont setActive(1) if no audiofocus
if(not (self.wantSfx and not self.AppHasAudioFocus)): if self.AppHasAudioFocus and self.sfxManagerIsValid:
self.sfxManager.setActive(self.wantSfx) self.sfxManager.setActive(bEnableSoundEffects)
self.sfxActive=bEnableSoundEffects
if(self.wantSfx): if bEnableSoundEffects:
self.notify.debug("Enabling sound effects") self.notify.debug("Enabling sound effects")
else: else:
self.notify.debug("Disabling sound effects") self.notify.debug("Disabling sound effects")
return 1
# these are meant to be called by the sw when app loses audio focus (switched out) # these are meant to be called by the sw when app loses audio focus (switched out)
def DisableAudio(self): def DisableAudio(self):
self.AppHasAudioFocus = 0 self.AppHasAudioFocus = 0
if (self.wantSfx and (self.sfxManager != None)): if self.sfxManagerIsValid:
self.sfxManager.setActive(0) self.sfxManager.setActive(0)
if (self.wantMusic and (self.musicManager != None)): if self.musicManagerIsValid:
self.musicManager.setActive(0) self.musicManager.setActive(0)
self.notify.debug("Disabling audio") self.notify.debug("Disabling audio")
def EnableAudio(self): def EnableAudio(self):
self.AppHasAudioFocus = 1 self.AppHasAudioFocus = 1
if (self.wantSfx and (self.sfxManager != None)): if self.sfxManagerIsValid:
self.sfxManager.setActive(1) self.sfxManager.setActive(self.sfxActive)
if (self.wantMusic and (self.musicManager != None)): if self.musicManagerIsValid:
self.musicManager.setActive(1) self.musicManager.setActive(self.musicActive)
self.notify.debug("Enabling audio") self.notify.debug("Enabling audio")
def run(self): def run(self):