diff -r -u lilypond.old/usr/bin/musicxml2ly lilypond/usr/bin/musicxml2ly --- lilypond.old/usr/bin/musicxml2ly 2007-08-16 11:10:11.000000000 +0200 +++ lilypond/usr/bin/musicxml2ly 2007-08-16 11:17:26.000000000 +0200 @@ -187,6 +187,93 @@ return ev +def musicxml_fermata_to_lily_event(mxl_event): + ev = musicexp.ArticulationEvent() + ev.type = "fermata" + try: + dir = mxl_event._attribute_dict['type'] + except KeyError: + pass + if ( dir ): + ev.force_direction = { "above": "^", "upright": "^", "below": "_", "downright": "_" }[dir]; + return ev + +def musicxml_tremolo_to_lily_event(mxl_event): + if ( mxl_event.get_name() != "tremolo" ): return + ev = musicexp.TremoloEvent() + ev.bars = mxl_event.get_text() + return ev + +# TODO: Some translations are missing! +articulations_dict = { + ##### ORNAMENTS + "trill-mark": "trill", + "turn": "turn", + #"delayed-turn": "?", + "inverted-turn": "reverseturn", + #"shake": "?", + #"wavy-line": "?", + "mordent": "mordent", + #"inverted-mordent": "?", + #"schleifer": "?" + ##### TECHNICALS + "up-bow": "upbow", + "down-bow": "downbow", + #"harmonic": "", + #"open-string": "", + #"thumb-position": "", + #"fingering": "", + #"pluck": "", + #"double-tongue": "", + #"triple-tongue": "", + #"stopped": "", + #"snap-pizzicato": "", + #"fret": "", + #"string": "", + #"hammer-on": "", + #"pull-off": "", + #"bend": "", + #"tap": "", + #"heel": "", + #"toe": "", + #"fingernails": "" + ##### ARTICULATIONS + "accent": "accent", + #"strong-accent": "", + "staccato": "staccato", + "tenuto": "tenuto", + #"detached-legato": "", + "staccatissimo": "staccatissimo", + #"spiccato": "", + #"scoop": "", + #"plop": "", + #"doit": "", + #"falloff": "", + "breath-mark": "breathe", + "caesura": "caesura"#, + #"stress": "", + #"unstress": "" +} + +def musicxml_articulation_to_lily_event(mxl_event): + ev = musicexp.ArticulationEvent() + try: + ev.type = articulations_dict[mxl_event.get_name()] + except: + return + + try: + dir = mxl_event._attribute_dict['placement'] + dir = mxl_event._attribute_dict['type'] + if ( dir ): + dir = { "above": "^", "upright": "^", "below": "_", "downright": "_" }[dir] + except KeyError: + pass + else: + ev.force_direction = dir + return ev + + instrument_drumtype_dict = { 'Acoustic Snare Drum': 'acousticsnare', 'Side Stick': 'sidestick', @@ -311,7 +398,7 @@ for n in voice._elements: if n.get_name () == 'forward': continue - + if not n.get_maybe_exist_named_child ('chord'): try: voice_builder.jumpto (n._when) @@ -330,6 +417,7 @@ for a in musicxml_attributes_to_lily (n): voice_builder.add_music (a, Rational (0)) continue + if not n.__class__.__name__ == 'Note': print 'not a Note or Attributes?', n @@ -368,6 +456,12 @@ notations = n.get_maybe_exist_typed_child (musicxml.Notations) tuplet_event = None span_events = [] + + # The element can have the following children (+ means implemented, ~ partially, - not): + # +tied | +slur | +tuplet | glissando | slide | + # ornaments | technical | articulations | dynamics | + # +fermata | arpeggiate | non-arpeggiate | + # accidental-mark | other-notation if notations: if notations.get_tuplet(): tuplet_event = notations.get_tuplet() @@ -390,6 +484,47 @@ mxl_tie = notations.get_tie () if mxl_tie and mxl_tie.type == 'start': ev_chord.append (musicexp.TieEvent ()) + + fermatas = notations.get_named_children ('fermata') + for a in fermatas: + ev = musicxml_fermata_to_lily_event(a); + if ev: ev_chord.append (ev) + + # Articulations can contain the following child elements: + # accent | strong-accent | staccato | tenuto | + # detached-legato | staccatissimo | spiccato | + # scoop | plop | doit | falloff | breath-mark | + # caesura | stress | unstress + articulations = notations.get_named_children('articulations') + for a in articulations: + for ch in a.get_all_children(): + ev = musicxml_articulation_to_lily_event( ch ) + if ev: ev_chord.append(ev) + + # Technical can contain the following child elements: + # up-bow | down-bow | harmonic | open-string | + # thumb-position | fingering | pluck | double-tongue | + # triple-tongue | stopped | snap-pizzicato | fret | + # string | hammer-on | pull-off | bend | tap | heel | + # toe | fingernails | other-technical > + technicals = notations.get_named_children('technical') + for a in technicals: + for ch in a.get_all_children(): + ev = musicxml_articulation_to_lily_event( ch ) + if ev: ev_chord.append(ev) + + # Ornaments can contain the following child elements: + # trill-mark | turn | delayed-turn | inverted-turn | + # shake | wavy-line | mordent | inverted-mordent | + # schleifer | tremolo | other-ornament, accidental-mark + ornaments = notations.get_named_children('ornaments') + for a in ornaments: + for ch in a.get_named_children('tremolo'): + ev = musicxml_tremolo_to_lily_event( ch ) + if ev: ev_chord.append(ev) + for ch in a.get_all_children(): + ev = musicxml_articulation_to_lily_event( ch ) + if ev: ev_chord.append(ev) mxl_beams = [b for b in n.get_named_children ('beam') if (b.get_type () in ('begin', 'end') diff -r -u lilypond.old/usr/share/lilypond/current/python/musicexp.py lilypond/usr/share/lilypond/current/python/musicexp.py --- lilypond.old/usr/share/lilypond/current/python/musicexp.py 2007-08-16 11:10:11.000000000 +0200 +++ lilypond/usr/share/lilypond/current/python/musicexp.py 2007-08-16 11:13:53.000000000 +0200 @@ -498,7 +498,34 @@ def ly_expression (self): return '~' - +class ArticulationEvent(Event): + def __init__(self): + self.type = None + self.force_direction = False + + def direction_mod(self): + dirstr='' + if (self.force_direction == 1 or self.force_direction == "^" or self.force_direction == "up" ): + dirstr += '^' + elif ( self.force_direction == -1 or self.force_direction == "_" or self.force_direction == "down" ): + dirstr += '_' + elif ( self.force_direction == 0 or self.force_direction == "-" ): + dirstr += '-' + return dirstr + + def ly_expression(self): + return '%s\\%s' % (self.direction_mod(), self.type) + + +class TremoloEvent(Event): + def __init__(self): + self.bars = 0; + def ly_expression(self): + str='' + if ( self.bars>0 ): + str += ':%s' % 2**(2+string.atoi(self.bars)) + return str + class RhythmicEvent(Event): def __init__ (self): Event.__init__ (self) diff -r -u lilypond.old/usr/share/lilypond/current/python/musicxml.py lilypond/usr/share/lilypond/current/python/musicxml.py --- lilypond.old/usr/share/lilypond/current/python/musicxml.py 2007-08-16 11:10:11.000000000 +0200 +++ lilypond/usr/share/lilypond/current/python/musicxml.py 2007-08-16 11:14:11.000000000 +0200 @@ -450,6 +450,20 @@ class Instrument (Music_xml_node): pass +class Fermata (Music_xml_node): pass +class Dynamics (Music_xml_node): pass +class Articulations (Music_xml_node): pass +class Accent (Music_xml_node): pass +class Staccato (Music_xml_node): pass +class Tenuto (Music_xml_node): pass +class Tremolo (Music_xml_node): pass +class Technical (Music_xml_node): pass +class Ornaments (Music_xml_node): pass + +class Direction(Music_xml_node): pass +class DirType(Music_xml_node): pass + + ## need this, not all classes are instantiated ## for every input file. class_dict = { @@ -477,6 +491,16 @@ 'type': Type, 'part-list': Part_list, 'staff': Staff, + 'fermata': Fermata, + 'articulations': Articulations, + 'accent': Accent, + 'staccato': Staccato, + 'tenuto': Tenuto, + 'tremolo': Tremolo, + 'technical': Technical, + 'ornaments': Ornaments, + 'direction': Direction, + 'direction-type': DirType } def name2class_name (name):