annotate abcfirstline.py @ 50:e666306c5ab1

Add list of tune first lines. Add a list of tune first lines to the Booke. First, a small Python script to filter a .abc file and spit out just enough to give a graphic of the first line without the title. Then generate these graphics and generate a new section in the Booke with a longtable of tune name and the first line graphic.
author Jim Hague <jim.hague@laicatc.com>
date Sun, 04 Mar 2012 20:16:48 +0000
parents
children 00a1bef43a34
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]
e666306c5ab1 Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
14 if start[0] != "|" and start[1] == ":":
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)