+# 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 = {}
+ def set_if_exists (field, value):
+ if value:
+ score_information[field] = value
+
+ work = tree.get_maybe_exist_named_child ('work')
+ if work:
+ set_if_exists ('title', work.get_work_title ())
+ set_if_exists ('worknumber', work.get_work_number ())
+ set_if_exists ('opus', work.get_opus ())
+ else:
+ movement_title = tree.get_maybe_exist_named_child ('movement-title')
+ if 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 ())
+ set_if_exists ('composer', ids.get_composer ())
+ set_if_exists ('arranger', ids.get_arranger ())
+ 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 ())
+
+ return score_information
+
+
+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 ()
+
+