From f0ef56b8736401a28f480a5265c982382d1a5fa6 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Wed, 7 Dec 2005 13:22:52 +0000 Subject: [PATCH] * scripts/musicxml2ly.py (musicxml_voice_to_lily_voice): don't forget (musicxml_voice_to_lily_voice): use pending_skip iso. ly_voice[-1] (main): add if __main__ for debugging. * scripts/musicxml2ly.py (progress): new function (musicxml_key_to_lily): don't barf on modeless keys. (create_skip_music): new function. (musicxml_spanner_to_lily_event): new function. Handle beams too. (musicxml_note_to_lily_main_event): new function. --- ChangeLog | 7 +++++++ scripts/musicxml2ly.py | 40 ++++++++++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 82d1a7ecb7..ec40ef7215 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2005-12-07 Han-Wen Nienhuys + * scripts/musicxml2ly.py (musicxml_voice_to_lily_voice): don't + forget + (musicxml_voice_to_lily_voice): use pending_skip iso. ly_voice[-1] + (main): add if __main__ for debugging. + + * python/musicxml.py (Accidental.__init__): new class. + * scripts/musicxml2ly.py (progress): new function (musicxml_key_to_lily): don't barf on modeless keys. (create_skip_music): new function. diff --git a/scripts/musicxml2ly.py b/scripts/musicxml2ly.py index 390a855727..2e911eafcc 100644 --- a/scripts/musicxml2ly.py +++ b/scripts/musicxml2ly.py @@ -223,6 +223,7 @@ def musicxml_voice_to_lily_voice (voice): ly_voice = [] ly_now = Rational (0) + pending_skip = Rational (0) tuplet_events = [] @@ -231,6 +232,9 @@ def musicxml_voice_to_lily_voice (voice): continue if isinstance (n, musicxml.Attributes): + ly_now += pending_skip + pending_skip = Rational (0) + ly_voice.extend (musicxml_attributes_to_lily (n)) continue @@ -241,13 +245,17 @@ def musicxml_voice_to_lily_voice (voice): if n.is_first () and ly_voice: ly_voice[-1].comment += '\n' + + main_event = musicxml_note_to_lily_main_event (n) + ev_chord = None if None == n.get_maybe_exist_typed_child (musicxml.Chord): - if ly_voice: - ly_now += ly_voice[-1].get_length () + ly_now += pending_skip + pending_skip = main_event.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) @@ -260,10 +268,8 @@ def musicxml_voice_to_lily_voice (voice): 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 = [] @@ -332,7 +338,7 @@ def musicxml_pitch_to_lily (mxl_pitch): p.octave = mxl_pitch.get_octave () - 4 return p -def get_all_voices (parts): +def synchronize_musicxml (parts): progress ("Synchronizing MusicXML...") all_voices = {} @@ -345,8 +351,12 @@ def get_all_voices (parts): m_name = 'Part' + p.id + 'Voice' + id m_name = musicxml_id_to_lily (m_name) all_voices[m_name] = voice + return all_voices +def get_all_voices (parts): + all_voices = synchronize_musicxml (parts) + progress ("Converting to LilyPond expressions...") all_ly_voices = {} for (k, v) in all_voices.items(): @@ -417,9 +427,7 @@ Copyright (c) 2005 by def convert (filename, output_name): - printer = musicexp.Output_printer() - progress ("Reading MusicXML...") tree = musicxml.read_musicxml (filename) @@ -439,11 +447,15 @@ def convert (filename, output_name): return voices -opt_parser = option_parser() +def main (): + opt_parser = option_parser() + + (options, args) = opt_parser.parse_args () + if not args: + opt_parser.print_usage() + sys.exit (2) -(options, args) = opt_parser.parse_args () -if not args: - opt_parser.print_usage() - sys.exit (2) + voices = convert (args[0], options.output) -voices = convert (args[0], options.output) +if __name__ == '__main__': + main() -- 2.39.5