From: John Gourlay Date: Fri, 29 Apr 2016 19:47:40 +0000 (-0400) Subject: Merge branch 'master' into philomelos X-Git-Tag: release/2.19.44-1~24^2~7 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=0398fdb9df24ac2e22a8cbff1b3c18ca04e9f221;p=lilypond.git Merge branch 'master' into philomelos Conflicts resolved in: python/musicexp.py python/musicxml.py scripts/musicxml2ly.py --- 0398fdb9df24ac2e22a8cbff1b3c18ca04e9f221 diff --cc python/musicexp.py index 40b58c81f4,f6b47c3c93..998267550e --- a/python/musicexp.py +++ b/python/musicexp.py @@@ -1514,17 -1255,14 +1520,17 @@@ class NotestyleEvent (Event): #class ch Event.__init__ (self) self.style = None self.filled = None + self.color = None def pre_chord_ly (self): + return_string = '' if self.style: - return "\\once \\override NoteHead.style = #%s" % self.style - else: - return '' + return_string += " \\once \\override NoteHead #'style = #%s" % self.style + if self.color: + return_string += " \\once \\override NoteHead #'color = #(rgb-color %s %s %s)" % (self.color[0], self.color[1], self.color[2]) + return return_string def pre_note_ly (self, is_chord_element): if self.style and is_chord_element: - return "\\tweak #'style #%s" % self.style + return "\\tweak style #%s" % self.style else: return '' def ly_expression (self): diff --cc python/musicxml.py index 48aa29450d,a061b6ea6e..f0b82f1333 --- a/python/musicxml.py +++ b/python/musicxml.py @@@ -118,54 -138,18 +118,55 @@@ class Xml_node return default -class Music_xml_node (Xml_node): - def __init__ (self): - Xml_node.__init__ (self) - self.duration = Rational (0) - self.start = Rational (0) +class Music_xml_node(Xml_node): + def __init__(self): + Xml_node.__init__(self) + self.duration = Rational(0) + self.start = Rational(0) + self.converted = False + self.voice_id = None; -class Work (Xml_node): - def get_work_information (self, tag): - wt = self.get_maybe_exist_named_child (tag) + +class Music_xml_spanner(Music_xml_node): + + def get_type(self): + if hasattr(self, 'type'): + return self.type + else: + return 0 + + def get_size(self): + if hasattr(self, 'size'): + return int(self.size) + else: + return 0 + + +class Measure_element(Music_xml_node): + + def get_voice_id(self): + voice_id = self.get_maybe_exist_named_child('voice') + if voice_id: + return voice_id.get_text() + else: + return None + + def is_first(self): + # Look at all measure elements(previously we had self.__class__, which + # only looked at objects of the same type! + cn = self._parent.get_typed_children(Measure_element) + # But only look at the correct voice; But include Attributes, too, which + # are not tied to any particular voice + cn = [c for c in cn if(c.get_voice_id() == self.get_voice_id()) or isinstance(c, Attributes)] + return cn[0] == self + + +class Work(Xml_node): + + def get_work_information(self, tag): + wt = self.get_maybe_exist_named_child(tag) if wt: - return wt.get_text () + return wt.get_text() else: return '' @@@ -428,22 -281,26 +429,31 @@@ class Unpitched(Music_xml_node) else: return None + def to_lily_object(self): + p = None + step = self.get_step() + if step: + p = musicexp.Pitch() + p.step = musicxml2ly_conversion.musicxml_step_to_lily(step) + octave = self.get_octave() + if octave and p: + p.octave = octave - 4 + return p + + + class Measure_element (Music_xml_node): + def get_voice_id (self): + voice = self.get_maybe_exist_named_child ('voice') + if voice: + return voice.get_text () + else: + return self.voice_id; + - def is_first (self): - # Look at all measure elements (previously we had self.__class__, which - # only looked at objects of the same type! - cn = self._parent.get_typed_children (Measure_element) - # But only look at the correct voice; But include Attributes, too, which - # are not tied to any particular voice - cn = [c for c in cn if (c.get_voice_id () == self.get_voice_id ()) or isinstance (c, Attributes)] - return cn[0] == self + -class Attributes (Measure_element): - def __init__ (self): - Measure_element.__init__ (self) +class Attributes(Measure_element): + + def __init__(self): + Measure_element.__init__(self) self._dict = {} self._original_tag = None self._time_signature_cache = None @@@ -1305,16 -653,34 +1315,34 @@@ class Part(Music_xml_node) problem = 'overfull' ## only for verbose operation. if problem <> 'incomplete' and previous_measure: - previous_measure.message ('%s measure? Expected: %s, Difference: %s' % (problem, now, new_now - now)) + previous_measure.message('%s measure? Expected: %s, Difference: %s' %(problem, now, new_now - now)) now = new_now measure_start_moment = now - measure_position = Rational (0) + measure_position = Rational(0) - for n in m.get_all_children(): + voice_id = None; + assign_to_next_voice = [] + for n in m.get_all_children (): + # assign a voice to all measure elements + if (n.get_name() == 'backup'): + voice_id = None; + + if isinstance(n, Measure_element): + if n.get_voice_id (): + voice_id = n.get_voice_id () + for i in assign_to_next_voice: + i.voice_id = voice_id + assign_to_next_voice = [] + else: + if voice_id: + n.voice_id = voice_id + else: + assign_to_next_voice.append (n) + # figured bass has a duration, but applies to the next note # and should not change the current measure position! - if isinstance (n, FiguredBass): - n._divisions = factor.denominator () + if isinstance(n, FiguredBass): + n._divisions = factor.denominator() n._when = now n._measure_position = measure_position continue @@@ -1573,114 -919,265 +1601,117 @@@ part._voices = voices - def get_voices (self): + def get_voices(self): return self._voices - def get_staff_attributes (self): - return self._staff_attributes_dict - -class Notations (Music_xml_node): - def get_tie (self): - ts = self.get_named_children ('tied') - starts = [t for t in ts if t.type == 'start'] - if starts: - return starts[0] - else: - return None - - def get_tuplets (self): - return self.get_typed_children (Tuplet) - -class Time_modification(Music_xml_node): - def get_fraction (self): - b = self.get_maybe_exist_named_child ('actual-notes') - a = self.get_maybe_exist_named_child ('normal-notes') - return (int(a.get_text ()), int (b.get_text ())) - - def get_normal_type (self): - tuplet_type = self.get_maybe_exist_named_child ('normal-type') - if tuplet_type: - dots = self.get_named_children ('normal-dot') - log = musicxml_duration_to_log (tuplet_type.get_text ().strip ()) - return (log , len (dots)) - else: - return None + def get_staff_attributes(self): + return self._staff_attributes_dict -class Accidental (Music_xml_node): - def __init__ (self): - Music_xml_node.__init__ (self) - self.editorial = False - self.cautionary = False - -class Music_xml_spanner (Music_xml_node): - def get_type (self): - if hasattr (self, 'type'): - return self.type - else: - return 0 - def get_size (self): - if hasattr (self, 'size'): - return string.atoi (self.size) - else: - return 0 -class Wedge (Music_xml_spanner): +class BarStyle(Music_xml_node): pass -class Tuplet (Music_xml_spanner): - def duration_info_from_tuplet_note (self, tuplet_note): - tuplet_type = tuplet_note.get_maybe_exist_named_child ('tuplet-type') - if tuplet_type: - dots = tuplet_note.get_named_children ('tuplet-dot') - log = musicxml_duration_to_log (tuplet_type.get_text ().strip ()) - return (log, len (dots)) - else: - return None - - # Return tuplet note type as (log, dots) - def get_normal_type (self): - tuplet = self.get_maybe_exist_named_child ('tuplet-normal') - if tuplet: - return self.duration_info_from_tuplet_note (tuplet) - else: - return None +class BeatType(Music_xml_node): + pass - def get_actual_type (self): - tuplet = self.get_maybe_exist_named_child ('tuplet-actual') - if tuplet: - return self.duration_info_from_tuplet_note (tuplet) - else: - return None +class BeatUnit(Music_xml_node): + pass - def get_tuplet_note_count (self, tuplet_note): - if tuplet_note: - tuplet_nr = tuplet_note.get_maybe_exist_named_child ('tuplet-number') - if tuplet_nr: - return int (tuplet_nr.get_text ()) - return None - def get_normal_nr (self): - return self.get_tuplet_note_count (self.get_maybe_exist_named_child ('tuplet-normal')) - def get_actual_nr (self): - return self.get_tuplet_note_count (self.get_maybe_exist_named_child ('tuplet-actual')) +class BeatUnitDot(Music_xml_node): + pass -class Bracket (Music_xml_spanner): +class Beats(Music_xml_node): pass -class Dashes (Music_xml_spanner): +class Bracket(Music_xml_spanner): pass -class Slur (Music_xml_spanner): - def get_type (self): - return self.type +class Chord(Music_xml_node): + pass -class Beam (Music_xml_spanner): - def get_type (self): - return self.get_text () - def is_primary (self): - if hasattr (self, 'number'): - return self.number == "1" - else: - return True +class Dashes(Music_xml_spanner): + pass -class Wavy_line (Music_xml_spanner): +class DirType(Music_xml_node): pass -class Pedal (Music_xml_spanner): +class Direction(Music_xml_node): pass -class Glissando (Music_xml_spanner): +class Dot(Music_xml_node): pass -class Slide (Music_xml_spanner): +class Elision(Music_xml_node): pass -class Octave_shift (Music_xml_spanner): - # default is 8 for the octave-shift! - def get_size (self): - if hasattr (self, 'size'): - return string.atoi (self.size) - else: - return 8 +class Extend(Music_xml_node): + pass -class Chord (Music_xml_node): +class FiguredBass(Music_xml_node): pass -class Dot (Music_xml_node): +class Glissando(Music_xml_spanner): pass -# Rests in MusicXML are blocks with a inside. This class is only -# for the inner element, not the whole rest block. -class Rest (Music_xml_node): - def __init__ (self): - Music_xml_node.__init__ (self) - self._is_whole_measure = False - def is_whole_measure (self): - return self._is_whole_measure - def get_step (self): - ch = self.get_maybe_exist_typed_child (get_class (u'display-step')) - if ch: - 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: - oct = ch.get_text ().strip () - return int (oct) - else: - return None +class Grace(Music_xml_node): + pass -class Type (Music_xml_node): +class Harmony(Music_xml_node): pass -class Grace (Music_xml_node): + +class Hash_comment(Music_xml_node): pass -class Staff (Music_xml_node): + +class KeyAlter(Music_xml_node): pass + class Direction (Measure_element): + pass -class DirType (Music_xml_node): ++ +class KeyOctave(Music_xml_node): pass -class Bend (Music_xml_node): - def bend_alter (self): - alter = self.get_maybe_exist_named_child ('bend-alter') - return interpret_alter_element (alter) +class KeyStep(Music_xml_node): + pass -class Words (Music_xml_node): +class Part_group(Music_xml_node): pass -class Harmony (Music_xml_node): +class Pedal(Music_xml_spanner): pass -class ChordPitch (Music_xml_node): - def step_class_name (self): - return u'root-step' - def alter_class_name (self): - return u'root-alter' - def get_step (self): - ch = self.get_unique_typed_child (get_class (self.step_class_name ())) - return ch.get_text ().strip () - def get_alteration (self): - ch = self.get_maybe_exist_typed_child (get_class (self.alter_class_name ())) - return interpret_alter_element (ch) - -class Root (ChordPitch): +class PerMinute(Music_xml_node): pass -class Bass (ChordPitch): - def step_class_name (self): - return u'bass-step' - def alter_class_name (self): - return u'bass-alter' +class Print(Music_xml_node): + pass -class ChordModification (Music_xml_node): - def get_type (self): - ch = self.get_maybe_exist_typed_child (get_class (u'degree-type')) - return {'add': 1, 'alter': 1, 'subtract': -1}.get (ch.get_text ().strip (), 0) - def get_value (self): - ch = self.get_maybe_exist_typed_child (get_class (u'degree-value')) - value = 0 - if ch: - value = int (ch.get_text ().strip ()) - return value - def get_alter (self): - ch = self.get_maybe_exist_typed_child (get_class (u'degree-alter')) - return interpret_alter_element (ch) - - -class Frame (Music_xml_node): - def get_frets (self): - return self.get_named_child_value_number ('frame-frets', 4) - def get_strings (self): - return self.get_named_child_value_number ('frame-strings', 6) - def get_first_fret (self): - return self.get_named_child_value_number ('first-fret', 1) - -class Frame_Note (Music_xml_node): - def get_string (self): - return self.get_named_child_value_number ('string', 1) - def get_fret (self): - return self.get_named_child_value_number ('fret', 0) - def get_fingering (self): - return self.get_named_child_value_number ('fingering', -1) - def get_barre (self): - n = self.get_maybe_exist_named_child ('barre') - if n: - return getattr (n, 'type', '') - else: - return '' +class Root(ChordPitch): + pass -class FiguredBass (Music_xml_node): +class Score_part(Music_xml_node): pass -class Beats (Music_xml_node): +class Slide(Music_xml_spanner): pass -class BeatType (Music_xml_node): +class Staff(Music_xml_node): pass -class BeatUnit (Music_xml_node): +class Text(Music_xml_node): pass -class BeatUnitDot (Music_xml_node): +class Type(Music_xml_node): pass -class PerMinute (Music_xml_node): +class Wavy_line(Music_xml_spanner): pass -class Print (Music_xml_node): +class Wedge(Music_xml_spanner): pass +class Words(Music_xml_node): + pass ## need this, not all classes are instantiated