From c237c107a38644a9c3c664800c11a016091744af Mon Sep 17 00:00:00 2001 From: skomoroh Date: Thu, 7 Sep 2006 22:57:07 +0000 Subject: [PATCH] - improved sound support git-svn-id: file:///home/shlomif/Backup/svn-dumps/PySolFC/svnsync-repos/pysolfc/PySolFC/trunk@65 efabe8c0-fbe8-4139-b769-b5e6d273206e --- MANIFEST.in | 30 +++++++++++--- README | 12 ++++-- pysollib/main.py | 4 +- pysollib/pysolaudio.py | 91 +++++++++++++++++------------------------- scripts/build.bat | 4 ++ setup.cfg | 1 + setup.py | 4 +- 7 files changed, 81 insertions(+), 65 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 4b3ed1a1..6fca5c92 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,4 @@ +# -*- mode: sh -*- ## MANIFEST.in for PySolFC ## ## code @@ -9,23 +10,42 @@ include pysollib/games/*.py pysollib/games/special/*.py include pysollib/games/ultra/*.py pysollib/games/mahjongg/*.py include scripts/build.bat scripts/create_iss.py scripts/mahjongg_utils.py include scripts/all_games.py scripts/cardset_viewer.py +#graft data/plugins ## -## data +## data - docs ## include docs/* graft data/html graft data/html-src +## +## data - images +## #graft data/images recursive-include data/images *.gif *.png -#graft data/music -#graft data/plugins -graft data/sound graft data/tiles include data/pysol.xbm data/pysol.xpm data/pysol.ico +## +## data - sound +## +#graft data/music +#include data/music/Astral_Dreams.COPYRIGHT +#include data/music/Astral_Dreams.it +include data/music/Bye_For_Now.COPYRIGHT +include data/music/Bye_For_Now.s3m +#include data/music/Past_and_Future.COPYRIGHT +#include data/music/Past_and_Future.it +include data/music/Ranger_Song.COPYRIGHT +include data/music/Ranger_Song.s3m +include data/music/Subsequential.COPYRIGHT +include data/music/Subsequential.mod +graft data/sound +## +## data - i18n +## include po/* graft locale ## -## cardsets +## data - cardsets ## graft data/cardset-2000 graft data/cardset-crystal-mahjongg diff --git a/README b/README index 5096417b..09c16afb 100644 --- a/README +++ b/README @@ -7,9 +7,15 @@ Requirements. - Python (2.3 or later) - Tkinter -- PySol-Sound-Server: http://www.pysol.org/ (not necessarily) -- PIL (Python Image Library): http://www.pythonware.com/products/pil (not necessarily) -- Freecell Solver: http://vipe.technion.ac.il/~shlomif/freecell-solver/ (not necessarily) + +** for sound support (not necessarily) ** +- PySol-Sound-Server: http://www.pysol.org/ +or +- PyGame: http://www.pygame.org/ + +** other modules (not necessarily) ** +- PIL (Python Image Library): http://www.pythonware.com/products/pil +- Freecell Solver: http://vipe.technion.ac.il/~shlomif/freecell-solver/ Installation. diff --git a/pysollib/main.py b/pysollib/main.py index 48e73d19..6638024b 100644 --- a/pysollib/main.py +++ b/pysollib/main.py @@ -408,14 +408,14 @@ Please check your %s installation. # init audio 2) app.audio.connectServer(app) - if app.audio.audiodev is None: + if not app.audio.CAN_PLAY_SOUND: app.opt.sound = 0 if not opts["nosound"] and not opts['sound-mod'] and pysolsoundserver and not app.audio.connected: print PACKAGE + ": could not connect to pysolsoundserver, sound disabled." warn_pysolsoundserver = 1 app.audio.updateSettings() # start up the background music - if app.audio.audiodev: + if app.audio.CAN_PLAY_MUSIC: music = app.music_manager.getAll() if music: app.music_playlist = list(music)[:] diff --git a/pysollib/pysolaudio.py b/pysollib/pysolaudio.py index bff63107..7ca18fd2 100644 --- a/pysollib/pysolaudio.py +++ b/pysollib/pysolaudio.py @@ -56,7 +56,7 @@ except ImportError: class AbstractAudioClient: - EXTENTIONS = r"\.((it)|(mod)|(mp3)|(pym)|(s3m)|(xm))$" + EXTENTIONS = r"\.((wav)|(it)|(mod)|(mp3)|(pym)|(s3m)|(xm))$" CAN_PLAY_SOUND = False CAN_PLAY_MUSIC = False @@ -72,10 +72,7 @@ class AbstractAudioClient: self.music_loop = 0 def __del__(self): - try: - self.destroy() - except: - pass + self.destroy() # start server - set self.server on success (may also set self.audiodev) def startServer(self): @@ -95,7 +92,8 @@ class AbstractAudioClient: # disconnect and stop server def destroy(self): - self._destroy() + if self.audiodev: + self._destroy() self.server = None self.audiodev = None self.connected = 0 @@ -189,15 +187,15 @@ class PysolSoundServerModuleClient(AbstractAudioClient): CAN_PLAY_MUSIC = True def __init__(self): - import pysolsoundserver AbstractAudioClient.__init__(self) + import pysolsoundserver def startServer(self): # use the module try: self.audiodev = pysolsoundserver self.audiodev.init() - self.server = 1 # success - see also tk/menubar.py + self.server = 1 except: if traceback: traceback.print_exc() self.server = None @@ -277,18 +275,12 @@ class Win32AudioClient(AbstractAudioClient): CAN_PLAY_MUSIC = False def __init__(self): - import winsound AbstractAudioClient.__init__(self) + import winsound + self.audiodev = winsound def startServer(self): - # use the built-in winsound module - try: - import winsound - self.audiodev = winsound - self.server = 0 # success - see also tk/menubar.py - except: - self.server = None - self.audiodev = None + pass def _playSample(self, filename, priority, loop, volume): a = self.audiodev @@ -397,25 +389,21 @@ class OSSAudioClient(AbstractAudioClient): CAN_PLAY_MUSIC = False def __init__(self): - import ossaudiodev, wave AbstractAudioClient.__init__(self) - - def startServer(self): try: import ossaudiodev, wave - self.server = 0 # success - see also tk/menubar.py - self.audiodev = ossaudiodev - pin, pout = os.pipe() - self.pout = pout - server = OSSAudioServer(pin) - pid = os.fork() - if pid == 0: - server.mainLoop() except: if traceback: traceback.print_exc() - self.server = None - self.audiodev = None + raise + self.audiodev = ossaudiodev + def startServer(self): + pin, pout = os.pipe() + self.pout = pout + server = OSSAudioServer(pin) + pid = os.fork() + if pid == 0: + server.mainLoop() def _playSample(self, filename, priority, loop, volume): ##print '_playSample:', filename, loop @@ -435,33 +423,32 @@ class OSSAudioClient(AbstractAudioClient): class PyGameAudioClient(AbstractAudioClient): - EXTENTIONS = r'\.((ogg)|(mp3)|(it)|(mod)|(s3m)|(xm)|(mid))$' - if os.name == 'nt': # without mp3 - EXTENTIONS = r'\.((ogg)|(it)|(mod)|(s3m)|(xm)|(mid))$' + EXTENTIONS = r'\.((ogg)|(mp3)|(wav)|(it)|(mod)|(s3m)|(xm)|(mid))$' CAN_PLAY_SOUND = True CAN_PLAY_MUSIC = True def __init__(self): - import pygame.mixer, pygame.time AbstractAudioClient.__init__(self) - - def startServer(self): try: import pygame.mixer, pygame.time - self.server = 0 # success - see also tk/menubar.py - self.audiodev = pygame.mixer + if os.name == 'nt': + # for py2exe + import pygame.base, pygame.rwobject, pygame.mixer_music self.mixer = pygame.mixer self.mixer.init() self.music = self.mixer.music self.time = pygame.time - self.sound = None - self.sound_channel = None - self.sound_priority = -1 except: - if traceback: traceback.print_exc() - self.server = None - self.audiodev = None + ##if traceback: traceback.print_exc() + raise + self.audiodev = self.mixer + self.sound = None + self.sound_channel = None + self.sound_priority = -1 + + def startServer(self): + pass def _playSample(self, filename, priority, loop, volume): ##print '_playSample:', filename, priority, loop, volume @@ -475,10 +462,10 @@ class PyGameAudioClient(AbstractAudioClient): self.sound = self.mixer.Sound(filename) self.sound.set_volume(vol) self.sound_channel = self.sound.play(loop) - self.sound_priority = priority except: if traceback: traceback.print_exc() pass + self.sound_priority = priority return 1 def _stopSamples(self): @@ -511,6 +498,11 @@ class PyGameAudioClient(AbstractAudioClient): if traceback: traceback.print_exc() self.time.wait(1000) + def _destroy(self): + self.mixer.stop() + self.mixer.quit() + self.music = None + def playContinuousMusic(self, music_list): ##print 'playContinuousMusic' self.music_list = music_list @@ -521,15 +513,6 @@ class PyGameAudioClient(AbstractAudioClient): th = Thread(target=self._playMusicLoop) th.start() - def _destroy(self): - try: - self.mixer.stop() - self.mixer.quit() - self.music = None - except: - if traceback: traceback.print_exc() - pass - def updateSettings(self): if not self.app.opt.sound or self.app.opt.sound_music_volume == 0: if self.music: diff --git a/scripts/build.bat b/scripts/build.bat index 3b1f4879..50ff6bfb 100755 --- a/scripts/build.bat +++ b/scripts/build.bat @@ -5,6 +5,10 @@ rm -rf dist mkdir dist cp -r locale dist cp fc-solve.exe dist +cp smpeg.dll dist +cp ogg.dll dist +cp vorbis.dll dist +cp vorbisfile.dll dist python setup.py py2exe python scripts\create_iss.py "d:\Program Files\Inno Setup 5\ISCC.exe" setup.iss diff --git a/setup.cfg b/setup.cfg index ea699b17..0ebc5083 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,3 +6,4 @@ force_manifest = 1 release = 1 doc_files = COPYING README use_bzip2 = 1 +group = Amusements/Games diff --git a/setup.py b/setup.py index bca3e377..7b418d89 100644 --- a/setup.py +++ b/setup.py @@ -21,9 +21,11 @@ datas = [ 'tiles', 'toolbar', ] -for s in open('MANIFEST.in'): +for s in file('MANIFEST.in'): if s.startswith('graft data/cardset-'): datas.append(s[11:].strip()) + elif s.startswith('include data/music/'): + datas.append(s[19:].strip()) data_files = [] for d in datas: for root, dirs, files in os.walk(os.path.join('data', d)):