view abcfirstline.py @ 356:6d4b2dab5fcc build-default-158

Corrections from Mick. 1. Add missing two last notes in final bar of B tune. 2. Move 'no chord' marker to start of 2nd repeat in A tune. 3. Mark middle B in last line of Horse's Brawl as Bb. 4. Last note of 4th bar of King of the Fairies should be quaver. 5. 4th bar of B tune should be same as 4th bar of A tune in Plane Tree. 6. Railway has change to Fiery Clock Face.
author Jim Hague <jim.hague@acm.org>
date Mon, 19 Aug 2013 10:09:02 +0100
parents 811151d3ae73
children 1b79867b4f35
line wrap: on
line source

#!/usr/bin/env python
#
# Write out a modified version of a .abc file with just the data
# to print the first line of the music only.
#

import sys

def process(inf):
    continued = False
    print "X:1"
    for line in inf:
        line = line.strip()
        # If it is empty or starts "%", ignore it.
        if len(line) == 0 or line[0] == "%":
            continue

        # Is it a header line? I.e. does it start LETTER COLON?
        # If so, output only ones we need.
        start = line[:2]
        if len(start) > 1 and start[1] == ":" and start[0].isalpha():
            if start[0] in ["M", "K", "L"]:
                print line
        # Output line. If it is a continuation, output at most one
        # continuation.
        else:
            print line
            if continued or line[-1] != "\\":
                break
            else:
                continued = True

if len(sys.argv) > 1:
    for arg in sys.argv[1:]:
        try:
            inf = open(arg, "r")
            process(inf)
        finally:
            inf.close()
else:
    process(sys.stdin)