-def compose_ly (code, options, type):
- option_dict = {}
-
- for i in options:
- if string.find (i, '=') > 0:
- (key, value) = re.split ('\s*=\s*', i)
- option_dict[key] = value
- else:
- if i in no_options.keys ():
- if no_options[i] in option_dict.keys ():
- del option_dict[no_options[i]]
- else:
- option_dict[i] = None
-
- has_linewidth = option_dict.has_key (LINEWIDTH)
- no_linewidth_value = 0
-
- # If LINEWIDTH is used without parameter, set it to default.
- if has_linewidth and option_dict[LINEWIDTH] == None:
- no_linewidth_value = 1
- del option_dict[LINEWIDTH]
-
- for i in default_ly_options.keys ():
- if i not in option_dict.keys ():
- option_dict[i] = default_ly_options[i]
-
- if not has_linewidth:
- if type == 'lilypond' or FRAGMENT in option_dict.keys ():
- option_dict[RAGGEDRIGHT] = None
-
- if type == 'lilypond':
- if LINEWIDTH in option_dict.keys ():
- del option_dict[LINEWIDTH]
- else:
- if RAGGEDRIGHT in option_dict.keys ():
- if LINEWIDTH in option_dict.keys ():
- del option_dict[LINEWIDTH]
-
- if QUOTE in option_dict.keys () or type == 'lilypond':
- if LINEWIDTH in option_dict.keys ():
- del option_dict[LINEWIDTH]
-
- if not INDENT in option_dict.keys ():
- option_dict[INDENT] = '0\\mm'
-
- # The QUOTE pattern from ly_options only emits the `linewidth'
- # keyword.
- if has_linewidth and QUOTE in option_dict.keys ():
- if no_linewidth_value:
- del option_dict[LINEWIDTH]
- else:
- del option_dict[QUOTE]
-
- if FRAGMENT in option_dict.keys ():
- body = FRAGMENT_LY
- else:
- body = FULL_LY
-
- # Defaults.
- relative = 1
- override = {}
- # The original concept of the `exampleindent' option is broken.
- # It is not possible to get a sane value for @exampleindent at all
- # without processing the document itself. Saying
- #
- # @exampleindent 0
- # @example
- # ...
- # @end example
- # @exampleindent 5
- #
- # causes ugly results with the DVI backend of texinfo since the
- # default value for @exampleindent isn't 5em but 0.4in (or a smaller
- # value). Executing the above code changes the environment
- # indentation to an unknown value because we don't know the amount
- # of 1em in advance since it is font-dependent. Modifying
- # @exampleindent in the middle of a document is simply not
- # supported within texinfo.
- #
- # As a consequence, the only function of @exampleindent is now to
- # specify the amount of indentation for the `quote' option.
- #
- # To set @exampleindent locally to zero, we use the @format
- # environment for non-quoted snippets.
- override[EXAMPLEINDENT] = r'0.4\in'
- override[LINEWIDTH] = texinfo_linewidths['@smallbook']
- override.update (default_ly_options)
-
- option_list = []
- for (key, value) in option_dict.items ():
- if value == None:
- option_list.append (key)
- else:
- option_list.append (key + '=' + value)
- option_string = string.join (option_list, ',')
-
- compose_dict = {}
- compose_types = [NOTES, PREAMBLE, LAYOUT, PAPER]
- for a in compose_types:
- compose_dict[a] = []
-
- for (key, value) in option_dict.items():
- (c_key, c_value) = \
- classic_lilypond_book_compatibility (key, value)
- if c_key:
- if c_value:
- ly.warning \
- (_ ("deprecated ly-option used: %s=%s" \
- % (key, value)))
- ly.warning \
- (_ ("compatibility mode translation: %s=%s" \
- % (c_key, c_value)))
- else:
- ly.warning \
- (_ ("deprecated ly-option used: %s" \
- % key))
- ly.warning \
- (_ ("compatibility mode translation: %s" \
- % c_key))
-
- (key, value) = (c_key, c_value)
-
- if value:
- override[key] = value
- else:
- if not override.has_key (key):
- override[key] = None
-
- found = 0
- for type in compose_types:
- if ly_options[type].has_key (key):
- compose_dict[type].append (ly_options[type][key])
- found = 1
- break
-
- 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
-