]> git.donarmstrong.com Git - lilypond.git/blobdiff - python/musicxml.py
musicxml2ly: title and subtitle (issue 1913), miscellaneous
[lilypond.git] / python / musicxml.py
index 7ba771fa8d6c77f72a27d1e47abd89ca91fcfa2c..50945e8d8d8b78fc19e95bd2a545f2a817eb47d0 100644 (file)
@@ -9,9 +9,6 @@ import lilylib as ly
 
 _ = ly._
 
-def error (str):
-    ly.stderr_write ((_ ("error: %s") % str) + "\n")
-
 
 def escape_ly_output_string (input_string):
     return_string = input_string
@@ -76,23 +73,23 @@ class Xml_node:
         return ''.join ([c.get_text () for c in self._children])
 
     def message (self, msg):
-        ly.stderr_write (msg+'\n')
+        ly.warning (msg)
 
         p = self
         while p:
-            sys.stderr.write ('  In: <%s %s>\n' % (p._name, ' '.join (['%s=%s' % item for item in p._attribute_dict.items ()])))
+            ly.progress ('  In: <%s %s>\n' % (p._name, ' '.join (['%s=%s' % item for item in p._attribute_dict.items ()])))
             p = p.get_parent ()
         
     def dump (self, indent = ''):
-        sys.stderr.write ('%s<%s%s>' % (indent, self._name, ''.join ([' %s=%s' % item for item in self._attribute_dict.items ()])))
+        ly.debug_output ('%s<%s%s>' % (indent, self._name, ''.join ([' %s=%s' % item for item in self._attribute_dict.items ()])))
         non_text_children = [c for c in self._children if not isinstance (c, Hash_text)]
         if non_text_children:
-            sys.stderr.write ('\n')
+            ly.debug_output ('\n')
         for c in self._children:
             c.dump (indent + "    ")
         if non_text_children:
-            sys.stderr.write (indent)
-        sys.stderr.write ('</%s>\n' % self._name)
+            ly.debug_output (indent)
+        ly.debug_output ('</%s>\n' % self._name)
 
         
     def get_typed_children (self, klass):
@@ -128,7 +125,7 @@ class Xml_node:
     def get_unique_typed_child (self, klass):
         cn = self.get_typed_children(klass)
         if len (cn) <> 1:
-            sys.stderr.write (self.__dict__ + '\n')
+            ly.error (self.__dict__)
             raise 'Child is not unique for', (klass, 'found', cn)
 
         return cn[0]
@@ -170,6 +167,14 @@ class Identification (Xml_node):
           ret.append (r.get_text ())
         return string.join (ret, "\n")
 
+    # get contents of the source-element (usually used for publishing information). (These contents are saved in a custom variable named "source" in the header of the .ly file.)
+    def get_source (self):
+        source = self.get_named_children ('source')
+        ret = []
+        for r in source:
+          ret.append (r.get_text ())
+        return string.join (ret, "\n")
+
     def get_creator (self, type):
         creators = self.get_named_children ('creator')
         # return the first creator tag that has the particular type
@@ -235,8 +240,6 @@ class Identification (Xml_node):
                     return mf.get_text () 
         return None
 
-
-
 class Duration (Music_xml_node):
     def get_length (self):
         dur = int (self.get_text ()) * Rational (1,4)
@@ -246,7 +249,7 @@ class Hash_comment (Music_xml_node):
     pass
 class Hash_text (Music_xml_node):
     def dump (self, indent = ''):
-        sys.stderr.write ('%s' % string.strip (self._data))
+        ly.debug_output ('%s' % string.strip (self._data))
 
 class Pitch (Music_xml_node):
     def get_step (self):
@@ -355,7 +358,7 @@ class Attributes (Measure_element):
 
             if mxl.get_maybe_exist_named_child ('senza-misura'):
                 # TODO: Handle pieces without a time signature!
-                error (_ ("Senza-misura time signatures are not yet supported!"))
+                ly.warning (_ ("Senza-misura time signatures are not yet supported!"))
                 return (4, 4)
             else:
                 signature = []
@@ -517,7 +520,7 @@ class Part_list (Music_xml_node):
         if instrument_name:
             return instrument_name
         else:
-            ly.stderr_write (_ ("Unable to find instrument for ID=%s\n") % id)
+            ly.warning (_ ("Unable to find instrument for ID=%s\n") % id)
             return "Grand Piano"
 
 class Part_group (Music_xml_node):