From: Reinhold Kainhofer Date: Wed, 31 Oct 2007 15:56:30 +0000 (+0100) Subject: MusicXML: Improvements / Fixes for articulations X-Git-Tag: release/2.11.35-1~52 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=61efd132a32f0ccad56b4f56bf7a795ab9e39073;p=lilypond.git MusicXML: Improvements / Fixes for articulations Implement some more conversions for articulations, make \context Staff actually use the type attribute instead of hard-coded "Staff", fix crashes due to empty type attributes in articulations. --- diff --git a/python/musicexp.py b/python/musicexp.py index d4f90827e2..edae323f79 100644 --- a/python/musicexp.py +++ b/python/musicexp.py @@ -685,9 +685,13 @@ class GlissandoEvent (SpanEvent): 1:''}.get (self.span_direction, '') class ArpeggioEvent(Event): + def __init__ (self): + Event.__init__ (self) + self.direction = 0 def wait_for_note (self): return True; def ly_expression (self): + # TODO: Use self.direction for up/down arpeggios return ('\\arpeggio') @@ -776,11 +780,17 @@ class ShortArticulationEvent (ArticulationEvent): # default is - return { 1: '^', -1: '_', 0: '-' }.get (self.force_direction, '-') def ly_expression (self): - return '%s%s' % (self.direction_mod (), self.type) + if self.type: + return '%s%s' % (self.direction_mod (), self.type) + else: + return '' class NoDirectionArticulationEvent (ArticulationEvent): def ly_expression (self): - return '\\%s' % self.type + if self.type: + return '\\%s' % self.type + else: + return '' class MarkupEvent (ShortArticulationEvent): def __init__ (self): @@ -1115,9 +1125,9 @@ class Staff (StaffGroup): for [staff_id, voices] in self.part_information: if staff_id: - printer ('\\context Staff = "%s" << ' % staff_id) + printer ('\\context %s = "%s" << ' % (self.stafftype, staff_id)) else: - printer ('\\context Staff << ') + printer ('\\context %s << ' % self.stafftype) printer.newline () n = 0 nr_voices = len (voices) diff --git a/python/musicxml.py b/python/musicxml.py index cd260a404b..cb8e1957cb 100644 --- a/python/musicxml.py +++ b/python/musicxml.py @@ -439,11 +439,11 @@ class Musicxml_voice: return self._lyrics - class Part (Music_xml_node): def __init__ (self): Music_xml_node.__init__ (self) self._voices = [] + self._staff_attributes_dict = {} def get_part_list (self): n = self @@ -679,6 +679,7 @@ class Part (Music_xml_node): for (s, vids) in staff_to_voice_dict.items (): staff_attributes = part.extract_attributes_for_staff (start_attr, s) staff_attributes.read_self () + part._staff_attributes_dict[s] = staff_attributes for v in vids: voices[v].insert (0, staff_attributes) voices[v]._elements[0].read_self() diff --git a/scripts/musicxml2ly.py b/scripts/musicxml2ly.py index be4cc8343a..9b99d3abd0 100644 --- a/scripts/musicxml2ly.py +++ b/scripts/musicxml2ly.py @@ -568,6 +568,13 @@ def musicxml_fermata_to_lily_event (mxl_event): ev.force_direction = dir return ev + +def musicxml_arpeggiate_to_lily_event (mxl_event): + ev = musicexp.ArpeggioEvent () + ev.direction = {"up": 1, "down": -1}.get (getattr (mxl_event, 'direction', None), 0) + return ev + + def musicxml_tremolo_to_lily_event (mxl_event): ev = musicexp.TremoloEvent () ev.bars = mxl_event.get_text () @@ -618,13 +625,13 @@ def musicxml_accidental_mark (mxl_event): # -) (class, name) (like string, only that a different class than ArticulationEvent is used) # TODO: Some translations are missing! articulations_dict = { - "accent": (musicexp.ShortArticulationEvent, ">"), + "accent": (musicexp.ShortArticulationEvent, ">"), # or "accent" "accidental-mark": musicxml_accidental_mark, "bend": musicxml_bend_to_lily_event, "breath-mark": (musicexp.NoDirectionArticulationEvent, "breathe"), #"caesura": "caesura", #"delayed-turn": "?", - #"detached-legato": "", + "detached-legato": (musicexp.ShortArticulationEvent, "_"), # or "portato" #"doit": "", #"double-tongue": "", "down-bow": "downbow", @@ -638,24 +645,23 @@ articulations_dict = { "inverted-mordent": "prall", "inverted-turn": "reverseturn", "mordent": "mordent", - #"open-string": "", + "open-string": "open", #"plop": "", #"pluck": "", - #"portato": (musicexp.ShortArticulationEvent, "_"), # does not exist in MusicXML #"pull-off": "", #"schleifer": "?", #"scoop": "", #"shake": "?", #"snap-pizzicato": "", #"spiccato": "", - "staccatissimo": (musicexp.ShortArticulationEvent, "|"), - "staccato": (musicexp.ShortArticulationEvent, "."), - "stopped": (musicexp.ShortArticulationEvent, "+"), + "staccatissimo": (musicexp.ShortArticulationEvent, "|"), # or "staccatissimo" + "staccato": (musicexp.ShortArticulationEvent, "."), # or "staccato" + "stopped": (musicexp.ShortArticulationEvent, "+"), # or "stopped" #"stress": "", "string": musicxml_string_event, - "strong-accent": (musicexp.ShortArticulationEvent, "^"), + "strong-accent": (musicexp.ShortArticulationEvent, "^"), # or "marcato" #"tap": "", - "tenuto": (musicexp.ShortArticulationEvent, "-"), + "tenuto": (musicexp.ShortArticulationEvent, "-"), # or "tenuto" #"thumb-position": "", #"toe": "", "turn": "turn", @@ -1211,7 +1217,9 @@ def musicxml_voice_to_lily_voice (voice): arpeggiate = notations.get_named_children ('arpeggiate') for a in arpeggiate: - ev_chord.append (musicexp.ArpeggioEvent ()) + ev = musicxml_arpeggiate_to_lily_event (a) + if ev: + ev_chord.append (ev) glissandos = notations.get_named_children ('glissando') for a in glissandos: @@ -1492,7 +1500,6 @@ def update_score_setup (score_structure, part_list, voices): staves = uniq_list (staves) staves.sort () for s in staves: - #((music, lyrics), mxlvoice)) thisstaff_raw_voices = [(voice_name, voice.lyrics_order) for (voice_name, voice) in nv_dict.items () if voice.voicedata._start_staff == s]