From: Reinhold Kainhofer Date: Mon, 3 Sep 2007 23:47:26 +0000 (+0200) Subject: MusicXML: Fine-tune chord detection in combination with dynamics X-Git-Tag: release/2.11.33-1~4^2~17^2 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=867397e2ddd23ae80a4a9ee2432582b62eefaac0;p=lilypond.git MusicXML: Fine-tune chord detection in combination with dynamics When trying to find the corresponding notes for notes with the indicator, we need to skip all dynamics, but must not cross bar lines. In particular, since we now also add dynamics events, we cannot automatically take the last event, but have to look for the last EventChord. Also some small bug fixes (need to quote texts with _, missing param in dead code, style, etc.) Signed-off-by: Reinhold Kainhofer --- diff --git a/python/musicexp.py b/python/musicexp.py index 797494ddb1..5c3b91a804 100644 --- a/python/musicexp.py +++ b/python/musicexp.py @@ -433,7 +433,7 @@ class Lyrics: return lstr -class EventChord(NestedMusic): +class EventChord (NestedMusic): def get_length (self): l = Rational (0) for e in self.elements: @@ -699,7 +699,7 @@ class NoteEvent(RhythmicEvent): self.forced_accidental = False def get_properties (self): - str = RhythmicEvent.get_properties () + str = RhythmicEvent.get_properties (self) if self.pitch: str += self.pitch.lisp_expression () diff --git a/python/musicxml.py b/python/musicxml.py index 86d3120958..e4d06a2a0a 100644 --- a/python/musicxml.py +++ b/python/musicxml.py @@ -5,7 +5,7 @@ import re def escape_ly_output_string (input_string): return_string = input_string - needs_quotes = re.search ("[0-9\" ,.]", return_string); + needs_quotes = re.search ("[0-9\" ,._-]", return_string); return_string = string.replace (return_string, "\"", "\\\"") if needs_quotes: return_string = "\"" + return_string + "\"" @@ -465,15 +465,15 @@ class Part (Music_xml_node): and n.get_maybe_exist_typed_child (Chord)): now = last_moment measure_position = last_measure_position - - last_moment = now - last_measure_position = measure_position - n._when = now + n._when = now n._measure_position = measure_position - n._duration = dur - now += dur - measure_position += dur + n._duration = dur + if dur > Rational (0): + last_moment = now + last_measure_position = measure_position + now += dur + measure_position += dur if n._name == 'note': instrument = n.get_maybe_exist_named_child ('instrument') if instrument: diff --git a/scripts/musicxml2ly.py b/scripts/musicxml2ly.py index 3f44e71c4f..d0bd418399 100644 --- a/scripts/musicxml2ly.py +++ b/scripts/musicxml2ly.py @@ -518,10 +518,19 @@ class LilyPondVoiceBuilder: def last_event_chord (self, starting_at): value = None + + # if the position matches, find the last EventChord, do not cross a bar line! + at = len( self.elements ) - 1 + while (at >= 0 and + not isinstance (self.elements[at], musicexp.EventChord) and + not isinstance (self.elements[at], musicexp.BarCheck)): + at -= 1 + if (self.elements - and isinstance (self.elements[-1], musicexp.EventChord) + and at >= 0 + and isinstance (self.elements[at], musicexp.EventChord) and self.begin_moment == starting_at): - value = self.elements[-1] + value = self.elements[at] else: self.jumpto (starting_at) value = None