Browse Source

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

Dave Schuyler 24 years ago
parent
commit
8ba7c32af2

+ 17 - 19
direct/src/gui/DirectButton.py

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

+ 10 - 12
direct/src/gui/DirectEntry.py

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

+ 0 - 4
direct/src/gui/DirectGuiGlobals.py

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

+ 10 - 21
direct/src/interval/SoundInterval.py

@@ -28,24 +28,16 @@ class SoundInterval(Interval):
         self.sound = sound
         self.loop = loop
         self.volume = volume
-        self.wantSound = base.wantSfx
         # If no duration given use sound's duration as interval's duration
-        if duration == 0.0:
-            if self.wantSound:
-                duration = self.sound.length()
-                if (duration == 0):
-                    self.notify.warning('zero length duration!')
-                # MPG - hack for Miles bug
-                #duration += 1.5
-                # DCR - hack for Miles bug - adding 1.5 seconds caused
-                # problems for MG_neg_buzzer.wav
-                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
+        if duration == 0.0 and self.sound != None:
+            duration = self.sound.length()
+            if (duration == 0):
+                self.notify.warning('zero length duration!')
+            # MPG - hack for Miles bug
+            #duration += 1.5
+            # DCR - hack for Miles bug - adding 1.5 seconds caused
+            # problems for MG_neg_buzzer.wav
+            duration += min(duration * 2.4, 1.5)
         # Generate unique name if necessary
         if (name == None):
             name = id
@@ -53,15 +45,12 @@ class SoundInterval(Interval):
         Interval.__init__(self, name, duration)
         # Update stopEvent
         self.stopEvent = id + '_stopEvent'
-        if self.wantSound:
-            self.stopEventList = [self.stopEvent]
+        self.stopEventList = [self.stopEvent]
 
     def updateFunc(self, t, event = IVAL_NONE):
         """ updateFunc(t, event)
         Go to time t
         """
-        if not self.wantSound:
-            return
         # Update sound based on current time
         if (t >= self.getDuration()):
             # If end of sound reached or stop event received, stop sound

+ 35 - 64
direct/src/showbase/ShowBase.py

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