From 7b7ce029c6aef9aa2665be862605afc0d72f40f0 Mon Sep 17 00:00:00 2001 From: Knut Petersen Date: Fri, 19 Jul 2019 00:05:00 +0200 Subject: [PATCH 1/2] Fix musicxml2ly.py / Python 2.4.5 incompatibility In LilyPond 2.19.44 code was introduced that improved musicxml2ly. Unfortunately, the new code introduced a dependency on Python 2.7+, although our installers only provide the ancient Python 2.4.5. If our Python 2.4.5 was used to interpret musicxml2ly, some parts of the generated lilypond source file were ok, in other parts every character was paired with an additional NUL byte. This commit fixes that problem by adding '.encode('utf-8')' at some places. A 2nd problem was that str.format() was used. Unfortunately, str.format() is only available in python 2.6+. The patch replaces affected code with syntax compatible to our Python 2.4.5. This patch triggered the bug fixed in commit 39c9d91c46 "Fix relocate-preamble.py bug". Do not cherry-pick without 39c9d91c46! (cherry picked from commit a77f3872078ca38ca7c269a9195bb579737d0698, without the changes to chordkind_dict because not all values start with the format string unless we pick commit 78225bc1b3) Conflicts: python/musicexp.py scripts/musicxml2ly.py --- python/musicexp.py | 6 ++---- python/musicxml.py | 2 +- scripts/musicxml2ly.py | 5 ++--- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/python/musicexp.py b/python/musicexp.py index 6de0b71b1e..edb753d712 100644 --- a/python/musicexp.py +++ b/python/musicexp.py @@ -817,7 +817,7 @@ class Lyrics: for l in self.lyrics_syllables: lstr += l #lstr += "\n}" - return lstr + return lstr.encode('utf-8') class Header: @@ -2230,9 +2230,7 @@ class StaffGroup: escape_instrument_string (self.short_instrument_name))) printer.newline () if self.sound: - printer.dump( - r'\set {stafftype}.midiInstrument = #"{sound}"'.format( - stafftype=self.stafftype, sound=self.sound)) + printer.dump (r'\set %s.midiInstrument = #"%s"' % (self.stafftype, self.sound)) printer.newline () self.print_ly_contents (printer) printer.newline () diff --git a/python/musicxml.py b/python/musicxml.py index ae5ca80a59..6b70e02cc5 100644 --- a/python/musicxml.py +++ b/python/musicxml.py @@ -43,7 +43,7 @@ class Xml_node: if not self._children: return '' - return ''.join([c.get_text() for c in self._children]) + return ''.join([c.get_text() for c in self._children]).encode('utf-8') def message(self, msg): ly.warning(msg) diff --git a/scripts/musicxml2ly.py b/scripts/musicxml2ly.py index e89c61ba14..d09973afdc 100755 --- a/scripts/musicxml2ly.py +++ b/scripts/musicxml2ly.py @@ -97,8 +97,7 @@ def extract_paper_information(score_partwise): if 1 < staff_size < 100: paper.global_staff_size = staff_size else: - msg = "paper.global_staff_size {} is too large, using defaults=20".format( - staff_size) + msg = "paper.global_staff_size %s is too large, using defaults=20" % staff_size warnings.warn(msg) paper.global_staff_size = 20 @@ -1248,7 +1247,7 @@ def musicxml_dynamics_to_lily_event(dynentry): " = #(make-dynamic-script \"" + dynamicstext + "\")" needed_additional_definitions.append(dynamicsname) event = musicexp.DynamicsEvent() - event.type = dynamicsname + event.type = dynamicsname.encode('utf-8') return event # Convert single-color two-byte strings to numbers 0.0 - 1.0 -- 2.24.0