From 68a704208153b3d9c4a8972e4d05c7e8fbe59621 Mon Sep 17 00:00:00 2001 From: Reinhold Kainhofer Date: Mon, 17 Sep 2007 00:39:38 +0200 Subject: [PATCH] MusicXML: Move printing out header information into its own class Signed-off-by: Reinhold Kainhofer --- python/musicexp.py | 20 ++++++++++++++++++++ scripts/musicxml2ly.py | 18 ++++-------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/python/musicexp.py b/python/musicexp.py index 4f4b262f77..5bd1436748 100644 --- a/python/musicexp.py +++ b/python/musicexp.py @@ -433,6 +433,26 @@ class Lyrics: return lstr +class Header: + def __init__ (self): + self.header_fields = {} + def set_field (self, field, value): + self.header_fields[field] = value + + def print_ly (self, printer): + printer.dump ("\header {") + printer.newline () + for (k,v) in self.header_fields.items (): + if v: + printer.dump ('%s = %s' % (k,v)) + printer.newline () + printer.dump ("}") + printer.newline () + printer.newline () + + + + class EventChord (NestedMusic): def __init__ (self): NestedMusic.__init__ (self) diff --git a/scripts/musicxml2ly.py b/scripts/musicxml2ly.py index 10b21980e3..11527b90c1 100644 --- a/scripts/musicxml2ly.py +++ b/scripts/musicxml2ly.py @@ -30,10 +30,10 @@ def error_message (str): # score information is contained in the , or tags # extract those into a hash, indexed by proper lilypond header attributes def extract_score_information (tree): - score_information = {} + header = musicexp.Header () def set_if_exists (field, value): if value: - score_information[field] = value + header.set_field (field, musicxml.escape_ly_output_string (value)) work = tree.get_maybe_exist_named_child ('work') if work: @@ -59,19 +59,9 @@ def extract_score_information (tree): set_if_exists ('encoder', ids.get_encoding_person ()) set_if_exists ('encodingdescription', ids.get_encoding_description ()) - return score_information + return header -def print_ly_information (printer, score_information): - printer.dump ('\header {') - printer.newline () - for (k, text) in score_information.items (): - printer.dump ('%s = %s' % (k, musicxml.escape_ly_output_string (text))) - printer.newline () - printer.dump ('}') - printer.newline () - printer.newline () - def musicxml_duration_to_lily (mxl_note): d = musicexp.Duration () @@ -1029,7 +1019,7 @@ def convert (filename, options): printer.set_file (open (defs_ly_name, 'w')) print_ly_preamble (printer, filename) - print_ly_information (printer, score_information) + score_information.print_ly (printer) print_voice_definitions (printer, part_list, voices) printer.close () -- 2.39.5