You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.9 KiB
67 lines
1.9 KiB
#!/usr/bin/env python3 |
|
import os |
|
|
|
def generate_ly(title=None, scores=None, copy=False, root=None): |
|
"""Generate a new lilypond file containing all entries from scores, if copy is False, they will be 'linked'""" |
|
|
|
# Find title |
|
if title is not None: |
|
title = "\\header {\n\ttitle = \""+ title + "\"\n}\n" |
|
else: |
|
title = "" |
|
|
|
|
|
# Content of scores |
|
scorestext = "" |
|
for item in scores: |
|
if item.startswith('std'): |
|
continue |
|
|
|
# item is always relative |
|
if root is not None: |
|
item = os.path.join(root, item) |
|
|
|
if not os.path.exists(item): |
|
continue |
|
|
|
if copy is True: |
|
with open(item, 'r') as f: |
|
for line in f: |
|
if line.startswith('\\include'): |
|
incline = line.replace('\\include', '').strip('"\' ') |
|
|
|
if os.path.isabs(incline): #already absolute |
|
incline = os.path.join(os.path.abspath(os.path.dirname(item)), incline) |
|
|
|
line = "\\include \""+incline+"\"" |
|
scorestext += line.replace('\r', '')+'\n' |
|
else: |
|
scorestext += '\\include \"' + os.path.join( os.path.abspath( os.curdir ) ,item) + '\"\n' |
|
|
|
|
|
## Output |
|
if scorestext == "": |
|
return False |
|
|
|
|
|
return """\\version \"2.19.65\" |
|
|
|
"""+ title + """ |
|
\\paper { |
|
#(define page-breaking ly:minimal-breaking) |
|
} |
|
|
|
%% Scores |
|
""" + scorestext |
|
|
|
|
|
if __name__ == "__main__": |
|
from argparse import ArgumentParser |
|
parser = ArgumentParser(__file__) |
|
parser.add_argument('-c', dest='copy', action='store_true', default=False, help="Copy files instead of just linkingi") |
|
parser.add_argument('-t', dest='title', default=None, help="Title for the set") |
|
parser.add_argument('scores', nargs='+') |
|
|
|
args = parser.parse_args() |
|
|
|
print(generate_ly(args.title, args.scores, args.copy))
|
|
|