Changeset 170:7cda0cc74e19


Ignore:
Timestamp:
05/12/12 15:48:45 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

The background sounds play back properly

Files:
15 added
8 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/acft.py

    r153 r170  
    230230        """Called when the flare has finished."""
    231231        (flareTimeFromFS, flareTime) = self.flight.flareFinished(flareEnd,
    232                                                                  flareEndFS)
     232                                                                 flareEndFS,
     233                                                                 tdRate)
    233234        self.logger.message(self._aircraftState.timestamp,
    234235                            "Flaretime: %.3f (from %s)" % \
  • src/mlx/checks.py

    r139 r170  
    77import util
    88from acars import ACARS
     9from sound import startSound
    910
    1011import time
     
    178179                    logger.message(state.timestamp, "Spoilers deployed")
    179180                    self._logged = True
     181                    config = flight.config
     182                    if config.enableSounds and config.speedbrakeAtTD:
     183                        startSound(const.SOUND_SPEEDBRAKE)
    180184            else:
    181185                self._spoilersExtension = state.spoilersExtension
  • src/mlx/const.py

    r165 r170  
    44
    55# The version of the program
    6 VERSION="0.04"
     6VERSION="0.05"
    77
    88#-------------------------------------------------------------------------------
     
    295295SOUND_DING = "ding.wav"
    296296
     297# Sound: notify
     298SOUND_NOTIFY = "notify.wav"
     299
     300# Sound: NOTAM
     301SOUND_NOTAM = "notam.mp3"
     302
     303# Sound: scream
     304SOUND_SCREAM = "sikoly.mp3"
     305
     306# Sound: boarding
     307SOUND_BOARDING = "board.mp3"
     308
     309# Sound: Malev theme
     310SOUND_MALEV = "malev.mp3"
     311
     312# Sound: taxi: Boeing 737 NG
     313SOUND_TAXI_BOEING737NG = "737taxi.mp3"
     314
     315# Sound: taxi: Boeing 767
     316SOUND_TAXI_BOEING767 = "767taxi.mp3"
     317
     318# Sound: taxi: Fokker F70
     319SOUND_TAXI_F70 = "F70taxi.mp3"
     320
     321# Sound: takeoff preparation request from the captain
     322SOUND_CAPTAIN_TAKEOFF = "cpt_takeoff.mp3"
     323
     324# Sound: cruise
     325SOUND_CRUISE = "TOC.mp3"
     326
     327# Sound: descent
     328SOUND_DESCENT = "TOD.mp3"
     329
     330# Sound: applause
     331SOUND_APPLAUSE = "taps.mp3"
     332
     333# Sound: speedbrake
     334SOUND_SPEEDBRAKE = "speed.mp3"
     335
     336# Sound: taxi after landing
     337SOUND_TAXIAFTERLAND = "TaxiAfterLand.mp3"
     338
     339
    297340#-------------------------------------------------------------------------------
    298341
  • src/mlx/flight.py

    r134 r170  
    22
    33#---------------------------------------------------------------------------------------
     4
     5from soundsched import SoundScheduler
    46
    57import const
     
    3234        gui.resetFlightStatus()
    3335
     36        self._soundScheduler = SoundScheduler(self)
     37        self._pilotHotkeyPressed = False
     38        self._checklistHotkeyPressed = False
     39
    3440        self.flareTimeFromFS = False
    3541        self.entranceExam = False
     
    5965        self._flareStartFS = None
    6066
     67        self._tdRate = None
     68
    6169    @property
    6270    def config(self):
     
    103111        """Get the VRef speed of the flight."""
    104112        return self._gui.vref
     113
     114    @property
     115    def tdRate(self):
     116        """Get the touchdown rate if known, None otherwise."""
     117        return self._tdRate
    105118
    106119    def handleState(self, oldState, currentState):
     
    111124        if self.startFuel is None:
    112125            self.startFuel = self.endFuel
     126       
     127        self._soundScheduler.schedule(currentState,
     128                                      self._pilotHotkeyPressed)
     129        self._pilotHotkeyPressed = False
    113130
    114131    def setStage(self, timestamp, stage):
     
    155172        self._flareStartFS = flareStartFS
    156173
    157     def flareFinished(self, flareEnd, flareEndFS):
     174    def flareFinished(self, flareEnd, flareEndFS, tdRate):
    158175        """Called when the flare time has ended.
    159176       
     
    162179        - the flare time
    163180        """
     181        self._tdRate = tdRate
    164182        if self.flareTimeFromFS:
    165183            return (True, flareEndFS - self._flareStartFS)
     
    176194        """Get the fleet and call the given callback."""
    177195        self._gui.getFleetAsync(callback = callback, force = force)
     196
     197    def pilotHotkeyPressed(self):
     198        """Called when the pilot hotkey is pressed."""
     199        self._pilotHotkeyPressed = True
     200
     201    def checklistHotkeyPressed(self):
     202        """Called when the checklist hotkey is pressed."""
     203        self._checklistHotkeyPressed = True
    178204
    179205    def _updateFlownDistance(self, currentState):
  • src/mlx/fs.py

    r152 r170  
    109109        if messageLevel==const.MESSAGELEVEL_SOUND or \
    110110           messageLevel==const.MESSAGELEVEL_BOTH:
    111             startSound(const.SOUND_DING)
     111            startSound(const.SOUND_NOTIFY
     112                       if messageType==const.MESSAGETYPE_VISIBILITY
     113                       else const.SOUND_DING)
    112114        if (messageLevel==const.MESSAGELEVEL_FS or \
    113115            messageLevel==const.MESSAGELEVEL_BOTH):
  • src/mlx/gui/flight.py

    r164 r170  
    1010from mlx.pirep import PIREP
    1111from mlx.i18n import xstr
     12from mlx.sound import startSound
    1213
    1314import datetime
     
    14231424                                                  bookedFlight.departureICAO,
    14241425                                                  bookedFlight.arrivalICAO)
     1426            startSound(const.SOUND_NOTAM)
    14251427
    14261428    def _notamsCallback(self, returned, result):
  • src/mlx/gui/gui.py

    r168 r170  
    11301130        """Handle the hotkeys."""
    11311131        if id==self._hotkeySetID:
    1132             print "gui.GUI._handleHotkeys", hotkeys
     1132            for index in hotkeys:
     1133                if index==0:
     1134                    self._flight.pilotHotkeyPressed()
     1135                else:
     1136                    self._flight.checklistHotkeyPressed()
  • src/mlx/sound.py

    r133 r170  
    44
    55import os
     6import traceback
    67
    78#------------------------------------------------------------------------------
     
    5051
    5152            self._requestCondition = threading.Condition()
    52             self._requestedPaths = []
    53             self._pendingAliases = []
     53            self._requests = []
     54            self._pending = []
    5455            self._count = 0
    5556
    5657            self.daemon = True
    5758
    58         def requestSound(self, name):
     59        def requestSound(self, name, finishCallback = None, extra = None):
    5960            """Request the playback of the sound with the given name."""
    6061            path = os.path.join(self._soundsDirectory, name)
    6162            with self._requestCondition:
    62                 self._requestedPaths.append(path)
     63                self._requests.append((path, (finishCallback, extra)))
    6364                self._requestCondition.notify()
    6465
     
    7273            while True:
    7374                with self._requestCondition:
    74                     if not self._requestedPaths:
    75                         if self._pendingAliases:
    76                             timeout = max(time.time() -
    77                                           self._pendingAliases[0][0], 0.0)
     75                    if not self._requests:
     76                        if self._pending:
     77                            timeout = max(time.time() - self._pending[0][0],
     78                                          0.0)
    7879                        else:
    7980                            timeout = 10.0
     
    8182                        self._requestCondition.wait(timeout)
    8283
    83                     requestedPaths = []
    84                     for path in self._requestedPaths:
    85                         requestedPaths.append((path, self._count))
     84                    requests = []
     85                    for (path, finishData) in self._requests:
     86                        requests.append((path, finishData, self._count))
    8687                        self._count += 1
    87                     self._requestedPaths = []
     88                    self._requests = []
    8889
    8990                    now = time.time()
    90                     aliasesToClose = []
    91                     while self._pendingAliases and \
    92                           self._pendingAliases[0][0]<=now:
    93                         aliasesToClose.append(self._pendingAliases[0][1])
    94                         del self._pendingAliases[0]
     91                    toClose = []
     92                    while self._pending and \
     93                          self._pending[0][0]<=now:
     94                        toClose.append(self._pending[0][1])
     95                        del self._pending[0]
    9596
    96                 for alias in aliasesToClose:
     97                for (alias, (finishCallback, extra)) in toClose:
     98                    success = True
    9799                    try:
    98100                        print "Closing", alias
     
    101103                    except Exception, e:
    102104                        print "Failed closing " + alias + ":", str(e)
     105                        success = False
    103106
    104                 for (path, counter) in requestedPaths:
     107                    if finishCallback is not None:
     108                        try:
     109                            finishCallback(success, extra)
     110                        except:
     111                            traceback.print_exc()
     112
     113                for (path, finishData, counter) in requests:
    105114                    try:
    106115                        alias = "mlxsound%d" % (counter,)
     
    117126                        timeout = time.time() + length / 1000.0
    118127                        with self._requestCondition:
    119                             self._pendingAliases.append((timeout, alias))
    120                             self._pendingAliases.sort()
     128                            self._pending.append((timeout, (alias, finishData)))
     129                            self._pending.sort()
    121130                        print "Started to play", path
    122131                    except Exception, e:
    123                         print "Failed to start playing " + path + ":", str(e)
     132                        print "Failed to start playing " + path + ":", str(e)                       
     133                        (finishCallback, extra) = finishData
     134                        if finishCallback is not None:
     135                            try:
     136                                finishCallback(None, extra)
     137                            except:
     138                                traceback.print_exc()
    124139
    125140    _thread = None
     
    132147        _thread.start()
    133148
    134     def startSound(name):
     149    def startSound(name, finishCallback = None, extra = None):
    135150        """Start playing back the given sound.
    136151       
    137152        name should be the name of a sound file relative to the sound directory
    138153        given in initializeSound."""
    139         _thread.requestSound(name)
     154        _thread.requestSound(name, finishCallback = finishCallback,
     155                             extra = extra)
    140156       
    141157#------------------------------------------------------------------------------
     
    147163        pass
    148164
    149     def startSound(name):
     165    def startSound(name, finishCallback = None, extra = None):
    150166        """Start playing back the given sound.
    151167
     
    157173
    158174if __name__ == "__main__":
     175    def callback(result, extra):
     176        print "callback", result, extra
     177   
    159178    initializeSound("e:\\home\\vi\\tmp")
    160     startSound("malev.mp3")
     179    startSound("malev.mp3", finishCallback = callback, extra="malev.mp3")
    161180    time.sleep(5)
    162     startSound("ding.wav")
     181    startSound("ding.wav", finishCallback = callback, extra="ding1.wav")
    163182    time.sleep(5)
    164     startSound("ding.wav")
     183    startSound("ding.wav", finishCallback = callback, extra="ding2.wav")
    165184    time.sleep(5)
    166     startSound("ding.wav")
     185    startSound("ding.wav", finishCallback = callback, extra="ding3.wav")
    167186    time.sleep(50)
    168187
Note: See TracChangeset for help on using the changeset viewer.