MusicXML: Correctly convert instrument names with line breaks
authorReinhold Kainhofer <reinhold@kainhofer.com>
Sun, 23 Sep 2007 08:39:49 +0000 (10:39 +0200)
committerReinhold Kainhofer <reinhold@kainhofer.com>
Wed, 3 Oct 2007 16:40:20 +0000 (18:40 +0200)
Convert line breaks in instrument names to
    \markup \columns {\line {..} \line {..}}
Also add regression test file.

Signed-off-by: Reinhold Kainhofer <reinhold@kainhofer.com>
python/musicexp.py

index 9c6e2341f3b01073aba34b146f61fd322b90b985..504cdf139a8c073999270f2f02c6dffb65fba547 100644 (file)
@@ -6,8 +6,17 @@ import re
 from rational import Rational
 
 
-def escape_output_string (input_string):
-    return "\"" + string.replace (input_string, "\"", "\\\"") + "\""
+def escape_instrument_string (input_string):
+    retstring = string.replace (input_string, "\"", "\\\"")
+    if re.match ('.*\n.*', retstring):
+        strings = retstring.split ('\r\n')
+        retstring = "\\markup { \\column { "
+        for s in strings:
+            retstring += "\\line {\"" + s + "\"} "
+        retstring += "} }"
+    else:
+        retstring = "\"" + retstring + "\""
+    return retstring
 
 class Output_stack_element:
     def __init__ (self):
@@ -949,11 +958,11 @@ class StaffGroup:
         printer.newline ()
         if self.stafftype and self.instrument_name:
             printer.dump ("\\set %s.instrumentName = %s" % (self.stafftype, 
-                    escape_output_string (self.instrument_name)))
+                    escape_instrument_string (self.instrument_name)))
             printer.newline ()
         if self.stafftype and self.short_instrument_name:
             printer.dump ("\\set %s.shortInstrumentName = %s\n" % (self.stafftype, 
-                    escape_output_string (self.short_instrument_name)))
+                    escape_instrument_string (self.short_instrument_name)))
             printer.newline ()
         self.print_ly_contents (printer)
         printer.newline ()