def musicxml_duration_to_lily (mxl_note):
d = musicexp.Duration ()
- # if the note has no Type child, then that method spits out a warning and
- # returns 0, i.e. a whole note
+ # if the note has no Type child, then that method returns None. In that case,
+ # use the <duration> tag instead. If that doesn't exist, either -> Error
d.duration_log = mxl_note.get_duration_log ()
-
- d.dots = len (mxl_note.get_typed_children (musicxml.Dot))
- # 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
+ if d.duration_log == None:
+ if mxl_note._duration > 0:
+ return rational_to_lily_duration (mxl_note._duration)
+ else:
+ mxl_note.message (_ ("Encountered note at %s without type and duration (=%s)") % (mxl_note.start, mxl_note._duration) )
+ return None
+ else:
+ d.dots = len (mxl_note.get_typed_children (musicxml.Dot))
+ # 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 rational_to_lily_duration (rational_len):
d = musicexp.Duration ()
new_list = []
last = 0
for (i1, i2, frac) in indices:
- if i1 >= i2:
+ if i1 > i2:
continue
new_list.extend (music_list[last:i1])
change.mode = mode
change.tonic = start_pitch
return change
+
+def musicxml_transpose_to_lily (attributes):
+ transpose = attributes.get_transposition ()
+ if not transpose:
+ return None
+
+ shift = musicexp.Pitch ()
+ octave_change = transpose.get_maybe_exist_named_child ('octave-change')
+ if octave_change:
+ shift.octave = string.atoi (octave_change.get_text ())
+ chromatic_shift = string.atoi (transpose.get_named_child ('chromatic').get_text ())
+ chromatic_shift_normalized = chromatic_shift % 12;
+ (shift.step, shift.alteration) = [
+ (0,0), (0,1), (1,0), (2,-1), (2,0),
+ (3,0), (3,1), (4,0), (5,-1), (5,0),
+ (6,-1), (6,0)][chromatic_shift_normalized];
+ shift.octave += (chromatic_shift - chromatic_shift_normalized) / 12
+
+ diatonic = transpose.get_maybe_exist_named_child ('diatonic')
+ if diatonic:
+ diatonic_step = string.atoi (diatonic.get_text ()) % 7
+ if diatonic_step != shift.step:
+ # We got the alter incorrect!
+ old_semitones = shift.semitones ()
+ shift.step = diatonic_step
+ new_semitones = shift.semitones ()
+ shift.alteration += old_semitones - new_semitones
+
+ transposition = musicexp.Transposition ()
+ transposition.pitch = musicexp.Pitch ().transposed (shift)
+ return transposition
+
+
def musicxml_attributes_to_lily (attrs):
elts = []
attr_dispatch = {
'clef': musicxml_clef_to_lily,
'time': musicxml_time_to_lily,
- 'key': musicxml_key_to_lily
+ 'key': musicxml_key_to_lily,
+ 'transpose': musicxml_transpose_to_lily,
}
for (k, func) in attr_dispatch.items ():
children = attrs.get_named_children (k)
is_beamed = True
elif beam_ev.span_direction == 1: # beam and thus melisma ends here
is_beamed = False
-
- 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))
# Extract the lyrics
if not rest and not ignore_lyrics: