'lilypond' : '(?m)^(?P<match>@lilypond(\[(?P<options>[^]]*)\])?{(?P<code>.*?)})',
'lilypond_block': r'''(?ms)^(?P<match>@lilypond(\[(?P<options>[^]]*)\])?\s(?P<code>.*?)@end lilypond)\s''',
'lilypond_file': '(?m)^(?P<match>@lilypondfile(\[(?P<options>[^]]*)\])?{(?P<filename>[^}]+)})',
- 'multiline_comment': r"(?sm)^\s*(?!@c\s+)(?P<code>@ignore\s.*?@end ignore)\s",
- 'singleline_comment': r"(?m)^.*(?P<match>(?P<code>@c([ \t][^\n]*|)\n))",
+ 'multiline_comment': r'(?sm)^\s*(?!@c\s+)(?P<code>@ignore\s.*?@end\s+ignore)\s',
+ 'singleline_comment': r'(?m)^.*(?P<match>(?P<code>@c([ \t][^\n]*|)\n))',
# don't do this: fucks up with @code{@{}
# 'verb': r'''(?P<code>@code{.*?})''',
'noindent' : r'''
indent = 0.0\mm''',
'notime' : r'''
- \translator {
+ \context {
\StaffContext
\remove Time_signature_engraver
}''',
<a href="%(base)s.ly">''',
OUTPUT: r'''
<img align="center" valign="center"
- border="0" src="%(picture)s" alt="[picture of music]">''',
+ border="0" src="%(image)s" alt="[image of music]">''',
PRINTFILENAME:'<p><tt><a href="%(base)s.ly">%(filename)s</a></tt></p>',
VERBATIM: r'''<pre>
%(verb)s</pre>''',
},
-
+
LATEX : {
AFTER: '',
BEFORE: '',
%(verb)s\end{verbatim}
''',
},
-
- TEXINFO : {
+
+ TEXINFO : {
AFTER: '',
BEFORE: '',
+ OUTPUT: r'''
+ @image{%(base)s,,,[image of music],%(ext)s}
+''',
PRINTFILENAME: '''@file{%(filename)s}
''',
VERBATIM: r'''@example
%(verb)s@end example
''',
-
},
-
}
PREAMBLE_LY = r'''%% Generated by %(program_name)s
}'''
FULL_LY = '%(code)s'
-texi_linewidths = { 'afourpaper': '160 \\mm',
- 'afourwide': '6.5\\in',
- 'afourlatex': '150 \\mm',
- 'smallbook': '5 \\in' ,
- 'letterpaper': '6\\in'}
+texinfo_linewidths = {
+ '@afourpaper': '160 \\mm',
+ '@afourwide': '6.5 \\in',
+ '@afourlatex': '150 \\mm',
+ '@smallbook': '5 \\in' ,
+ '@letterpaper': '6\\in',
+ }
def classic_lilypond_book_compatibility (o):
if o == 'singleline':
body = FULL_LY
# defaults
- relative = 0
+ relative = 1
staffsize = 16
override = {}
override.update (default_ly_options)
if RELATIVE in override.keys () and override[RELATIVE]:
relative = string.atoi (override[RELATIVE])
- relative_quotes = (",,,", ",,", ",", "", "'", "''", "'''")[relative+4]
+ relative_quotes = ''
+
+ # 1 = central C
+ if relative < 0:
+ relative_quotes += ',' * (- relative)
+ elif relative > 0:
+ relative_quotes += "'" * relative
+
program_name = __main__.program_name
paper_string = string.join (paper_options, '\n ') % override
preamble_string = string.join (preamble_options, '\n ') % override
def is_outdated (self):
base = self.basename ()
+ ## FIXME: adding PNG to is_outdated test fixes
+ ## interrupted (web) builds.
+ ## should only do this if PNG is actually target
if os.path.exists (base + '.ly') \
and os.path.exists (base + '.tex') \
+ and os.path.exists (base + '.png') \
and (use_hash_p \
or self.ly () == open (base + '.ly').read ()):
# TODO: something smart with target formats
func = Lilypond_snippet.__dict__ ['output_' + self.format]
return func (self)
- def output_html (self):
+ def get_images (self):
base = self.basename ()
- str = ''
- if format == HTML:
- str = self.output_print_filename (HTML)
- if VERBATIM in self.options:
- verb = verbatim_html (self.substring ('code'))
- str += write (output[HTML][VERBATIM] % vars ())
-
# URGUGHUGHUGUGHU
single = '%(base)s.png' % vars ()
multiple = '%(base)s-page1.png' % vars ()
- pictures = (single,)
+ images = (single,)
if os.path.exists (multiple) \
and (not os.path.exists (single)\
or (os.stat (multiple)[stat.ST_MTIME] \
> os.stat (single)[stat.ST_MTIME])):
- pictures = glob.glob ('%(base)s-page*.png' % vars ())
+ images = glob.glob ('%(base)s-page*.png' % vars ())
+ return images
+ def output_html (self):
+ str = ''
+ base = self.basename ()
+ if format == HTML:
+ str += self.output_print_filename (HTML)
+ if VERBATIM in self.options:
+ verb = verbatim_html (self.substring ('code'))
+ str += write (output[HTML][VERBATIM] % vars ())
+
str += output[HTML][BEFORE] % vars ()
- for picture in pictures:
+ for image in self.get_images ():
+ base, ext = os.path.splitext (image)
str += output[HTML][OUTPUT] % vars ()
str += output[HTML][AFTER] % vars ()
return str
-
+
+ def output_info (self):
+ str = self.output_print_filename (HTML)
+ str = output[TEXINFO][BEFORE] % vars ()
+ for image in self.get_images ():
+ base, ext = os.path.splitext (image)
+ # URG, makeinfo implicitely prepends dot to ext
+ # specifying no extension is most robust
+ ext = ''
+ str += output[TEXINFO][OUTPUT] % vars ()
+ str += output[TEXINFO][AFTER] % vars ()
+ return str
+
def output_latex (self):
str = ''
base = self.basename ()
if format == LATEX:
- str = self.output_print_filename (LATEX)
+ str += self.output_print_filename (LATEX)
if VERBATIM in self.options:
verb = self.substring ('code')
str += (output[LATEX][VERBATIM] % vars ())
def output_texinfo (self):
str = ''
+ # self.output_print_filename (TEXINFO)
+ str += ('@html\n' + self.output_print_filename (HTML)
+ + '\n@end html\n')
+ str += ('@tex\n' + self.output_print_filename (LATEX)
+ + '\n@end tex\n')
base = self.basename ()
if TEXIDOC in self.options:
texidoc = base + '.texidoc'
verb = verbatim_texinfo (self.substring ('code'))
str += (output[TEXINFO][VERBATIM] % vars ())
+ str += ('@ifinfo\n' + self.output_info () + '\n@end ifinfo\n')
str += ('@tex\n' + self.output_latex () + '\n@end tex\n')
str += ('@html\n' + self.output_html () + '\n@end html\n')
- # need par after picture
+ # need par after image
str += '\n'
return str
m = res[type].search (s[index:endex])
if not m:
continue
-
+
cl = Snippet
if snippet_type_to_class.has_key (type):
cl = snippet_type_to_class[type]
if found[type] \
and (not first or found[type][0] < found[first][0]):
first = type
+
+ # FIXME.
+
+ # Limiting the search space is a cute
+ # idea, but this *requires* to search
+ # for possible containing blocks
+ # first, at least long as we do not
+ # search for the start of blocks, but
+ # always/directly for the entire
+ # @block ... @end block.
+
endex = found[first][0]
if not first:
(start , snip) = found[first]
snippets.append (Substring (s, index, start))
snippets.append (snip)
+ found[first] = None
index = start + len (snip.match.group (0))
return snippets
output_filename = (output_name
+ '/' + input_base
+ format2ext[format])
+
+
+ if (os.path.exists (input_filename) and
+ os.path.exists (output_filename) and
+ os.path.samefile (output_filename, input_fullname)):
+ ly.error (_("Output would overwrite input file; use --output."))
+ sys.exit (2)
+
output_file = open (output_filename, 'w')
if output_name:
os.chdir (output_name)
ly.progress (_ ("Reading %s...") % input_fullname)
source = in_handle.read ()
ly.progress ('\n')
-
+
+ # FIXME: containing blocks must be first, see find_toplevel_snippets
snippet_types = (
+ 'multiline_comment',
+ 'verbatim',
'lilypond_block',
# 'verb',
- 'verbatim',
'singleline_comment',
- 'multiline_comment',
'lilypond_file',
'include',
'lilypond', )
default_ly_options[LINEWIDTH] = '''%.0f\\pt''' \
% textwidth
elif format == TEXINFO:
- for (k, v) in texi_linewidths.items ():
- s = chunks[0].replacement_text ()
- if re.search (k, s):
+ for (k, v) in texinfo_linewidths.items ():
+ # FIXME: @paper is usually not in chunk #0:
+ # \input texinfo @c -*-texinfo-*-
+ # bluntly search first K of source
+ # s = chunks[0].replacement_text ()
+ if re.search (k, source[:1024]):
default_ly_options[LINEWIDTH] = v
break