]> git.donarmstrong.com Git - lilypond.git/commitdiff
abc2ly: Convert the Q: field to \tempo (rather than tempoWholesPerMinute in the midi...
authorReinhold Kainhofer <reinhold@kainhofer.com>
Thu, 12 Nov 2009 16:22:05 +0000 (17:22 +0100)
committerReinhold Kainhofer <reinhold@kainhofer.com>
Thu, 12 Nov 2009 16:25:18 +0000 (17:25 +0100)
scripts/abc2ly.py

index f844b7dc13e2b84ab468d7718b1f418ff9a0844c..53b0e34fca0af82375a4a2f871610426d098dd10 100644 (file)
@@ -255,19 +255,17 @@ def dump_voices (outf):
         outf.write ("\n}")
 
 def try_parse_q(a):
-    global midi_specs
-    #assume that Q takes the form "Q:1/4=120"
+    #assume that Q takes the form "Q:'opt. description' 1/4=120"
     #There are other possibilities, but they are deprecated
-    if a.count ('/') == 1:
-        array = a.split('/')
-        numerator=array[0]
-        if int(numerator) != 1:
-            sys.stderr.write("abc2ly: Warning, unable to translate a Q specification with a numerator of %s: %s\n" % (numerator, a))
-        array2 = array[1].split ('=')
-        denominator=array2[0]
-        perminute=array2[1]
-        duration = str (int (denominator) / int (numerator))
-        midi_specs = ' '.join(["\n\t\t\\context {\n\t\t \\Score tempoWholesPerMinute = #(ly:make-moment ", perminute, " ", duration, ")\n\t\t }\n"])
+    r = re.compile ('^(.*) *([0-9]+) */ *([0-9]+) *=* *([0-9]+)\s*')
+    m = r.match (a)
+    if m:
+        descr = m.group(1) # possibly empty
+        numerator = int(m.group (2))
+        denominator = int(m.group (3))
+        tempo = m.group (4)
+        dur = duration_to_lilypond_duration ((numerator,denominator), 1, 0)
+        voices_append ("\\tempo " + descr + " " + dur + "=" + tempo + "\n")
     else:
         sys.stderr.write("abc2ly: Warning, unable to parse Q specification: %s\n" % a)