]> git.donarmstrong.com Git - lilypond.git/commitdiff
MusicXML: Better support for dynamics
authorReinhold Kainhofer <reinhold@kainhofer.com>
Wed, 6 Feb 2008 15:27:56 +0000 (16:27 +0100)
committerReinhold Kainhofer <reinhold@kainhofer.com>
Wed, 6 Feb 2008 15:27:56 +0000 (16:27 +0100)
-) Use #(make-dynamic-script...) instead of \markup for unknown dynamics
-) Add definitions of unknown dynamics at the top of the converted file
-) Add test case for note-attached dynamics

input/regression/musicxml/02a-Notations-MusicXML.xml
python/musicexp.py
scripts/musicxml2ly.py

index aad78ffc58658aab4cb87a8c54a80378c4e09609..0e3f1c9c2904544fe390fe8d8b4a15dce518893b 100644 (file)
       </barline>
     </measure>
     
-    <!-- General tests: multiple notations, directions, pedal spanners, etc. -->
+    <!-- Dynamics, attached to notes by putting them inside <notations> tags -->
     <measure number="22">
+      <note>
+        <pitch>
+          <step>C</step><octave>5</octave>
+        </pitch>
+        <duration>1</duration>
+        <voice>1</voice>
+        <type>quarter</type>
+        <notations>
+          <dynamics><f/></dynamics>
+        </notations>
+        <lyric number="1"><text>f</text></lyric>
+      </note>
+      <note>
+        <pitch>
+          <step>C</step><octave>5</octave>
+        </pitch>
+        <duration>1</duration>
+        <voice>1</voice>
+        <type>quarter</type>
+        <notations>
+          <dynamics><ppp/></dynamics>
+        </notations>
+        <lyric number="1"><text>ppp</text></lyric>
+      </note>
+      <note>
+        <pitch>
+          <step>C</step><octave>5</octave>
+        </pitch>
+        <duration>1</duration>
+        <voice>1</voice>
+        <type>quarter</type>
+        <notations>
+          <dynamics><sfp/></dynamics>
+        </notations>
+        <lyric number="1"><text>sfp</text></lyric>
+      </note>
+      <note>
+        <pitch>
+          <step>C</step><octave>5</octave>
+        </pitch>
+        <duration>1</duration>
+        <voice>1</voice>
+        <type>quarter</type>
+        <notations>
+          <dynamics><other-dynamics>sfffz</other-dynamics></dynamics>
+        </notations>
+        <lyric number="1"><text>Oth.dyn.</text></lyric>
+      </note>
+    </measure>
+    
+    <!-- General tests: multiple notations, directions, pedal spanners, etc. -->
+    <measure number="23">
       <direction placement="below">
         <direction-type>
           <pedal line="no" relative-x="-9" type="start"/>
index 60c93521c307c7672181ca1571a4aef2e2dced2f..07e4f5d7928f42f476ea17dfc3c0ad48238eb2e6 100644 (file)
@@ -872,27 +872,17 @@ class HairpinEvent (SpanEvent):
 class DynamicsEvent (Event):
     def __init__ (self):
         self.type = None
-        self.available_commands = [ "ppppp", "pppp", "ppp", "pp", "p", 
-                                    "mp", "mf", 
-                                    "f", "ff", "fff", "ffff", 
-                                    "fp", "sf", "sff", "sp", "spp", "sfz", "rfz" ];
     def wait_for_note (self):
         return True;
     def ly_expression (self):
-        if self.type == None:
-            return;
-        elif self.type in self.available_commands:
+        if self.type:
             return '\%s' % self.type
         else:
-            return '-\markup{ \dynamic %s }' % self.type
-        
+            return;
+
     def print_ly (self, printer):
-        if self.type == None:
-            return
-        elif self.type in self.available_commands:
+        if self.type:
             printer.dump ("\\%s" % self.type)
-        else:
-            printer.dump ("-\\markup{ \\dynamic %s }" % self.type)
 
 
 class TextEvent (Event):
index 14c09dadbded444d28d8077e1d695c70481af767..cbed28f62aded04dbf1f49e057d211d63764c548 100644 (file)
@@ -49,8 +49,7 @@ additional_definitions = {
       )
     )
   )
-)
-"""
+)"""
 }
 
 def round_to_two_digits (val):
@@ -928,15 +927,26 @@ def musicxml_articulation_to_lily_event (mxl_event):
     return ev
 
 
+
 def musicxml_dynamics_to_lily_event (dynentry):
-    dynamics_available = ( "p", "pp", "ppp", "pppp", "ppppp", "pppppp",
-        "f", "ff", "fff", "ffff", "fffff", "ffffff",
-        "mp", "mf", "sf", "sfp", "sfpp", "fp",
-        "rf", "rfz", "sfz", "sffz", "fz" )
-    if not dynentry.get_name() in dynamics_available:
+    dynamics_available = (
+        "ppppp", "pppp", "ppp", "pp", "p", "mp", "mf", 
+        "f", "ff", "fff", "ffff", "fp", "sf", "sff", "sp", "spp", "sfz", "rfz" )
+    dynamicsname = dynentry.get_name ()
+    if dynamicsname == "other-dynamics":
+        dynamicsname = dynentry.get_text ()
+    if not dynamicsname:
         return
+
+    if not dynamicsname in dynamics_available:
+        # Get rid of - in tag names (illegal in ly tags!)
+        dynamicstext = dynamicsname
+        dynamicsname = string.replace (dynamicsname, "-", "")
+        additional_definitions[dynamicsname] = dynamicsname + \
+              "=#(make-dynamic-script \"" + dynamicstext + "\")"
+        needed_additional_definitions.append (dynamicsname)
     event = musicexp.DynamicsEvent ()
-    event.type = dynentry.get_name ()
+    event.type = dynamicsname
     return event
 
 # Convert single-color two-byte strings to numbers 0.0 - 1.0
@@ -1804,6 +1814,7 @@ def print_ly_additional_definitions (printer, filename):
         printer.newline ()
     for a in set(needed_additional_definitions):
         printer.print_verbatim (additional_definitions.get (a, ''))
+        printer.newline ()
     printer.newline ()
 
 # Read in the tree from the given I/O object (either file or string) and