return res
-def musicxml_chordroot_to_lily (mxl_root):
- r = musicexp.ChordRoot ()
- r.alteration = mxl_root.get_alteration ()
- r.step = musicxml_step_to_lily (mxl_root.get_step ())
+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 ())
return r
chordkind_dict = {
- 'major': '',
+ 'major': '5',
'minor': 'm',
'augmented': 'aug',
'diminished': 'dim',
#'pedal': '???',(pedal-point bass)
#'power': '???',(perfect fifth)
#'Tristan': '???',
- #'other': '',
- 'none': '',
+ 'other': '1',
+ 'none': None,
}
def musicxml_chordkind_to_lily (kind):
res = chordkind_dict.get (kind, None)
- if not res:
+ # Check for None, since a major chord is converted to ''
+ if res == None:
error_message (_ ("Unable to convert chord type %s to lilypond.") % kind)
return res
root = n.get_maybe_exist_named_child ('root')
if root:
ev = musicexp.ChordNameEvent ()
- ev.root = musicxml_chordroot_to_lily (root)
+ ev.root = musicxml_chordpitch_to_lily (root)
kind = n.get_maybe_exist_named_child ('kind')
if kind:
ev.kind = musicxml_chordkind_to_lily (kind.get_text ())
+ if not ev.kind:
+ return res
+ bass = n.get_maybe_exist_named_child ('bass')
+ if bass:
+ ev.bass = musicxml_chordpitch_to_lily (bass)
+ inversion = n.get_maybe_exist_named_child ('inversion')
+ if inversion:
+ # TODO: Lilypond does not support inversions, does it?
+ pass
+ for deg in n.get_named_children ('degree'):
+ d = musicexp.ChordModification ()
+ d.type = deg.get_type ()
+ d.step = deg.get_value ()
+ d.alteration = deg.get_alter ()
+ ev.add_modification (d)
#TODO: convert the user-symbols attribute:
#major: a triangle, like Unicode 25B3
#minor: -, like Unicode 002D
#augmented: +, like Unicode 002B
#diminished: (degree), like Unicode 00B0
#half-diminished: (o with slash), like Unicode 00F8
- # TODO: Convert the inversion and bass children
- for deg in n.get_named_children ('degree'):
- # TODO: Convert the added/removed degrees to lilypond
- pass
if ev and ev.root:
res.append (ev)
self.begin_moment = Rational (0)
self.pending_multibar = Rational (0)
self.ignore_skips = False
+ self.has_relevant_elements = False
def _insert_multibar (self):
r = musicexp.MultiMeasureRest ()
if self.pending_multibar > Rational (0):
self._insert_multibar ()
+ self.has_relevant_elements = True
self.elements.append (music)
self.begin_moment = self.end_moment
self.set_duration (duration)
assert isinstance (command, musicexp.Music)
if self.pending_multibar > Rational (0):
self._insert_multibar ()
+ self.has_relevant_elements = True
self.elements.append (command)
def add_barline (self, barline):
# TODO: Implement merging of default barline and custom bar line
self.pending_dynamics.append (dynamic)
def add_bar_check (self, number):
+ # re/store has_relevant_elements, so that a barline alone does not
+ # trigger output for figured bass, chord names
+ has_relevant = self.has_relevant_elements
b = musicexp.BarLine ()
b.bar_number = number
self.add_barline (b)
+ self.has_relevant_elements = has_relevant
def jumpto (self, moment):
current_end = self.end_moment + self.pending_multibar
num = 0
if num > 0:
voice_builder.add_bar_check (num)
+ figured_bass_builder.add_bar_check (num)
+ chordnames_builder.add_bar_check (num)
main_event = musicxml_note_to_lily_main_event (n)
if main_event and not first_pitch:
return_value.ly_voice = v
# create \figuremode { figured bass elements }
- if figured_bass_builder.elements:
+ if figured_bass_builder.has_relevant_elements:
fbass_music = musicexp.SequentialMusic ()
fbass_music.elements = figured_bass_builder.elements
v = musicexp.ModeChangingMusicWrapper()
return_value.figured_bass = v
# create \chordmode { chords }
- if chordnames_builder.elements:
+ if chordnames_builder.has_relevant_elements:
cname_music = musicexp.SequentialMusic ()
cname_music.elements = chordnames_builder.elements
v = musicexp.ModeChangingMusicWrapper()