From c4d028afdec2ee6e3cbbd661ed750ee9f5cf4c8f Mon Sep 17 00:00:00 2001 From: Patrick Schmidt Date: Thu, 6 Oct 2011 20:32:46 -0600 Subject: [PATCH] musicxml2ly: title and subtitle (issue 1913), miscellaneous musicxml2ly: titles (fixes issue 1913), tagline, conversion-info, , midi-cmd-line-option, center-column long instrument names 1) if XML: bli AND bla --> 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 -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 -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 | 14 +++++++++++++- python/musicxml.py | 10 ++++++++-- scripts/musicxml2ly.py | 36 +++++++++++++++++++++++++++++------- 3 files changed, 50 insertions(+), 10 deletions(-) diff --git a/python/musicexp.py b/python/musicexp.py index 2417465627..d105ef333d 100644 --- a/python/musicexp.py +++ b/python/musicexp.py @@ -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: diff --git a/python/musicxml.py b/python/musicxml.py index 278e108b1d..50945e8d8d 100644 --- a/python/musicxml.py +++ b/python/musicxml.py @@ -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) diff --git a/scripts/musicxml2ly.py b/scripts/musicxml2ly.py index 322dfe91ae..c6e0b64c53 100644 --- a/scripts/musicxml2ly.py +++ b/scripts/musicxml2ly.py @@ -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) -- 2.39.2