+2002-05-15 Han-Wen <hanwen@cs.uu.nl>
+
+ * scripts/lilypond-book.py: add --no-music option: strip all blocks.
+ (completize_preamble): don't barf if no preamble present.
+ (do_file): allow extensions on --output
+
+ * scripts/ly2dvi.py (make_preview): make automatic preview of
+ first system. Small cleanups.
+
2002-05-13 Han-Wen Nienhuys <hanwen@cs.uu.nl>
* lily/parser.yy (My_lily_parser): uncomment code. (Causes
prepend @code{PREF} before each @code{-M} dependency
@item -n, --no-lily
don't run lilypond, but do generate the @code{.ly} files
+@item --no-music
+ strip all lilypond blocks from the file.
@item --no-pictures
don't generate pictures when processing texinfo.
@item --read-lys
@end table
-
-@command{lilypond-book} is written in python 1.5, so you have to install
-@uref{http://www.python.org,python}.
-
-
-
@section Bugs
The La@TeX{} \includeonly@{...@} command is ignored.
Generate output to @var{FILE}. The extension of @var{FILE} is ignored.
@item -P,--postscript
Also generate PostScript output, using dvips.
+@item --preview
+ Also generate a picture of the first system of the score.
@item -s,--set=@var{KEY}=@var{VAL}
Add @var{KEY}= @var{VAL} to the settings, overriding those specified
in the files. Possible keys: @code{language}, @code{latexheaders},
#ifndef SOURCE_FILE_HH
#define SOURCE_FILE_HH
+#include <iostream.h>
+
#include "flower-proto.hh"
#include "string.hh"
#include "interval.hh"
#ifndef STRING_HH
#define STRING_HH
+
+#if ( __GNUC__ > 2 )
#include <iostream.h> /* gcc 3.0 */
+#else
+class ostream;
+#endif
+
#include "arithmetic-operator.hh"
#include "flower-proto.hh"
#include "string-handle.hh"
#include "item.hh"
#include "spanner.hh"
#include "warn.hh"
-#include "text-item.hh" // debug output.
-#include "font-interface.hh" // debug output.
#define DEBUG_QUANTING 0
+
+#if DEBUG_QUANTING
+#include "text-item.hh" // debug output.
+#include "font-interface.hh" // debug output.
+#endif
+
+
const int INTER_QUANT_PENALTY = 1000;
const int SECONDARY_BEAM_DEMERIT = 15;
const int STEM_LENGTH_DEMERIT_FACTOR = 5;
gh_double2scm (qscores[best_idx].yr))
);
- if (DEBUG_QUANTING)
- {
- // debug quanting
- me->set_grob_property ("quant-score",
- gh_double2scm (qscores[best_idx].demerits));
- me->set_grob_property ("best-idx", gh_int2scm (best_idx));
- }
+#if DEBUG_QUANTING
+
+ // debug quanting
+ me->set_grob_property ("quant-score",
+ gh_double2scm (qscores[best_idx].demerits));
+ me->set_grob_property ("best-idx", gh_int2scm (best_idx));
+#endif
return SCM_UNSPECIFIED;
}
->get_bound (LEFT)->relative_coordinate (0, X_AXIS),
X_AXIS);
- if (DEBUG_QUANTING)
+#if (DEBUG_QUANTING)
{
/*
This code prints the demerits for each beam. Perhaps this
Molecule tm = Text_item::text2molecule (me, ly_str02scm (str.ch_C ()), properties);
mol.add_at_edge (Y_AXIS, UP, tm, 5.0);
}
-
+#endif
+
return mol.smobbed_copy ();
}
import os
import stat
import string
-
-
import getopt
import sys
import __main__
errorport = sys.stderr
verbose_p = 0
+
+
try:
import gettext
gettext.bindtextdomain ('lilypond', localedir)
g_read_lys = 0
g_do_pictures = 1
g_num_cols = 1
+g_do_music = 1
format = ''
g_run_lilypond = 1
('PREF', '', 'dep-prefix', 'prepend PREF before each -M dependency'),
('', 'n', 'no-lily', 'don\'t run lilypond'),
('', '', 'no-pictures', "don\'t generate pictures"),
+ ('', '', 'no-music', "strip all lilypond blocks from output"),
('', '', 'read-lys', "don't write ly files."),
('FILE', 'o', 'outname', 'filename main output file'),
('FILE', '', 'outdir', "where to place generated files"),
paperguru.m_fontsize = int(m.group(1))
break
- while chunks[idx][0] != 'preamble-end':
+ while idx < len(chunks) and chunks[idx][0] != 'preamble-end':
if chunks[idx] == 'ignore':
idx = idx + 1
continue
m = get_re('def-post-re').search(chunk[1])
if m:
post_b = 1
+
if chunk[0] == 'input':
m = get_re('usepackage-graphics').search(chunk[1])
if m:
graphics_b = 1
x = 0
- while chunks[x][0] != 'preamble-end':
+ while x < len (chunks) and chunks[x][0] != 'preamble-end':
x = x + 1
+
+ if x == len(chunks):
+ return chunks
+
if not pre_b:
chunks.insert(x, ('input', get_output ('output-default-pre')))
if not post_b:
chunks.insert(x, ('input', get_output ('output-default-post')))
if not graphics_b:
chunks.insert(x, ('input', get_output ('usepackage-graphics')))
+
return chunks
(options, content))]
def make_lilypond_block(m):
+ if not g_do_music:
+ return []
+
if m.group('options'):
options = get_re('option-sep').split (m.group('options'))
else:
newbody = newbody + get_output (s) % {'fn': basename }
return ('lilypond', newbody, opts, todo, basename)
-def process_lilypond_blocks(outname, chunks):#ugh rename
+def process_lilypond_blocks(chunks):#ugh rename
newchunks = []
# Count sections/chapters.
for c in chunks:
error ('Error command exited with value %d\n' % st)
return st
+def quiet_system (cmd, name):
+ if not verbose_p:
+ progress ( _("Running %s...") % name)
+ cmd = cmd + ' 1> /dev/null 2> /dev/null'
+
+ return system (cmd)
def get_bbox (filename):
system ('gs -sDEVICE=bbox -q -sOutputFile=- -dNOPAUSE %s -c quit > %s.bbox 2>&1 ' % (filename, filename))
cmd = r'''gs -g%dx%d -sDEVICE=pgm -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -q -sOutputFile=- -r%d -dNOPAUSE %s %s -c quit | pnmtopng > %s'''
cmd = cmd % (x, y, res, name + '.trans.eps', name + '.eps',name + '.png')
- if not verbose_p:
- progress ( _("Running %s...") % 'gs')
- cmd = cmd + ' 1> /dev/null 2> /dev/null'
-
+ quiet_system (cmd, 'gs')
+
try:
status = system (cmd)
except:
texfiles = string.join (tex, ' ')
cmd = 'lilypond --header=texidoc %s %s %s' \
% (lilyopts, g_extra_opts, texfiles)
- if not verbose_p:
- progress ( _("Running %s...") % 'LilyPond')
- cmd = cmd + ' 1> /dev/null 2> /dev/null'
- system (cmd)
+ quiet_system (cmd, 'LilyPond')
#
# Ugh, fixing up dependencies for .tex generation
for e in eps:
cmd = r"tex '\nonstopmode \input %s'" % e
- if not verbose_p:
- progress ( _("Running %s...") % 'TeX')
- cmd = cmd + ' 1> /dev/null 2> /dev/null'
- system (cmd)
+ quiet_system (cmd, 'TeX')
cmd = r"dvips -E -o %s %s" % (e + '.eps', e)
- if not verbose_p:
- progress ( _("Running %s...") % 'dvips')
- cmd = cmd + ' 1> /dev/null 2> /dev/null'
- system (cmd)
+ quiet_system (cmd, 'dvips')
for g in png:
make_pixmap (g)
return newchunks
+##docme: why global?
foutn=""
def do_file(input_filename):
global foutn
elif input_filename == '-' or input_filename == "/dev/stdin":
my_outname = '-'
else:
- my_outname = os.path.basename (os.path.splitext(input_filename)[0])
+ my_outname = os.path.basename (os.path.splitext(input_filename)[0]) + '.' + format
my_depname = my_outname + '.dep'
chunks = read_doc_file(input_filename)
#for c in chunks: print "c:", c;
#sys.exit()
scan_preamble(chunks)
- chunks = process_lilypond_blocks(my_outname, chunks)
+ chunks = process_lilypond_blocks(chunks)
# Do It.
if __main__.g_run_lilypond:
foutn = "<stdout>"
__main__.do_deps = 0
else:
- ## ugh, ugh.
- foutn = os.path.join (g_outdir, my_outname + '.' + format)
- ## foutn = os.path.join (g_outdir, my_outname)
+ foutn = os.path.join (g_outdir, my_outname)
sys.stderr.write ("Writing `%s'\n" % foutn)
fout = open (foutn, 'w')
for c in chunks:
g_dep_prefix = a
elif o == '--no-pictures':
g_do_pictures = 0
+ elif o == '--no-music':
+ g_do_music = 0
elif o == '--read-lys':
g_read_lys = 1
elif o == '--outdir':
if verbose_p:
progress (_ ("Invoking `%s\'") % cmd)
+
st = os.system (cmd)
if st:
name = re.match ('[ \t]*([^ \t]*)', cmd).group (1)
errorport = sys.stderr
keep_temp_dir_p = 0
verbose_p = 0
+preview_p = 0
try:
import gettext
(_ ("FILE"), 'o', 'output', _ ("write ouput to FILE")),
(_ ("FILE"), 'f', 'find-pfa', _ ("find pfa fonts used in FILE")),
# why capital P?
+ ('', '', 'preview', _("Make a picture of the first system.")),
('', 'P', 'postscript', _ ("generate PostScript output")),
(_ ("KEY=VAL"), 's', 'set', _ ("change global setting KEY to VAL")),
('', 'V', 'verbose', _ ("verbose")),
paper_p = 1
output_name = ''
-targets = {
- 'DVI' : 0,
- 'LATEX' : 0,
- 'MIDI' : 0,
- 'TEX' : 0,
- }
+
+## docme: what does this do?
+targets = [ 'DVI', 'LATEX', 'MIDI', 'TEX']
track_dependencies_p = 0
dependency_files = []
for (k,v) in os.environ.items ():
sys.stderr.write ("%s=\"%s\"\n" % (k,v))
+def quiet_system (cmd, name):
+ if not verbose_p:
+ progress ( _("Running %s...") % name)
+ cmd = cmd + ' 1> /dev/null 2> /dev/null'
+
+ return system (cmd)
+
+
def run_lilypond (files, outbase, dep_prefix):
opts = ''
# opts = opts + '--output=%s.tex' % outbase
# for better debugging!
print_environment ()
print opts, fs
- system ('lilypond %s %s ' % (opts, fs))
+ system ('lilypond %s %s ' % (opts, fs), 'lilypond')
def analyse_lilypond_output (filename, extra):
}
#TODO: should set textheight (enlarge) depending on papersize.
-
-def global_latex_definition (tfiles, extra):
- '''construct preamble from EXTRA, dump Latex stuff for each
-lily output file in TFILES after that, and return the Latex file constructed. '''
-
-
+def global_latex_preamble (extra):
+ '''construct preamble from EXTRA,'''
s = ""
s = s + '% generation tag\n'
else:
s = s + '\\pagestyle{empty}\n'
- s = s + '\\begin{document}\n'
+
+ return s
+
+
+def global_latex_definition (tfiles, extra):
+ '''construct preamble from EXTRA, dump Latex stuff for each
+lily output file in TFILES after that, and return the Latex file constructed. '''
+
+
+ s = global_latex_preamble (extra) + '\\begin{document}\n'
s = s + '\\thispagestyle{firstpage}\n'
first = 1
f.close ()
cmd = 'latex \\\\nonstopmode \\\\input %s' % latex_fn
-
- if not verbose_p:
- progress ( _("Running %s...") % 'LaTeX')
- cmd = cmd + ' 1> /dev/null 2> /dev/null'
-
- system (cmd)
+ quiet_system (cmd, 'LaTeX')
+
+ if preview_p:
+ # make a preview by rendering only the 1st line.
+ preview_fn = outbase + '.preview.tex'
+ f = open(preview_fn, 'w')
+ f.write (r'''
+%s
+\input lilyponddefs
+\pagestyle{empty}
+\begin{document}
+\def\interscoreline{\endinput}
+\input %s
+\end{document}
+''' % (global_latex_preamble (extra), outbase))
+
+ f.close()
+ cmd = 'latex \\\\nonstopmode \\\\input %s' % preview_fn
+ quiet_system (cmd, "LaTeX for preview")
+
def run_dvips (outbase, extra):
opts = opts + ' -tlandscape'
cmd = 'dvips %s -o%s %s' % (opts, outbase + '.ps', outbase + '.dvi')
+ quiet_system (cmd, 'dvips')
+
+ if preview_p:
+ cmd = 'dvips -E -o%s %s' % ( outbase + '.preview.ps', outbase + '.preview.dvi')
+ quiet_system (cmd, 'dvips for preview')
+
+def get_bbox (filename):
+ # cut & paste
+ system ('gs -sDEVICE=bbox -q -sOutputFile=- -dNOPAUSE %s -c quit > %s.bbox 2>&1 ' % (filename, filename))
+
+ box = open (filename + '.bbox').read()
+ m = re.match ('^%%BoundingBox: ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)', box)
+ gr = []
+ if m:
+ gr = map (string.atoi, m.groups ())
- if not verbose_p:
- progress ( _("Running %s...") % 'dvips')
- cmd = cmd + ' 1> /dev/null 2> /dev/null'
-
- system (cmd)
+ return gr
+
+#
+# cut & paste from lilypond-book.
+#
+def make_preview (name, extra):
+ bbox = get_bbox (name + '.preview.ps')
+ margin = 0
+ fo = open (name + '.trans.eps' , 'w')
+ fo.write ('%d %d translate\n' % (-bbox[0]+margin, -bbox[1]+margin))
+ fo.close ()
+
+ res = 90
+
+ x = (2* margin + bbox[2] - bbox[0]) * res / 72.
+ y = (2* margin + bbox[3] - bbox[1]) * res / 72.
+
+ cmd = r'''gs -g%dx%d -sDEVICE=pgm -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -q -sOutputFile=- -r%d -dNOPAUSE %s %s -c quit | pnmtopng > %s'''
+
+ cmd = cmd % (x, y, res, name + '.trans.eps', name + '.preview.ps',name + '.png')
+ quiet_system (cmd, 'gs')
+
+ try:
+ status = system (cmd)
+ except:
+ os.unlink (name + '.png')
+ error ("Removing output file")
+
+
def generate_dependency_file (depfile, outname):
df = open (depfile, 'w')
elif o == '--include' or o == '-I':
include_path.append (a)
elif o == '--postscript' or o == '-P':
- targets['PS'] = 0
+ targets.append ('PS')
elif o == '--keep' or o == '-k':
keep_temp_dir_p = 1
elif o == '--no-lily':
lily_p = 0
+ elif o == '--preview':
+ preview_p = 1
+ targets.append ('PNG')
+
elif o == '--no-paper' or o == '-m':
- targets = {}
- targets['MIDI'] = 0
+
+ targets = ['MIDI']
paper_p = 0
elif o == '--output' or o == '-o':
output_name = a
dep_prefix = 0
reldir = os.path.dirname (output_name)
- if outdir != '.' and (track_dependencies_p or targets.keys ()):
+ if outdir != '.' and (track_dependencies_p or targets):
mkdir_p (outdir, 0777)
setup_environment ()
# - init.ly setup failure
# - parse error in .ly
# - unexpected: assert/core dump
- targets = {}
+ targets = []
traceback.print_exc ()
- if targets.has_key ('DVI') or targets.has_key ('PS'):
+ if 'PNG' in targets and 'PS' not in targets:
+ targets.append ('PS')
+ if 'PS' in targets and 'DVI' not in targets:
+ targets.append('DVI')
+
+ if 'DVI' in targets:
try:
run_latex (files, outbase, extra_init)
# unless: add --tex, or --latex?
- del targets['TEX']
- del targets['LATEX']
+ targets.remove ('TEX')
+ targets.remove('LATEX')
except:
# TODO: friendly message about TeX/LaTeX setup,
# trying to run tex/latex by hand
- if targets.has_key ('DVI'):
- del targets['DVI']
- if targets.has_key ('PS'):
- del targets['PS']
+ if 'DVI' in targets:
+ targets.remove ('DVI')
+ if 'PS' in targets:
+ targets.remove ('PS')
traceback.print_exc ()
- if targets.has_key ('PS'):
+ if 'PS' in targets:
try:
run_dvips (outbase, extra_init)
except:
- if targets.has_key ('PS'):
- del targets['PS']
+ if 'PS' in targets:
+ targets.remove ('PS')
traceback.print_exc ()
+ if 'PNG' in targets:
+ make_preview (outbase, extra_init)
+
# add DEP to targets?
if track_dependencies_p:
depfile = os.path.join (outdir, outbase + '.dep')
progress (_ ("dependencies output to `%s'...") % depfile)
# Hmm, if this were a function, we could call it the except: clauses
- for i in targets.keys ():
+ for i in targets:
ext = string.lower (i)
cp_to_dir ('.*\.%s$' % ext, outdir)
outname = outbase + '.' + string.lower (i)