annotate abcfirstline.py @ 54:00a1bef43a34

Fix past end of string bug in Python first line hack.
author Jim Hague <jim.hague@laicatc.com>
date Sun, 04 Mar 2012 21:44:31 +0000
parents e666306c5ab1
children 811151d3ae73
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
50
e666306c5ab1 Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
1 #!/usr/bin/env python
e666306c5ab1 Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
2 #
e666306c5ab1 Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
3 # Write out a modified version of a .abc file with just the data
e666306c5ab1 Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
4 # to print the first line of the music only.
e666306c5ab1 Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
5 #
e666306c5ab1 Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
6
e666306c5ab1 Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
7 import sys
e666306c5ab1 Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
8
e666306c5ab1 Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
9 def process(inf):
e666306c5ab1 Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
10 print "X:1"
e666306c5ab1 Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
11 for line in inf:
e666306c5ab1 Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
12 line = line.strip()
e666306c5ab1 Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
13 start = line[:2]
54
00a1bef43a34 Fix past end of string bug in Python first line hack.
Jim Hague <jim.hague@laicatc.com>
parents: 50
diff changeset
14 if len(start) > 1 and start[0] != "|" and start[1] == ":":
50
e666306c5ab1 Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
15 if start[0] in ["M", "K", "L"]:
e666306c5ab1 Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
16 print line
e666306c5ab1 Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
17 elif start[0] != "%":
e666306c5ab1 Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
18 print line
e666306c5ab1 Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
19 if line[-1] != "\\":
e666306c5ab1 Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
20 break
e666306c5ab1 Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
21
e666306c5ab1 Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
22 if len(sys.argv) > 1:
e666306c5ab1 Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
23 for arg in sys.argv[1:]:
e666306c5ab1 Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
24 try:
e666306c5ab1 Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
25 inf = open(arg, "r")
e666306c5ab1 Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
26 process(inf)
e666306c5ab1 Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
27 finally:
e666306c5ab1 Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
28 inf.close()
e666306c5ab1 Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
29 else:
e666306c5ab1 Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
30 process(sys.stdin)