X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=python%2Fmusicxml.py;h=be3c61ca8f99a9bc4cf0ba8d7d0c992826359eba;hb=5e14d063f5098df2977dfb5fc9cadd281f800958;hp=8413480aef40c668679ce9818ce35cfb213677ae;hpb=35cc20ad3b54a73a183f4453ab2df7dd85320f55;p=lilypond.git diff --git a/python/musicxml.py b/python/musicxml.py index 8413480aef..be3c61ca8f 100644 --- a/python/musicxml.py +++ b/python/musicxml.py @@ -15,7 +15,7 @@ def error (str): def escape_ly_output_string (input_string): return_string = input_string - needs_quotes = not re.match (u"^[a-zA-ZäöüÜÄÖßñ]*$", return_string); + needs_quotes = not re.match (u"^[a-zA-ZäöüÜÄÖß,\.!:ñ]*$", return_string); if needs_quotes: return_string = "\"" + string.replace (return_string, "\"", "\\\"") + "\"" return return_string @@ -37,6 +37,15 @@ def musicxml_duration_to_log (dur): +def interpret_alter_element (alter_elm): + alter = 0 + if alter_elm: + val = eval(alter_elm.get_text ()) + if type (val) in (int, float): + alter = val + return alter + + class Xml_node: def __init__ (self): self._children = [] @@ -246,16 +255,12 @@ class Pitch (Music_xml_node): return step def get_octave (self): ch = self.get_unique_typed_child (get_class (u'octave')) - - step = ch.get_text ().strip () - return int (step) + octave = ch.get_text ().strip () + return int (octave) def get_alteration (self): ch = self.get_maybe_exist_typed_child (get_class (u'alter')) - alter = 0 - if ch: - alter = int (ch.get_text ().strip ()) - return alter + return interpret_alter_element (ch) class Unpitched (Music_xml_node): def get_step (self): @@ -413,9 +418,9 @@ class Attributes (Measure_element): current_step = 0 for i in key.get_all_children (): if isinstance (i, KeyStep): - current_step = int (i.get_text ()) + current_step = i.get_text ().strip () elif isinstance (i, KeyAlter): - alterations.append ([current_step, int (i.get_text ())]) + alterations.append ([current_step, interpret_alter_element (i)]) elif isinstance (i, KeyOctave): nr = -1 if hasattr (i, 'number'): @@ -426,8 +431,6 @@ class Attributes (Measure_element): else: i.message (_ ("Key alteration octave given for a " "non-existing alteration nr. %s, available numbers: %s!") % (nr, len(alterations))) - i.message ( "Non-standard key signature (after octave %s for alter nr %s): %s" % (i.get_text (), nr, alterations)) - i.message ( "Non-standard key signature with alterations %s found!" % alterations) return alterations def get_transposition (self): @@ -537,6 +540,8 @@ class Syllabic (Music_xml_node): return (text == "begin") or (text == "middle") class Elision (Music_xml_node): pass +class Extend (Music_xml_node): + pass class Text (Music_xml_node): pass @@ -824,7 +829,7 @@ class Part (Music_xml_node): if not (isinstance (n, Note) or isinstance (n, Attributes) or isinstance (n, Direction) or isinstance (n, Partial) or isinstance (n, Barline) or isinstance (n, Harmony) or - isinstance (n, FiguredBass) ): + isinstance (n, FiguredBass) or isinstance (n, Print)): continue if isinstance (n, Attributes) and not start_attr: @@ -840,7 +845,7 @@ class Part (Music_xml_node): voices[v].add_element (staff_attributes) continue - if isinstance (n, Partial) or isinstance (n, Barline): + if isinstance (n, Partial) or isinstance (n, Barline) or isinstance (n, Print): for v in voices.keys (): voices[v].add_element (n) continue @@ -993,7 +998,10 @@ class Beam (Music_xml_spanner): def get_type (self): return self.get_text () def is_primary (self): - return self.number == "1" + if hasattr (self, 'number'): + return self.number == "1" + else: + return True class Wavy_line (Music_xml_spanner): pass @@ -1032,15 +1040,14 @@ class Rest (Music_xml_node): def get_step (self): ch = self.get_maybe_exist_typed_child (get_class (u'display-step')) if ch: - step = ch.get_text ().strip () - return step + return ch.get_text ().strip () else: return None def get_octave (self): ch = self.get_maybe_exist_typed_child (get_class (u'display-octave')) if ch: - step = ch.get_text ().strip () - return int (step) + oct = ch.get_text ().strip () + return int (oct) else: return None @@ -1059,10 +1066,7 @@ class DirType (Music_xml_node): class Bend (Music_xml_node): def bend_alter (self): alter = self.get_maybe_exist_named_child ('bend-alter') - if alter: - return alter.get_text() - else: - return 0 + return interpret_alter_element (alter) class Words (Music_xml_node): pass @@ -1080,10 +1084,7 @@ class ChordPitch (Music_xml_node): return ch.get_text ().strip () def get_alteration (self): ch = self.get_maybe_exist_typed_child (get_class (self.alter_class_name ())) - alter = 0 - if ch: - alter = int (ch.get_text ().strip ()) - return alter + return interpret_alter_element (ch) class Root (ChordPitch): pass @@ -1106,10 +1107,7 @@ class ChordModification (Music_xml_node): return value def get_alter (self): ch = self.get_maybe_exist_typed_child (get_class (u'degree-alter')) - value = 0 - if ch: - value = int (ch.get_text ().strip ()) - return value + return interpret_alter_element (ch) class Frame (Music_xml_node): @@ -1152,6 +1150,9 @@ class BeatUnitDot (Music_xml_node): class PerMinute (Music_xml_node): pass +class Print (Music_xml_node): + pass + ## need this, not all classes are instantiated @@ -1180,6 +1181,7 @@ class_dict = { 'direction-type': DirType, 'duration': Duration, 'elision': Elision, + 'extend': Extend, 'frame': Frame, 'frame-note': Frame_Note, 'figured-bass': FiguredBass, @@ -1201,6 +1203,7 @@ class_dict = { 'pedal': Pedal, 'per-minute': PerMinute, 'pitch': Pitch, + 'print': Print, 'rest': Rest, 'root': Root, 'score-part': Score_part,