Mercurial > dottes
annotate abcfirstline.py @ 153:3c0cd71a4e83
Add Skirmish/British Grenadiers. From web search.
author | Jim Hague <jim.hague@laicatc.com> |
---|---|
date | Fri, 11 May 2012 20:01:23 +0100 |
parents | 811151d3ae73 |
children | 1b79867b4f35 |
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): |
64
811151d3ae73
Improve first line extractor. Only output at most two lines.
Jim Hague <jim.hague@acm.org>
parents:
54
diff
changeset
|
10 continued = False |
50
e666306c5ab1
Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff
changeset
|
11 print "X:1" |
e666306c5ab1
Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff
changeset
|
12 for line in inf: |
e666306c5ab1
Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff
changeset
|
13 line = line.strip() |
64
811151d3ae73
Improve first line extractor. Only output at most two lines.
Jim Hague <jim.hague@acm.org>
parents:
54
diff
changeset
|
14 # If it is empty or starts "%", ignore it. |
811151d3ae73
Improve first line extractor. Only output at most two lines.
Jim Hague <jim.hague@acm.org>
parents:
54
diff
changeset
|
15 if len(line) == 0 or line[0] == "%": |
811151d3ae73
Improve first line extractor. Only output at most two lines.
Jim Hague <jim.hague@acm.org>
parents:
54
diff
changeset
|
16 continue |
811151d3ae73
Improve first line extractor. Only output at most two lines.
Jim Hague <jim.hague@acm.org>
parents:
54
diff
changeset
|
17 |
811151d3ae73
Improve first line extractor. Only output at most two lines.
Jim Hague <jim.hague@acm.org>
parents:
54
diff
changeset
|
18 # Is it a header line? I.e. does it start LETTER COLON? |
811151d3ae73
Improve first line extractor. Only output at most two lines.
Jim Hague <jim.hague@acm.org>
parents:
54
diff
changeset
|
19 # If so, output only ones we need. |
50
e666306c5ab1
Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff
changeset
|
20 start = line[:2] |
64
811151d3ae73
Improve first line extractor. Only output at most two lines.
Jim Hague <jim.hague@acm.org>
parents:
54
diff
changeset
|
21 if len(start) > 1 and start[1] == ":" and start[0].isalpha(): |
50
e666306c5ab1
Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff
changeset
|
22 if start[0] in ["M", "K", "L"]: |
e666306c5ab1
Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff
changeset
|
23 print line |
64
811151d3ae73
Improve first line extractor. Only output at most two lines.
Jim Hague <jim.hague@acm.org>
parents:
54
diff
changeset
|
24 # Output line. If it is a continuation, output at most one |
811151d3ae73
Improve first line extractor. Only output at most two lines.
Jim Hague <jim.hague@acm.org>
parents:
54
diff
changeset
|
25 # continuation. |
811151d3ae73
Improve first line extractor. Only output at most two lines.
Jim Hague <jim.hague@acm.org>
parents:
54
diff
changeset
|
26 else: |
50
e666306c5ab1
Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff
changeset
|
27 print line |
64
811151d3ae73
Improve first line extractor. Only output at most two lines.
Jim Hague <jim.hague@acm.org>
parents:
54
diff
changeset
|
28 if continued or line[-1] != "\\": |
50
e666306c5ab1
Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff
changeset
|
29 break |
64
811151d3ae73
Improve first line extractor. Only output at most two lines.
Jim Hague <jim.hague@acm.org>
parents:
54
diff
changeset
|
30 else: |
811151d3ae73
Improve first line extractor. Only output at most two lines.
Jim Hague <jim.hague@acm.org>
parents:
54
diff
changeset
|
31 continued = True |
50
e666306c5ab1
Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff
changeset
|
32 |
e666306c5ab1
Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff
changeset
|
33 if len(sys.argv) > 1: |
e666306c5ab1
Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff
changeset
|
34 for arg in sys.argv[1:]: |
e666306c5ab1
Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff
changeset
|
35 try: |
e666306c5ab1
Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff
changeset
|
36 inf = open(arg, "r") |
e666306c5ab1
Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff
changeset
|
37 process(inf) |
e666306c5ab1
Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff
changeset
|
38 finally: |
e666306c5ab1
Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff
changeset
|
39 inf.close() |
e666306c5ab1
Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff
changeset
|
40 else: |
e666306c5ab1
Add list of tune first lines.
Jim Hague <jim.hague@laicatc.com>
parents:
diff
changeset
|
41 process(sys.stdin) |