]> git.donarmstrong.com Git - lilypond.git/commitdiff
MusicXML: overriding part-name by part-name-display in score-part definition
authorReinhold Kainhofer <reinhold@kainhofer.com>
Mon, 22 Feb 2010 12:53:00 +0000 (13:53 +0100)
committerReinhold Kainhofer <reinhold@kainhofer.com>
Mon, 22 Feb 2010 13:09:08 +0000 (14:09 +0100)
input/regression/musicxml/41i-PartNameDisplay-Override.xml [new file with mode: 0644]
scripts/musicxml2ly.py

diff --git a/input/regression/musicxml/41i-PartNameDisplay-Override.xml b/input/regression/musicxml/41i-PartNameDisplay-Override.xml
new file mode 100644 (file)
index 0000000..bcc8963
--- /dev/null
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 1.1 Partwise//EN"
+                                "http://www.musicxml.org/dtds/partwise.dtd">
+<score-partwise version="1.1">
+  <identification>
+    <miscellaneous>
+      <miscellaneous-field name="description">MusicXML allows part-name and
+            part-name-display in the score-part element. If part-name-display
+            is given, it overrides the part-name for display.
+
+            The first staff uses only part-name, while the second one (same
+            part-name) overrides it with a custom text. Similar for the
+            part-abbreviation used in subsequent staves.
+      </miscellaneous-field>
+    </miscellaneous>
+  </identification>
+  <part-list>
+    <score-part id="P1">
+      <part-name>Part name</part-name>
+      <part-abbreviation>abbrv.</part-abbreviation>
+    </score-part>
+    <score-part id="P2">
+      <part-name>Part name</part-name>
+      <part-name-display><display-text>Overridden Part Name</display-text></part-name-display>
+      <part-abbreviation>abbrv.</part-abbreviation>
+      <part-abbreviation-display><display-text>Overr.abbrv.</display-text></part-abbreviation-display>
+    </score-part>
+  </part-list>
+  <!--=========================================================-->
+  <part id="P1">
+    <measure number="1">
+      <attributes>
+        <divisions>1</divisions>
+      </attributes>
+      <note>
+        <pitch>
+          <step>C</step>
+          <octave>4</octave>
+        </pitch>
+        <duration>4</duration>
+        <voice>1</voice>
+        <type>whole</type>
+      </note>
+    </measure>
+    <measure number="2">
+      <print new-system="yes" />
+      <note>
+        <pitch>
+          <step>C</step>
+          <octave>4</octave>
+        </pitch>
+        <duration>4</duration>
+        <voice>1</voice>
+        <type>whole</type>
+      </note>
+    </measure>
+  </part>
+  <!--=========================================================-->
+  <part id="P2">
+    <measure number="1">
+      <attributes>
+        <divisions>1</divisions>
+      </attributes>
+      <note>
+        <pitch>
+          <step>C</step>
+          <octave>4</octave>
+        </pitch>
+        <duration>4</duration>
+        <voice>1</voice>
+        <type>whole</type>
+      </note>
+    </measure>
+    <measure number="2">
+      <print new-system="yes" />
+      <note>
+        <pitch>
+          <step>C</step>
+          <octave>4</octave>
+        </pitch>
+        <duration>4</duration>
+        <voice>1</voice>
+        <type>whole</type>
+      </note>
+    </measure>
+  </part>
+  <!--=========================================================-->
+</score-partwise>
index 8649094fa72a37b5205d5e1b4269d90141798a34..e89c94811e9c9a8a36d5c2c001c49fdc7522d804 100644 (file)
@@ -439,9 +439,20 @@ def extract_score_structure (part_list, staffinfo):
         # Finale gives unnamed parts the name "MusicXML Part" automatically!
         if partname and partname.get_text() != "MusicXML Part":
             staff.instrument_name = partname.get_text ()
-        if el.get_maybe_exist_named_child ('part-abbreviation'):
-            staff.short_instrument_name = el.get_maybe_exist_named_child ('part-abbreviation').get_text ()
+        # part-name-display overrides part-name!
+        partname = el.get_maybe_exist_named_child ("part-name-display")
+        if partname:
+            staff.instrument_name = extract_display_text (partname)
+
+        partdisplay = el.get_maybe_exist_named_child ('part-abbreviation')
+        if partdisplay:
+            staff.short_instrument_name = partdisplay.get_text ()
+        # part-abbreviation-display overrides part-abbreviation!
+        partdisplay = el.get_maybe_exist_named_child ("part-abbreviation-display")
+        if partdisplay:
+            staff.short_instrument_name = extract_display_text (partdisplay)
         # TODO: Read in the MIDI device / instrument
+
         return staff
 
     def read_score_group (el):
@@ -933,6 +944,14 @@ def musicxml_attributes_to_lily (attrs):
 
     return elts
 
+def extract_display_text (el):
+    child = el.get_maybe_exist_named_child ("display-text")
+    if child:
+        return child.get_text ()
+    else:
+        return False
+
+
 def musicxml_print_to_lily (el):
     # TODO: Implement other print attributes
     #  <!ELEMENT print (page-layout?, system-layout?, staff-layout*,