2005-12-07 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ * 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.
ly_voice = []
ly_now = Rational (0)
+ pending_skip = Rational (0)
tuplet_events = []
continue
if isinstance (n, musicxml.Attributes):
+ ly_now += pending_skip
+ pending_skip = Rational (0)
+
ly_voice.extend (musicxml_attributes_to_lily (n))
continue
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)
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 = []
p.octave = mxl_pitch.get_octave () - 4
return p
-def get_all_voices (parts):
+def synchronize_musicxml (parts):
progress ("Synchronizing MusicXML...")
all_voices = {}
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():
def convert (filename, output_name):
-
printer = musicexp.Output_printer()
-
progress ("Reading MusicXML...")
tree = musicxml.read_musicxml (filename)
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()