]> git.donarmstrong.com Git - lilypond.git/commitdiff
MusicXML: Add command line option to not convert directions on articulations, etc.
authorReinhold Kainhofer <reinhold@kainhofer.com>
Tue, 13 Nov 2007 23:53:27 +0000 (00:53 +0100)
committerReinhold Kainhofer <reinhold@kainhofer.com>
Tue, 13 Nov 2007 23:53:27 +0000 (00:53 +0100)
Add --nd or --no-articulation-directions command-line option, which causes
musicxml2ly to not convert ^ or _ up/down indicators for articulations, texts, etc.
Rather, "-" is used where necessary.

I'm now storing the command-line options in another global variable, so that one
can access them anywhere in the whole script.

make/lysdoc-targets.make
scripts/musicxml2ly.py

index 28b84beee2c6616260584b6fe3fbd222f2bc4f75..fe662ddb64f6c8ed8ab5aaf88cccdf5c1e9c9ad4 100644 (file)
@@ -16,6 +16,6 @@ local-test:
                echo -e '\n\n\n' ; \
                git diff ; \
        fi > $(outdir)/tree.gittxt
-       $(MAKE) LILYPOND_BOOK_LILYPOND_FLAGS="-dbackend=eps --formats=ps $(LILYPOND_JOBS) -dseparate-log-files -dinclude-eps-fonts -dgs-load-lily-fonts --header=texidoc -I $(top-src-dir)/input/manual -ddump-profile -dcheck-internal-types -ddump-signatures -danti-alias-factor=1" LILYPOND_BOOK_VERBOSE= $(outdir)/collated-files.html
+       $(MAKE) LILYPOND_BOOK_LILYPOND_FLAGS="-dbackend=eps --formats=ps,png $(LILYPOND_JOBS) -dseparate-log-files -dinclude-eps-fonts -dgs-load-lily-fonts --header=texidoc -I $(top-src-dir)/input/manual -ddump-profile -dcheck-internal-types -ddump-signatures -danti-alias-factor=1" LILYPOND_BOOK_VERBOSE= $(outdir)/collated-files.html
        rsync -L -a --exclude 'out-*' --exclude 'out' --exclude mf --exclude source --exclude mf $(top-build-dir)/out/share $(outdir)
 
index e54dd440d16da9e5a2780ea4d453b00308dae498..e04578aecd1de62227aa71ef5dfcdf60b6149a5d 100644 (file)
@@ -19,6 +19,8 @@ import musicexp
 
 from rational import Rational
 
+# Store command-line options in a global variable, so we can access them everythwere
+options = None
 
 def progress (str):
     sys.stderr.write (str + '\n')
@@ -753,21 +755,21 @@ def musicxml_spanner_to_lily_event (mxl_event):
     return ev
 
 def musicxml_direction_to_indicator (direction):
-    return { "above": 1, "upright": 1, "below": -1, "downright": -1 }.get (direction, '')
+    return { "above": 1, "upright": 1, "up":1, "below": -1, "downright": -1, "down": -1 }.get (direction, 0)
 
 def musicxml_fermata_to_lily_event (mxl_event):
     ev = musicexp.ArticulationEvent ()
     ev.type = "fermata"
     if hasattr (mxl_event, 'type'):
       dir = musicxml_direction_to_indicator (mxl_event.type)
-      if dir:
+      if dir and options.convert_directions:
         ev.force_direction = dir
     return ev
 
 
 def musicxml_arpeggiate_to_lily_event (mxl_event):
     ev = musicexp.ArpeggioEvent ()
-    ev.direction = {"up": 1, "down": -1}.get (getattr (mxl_event, 'direction', None), 0)
+    ev.direction = musicxml_direction_to_indicator (getattr (mxl_event, 'direction', None))
     return ev
 
 
@@ -896,10 +898,12 @@ def musicxml_articulation_to_lily_event (mxl_event):
 
     # Some articulations use the type attribute, other the placement...
     dir = None
-    if hasattr (mxl_event, 'type'):
+    if hasattr (mxl_event, 'type') and options.convert_directions:
         dir = musicxml_direction_to_indicator (mxl_event.type)
-    if hasattr (mxl_event, 'placement'):
+    if hasattr (mxl_event, 'placement') and options.convert_directions:
         dir = musicxml_direction_to_indicator (mxl_event.placement)
+    if dir:
+        ev.force_direction = dir
     return ev
 
 
@@ -938,7 +942,7 @@ def musicxml_words_to_lily_event (words):
     text = re.sub (' *\n? *$', '', text)
     event.text = text
 
-    if hasattr (words, 'default-y'):
+    if hasattr (words, 'default-y') and options.convert_directions:
         offset = getattr (words, 'default-y')
         try:
             off = string.atoi (offset)
@@ -1624,6 +1628,12 @@ Copyright (c) 2005--2007 by
                   action = "store",
                   help = _ ("Use a different language file, e.g. 'deutsch' for deutsch.ly."))
 
+    p.add_option ('--no-articulation-directions', '--nd',
+                  action = "store_false",
+                  default = True,
+                  dest = "convert_directions",
+                  help = _ ("Do not convert directions (^, _ or -) for articulations."))
+
     p.add_option ('-o', '--output',
                   metavar=_ ("FILE"),
                   action="store",
@@ -1809,6 +1819,7 @@ def get_existing_filename_with_extension (filename, ext):
 def main ():
     opt_parser = option_parser()
 
+    global options
     (options, args) = opt_parser.parse_args ()
     if not args:
         opt_parser.print_usage()