Changeset 170:7cda0cc74e19 for src
- Timestamp:
- 05/12/12 15:48:45 (13 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- src/mlx
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/acft.py
r153 r170 230 230 """Called when the flare has finished.""" 231 231 (flareTimeFromFS, flareTime) = self.flight.flareFinished(flareEnd, 232 flareEndFS) 232 flareEndFS, 233 tdRate) 233 234 self.logger.message(self._aircraftState.timestamp, 234 235 "Flaretime: %.3f (from %s)" % \ -
src/mlx/checks.py
r139 r170 7 7 import util 8 8 from acars import ACARS 9 from sound import startSound 9 10 10 11 import time … … 178 179 logger.message(state.timestamp, "Spoilers deployed") 179 180 self._logged = True 181 config = flight.config 182 if config.enableSounds and config.speedbrakeAtTD: 183 startSound(const.SOUND_SPEEDBRAKE) 180 184 else: 181 185 self._spoilersExtension = state.spoilersExtension -
src/mlx/const.py
r165 r170 4 4 5 5 # The version of the program 6 VERSION="0.0 4"6 VERSION="0.05" 7 7 8 8 #------------------------------------------------------------------------------- … … 295 295 SOUND_DING = "ding.wav" 296 296 297 # Sound: notify 298 SOUND_NOTIFY = "notify.wav" 299 300 # Sound: NOTAM 301 SOUND_NOTAM = "notam.mp3" 302 303 # Sound: scream 304 SOUND_SCREAM = "sikoly.mp3" 305 306 # Sound: boarding 307 SOUND_BOARDING = "board.mp3" 308 309 # Sound: Malev theme 310 SOUND_MALEV = "malev.mp3" 311 312 # Sound: taxi: Boeing 737 NG 313 SOUND_TAXI_BOEING737NG = "737taxi.mp3" 314 315 # Sound: taxi: Boeing 767 316 SOUND_TAXI_BOEING767 = "767taxi.mp3" 317 318 # Sound: taxi: Fokker F70 319 SOUND_TAXI_F70 = "F70taxi.mp3" 320 321 # Sound: takeoff preparation request from the captain 322 SOUND_CAPTAIN_TAKEOFF = "cpt_takeoff.mp3" 323 324 # Sound: cruise 325 SOUND_CRUISE = "TOC.mp3" 326 327 # Sound: descent 328 SOUND_DESCENT = "TOD.mp3" 329 330 # Sound: applause 331 SOUND_APPLAUSE = "taps.mp3" 332 333 # Sound: speedbrake 334 SOUND_SPEEDBRAKE = "speed.mp3" 335 336 # Sound: taxi after landing 337 SOUND_TAXIAFTERLAND = "TaxiAfterLand.mp3" 338 339 297 340 #------------------------------------------------------------------------------- 298 341 -
src/mlx/flight.py
r134 r170 2 2 3 3 #--------------------------------------------------------------------------------------- 4 5 from soundsched import SoundScheduler 4 6 5 7 import const … … 32 34 gui.resetFlightStatus() 33 35 36 self._soundScheduler = SoundScheduler(self) 37 self._pilotHotkeyPressed = False 38 self._checklistHotkeyPressed = False 39 34 40 self.flareTimeFromFS = False 35 41 self.entranceExam = False … … 59 65 self._flareStartFS = None 60 66 67 self._tdRate = None 68 61 69 @property 62 70 def config(self): … … 103 111 """Get the VRef speed of the flight.""" 104 112 return self._gui.vref 113 114 @property 115 def tdRate(self): 116 """Get the touchdown rate if known, None otherwise.""" 117 return self._tdRate 105 118 106 119 def handleState(self, oldState, currentState): … … 111 124 if self.startFuel is None: 112 125 self.startFuel = self.endFuel 126 127 self._soundScheduler.schedule(currentState, 128 self._pilotHotkeyPressed) 129 self._pilotHotkeyPressed = False 113 130 114 131 def setStage(self, timestamp, stage): … … 155 172 self._flareStartFS = flareStartFS 156 173 157 def flareFinished(self, flareEnd, flareEndFS ):174 def flareFinished(self, flareEnd, flareEndFS, tdRate): 158 175 """Called when the flare time has ended. 159 176 … … 162 179 - the flare time 163 180 """ 181 self._tdRate = tdRate 164 182 if self.flareTimeFromFS: 165 183 return (True, flareEndFS - self._flareStartFS) … … 176 194 """Get the fleet and call the given callback.""" 177 195 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 178 204 179 205 def _updateFlownDistance(self, currentState): -
src/mlx/fs.py
r152 r170 109 109 if messageLevel==const.MESSAGELEVEL_SOUND or \ 110 110 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) 112 114 if (messageLevel==const.MESSAGELEVEL_FS or \ 113 115 messageLevel==const.MESSAGELEVEL_BOTH): -
src/mlx/gui/flight.py
r164 r170 10 10 from mlx.pirep import PIREP 11 11 from mlx.i18n import xstr 12 from mlx.sound import startSound 12 13 13 14 import datetime … … 1423 1424 bookedFlight.departureICAO, 1424 1425 bookedFlight.arrivalICAO) 1426 startSound(const.SOUND_NOTAM) 1425 1427 1426 1428 def _notamsCallback(self, returned, result): -
src/mlx/gui/gui.py
r168 r170 1130 1130 """Handle the hotkeys.""" 1131 1131 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 4 4 5 5 import os 6 import traceback 6 7 7 8 #------------------------------------------------------------------------------ … … 50 51 51 52 self._requestCondition = threading.Condition() 52 self._request edPaths = []53 self._pending Aliases= []53 self._requests = [] 54 self._pending = [] 54 55 self._count = 0 55 56 56 57 self.daemon = True 57 58 58 def requestSound(self, name ):59 def requestSound(self, name, finishCallback = None, extra = None): 59 60 """Request the playback of the sound with the given name.""" 60 61 path = os.path.join(self._soundsDirectory, name) 61 62 with self._requestCondition: 62 self._request edPaths.append(path)63 self._requests.append((path, (finishCallback, extra))) 63 64 self._requestCondition.notify() 64 65 … … 72 73 while True: 73 74 with self._requestCondition: 74 if not self._request edPaths:75 if self._pending Aliases: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) 78 79 else: 79 80 timeout = 10.0 … … 81 82 self._requestCondition.wait(timeout) 82 83 83 request edPaths = []84 for path in self._requestedPaths:85 request edPaths.append((path, self._count))84 requests = [] 85 for (path, finishData) in self._requests: 86 requests.append((path, finishData, self._count)) 86 87 self._count += 1 87 self._request edPaths = []88 self._requests = [] 88 89 89 90 now = time.time() 90 aliasesToClose = []91 while self._pending Aliasesand \92 self._pending Aliases[0][0]<=now:93 aliasesToClose.append(self._pendingAliases[0][1])94 del self._pending Aliases[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] 95 96 96 for alias in aliasesToClose: 97 for (alias, (finishCallback, extra)) in toClose: 98 success = True 97 99 try: 98 100 print "Closing", alias … … 101 103 except Exception, e: 102 104 print "Failed closing " + alias + ":", str(e) 105 success = False 103 106 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: 105 114 try: 106 115 alias = "mlxsound%d" % (counter,) … … 117 126 timeout = time.time() + length / 1000.0 118 127 with self._requestCondition: 119 self._pending Aliases.append((timeout, alias))120 self._pending Aliases.sort()128 self._pending.append((timeout, (alias, finishData))) 129 self._pending.sort() 121 130 print "Started to play", path 122 131 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() 124 139 125 140 _thread = None … … 132 147 _thread.start() 133 148 134 def startSound(name ):149 def startSound(name, finishCallback = None, extra = None): 135 150 """Start playing back the given sound. 136 151 137 152 name should be the name of a sound file relative to the sound directory 138 153 given in initializeSound.""" 139 _thread.requestSound(name) 154 _thread.requestSound(name, finishCallback = finishCallback, 155 extra = extra) 140 156 141 157 #------------------------------------------------------------------------------ … … 147 163 pass 148 164 149 def startSound(name ):165 def startSound(name, finishCallback = None, extra = None): 150 166 """Start playing back the given sound. 151 167 … … 157 173 158 174 if __name__ == "__main__": 175 def callback(result, extra): 176 print "callback", result, extra 177 159 178 initializeSound("e:\\home\\vi\\tmp") 160 startSound("malev.mp3" )179 startSound("malev.mp3", finishCallback = callback, extra="malev.mp3") 161 180 time.sleep(5) 162 startSound("ding.wav" )181 startSound("ding.wav", finishCallback = callback, extra="ding1.wav") 163 182 time.sleep(5) 164 startSound("ding.wav" )183 startSound("ding.wav", finishCallback = callback, extra="ding2.wav") 165 184 time.sleep(5) 166 startSound("ding.wav" )185 startSound("ding.wav", finishCallback = callback, extra="ding3.wav") 167 186 time.sleep(50) 168 187
Note:
See TracChangeset
for help on using the changeset viewer.