class EventChord (NestedMusic):
+ def __init__ (self):
+ NestedMusic.__init__ (self)
+ self.grace_elements = []
+ def append_grace (self, element):
+ if element:
+ self.grace_elements.append (element)
+
def get_length (self):
l = Rational (0)
for e in self.elements:
other_events = [e for e in self.elements if
not isinstance (e, RhythmicEvent)]
+ if self.grace_elements and self.elements:
+ printer ('\grace {')
+ for g in self.grace_elements:
+ g.print_ly (printer)
+ printer ('}')
+
if rest_events:
rest_events[0].print_ly (printer)
elif len (note_events) == 1:
d.duration_log = mxl_note.get_duration_log ()
d.dots = len (mxl_note.get_typed_children (musicxml.Dot))
- d.factor = mxl_note._duration / d.get_length ()
+ # Grace notes by specification have duration 0, so no time modification
+ # factor is possible. It even messes up the output with *0/1
+ if not mxl_note.get_maybe_exist_typed_child (musicxml.Grace):
+ d.factor = mxl_note._duration / d.get_length ()
return d
def add_multibar_rest (self, duration):
self.pending_multibar += duration
-
+
+ def set_duration (self, duration):
+ self.end_moment = self.begin_moment + duration
+ def current_duration (self):
+ return self.end_moment - self.begin_moment
def add_music (self, music, duration):
assert isinstance (music, musicexp.Music)
self.elements.append (music)
self.begin_moment = self.end_moment
- self.end_moment = self.begin_moment + duration
+ self.set_duration (duration)
# Insert all pending dynamics right after the note/rest:
if duration > Rational (0):
if not ev_chord:
ev_chord = musicexp.EventChord()
voice_builder.add_music (ev_chord, n._duration)
-
- ev_chord.append (main_event)
+ # When a note/chord has grace notes (duration==0), the duration of the
+ # event chord is not yet known, but the event chord was already added
+ # with duration 0. The following correct this when we hit the real note!
+ if voice_builder.current_duration () == 0 and n._duration > 0:
+ voice_builder.set_duration (n._duration)
+ if n.get_maybe_exist_typed_child (musicxml.Grace):
+ ev_chord.append_grace (main_event)
+ else:
+ ev_chord.append (main_event)
notations = n.get_maybe_exist_typed_child (musicxml.Notations)
tuplet_event = None