]> git.donarmstrong.com Git - lilypond.git/commitdiff
MusicXML: Move printing out header information into its own class
authorReinhold Kainhofer <reinhold@kainhofer.com>
Sun, 16 Sep 2007 22:39:38 +0000 (00:39 +0200)
committerReinhold Kainhofer <reinhold@kainhofer.com>
Wed, 3 Oct 2007 16:39:28 +0000 (18:39 +0200)
Signed-off-by: Reinhold Kainhofer <reinhold@kainhofer.com>
python/musicexp.py
scripts/musicxml2ly.py

index 4f4b262f77e054f2f76e5d2a6976279f8826fb92..5bd1436748dcfb137c3b9ace71e8b86257b9243e 100644 (file)
@@ -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)
index 10b21980e340973cfacea51bc7970a1d4c421e9a..11527b90c11f4fb53809116c13e25314c44e1817 100644 (file)
@@ -30,10 +30,10 @@ def error_message (str):
 # score information is contained in the <work>, <identification> or <movement-title> 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 ()