From fdda1b92ce1ddb43522b2722d28f3ad20c679e1a Mon Sep 17 00:00:00 2001 From: Reinhold Kainhofer Date: Tue, 11 Nov 2008 23:07:05 +0100 Subject: [PATCH] MusicXML: Keep track of time sig; Print MM rests in multiples of time sig --- .../00m-MultimeasureRests-TimeSignatures.xml | 162 ++++++++++++++++++ scripts/musicxml2ly.py | 27 ++- 2 files changed, 185 insertions(+), 4 deletions(-) create mode 100644 input/regression/musicxml/00m-MultimeasureRests-TimeSignatures.xml diff --git a/input/regression/musicxml/00m-MultimeasureRests-TimeSignatures.xml b/input/regression/musicxml/00m-MultimeasureRests-TimeSignatures.xml new file mode 100644 index 0000000000..30b51548db --- /dev/null +++ b/input/regression/musicxml/00m-MultimeasureRests-TimeSignatures.xml @@ -0,0 +1,162 @@ + + + + Multi-bar formatting (different time signatures) + + Reinhold Kainhofer + Public Domain + + Finale 2008 for Windows + Dolet Light for Finale 2008 + 2008-11-11 + + + + + MusicXML Part + + Acoustic Grand Piano + + + 1 + 1 + + + + + + + + 1 + + 0 + major + + + + G + 2 + + + 2 + + + + + 4 + 1 + + + + + + + 4 + 1 + + + + + + + + 3 + + + + + 3 + 1 + + + + + + + 3 + 1 + + + + + + + 3 + 1 + + + + + + + + 2 + + + + + 2 + 1 + + + + + + + 2 + 1 + + + + + + + + 2 + + + + + 4 + 1 + + + + + + + 4 + 1 + + + + + + + C + 5 + + 4 + 1 + whole + + + light-heavy + + + + + diff --git a/scripts/musicxml2ly.py b/scripts/musicxml2ly.py index b015072732..ec21882214 100644 --- a/scripts/musicxml2ly.py +++ b/scripts/musicxml2ly.py @@ -1556,17 +1556,23 @@ class LilyPondVoiceBuilder: self.pending_multibar = Rational (0) self.ignore_skips = False self.has_relevant_elements = False + self.measure_length = (4, 4) def _insert_multibar (self): r = musicexp.MultiMeasureRest () - r.duration = musicexp.Duration() - r.duration.duration_log = 0 - r.duration.factor = self.pending_multibar + lenfrac = Rational (self.measure_length[0], self.measure_length[1]) + r.duration = rational_to_lily_duration (lenfrac) + r.duration.factor *= self.pending_multibar / lenfrac self.elements.append (r) self.begin_moment = self.end_moment self.end_moment = self.begin_moment + self.pending_multibar self.pending_multibar = Rational (0) - + + def set_measure_length (self, mlen): + if (mlen != self.measure_length) and self.pending_multibar: + self._insert_multibar () + self.measure_length = mlen + def add_multibar_rest (self, duration): self.pending_multibar += duration @@ -1697,6 +1703,13 @@ def musicxml_step_to_lily (step): else: return None +def measure_length_from_attributes (attr, current_measure_length): + mxl = attr.get_named_attribute ('time') + if mxl: + return attr.get_time_signature () + else: + return current_measure_length + def musicxml_voice_to_lily_voice (voice): tuplet_events = [] modes_found = {} @@ -1729,6 +1742,8 @@ def musicxml_voice_to_lily_voice (voice): voice_builder = LilyPondVoiceBuilder () figured_bass_builder = LilyPondVoiceBuilder () chordnames_builder = LilyPondVoiceBuilder () + current_measure_length = (4, 4) + voice_builder.set_measure_length (current_measure_length) for n in voice._elements: if n.get_name () == 'forward': @@ -1791,6 +1806,10 @@ def musicxml_voice_to_lily_voice (voice): for a in musicxml_attributes_to_lily (n): voice_builder.add_command (a) + measure_length = measure_length_from_attributes (n, current_measure_length) + if current_measure_length != measure_length: + current_measure_length = measure_length + voice_builder.set_measure_length (current_measure_length) continue if isinstance (n, musicxml.Barline): -- 2.39.2