]> git.donarmstrong.com Git - lilypond.git/commitdiff
musicxml2ly: title and subtitle (issue 1913), miscellaneous
authorPatrick Schmidt <ptrcklschmdt@googlemail.com>
Fri, 7 Oct 2011 02:32:46 +0000 (20:32 -0600)
committerColin Campbell <colinpkcampbell@gmail.com>
Fri, 7 Oct 2011 02:32:46 +0000 (20:32 -0600)
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)

python/musicexp.py
python/musicxml.py
scripts/musicxml2ly.py

index 24174656273198be6d69abd7a7171fd1879d101b..d105ef333d2bfb8f50f2dba428b4fbb00caf29e0 100644 (file)
@@ -19,7 +19,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 += "} }"
@@ -198,6 +198,17 @@ class Duration:
 
         return base * dot_fact * self.factor
 
+# implement the midi command line option '-m' and '--midi'
+# if TRUE add midi-block to .ly file (see below)
+def set_create_midi (option):
+    global midi_option
+    midi_option = option
+
+def get_create_midi ():
+    try:
+        return midi_option
+    except:
+        return False
 
 # Implement the different note names for the various languages
 def pitch_generic (pitch, notenames, accidentals):
@@ -1919,6 +1930,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 278e108b1da4075b436ba8af7fe4ba0f7890f465..50945e8d8d8b78fc19e95bd2a545f2a817eb47d0 100644 (file)
@@ -167,6 +167,14 @@ class Identification (Xml_node):
           ret.append (r.get_text ())
         return string.join (ret, "\n")
 
+    # get contents of the source-element (usually used for publishing information). (These contents are saved in a custom variable named "source" in the header of the .ly file.)
+    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
@@ -232,8 +240,6 @@ class Identification (Xml_node):
                     return mf.get_text () 
         return None
 
-
-
 class Duration (Music_xml_node):
     def get_length (self):
         dur = int (self.get_text ()) * Rational (1,4)
index 322dfe91ae622bd5129dd299ed7e6c33ff251deb..c6e0b64c530f24aa8106975f7605423790861ece 100644 (file)
@@ -165,16 +165,26 @@ 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 exist use movement-title as subtitle.
+    # if there is only a movement-title (or work-title is empty or missing) the movement-title should be typeset as a title
+    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 ())
+    elif movement_title:
+        set_if_exists ('title', movement_title.get_text ())
+
     identifications = tree.get_named_children ('identification')
     for ids in identifications:
         set_if_exists ('copyright', ids.get_rights ())
@@ -183,12 +193,14 @@ 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 ())
         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 ());
 
         # Finally, apply the required compatibility modes
@@ -2648,6 +2660,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")
@@ -2760,7 +2779,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 by musicxml2ly from %s\n' % filename)
 
 def print_ly_additional_definitions (printer, filename):
     if needed_additional_definitions:
@@ -2915,6 +2934,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)