1
0
Fork 0
mirror of https://github.com/kastdeur/lilydrum.git synced 2025-05-17 13:29:12 +02:00

Moved Book scripts around,

few edits to music
This commit is contained in:
Eric Teunis de Boone 2015-12-11 11:25:33 +01:00
parent 9ce97ffc8b
commit 2cbc0c9bd6
29 changed files with 170 additions and 202 deletions

View file

@ -51,6 +51,12 @@ class MakeDrum:
action='store_true', dest='view_spacing', default=False,
help='Turn on "Paper.annotatespacing".')
parser.add_argument('-g','--generated',
dest='gen_out', default=self.TMP_DIR,
help='Put generated lilyfiles in $gen_out')
parser.add_argument('--no-compile', default=True,
action='store_false', dest='compile',
help='Do not compile generated Lilypond files')
parser.add_argument('--no-log',
action='store_false', dest='log', default=True,
help='Do not generate log files.')
@ -61,7 +67,7 @@ class MakeDrum:
dest='out_dir', default='pdf',
help='Output dir, for lilypond. If it doesn\'t exist, try to create it')
parser.add_argument('music_file',
default='', nargs='+',
default='', nargs='*',
help='file to process')
parser.add_argument('-@', '--list_file',
dest='list_file', default='',
@ -86,6 +92,11 @@ class MakeDrum:
if self.args.list_file != '':
self.args.music_file.append(open(self.args.list_file, 'r').readlines())
close(self.args.list_file)
# Check for files
if not self.args.music_file:
parser.print_usage()
return
# Clean up of files
self.remove_tmp_dir = self.args.clean
@ -103,20 +114,14 @@ class MakeDrum:
os.chdir(self.MASTER_DIR)
for file_path in self.args.music_file:
self.processit(self.TMP_DIR, os.path.join(self.RUN_DIR, file_path))
self.processit(self.TMP_DIR, os.path.join(self.RUN_DIR, file_path), self.args.gen_out, self.args.compile)
#if not
#os.rmdir(self.TMP_DIR)
os.chdir(self.RUN_DIR)
def processit(self, tmp_dir, file):
if self.args.log:
logfile = os.path.join(self.TMP_DIR, os.path.relpath(file).replace(".ly", '').replace('/', '-')+'.log')
log = ' > '+logfile+' 2>&1'
else:
log = ''
def processit(self, tmp_dir, file, gen_out, compile):
if self.args.format is None:
if file.endswith(".book"):
header_format = "header_book"
@ -127,27 +132,49 @@ class MakeDrum:
tmp_file = self.maketemplate(tmp_dir, file, header_format)
print ('Compiling ', file, end=' ', flush=True)
if not self.args.log:
print()
if gen_out is not None and gen_out != tmp_dir:
new_tmp_file = os.path.basename(tmp_file).replace(self.TMP_PREFIX, '');
print ('Moving ', tmp_file, ' to ', new_tmp_file, end=' ', flush=True)
gen_dir = os.path.join(self.RUN_DIR, gen_out);
# if not dir $gen_out, make it
if not os.path.exists(gen_dir):
try: os.makedirs(gen_dir)
except:
print('[Error]')
print(' ! Seems like the {} directory cannot be created'.format(gen_dir))
return
# mv file to dir, remove self.TMP_PREFIX
os.rename(tmp_file, os.path.join(gen_dir, new_tmp_file))
tmp_file = new_tmp_file
print('[OK]')
lilyout = os.path.join(os.path.curdir, self.args.out_dir, os.path.basename(tmp_file).replace(self.TMP_PREFIX, '').replace(".ly", ''))
lilycmd = self.LILYPOND+' --pdf --output='+lilyout+' '+tmp_file+log
if os.system(lilycmd) != 0:
self.remove_tmp_dir = False
print ('[Error]')
if compile:
if self.args.log:
print (' ! Did not compile, please see the log at ', logfile)
else :
print ('[OK]')
logfile = os.path.join(self.TMP_DIR, os.path.relpath(file).replace(".ly", '').replace('/', '-')+'.log')
log = ' > '+logfile+' 2>&1'
else:
log = ''
if self.args.clean:
#remove files
print ('Compiling ', file, end=' ', flush=True)
if not self.args.log:
print()
lilyout = os.path.join(self.RUN_DIR, self.args.out_dir, os.path.basename(tmp_file).replace(self.TMP_PREFIX, '').replace(".ly", ''))
print (lilyout)
lilycmd = self.LILYPOND+' --pdf --output='+lilyout+' '+tmp_file+log
if os.system(lilycmd) != 0:
self.remove_tmp_dir = False
print ('[Error]')
if self.args.log:
os.remove(logfile)
os.remove(tmp_file)
print (' ! Did not compile, please see the log at ', logfile)
else :
print ('[OK]')
if self.args.clean:
#remove files
if self.args.log:
os.remove(logfile)
os.remove(tmp_file)
def maketemplate(self, tmp_dir, file, header_format):
lily_includes = ''
@ -157,11 +184,9 @@ class MakeDrum:
for ext in ['full', 'side', 'tenor', 'bass', 'drum', 'snare']:
if ext in file:
include_drum_file = True
for ext in ['full', 'pipes']:
if ext in file:
include_pipe_file = True
if include_drum_file:
lily_includes = lily_includes + u"""
\\include \""""+self.args.lilydrum+"""\"
@ -178,14 +203,14 @@ class MakeDrum:
out_file.write(u'\ufeff')
out_file.write(u"""
% Generated from """+file+""" by """+__file__+"""
% Generated from """+file+""" by """+__file__+""" version """+self.VERSION+"""
\\version "2.18.0"
#(ly:set-option 'point-and-click #f)
"""+ lily_includes +"""
\\include \""""+header_format+""".ily"
\\include \""""+os.path.join(os.path.abspath(self.MASTER_DIR), header_format.strip(".ily")+""".ily""")+"""\"
#(set-global-staff-size """+self.args.staffsize+""")
#(set-default-paper-size \""""+self.args.papersize+"""\" '"""+self.args.orientation+""")
@ -204,7 +229,7 @@ class MakeDrum:
# Rewrite includes to absolute location of file
incline = line.replace('\\include', '').strip('"\' ')
if not incline.startswith('\\'): #already absolute
incline = os.path.join(os.path.relpath(os.path.dirname(file)), incline)
incline = os.path.join(os.path.abspath(os.path.dirname(file)), incline)
line = "\\include \""+incline+"\""
if printit:
out_file.write(line.replace('\r', '')+'\n')
@ -212,6 +237,4 @@ class MakeDrum:
# Return tmp_file_path
return tmp_file
MakeDrum();