-
- ly_voice = []
- ly_now = Rational (0)
-
- tuplet_events = []
-
- for n in voice:
- if n.get_name () == 'forward':
- continue
-
- if isinstance (n, musicxml.Attributes):
- ly_voice.extend (musicxml_attributes_to_lily (n))
- continue
-
- if not n.__class__.__name__ == 'Note':
- print 'not a Note or Attributes?', n
- continue
-
- if n.is_first () and ly_voice:
- ly_voice[-1].comment += '\n'
-
- ev_chord = None
- if None == n.get_maybe_exist_typed_child (musicxml.Chord):
- if ly_voice:
- ly_now += ly_voice[-1].get_length ()
-
- if ly_now <> n._when:
- diff = n._when - ly_now
- if diff < Rational (0):
- print 'huh: negative skip', n._when, ly_now, n._duration
- diff = Rational (1,314159265)
-
- ly_voice.append (create_skip_music (diff))
- ly_now = n._when
-
- ly_voice.append (musicexp.EventChord())
- else:
- pass
-
- ev_chord = ly_voice[-1]
-
- main_event = musicxml_note_to_lily_main_event (n)
- ev_chord.append (main_event)
-
- notations = n.get_maybe_exist_typed_child (musicxml.Notations)
- tuplet_event = None
- span_events = []
- if notations:
- if notations.get_tuplet():
- mod = n.get_maybe_exist_typed_child (musicxml.Time_modification)
- frac = (1,1)
- if mod:
- frac = mod.get_fraction ()
-
- tuplet_events.append ((ev_chord, tuplet_event, frac))
-
- slurs = [s for s in notations.get_named_children ('slur')
- if s.get_type () in ('start','stop')]
- if slurs:
- if len (slurs) > 1:
- print 'more than 1 slur?'
-
- lily_ev = musicxml_spanner_to_lily_event (slurs[0])
- ev_chord.append (lily_ev)
-
- mxl_tie = notations.get_tie ()
- if mxl_tie and mxl_tie.type == 'start':
- ev_chord.append (musicexp.TieEvent ())
-
- mxl_beams = [b for b in n.get_named_children ('beam')
- if b.get_type () in ('begin', 'end')]
- if mxl_beams:
- beam_ev = musicxml_spanner_to_lily_event (mxl_beams[0])
- if beam_ev:
- ev_chord.append (beam_ev)
-
- if tuplet_event:
- mod = n.get_maybe_exist_typed_child (musicxml.Time_modification)
- frac = (1,1)
- if mod:
- frac = mod.get_fraction ()
-
- tuplet_events.append ((ev_chord, tuplet_event, frac))
-
- ly_voice = group_tuplets (ly_voice, tuplet_events)
-
- seq_music = musicexp.SequentialMusic()
-
- seq_music.elements = ly_voice
- return seq_music
+ tuplet_events = []
+ modes_found = {}
+
+ voice_builder = LilyPondVoiceBuilder()
+
+ for n in voice._elements:
+ if n.get_name () == 'forward':
+ continue
+
+ if not n.get_maybe_exist_named_child ('chord'):
+ try:
+ voice_builder.jumpto (n._when)
+ except NegativeSkip, neg:
+ voice_builder.correct_negative_skip (n._when)
+ n.message ("Negative skip? from %s to %s, diff %s" % (neg.here, neg.dest, neg.dest - neg.here))
+
+ if isinstance (n, musicxml.Attributes):
+ if n.is_first () and n._measure_position == Rational (0):
+ voice_builder.add_bar_check (int (n.get_parent ().number))
+ for a in musicxml_attributes_to_lily (n):
+ voice_builder.add_music (a, Rational (0))
+ continue
+
+ if not n.__class__.__name__ == 'Note':
+ print 'not a Note or Attributes?', n
+ continue
+
+ rest = n.get_maybe_exist_typed_child (musicxml.Rest)
+ if (rest
+ and rest.is_whole_measure ()):
+
+ voice_builder.add_multibar_rest (n._duration)
+ continue
+
+ if n.is_first () and n._measure_position == Rational (0):
+ num = int (n.get_parent ().number)
+ voice_builder.add_bar_check (num)
+
+ main_event = musicxml_note_to_lily_main_event (n)
+
+ try:
+ if main_event.drum_type:
+ modes_found['drummode'] = True
+ except AttributeError:
+ pass
+
+
+ ev_chord = voice_builder.last_event_chord (n._when)
+ if not ev_chord:
+ ev_chord = musicexp.EventChord()
+ voice_builder.add_music (ev_chord, n._duration)
+
+ ev_chord.append (main_event)
+
+ notations = n.get_maybe_exist_typed_child (musicxml.Notations)
+ tuplet_event = None
+ span_events = []
+ if notations:
+ if notations.get_tuplet():
+ tuplet_event = notations.get_tuplet()
+ mod = n.get_maybe_exist_typed_child (musicxml.Time_modification)
+ frac = (1,1)
+ if mod:
+ frac = mod.get_fraction ()
+
+ tuplet_events.append ((ev_chord, tuplet_event, frac))
+
+ slurs = [s for s in notations.get_named_children ('slur')
+ if s.get_type () in ('start','stop')]
+ if slurs:
+ if len (slurs) > 1:
+ print 'more than 1 slur?'
+
+ lily_ev = musicxml_spanner_to_lily_event (slurs[0])
+ ev_chord.append (lily_ev)
+
+ mxl_tie = notations.get_tie ()
+ if mxl_tie and mxl_tie.type == 'start':
+ ev_chord.append (musicexp.TieEvent ())
+
+ mxl_beams = [b for b in n.get_named_children ('beam')
+ if (b.get_type () in ('begin', 'end')
+ and b.is_primary ())]
+ if mxl_beams:
+ beam_ev = musicxml_spanner_to_lily_event (mxl_beams[0])
+ if beam_ev:
+ ev_chord.append (beam_ev)
+
+ if tuplet_event:
+ mod = n.get_maybe_exist_typed_child (musicxml.Time_modification)
+ frac = (1,1)
+ if mod:
+ frac = mod.get_fraction ()
+
+ tuplet_events.append ((ev_chord, tuplet_event, frac))
+
+ ## force trailing mm rests to be written out.
+ voice_builder.add_music (musicexp.EventChord (), Rational (0))
+
+ ly_voice = group_tuplets (voice_builder.elements, tuplet_events)
+
+ seq_music = musicexp.SequentialMusic()
+
+ if 'drummode' in modes_found.keys ():
+ ## \key <pitch> barfs in drummode.
+ ly_voice = [e for e in ly_voice
+ if not isinstance(e, musicexp.KeySignatureChange)]
+
+ seq_music.elements = ly_voice
+
+
+
+ if len (modes_found) > 1:
+ print 'Too many modes found', modes_found.keys ()
+
+ return_value = seq_music
+ for mode in modes_found.keys ():
+ v = musicexp.ModeChangingMusicWrapper()
+ v.element = return_value
+ v.mode = mode
+ return_value = v
+
+ return return_value