_ = ly._
import utilities
+import musicxml2ly_conversion
import musicxml
import musicexp
ly.warning(_("Unprocessed PartGroupInfo %s encountered") % self)
return ''
-def musicxml_step_to_lily(step):
- if step:
- return (ord(step) - ord('A') + 7 - 2) % 7
- else:
- return None
-
def staff_attributes_to_string_tunings(mxl_attr):
details = mxl_attr.get_maybe_exist_named_child('staff-details')
if not details:
step = i.get_named_child(u'tuning-step')
step = step.get_text().strip()
- p.step = musicxml_step_to_lily(step)
+ p.step = musicxml2ly_conversion.musicxml_step_to_lily(step)
octave = i.get_named_child(u'tuning-octave')
octave = octave.get_text().strip()
-def rational_to_lily_duration(rational_len):
- d = musicexp.Duration()
-
- rational_len.normalize_self()
- d_log = {1: 0, 2: 1, 4:2, 8:3, 16:4, 32:5, 64:6, 128:7, 256:8, 512:9}.get(rational_len.denominator(), -1)
-
- # Duration of the form 1/2^n or 3/2^n can be converted to a simple lilypond duration
- dots = {1: 0, 3: 1, 7: 2, 15: 3, 31: 4, 63: 5, 127: 6}.get(rational_len.numerator(), -1)
- if(d_log >= dots >= 0):
- # account for the dots!
- d.duration_log = d_log - dots
- d.dots = dots
- elif(d_log >= 0):
- d.duration_log = d_log
- d.factor = Rational(rational_len.numerator())
- else:
- ly.warning(_("Encountered rational duration with denominator %s, "
- "unable to convert to lilypond duration") %
- rational_len.denominator())
- # TODO: Test the above error message
- return None
-
- return d
def musicxml_partial_to_lily(partial_len):
if partial_len > 0:
p = musicexp.Partial()
- p.partial = rational_to_lily_duration(partial_len)
+ p.partial = musicxml2ly_conversion.rational_to_lily_duration(partial_len)
return p
else:
return None
while pos < len(music_list) and not repeat_replaced:
e = music_list[pos]
repeat_finished = False
- if isinstance(e, RepeatMarker):
+ if isinstance(e, musicxml2ly_conversion.RepeatMarker):
if not repeat_times and e.times:
repeat_times = e.times
if e.direction == -1:
if repeat_end < 0:
repeat_end = pos
final_marker = pos
- elif isinstance(e, EndingMarker):
+ elif isinstance(e, musicxml2ly_conversion.EndingMarker):
if e.direction == -1:
if repeat_start < 0:
repeat_start = 0
# MusicXML contains C,D,E,F,G,A,B as steps, lily uses 0-7, so convert
alterations = []
for k in key_sig:
- k[0] = musicxml_step_to_lily(k[0])
+ k[0] = musicxml2ly_conversion.musicxml_step_to_lily(k[0])
alterations.append(k)
change.non_standard_alterations = alterations
return change
return elts
-class Marker(musicexp.Music):
- def __init__(self):
- self.direction = 0
- self.event = None
- def print_ly(self, printer):
- ly.warning(_("Encountered unprocessed marker %s\n") % self)
- pass
- def ly_expression(self):
- return ""
-class RepeatMarker(Marker):
- def __init__(self):
- Marker.__init__(self)
- self.times = 0
-class EndingMarker(Marker):
- pass
spanner_event_dict = {
#"shake": "?",
"snap-pizzicato": "snappizzicato",
#"spiccato": "?",
- "staccatissimo": (musicexp.ShortArticulationEvent, "|"), # or "staccatissimo"
+ "staccatissimo": (musicexp.ShortArticulationEvent, "!"), # or "staccatissimo"
"staccato": (musicexp.ShortArticulationEvent, "."), # or "staccato"
"stopped": (musicexp.ShortArticulationEvent, "+"), # or "stopped"
#"stress": "?",
def musicxml_chordpitch_to_lily(mxl_cpitch):
r = musicexp.ChordPitch()
r.alteration = mxl_cpitch.get_alteration()
- r.step = musicxml_step_to_lily(mxl_cpitch.get_step())
+ r.step = musicxml2ly_conversion.musicxml_step_to_lily(mxl_cpitch.get_step())
return r
chordkind_dict = {
string_tunings = [musicexp.Pitch()] * lines
for i in range(0, lines):
p = musicexp.Pitch()
- p.step = musicxml_step_to_lily(((("E","A","D","G","B")*(lines/5+1))[0:lines])[i])
+ p.step = musicxml2ly_conversion.musicxml_step_to_lily(((("E","A","D","G","B")*(lines/5+1))[0:lines])[i])
p.octave = (([-2+int(x%5>1)+2*(x/5) for x in range(0,lines)][0:lines])[i])
p.alteration = 0
p._force_absolute_pitch = True
# apply the duration to res
length = Rational(int(dur.get_text()), n._divisions) * Rational(1, 4)
res.set_real_duration(length)
- duration = rational_to_lily_duration(length)
+ duration = musicxml2ly_conversion.rational_to_lily_duration(length)
if duration:
res.set_duration(duration)
if hasattr(n, 'parentheses') and n.parentheses == "yes":
layout_information.set_context_item('Score', 'skipBars = ##t')
r = musicexp.MultiMeasureRest()
lenfrac = self.measure_length
- r.duration = rational_to_lily_duration(lenfrac)
+ r.duration = musicxml2ly_conversion.rational_to_lily_duration(lenfrac)
r.duration.factor *= self.pending_multibar / lenfrac
self.elements.append(r)
self.begin_moment = self.end_moment
def is_rest(elem):
return elem.get_typed_children(musicxml.Rest)
+ def is_chord(elem):
+ return elem.get_typed_children(musicxml.Chord)
+
def is_note_and_not_rest(elem):
return is_note(elem) and not is_rest(elem)
not note_has_lyric_belonging_to_lyric_part:
result.append('\skip1 ')
# Note does not have any lyric attached to it.
+ elif is_chord(elem):
+ # note without lyrics part of a chord. MusicXML format is
+ # unclear if a chord element could contain a lyric, lets
+ # asume that we do not want to put a skip here.
+ continue
elif is_note_and_not_rest(elem):
result.append('\skip1 ')
figured_bass_builder.add_barline(a, False)
chordnames_builder.add_barline(a, False)
fretboards_builder.add_barline(a, False)
- elif isinstance(a, RepeatMarker) or isinstance(a, EndingMarker):
+ elif isinstance(a, musicxml2ly_conversion.RepeatMarker) or isinstance(a, musicxml2ly_conversion.EndingMarker):
voice_builder.add_command(a)
figured_bass_builder.add_barline(a, False)
chordnames_builder.add_barline(a, False)
p.version = ('%prog (LilyPond) ' + lilypond_version + '\n\n'
+
-_ ("""Copyright (c) 2005--2015 by
+_ ("""Copyright (c) 2005--2016 by
Han-Wen Nienhuys <hanwen@xs4all.nl>,
Jan Nieuwenhuizen <janneke@gnu.org> and
Reinhold Kainhofer <reinhold@kainhofer.com>