]> git.donarmstrong.com Git - lilypond.git/commitdiff
MusicXML: Add support for longa and breve notes, fix error messages
authorReinhold Kainhofer <reinhold@kainhofer.com>
Wed, 27 Feb 2008 14:36:51 +0000 (15:36 +0100)
committerReinhold Kainhofer <reinhold@kainhofer.com>
Wed, 27 Feb 2008 14:43:07 +0000 (15:43 +0100)
-) Longa and breve notes have a duration_log < 0, so I can't use
   1<<duration_log and write that out as the duration in lilypond.
 Instead, I need to check for negative durations manually and
 output \longa or \breve for these notes!
-) Update the musicxml regression test to also check longa and breve
   notes (and their dotted versions)
-) Correctly import lilylib as ly (in particular, since the
   error messages used ly.stderr_write already!!!!)

Signed-off-by: Reinhold Kainhofer <reinhold@kainhofer.com>
input/regression/musicxml/00c-Basics-Durations.xml
python/musicexp.py
python/musicxml.py
scripts/musicxml2ly.py

index cbb8dc62ede1a132d4bc56e8bd698287656fba50..4674d04517fb6d353a6f8741ab1210cd59f11da4 100644 (file)
   <part id="P1">
     <measure number="1">
       <attributes>
-        <divisions>32</divisions>
+        <divisions>64</divisions>
         <key>
           <fifths>0</fifths>
           <mode>major</mode>
         </key>
-        <time symbol="common">
-          <beats>4</beats>
+        <time>
+          <beats>24</beats>
           <beat-type>4</beat-type>
         </time>
         <clef>
           <step>C</step>
           <octave>5</octave>
         </pitch>
-        <duration>128</duration>
-        <tie type="start"/>
+        <duration>1024</duration>
         <voice>1</voice>
-        <type>whole</type>
-        <notations>
-          <tied type="start"/>
-        </notations>
+        <type>longa</type>
       </note>
-    </measure>
-    <!--=======================================================-->
-    <measure number="2">
       <note>
         <pitch>
           <step>C</step>
           <octave>5</octave>
         </pitch>
-        <duration>128</duration>
-        <tie type="stop"/>
+        <duration>512</duration>
         <voice>1</voice>
-        <type>whole</type>
-        <notations>
-          <tied type="stop"/>
-        </notations>
+        <type>breve</type>
       </note>
     </measure>
     <!--=======================================================-->
-    <measure number="3">
+    <measure number="2">
       <note>
         <pitch>
           <step>C</step>
           <octave>5</octave>
         </pitch>
-        <duration>128</duration>
+        <duration>256</duration>
         <voice>1</voice>
         <type>whole</type>
       </note>
-    </measure>
-    <!--=======================================================-->
-    <measure number="4">
       <note>
         <pitch>
           <step>C</step>
           <octave>5</octave>
         </pitch>
-        <duration>64</duration>
+        <duration>128</duration>
         <voice>1</voice>
         <type>half</type>
         <stem>down</stem>
@@ -89,7 +75,7 @@
           <step>C</step>
           <octave>5</octave>
         </pitch>
-        <duration>32</duration>
+        <duration>64</duration>
         <voice>1</voice>
         <type>quarter</type>
         <stem>down</stem>
@@ -99,7 +85,7 @@
           <step>C</step>
           <octave>5</octave>
         </pitch>
-        <duration>16</duration>
+        <duration>32</duration>
         <voice>1</voice>
         <type>eighth</type>
         <stem>down</stem>
           <step>C</step>
           <octave>5</octave>
         </pitch>
-        <duration>8</duration>
+        <duration>16</duration>
         <voice>1</voice>
         <type>16th</type>
         <stem>down</stem>
           <step>C</step>
           <octave>5</octave>
         </pitch>
-        <duration>4</duration>
+        <duration>8</duration>
         <voice>1</voice>
         <type>32nd</type>
         <stem>down</stem>
           <step>C</step>
           <octave>5</octave>
         </pitch>
-        <duration>2</duration>
+        <duration>4</duration>
         <voice>1</voice>
         <type>64th</type>
         <stem>down</stem>
           <step>C</step>
           <octave>5</octave>
         </pitch>
-        <duration>1</duration>
+        <duration>2</duration>
         <voice>1</voice>
         <type>128th</type>
         <stem>down</stem>
           <step>C</step>
           <octave>5</octave>
         </pitch>
-        <duration>1</duration>
+        <duration>2</duration>
         <voice>1</voice>
         <type>128th</type>
         <stem>down</stem>
       </note>
     </measure>
     <!--=======================================================-->
+    <measure number="4">
+      <note>
+        <pitch>
+          <step>C</step>
+          <octave>5</octave>
+        </pitch>
+        <duration>1536</duration>
+        <voice>1</voice>
+        <type>longa</type>
+        <dot/>
+      </note>
+    </measure>
+    <!--=======================================================-->
     <measure number="5">
       <note>
         <pitch>
           <step>C</step>
           <octave>5</octave>
         </pitch>
-        <duration>96</duration>
+        <duration>768</duration>
         <voice>1</voice>
-        <type>half</type>
+        <type>breve</type>
         <dot/>
-        <stem>down</stem>
       </note>
       <note>
         <pitch>
           <step>C</step>
           <octave>5</octave>
         </pitch>
-        <duration>32</duration>
+        <duration>384</duration>
         <voice>1</voice>
-        <type>quarter</type>
-        <stem>down</stem>
+        <type>whole</type>
+        <dot/>
       </note>
-    </measure>
-    <!--=======================================================-->
-    <measure number="6">
       <note>
         <pitch>
           <step>C</step>
           <octave>5</octave>
         </pitch>
-        <duration>48</duration>
+        <duration>192</duration>
+        <voice>1</voice>
+        <type>half</type>
+        <dot/>
+      </note>
+      <note>
+        <pitch>
+          <step>C</step>
+          <octave>5</octave>
+        </pitch>
+        <duration>96</duration>
         <voice>1</voice>
         <type>quarter</type>
         <dot/>
           <step>C</step>
           <octave>5</octave>
         </pitch>
-        <duration>24</duration>
+        <duration>48</duration>
         <voice>1</voice>
         <type>eighth</type>
         <dot/>
           <step>C</step>
           <octave>5</octave>
         </pitch>
-        <duration>12</duration>
+        <duration>24</duration>
         <voice>1</voice>
         <type>16th</type>
         <dot/>
           <step>C</step>
           <octave>5</octave>
         </pitch>
-        <duration>6</duration>
+        <duration>12</duration>
         <voice>1</voice>
         <type>32nd</type>
         <dot/>
           <step>C</step>
           <octave>5</octave>
         </pitch>
-        <duration>3</duration>
+        <duration>6</duration>
         <voice>1</voice>
         <type>64th</type>
         <dot/>
-        <stem>down</stem>
         <beam number="1">continue</beam>
         <beam number="2">continue</beam>
         <beam number="3">continue</beam>
           <step>C</step>
           <octave>5</octave>
         </pitch>
-        <duration>2</duration>
+        <duration>3</duration>
         <voice>1</voice>
         <type>128th</type>
         <dot/>
-        <stem>down</stem>
         <beam number="1">continue</beam>
         <beam number="2">continue</beam>
         <beam number="3">continue</beam>
           <step>C</step>
           <octave>5</octave>
         </pitch>
-        <duration>2</duration>
+        <duration>3</duration>
         <voice>1</voice>
         <type>128th</type>
         <dot/>
-        <stem>down</stem>
         <beam number="1">end</beam>
         <beam number="2">end</beam>
         <beam number="3">end</beam>
index adce6911013d207cbb5042f068d3ab975ad9b0a5..862b5d8c4f70f5148c0a5b1899588b1859014c59 100644 (file)
@@ -2,9 +2,9 @@ import inspect
 import sys
 import string
 import re
-import lilylib
+import lilylib as ly
 
-_ = lilylib._
+_ = ly._
 
 from rational import Rational
 
@@ -155,8 +155,12 @@ class Duration:
     def ly_expression (self, factor = None):
         if not factor:
             factor = self.factor
-            
-        str = '%d%s' % (1 << self.duration_log, '.'*self.dots)
+
+        if self.duration_log < 0:
+            str = {-1: "\\breve", -2: "\\longa"}.get (self.duration_log, "1")
+        else:
+            str = '%d' % (1 << self.duration_log)
+        str += '.'*self.dots
 
         if factor <> Rational (1,1):
             if factor.denominator () <> 1:
index e9d1ef8bedebd195450a78660f3ff716379dbc5e..7c398e1e5d7a5f73a97b3a25d22bcbf37122f289 100644 (file)
@@ -5,9 +5,9 @@ from rational import *
 import re
 import sys
 import copy
-import lilylib
+import lilylib as ly
 
-_ = lilylib._
+_ = ly._
 
 def error (str):
     ly.stderr_write ((_ ("error: %s") % str) + "\n")
@@ -51,7 +51,7 @@ class Xml_node:
        return ''.join ([c.get_text () for c in self._children])
 
     def message (self, msg):
-        lilylib.stderr_write (msg+'\n')
+        ly.stderr_write (msg+'\n')
 
         p = self
         while p:
@@ -340,7 +340,7 @@ class Note (Measure_element):
                     'half': 1,
                     'whole': 0,
                     'breve': -1,
-                    'long': -2}.get (log, 0)
+                    'longa': -2}.get (log, 0)
        elif self.get_maybe_exist_named_child (u'grace'):
            # FIXME: is it ok to default to eight note for grace notes?
            return 3
@@ -379,7 +379,7 @@ class Part_list (Music_xml_node):
         if instrument_name:
             return instrument_name
         else:
-            lilylib.stderr_write (_ ("Unable to find find instrument for ID=%s\n") % id)
+            ly.stderr_write (_ ("Unable to find find instrument for ID=%s\n") % id)
             return "Grand Piano"
 
 class Part_group (Music_xml_node):
index e594aa7d47bbd6dbfdaacff8b7047c9bef0c0fe9..f808a8325b5a67655ac0cd3ffce223258a332150 100644 (file)
@@ -1386,6 +1386,7 @@ class LilyPondVoiceBuilder:
                 else:
                     duration_factor = Rational (diff.numerator ())
             else:
+                # for skips of a whole or more, simply use s1*factor
                 duration_log = 0
                 duration_factor = diff
             skip.duration.duration_log = duration_log