Fix musicxml2ly.py - incomplete attempt (issue 558920043 by knupero@gmail.com)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Fix musicxml2ly.py - incomplete attempt (issue 558920043 by knupero@gmail.com)

knupero
Reviewers: ,

Message:
Won't be able to work on this until next week, maybe somebody has an
idea how to fix the rest.

Description:
Fix musicxml2ly.py - incomplete attempt

Our current musicxml2ly code requires at
least python2 2.7.0. The installers provide
python 2.4.5.

If the python 2.4.5 is used for musicxml2ly,
some parts of the generated lilypond source
file are ok, in other parts every character
is paired with an additional NUL byte.

This patch tries to fix the problem. It is
incomplete, DO NOT COUNTDOWN.

There are 127 xml files in our regression
test. With this patch the *.ly files for
120 xml files are identical when python
2.7.16 and python 2.4.5 are used as
as interpreters. Processing of the following
7 files is broken and needs to be fixed:

   46g-PickupMeasure-Chordnames-FiguredBass.xml
   61g-Lyrics-NameNumber.xml
   71a-Chordnames.xml
   71c-ChordsFrets.xml
   71d-ChordsFrets-Multistaff.xml
   71f-AllChordTypes.xml
   71g-MultipleChordnames.xml

For six of those files identical tracebacks are
generated by python 2.4.5:
musicxml2ly: Output to `71g-MultipleChordnames.ly'
Traceback (most recent call last):
   File "/home/knut/lilypond/usr/bin/musicxml2ly", line 3296, in ?
     main()
   File "/home/knut/lilypond/usr/bin/musicxml2ly", line 3290, in main
     voices = convert(filename, options)
   File "/home/knut/lilypond/usr/bin/musicxml2ly", line 3207, in convert
     print_voice_definitions(printer, part_list, voices)
   File "/home/knut/lilypond/usr/bin/musicxml2ly", line 2972, in
print_voice_definitions
     voice.chordnames.print_ly (printer)
   File
"/home/knut/lilypond/usr/share/lilypond/current/python/musicexp.py",
line 562, in print_ly
     MusicWrapper.print_ly (self, func)
   File
"/home/knut/lilypond/usr/share/lilypond/current/python/musicexp.py",
line 553, in print_ly
     self.element.print_ly (func)
   File
"/home/knut/lilypond/usr/share/lilypond/current/python/musicexp.py",
line 754, in print_ly
     e.print_ly (printer)
   File
"/home/knut/lilypond/usr/share/lilypond/current/python/musicexp.py",
line 546, in print_ly
     printer (self.ly_expression ())
   File
"/home/knut/lilypond/usr/share/lilypond/current/python/musicexp.py",
line 1598, in ly_expression
     value = self.kind.format(value)

Processing of 61g-Lyrics-NameNumber.xml
fails differently without traceback.

I would feel better if I would understand
why unicode strings are generated in some
parts of the code, and why the behaviour
changed between 2.4.5 and 2.7.0. I did not
find a file that that documents this change.

Everybody is invited to join backportig
of musicxml2ly ;-)

Please review this at https://codereview.appspot.com/558920043/

Affected files (+3, -3 lines):
   M python/musicexp.py
   M python/musicxml.py
   M scripts/musicxml2ly.py


Index: python/musicexp.py
diff --git a/python/musicexp.py b/python/musicexp.py
index  
2aba0e5d9343fb3e5dac9531a0fea597735b2691..84448db344d718e63ae83212c34f2a65a014a7b2  
100644
--- a/python/musicexp.py
+++ b/python/musicexp.py
@@ -816,7 +816,7 @@ class Lyrics:
          for l in self.lyrics_syllables:
              lstr += l
          #lstr += "\n}"
-        return lstr
+        return lstr.encode('utf-8')

  class Header:

Index: python/musicxml.py
diff --git a/python/musicxml.py b/python/musicxml.py
index  
ae5ca80a59647dca423d6b374bf6b595b53ee315..6b70e02cc580434436bedd82ac502a16bea94c98  
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)
Index: scripts/musicxml2ly.py
diff --git a/scripts/musicxml2ly.py b/scripts/musicxml2ly.py
index  
a30ac63423f04189b8c69392697e73698d086b9e..e01187ab17c4c064d487dc14a724bae598f0345a  
100755
--- a/scripts/musicxml2ly.py
+++ b/scripts/musicxml2ly.py
@@ -1248,7 +1248,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



_______________________________________________
lilypond-devel mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-devel
Reply | Threaded
Open this post in threaded view
|

Re: Fix musicxml2ly.py - incomplete attempt (issue 558920043 by knupero@gmail.com)

knupero
Ready for review now

https://codereview.appspot.com/558920043/

_______________________________________________
lilypond-devel mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-devel