- for o in opts:
- m = re.search ('intertext="(.*?)"', o)
- if m:
- newbody = newbody + m.group (1) + "\n\n"
-
- if 'noinline' in opts:
- s = 'output-noinline'
- elif format == 'latex':
- if 'eps' in opts:
- s = 'output-eps'
- else:
- s = 'output-tex'
- else: # format == 'html' or format == 'texi':
- s = 'output-all'
- newbody = newbody + get_output (s) % {'fn': basename }
- return ('lilypond', newbody, opts, todo, basename)
-
-def process_lilypond_blocks(chunks):#ugh rename
- newchunks = []
- # Count sections/chapters.
- for c in chunks:
- if c[0] == 'lilypond':
- c = schedule_lilypond_block (c)
- elif c[0] == 'numcols':
- paperguru.m_num_cols = c[2]
- newchunks.append (c)
- return newchunks
-
-
-
-def system (cmd):
- sys.stderr.write ("invoking `%s'\n" % cmd)
- st = os.system (cmd)
- if st:
- 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))
-
- 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 ())
-
- return gr
-
-def make_pixmap (name):
- bbox = get_bbox (name + '.eps')
- margin = 0
- fo = open (name + '.trans.eps' , 'w')
- fo.write ('%d %d translate\n' % (-bbox[0]+margin, -bbox[1]+margin))
- fo.close ()
+ if not found and key not in simple_options:
+ ly.warning (_ ("ignoring unknown ly option: %s") % i)
+
+ # URGS
+ if RELATIVE in override.keys () and override[RELATIVE]:
+ relative = string.atoi (override[RELATIVE])
+
+ 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 (compose_dict[PAPER], '\n ') % override
+ layout_string = \
+ string.join (compose_dict[LAYOUT], '\n ') % override
+ notes_string = \
+ string.join (compose_dict[NOTES], '\n ') % vars ()
+ preamble_string = \
+ string.join (compose_dict[PREAMBLE], '\n ') % override
+
+ return (PREAMBLE_LY + body) % vars ()
+
+# BARF
+# Use lilypond for latex (.lytex) books,
+# and lilypond --preview for html, texinfo books?
+def to_eps (file):
+ cmd = r'latex "\nonstopmode \input %s"' % file
+ # Ugh. (La)TeX writes progress and error messages on stdout.
+ # Redirect to stderr.
+ cmd = '(( %s >&2 ) >&- )' % cmd
+ ly.system (cmd)
+ ly.system (
+ 'dvips -Ppdf -u+ec-mftrace.map -u+lilypond.map -E -o %s.eps %s' \
+ % (file, file))
+
+ # Check if it really is EPS.
+ # Otherwise music glyphs disappear from 2nd and following pages.
+
+ # TODO: Should run dvips -pp -E per page, then we get proper
+ # cropping as well.
+
+ f = open ('%s.eps' % file)
+ for x in range (0, 10):
+ if re.search ('^%%Pages: ', f.readline ()):
+ # Make non-EPS.
+ ly.system (
+ 'dvips -Ppdf -u+ec-mftrace.map -u+lilypond.map -o %s.eps %s' \
+ % (file, file))
+ break
+
+def find_file (name):
+ for i in include_path:
+ full = os.path.join (i, name)
+ if os.path.exists (full):
+ return full
+ ly.error (_ ("file not found: %s") % name + '\n')
+ ly.exit (1)
+ return ''
+
+def verbatim_html (s):
+ return re.sub ('>', '>',
+ re.sub ('<', '<',
+ re.sub ('&', '&', s)))
+
+def verbatim_texinfo (s):
+ return re.sub ('{', '@{',
+ re.sub ('}', '@}',
+ re.sub ('@', '@@', s)))
+
+def split_options (option_string):
+ return re.split (format_res[format]['option_sep'], option_string)
+
+class Chunk:
+ def replacement_text (self):
+ return ''
+
+ def filter_text (self):
+ return self.replacement_text ()
+
+ def ly_is_outdated (self):
+ return 0
+
+ def png_is_outdated (self):
+ return 0
+
+class Substring (Chunk):
+ def __init__ (self, source, start, end):
+ self.source = source
+ self.start = start
+ self.end = end
+
+ def replacement_text (self):
+ return self.source[self.start:self.end]
+
+class Snippet (Chunk):
+ def __init__ (self, type, match, format):
+ self.type = type
+ self.match = match
+ self.hash = 0
+ self.options = []
+ self.format = format
+
+ def replacement_text (self):
+ return self.match.group ('match')
+
+ def substring (self, s):
+ return self.match.group (s)
+
+ def __repr__ (self):
+ return `self.__class__` + ' type = ' + self.type
+
+class Include_snippet (Snippet):
+ def processed_filename (self):
+ f = self.substring ('filename')
+ return os.path.splitext (f)[0] + format2ext[format]
+
+ def replacement_text (self):
+ s = self.match.group ('match')
+ f = self.substring ('filename')
+
+ return re.sub (f, self.processed_filename (), s)
+
+class Lilypond_snippet (Snippet):
+ def __init__ (self, type, match, format):
+ Snippet.__init__ (self, type, match, format)
+ os = match.group ('options')
+ if os:
+ self.options = split_options (os)
+
+ def ly (self):
+ return self.substring ('code')
+
+ def full_ly (self):
+ s = self.ly ()
+ if s:
+ return compose_ly (s, self.options, self.type)
+ return ''
+
+ # TODO: Use md5?
+ def get_hash (self):
+ if not self.hash:
+ self.hash = abs (hash (self.full_ly ()))
+ return self.hash
+
+ def basename (self):
+ if use_hash_p:
+ return 'lily-%d' % self.get_hash ()
+ raise 'to be done'
+
+ def write_ly (self):
+ outf = open (self.basename () + '.ly', 'w')
+ outf.write (self.full_ly ())
+
+ open (self.basename () + '.txt', 'w').write ('image of music')
+
+ def ly_is_outdated (self):
+ base = self.basename ()
+
+ tex_file = '%s.tex' % base
+ ly_file = '%s.ly' % base
+ ok = os.path.exists (ly_file) \
+ and os.path.exists (tex_file)\
+ and os.stat (tex_file)[stat.ST_SIZE] \
+ and open (tex_file).readlines ()[-1][1:-1] \
+ == 'lilypondend'
+
+ if ok and (use_hash_p \
+ or self.ly () == open (ly_file).read ()):
+ # TODO: Do something smart with target formats
+ # (ps, png) and m/ctimes.
+ return None
+ return self
+
+ def png_is_outdated (self):
+ base = self.basename ()
+ ok = self.ly_is_outdated ()
+ if format == HTML or format == TEXINFO:
+ ok = ok and (os.path.exists (base + '.png')
+ or glob.glob (base + '-page*.png'))
+ return not ok
+ def texstr_is_outdated (self):
+ base = self.basename ()
+ ok = self.ly_is_outdated ()
+ ok = ok and (os.path.exists (base + '.texstr'))
+ return not ok