annotate music.py @ 612:73f134f84c7f

Request a RGB888 context, since SDL2’s default of RGB332 sucks. On X11/GLX, it will select the first config available, that is the best one, while on EGL it will iterate over them to select the one closest to what the application requested. Of course, anything lower than RGB888 looks bad and we really don’t want that.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 26 Mar 2015 20:20:37 +0100
parents b0b8825296d0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
414
b0b8825296d0 Follow the PEP-0394 guidelines, migrating from python to python2.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 326
diff changeset
1 #!/usr/bin/env python2
326
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2 # -*- encoding: utf-8 -*-
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3 ##
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 ## Copyright (C) 2012 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5 ##
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6 ## This program is free software; you can redistribute it and/or modify
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7 ## it under the terms of the GNU General Public License as published
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8 ## by the Free Software Foundation; version 3 only.
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9 ##
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10 ## This program is distributed in the hope that it will be useful,
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13 ## GNU General Public License for more details.
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14 ##
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
15
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
16 import argparse
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17 import os
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19 import pyximport
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20 pyximport.install()
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
22 from pytouhou.resource.loader import Loader
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
23 from pytouhou.ui.music import InfiniteWaveSource, ZwavSource
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
24 from pyglet.app import run
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
25
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
26
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
27 def get_wav_source(bgm, resource_loader):
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
28 posname = bgm.replace('bgm/', '').replace('.mid', '.pos')
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
29 track = resource_loader.get_track(posname)
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
30 wavname = os.path.join(resource_loader.game_dir, bgm.replace('.mid', '.wav'))
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31 try:
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
32 source = InfiniteWaveSource(wavname, track.start, track.end)
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
33 except IOError:
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
34 source = None
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
35 return source
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
36
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
37
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
38 def get_zwav_source(track, resource_loader):
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
39 fmt = resource_loader.get_fmt('thbgm.fmt')
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
40 try:
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
41 source = ZwavSource('thbgm.dat', fmt[track])
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
42 except IOError:
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
43 source = None
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
44 return source
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
45
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
46
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
47 def main(path, track, zwav, data):
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
48 resource_loader = Loader(path)
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
49 resource_loader.scan_archives(data)
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
50
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
51 if not zwav:
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
52 source = get_wav_source('bgm/th06_%02d.mid' % track, resource_loader)
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
53 else:
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
54 source = get_zwav_source(track, resource_loader)
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
55
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
56 source.play()
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
57
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
58 run()
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
59
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
60
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
61 pathsep = os.path.pathsep
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
62 default_data = (pathsep.join(('MD.DAT', 'th6*MD.DAT', '*MD.DAT', '*md.dat')),)
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
63
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
64
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
65 parser = argparse.ArgumentParser(description='Player for Touhou 6 music.')
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
66
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
67 parser.add_argument('data', metavar='DAT', default=default_data, nargs='*', help='Game’s data files')
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
68 parser.add_argument('-p', '--path', metavar='DIRECTORY', default='.', help='Game directory path.')
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
69 parser.add_argument('-t', '--track', metavar='TRACK', type=int, required=True, help='The track to play, in game order.')
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
70 parser.add_argument('-z', '--zwav', action='store_true', default=False, help='Must be set when playing from PCB or newer.')
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
71
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
72 args = parser.parse_args()
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
73
efcdf2ce747c Add a very simple music player, for testing purpose.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
74 main(args.path, args.track, args.zwav, tuple(args.data))