Reviewers: Reinhold,
Description:
musicxml2ly: title and subtitle (issue 1913), miscellaneous
musicxml2ly: titles (fixes issue 1913), tagline, conversion-info,
<source>, midi-cmd-line-option, center-column long instrument names
1) if XML: <work-title>bli</work-title> AND <movement-title>bla
</movement-title> --> LilyPond: title = bla subtitle = bli
2) the tagline of a piece engraved by LilyPond should not contain any
information as to the encoding software of the .xml file. The standard
Lilypond-tagline should be used.
3) the conversion info should contain the name of the conversion tool
4) the <source>-element is converted to a custom LilyPond-variable
named "source" in the header. (it is usually used for publishing
information)
5) a command line option for a midi block was added
6) multi-lined instrument names are now typeset in center-columns
7) the <miscellaneous>-element is currently translated into a header-
variable "texidoc" which is important for the documentation. I'd suggest
to call it "miscellaneous" by default and call it "texinfo" when
activated via a command line option. (Not implemented yet)
Please review this at http://codereview.appspot.com/5096050/
Affected files:
M python/musicexp.py
M python/musicxml.py
M scripts/musicxml2ly.py
Index: python/musicexp.py
diff --git a/python/musicexp.py b/python/musicexp.py
index
68318678de073ea8ae5fec845dd6f8794793b94d..37cd3035f9905e164bd2ade8099f6abfd1f16fb3
100644
--- a/python/musicexp.py
+++ b/python/musicexp.py
@@ -22,7 +22,7 @@ def escape_instrument_string (input_string):
if re.match ('.*[\r\n]+.*', retstring):
rx = re.compile (r'[\n\r]+')
strings = rx.split (retstring)
- retstring = "\\markup { \\column { "
+ retstring = "\\markup { \\center-column { "
for s in strings:
retstring += "\\line {\"" + s + "\"} "
retstring += "} }"
@@ -60,7 +60,7 @@ class Output_printer:
def dump_version (self):
self.newline ()
- self.print_verbatim ('\\version "@TOPLEVEL_VERSION@"')
+ self.print_verbatim ('\\version "2.15.13"')
self.newline ()
def get_indent (self):
@@ -272,6 +272,16 @@ def set_pitch_language (language):
"vlaams": pitch_vlaams}
pitch_generating_function = function_dict.get (language, pitch_general)
+def set_create_midi (option):
+ global midi_option
+ midi_option = option
+
+def get_create_midi ():
+ try:
+ return midi_option
+ except:
+ return False
+
# global variable to hold the formatting function.
pitch_generating_function = pitch_general
@@ -1499,7 +1509,7 @@ class TimeSignatureChange (Music):
def ly_expression (self):
st = ''
- # Print out the style if we have ome, but the '() should only be
+ # Print out the style if we have one, but the '() should only be
# forced for 2/2 or 4/4, since in all other cases we'll get numeric
# signatures anyway despite the default 'C signature style!
is_common_signature = self.fractions in ([2,2], [4,4], [4,2])
@@ -1922,6 +1932,7 @@ class Score:
self.contents.set_part_information (part_id, staves_info)
def print_ly (self, printer):
+ self.create_midi = get_create_midi ()
printer.dump ("\\score {");
printer.newline ()
if self.contents:
Index: python/musicxml.py
diff --git a/python/musicxml.py b/python/musicxml.py
index
7ba771fa8d6c77f72a27d1e47abd89ca91fcfa2c..b4ba102fa039c68e5d4407955eab98cb7187d049
100644
--- a/python/musicxml.py
+++ b/python/musicxml.py
@@ -170,6 +170,13 @@ class Identification (Xml_node):
ret.append (r.get_text ())
return string.join (ret, "\n")
+ def get_source (self):
+ source = self.get_named_children ('source')
+ ret = []
+ for r in source:
+ ret.append (r.get_text ())
+ return string.join (ret, "\n")
+
def get_creator (self, type):
creators = self.get_named_children ('creator')
# return the first creator tag that has the particular type
@@ -235,7 +242,14 @@ class Identification (Xml_node):
return mf.get_text ()
return None
-
+ def get_miscellaneous (self):
+ misc = self.get_named_children ('miscellaneous')
+ for m in misc:
+ misc_fields = m.get_named_children ('miscellaneous-field')
+ for mf in misc_fields:
+ if hasattr (mf, 'name') and mf.name == 'description':
+ return mf.get_text ()
+ return None
class Duration (Music_xml_node):
def get_length (self):
Index: scripts/musicxml2ly.py
diff --git a/scripts/musicxml2ly.py b/scripts/musicxml2ly.py
index
2b630029b6223bbb061580201fa54f3874d66c31..2cf4890799c2c715924cd44c992cf6431b22ee5e
100644
--- a/scripts/musicxml2ly.py
+++ b/scripts/musicxml2ly.py
@@ -1,4 +1,4 @@
-#!@TARGET_PYTHON@
+#!/usr/bin/python
# -*- coding: utf-8 -*-
import optparse
import sys
@@ -11,7 +11,26 @@ import tempfile
import StringIO
"""
-@relocate-preamble@
+
+This generic code used for all python scripts.
+
+The quotes are to ensure that the source .py file can still be
+run as a python script, but does not include any sys.path handling.
+Otherwise, the lilypond-book calls inside the build
+might modify installed .pyc files.
+
+"""
+
+for d in ['/usr/local/share/lilypond/2.15.13',
+ '/usr/local/lib/lilypond/2.15.13']:
+ sys.path.insert (0, os.path.join (d, 'python'))
+
+# dynamic relocation, for GUB binaries.
+bindir = os.path.abspath (os.path.dirname (sys.argv[0]))
+for p in ['share', 'lib']:
+ datadir = os.path.abspath (bindir
+ '/../%s/lilypond/current/python/' % p)
+ sys.path.insert (0, datadir)
+"""
"""
import lilylib as ly
@@ -173,16 +192,23 @@ def extract_score_information (tree):
if value:
header.set_field (field, musicxml.escape_ly_output_string
(value))
- movement_title = tree.get_maybe_exist_named_child ('movement-title')
- if movement_title:
- set_if_exists ('title', movement_title.get_text ())
work = tree.get_maybe_exist_named_child ('work')
if work:
- # Overwrite the title from movement-title with work->title
- set_if_exists ('title', work.get_work_title ())
set_if_exists ('worknumber', work.get_work_number ())
set_if_exists ('opus', work.get_opus ())
+ movement_title = tree.get_maybe_exist_named_child ('movement-title')
+
+ # use either work-title or movement-title as title. If both exists,
+ # (or work-title is empty) use movement-title as subtitle.
+ if work:
+ work_title = work.get_work_title ()
+ set_if_exists ('title', work_title)
+ if work_title == '':
+ set_if_exists ('title', movement_title.get_text ())
+ elif movement_title:
+ set_if_exists ('subtitle', movement_title.get_text ())
+
identifications = tree.get_named_children ('identification')
for ids in identifications:
set_if_exists ('copyright', ids.get_rights ())
@@ -191,13 +217,18 @@ def extract_score_information (tree):
set_if_exists ('editor', ids.get_editor ())
set_if_exists ('poet', ids.get_poet ())
- set_if_exists ('tagline', ids.get_encoding_software ())
+# After the conversion to LilyPond the tagline should not contain the name
of the software that was used to generate the .xml file. Instead the
standard LilyPond-tagline should be typeset. (Information on the encoding
software of the .xml file is saved in a custom variable
named 'encodingsoftware'.)
+# set_if_exists ('tagline', ids.get_encoding_software ())
set_if_exists ('encodingsoftware', ids.get_encoding_software ())
set_if_exists ('encodingdate', ids.get_encoding_date ())
set_if_exists ('encoder', ids.get_encoding_person ())
set_if_exists ('encodingdescription', ids.get_encoding_description
())
+ set_if_exists ('source', ids.get_source ())
+ # miscellaneous --> texidoc:
set_if_exists ('texidoc', ids.get_file_description ());
+ # miscellaneous --> miscellaneous
+# set_if_exists ('miscellaneous', ids.get_miscellaneous ());
# Finally, apply the required compatibility modes
# Some applications created wrong MusicXML files, so we need to
@@ -2562,7 +2593,7 @@ If the given filename is -, musicxml2ly reads from
the command line.
action="help",
help=_ ("show this help and exit"))
- p.version = ('''%prog (LilyPond) @TOPLEVEL_VERSION@\n\n'''
+ p.version = ('''%prog (LilyPond) 2.15.13\n\n'''
+
_ ("""Copyright (c) 2005--2011 by
Han-Wen Nienhuys <han...@xs4all.nl>,
@@ -2644,6 +2675,13 @@ information.""") % 'lilypond')
type = 'string',
dest = 'output_name',
help = _ ("set output filename to FILE, stdout if -"))
+
+ p.add_option ('-m', '--midi',
+ action = "store_true",
+ default = False,
+ dest = "midi",
+ help = _("add midi-block to .ly file"))
+
p.add_option_group ('',
description = (
_ ("Report bugs via %s")
@@ -2756,7 +2794,7 @@ def update_layout_information ():
def print_ly_preamble (printer, filename):
printer.dump_version ()
- printer.print_verbatim ('%% automatically converted from %s\n' %
filename)
+ printer.print_verbatim ('%% automatically converted with musicxml2ly
from %s\n' % filename)
def print_ly_additional_definitions (printer, filename):
if needed_additional_definitions:
@@ -2911,6 +2949,9 @@ def main ():
opt_parser.print_usage()
sys.exit (2)
+ if options.midi:
+ musicexp.set_create_midi (options.midi)
+
if options.language:
musicexp.set_pitch_language (options.language)
needed_additional_definitions.append (options.language)
_______________________________________________
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel