X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scripts%2Fabc2ly.py;h=e28577fb1c88b9eaed15d91b6b3309c5f42fc616;hb=f246d4ebb4d5d60a7143e3a1705ca720a24a1e7d;hp=664d73ec481ffebf47f1f8a640bc1d0759c7a177;hpb=3761f50a69bd34d6ff6da9c6a18d25c006d44362;p=lilypond.git diff --git a/scripts/abc2ly.py b/scripts/abc2ly.py index 664d73ec48..e28577fb1c 100644 --- a/scripts/abc2ly.py +++ b/scripts/abc2ly.py @@ -1,4 +1,4 @@ -#!@PYTHON@ +#!@TARGET_PYTHON@ # -*- coding: utf-8 -*- # once upon a rainy monday afternoon. # @@ -33,6 +33,7 @@ # %%LY now supported. # \breve and \longa supported. # M:none doesn't crash lily. +# lilypond '--' supported. # Enhancements (Guy Gascoigne-Piggford) # @@ -77,25 +78,16 @@ import os program_name = sys.argv[0] -datadir = '@local_lilypond_datadir@' -if not os.path.isdir (datadir): - datadir = '@lilypond_datadir@' - -sys.path.insert (0, os.path.join (datadir, 'python')) - -if os.environ.has_key ('LILYPONDPREFIX'): - datadir = os.environ['LILYPONDPREFIX'] - while datadir[-1] == os.sep: - datadir= datadir[:-1] - - datadir = os.path.join (datadir, "share/lilypond/current/") -sys.path.insert (0, os.path.join (datadir, 'python')) +for d in ['@lilypond_datadir@', + '@lilypond_libdir@']: + sys.path.insert (0, os.path.join (d, 'python')) # dynamic relocation, for GUB binaries. -bindir = os.path.split (sys.argv[0])[0] +bindir = os.path.abspath (os.path.split (sys.argv[0])[0]) for p in ['share', 'lib']: datadir = os.path.abspath (bindir + '/../%s/lilypond/current/python/' % p) - sys.path.insert (0, os.path.join (datadir)) + sys.path.insert (0, datadir) + import lilylib as ly global _;_=ly._ @@ -263,13 +255,13 @@ def try_parse_q(a): if string.count(a, '/') == 1: array=string.split(a,'/') numerator=array[0] - if numerator != 1: + 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=string.split(array[1],'=') denominator=array2[0] perminute=array2[1] duration=str(string.atoi(denominator)/string.atoi(numerator)) - midi_specs=string.join(["\\tempo", duration, "=", perminute]) + midi_specs=string.join([" \n\t\t\context {\n\t\t \Score tempoWholesPerMinute = #(ly:make-moment ", perminute, " ", duration, ")\n\t\t }\n"]) else: sys.stderr.write("abc2ly: Warning, unable to parse Q specification: %s\n" % a) @@ -536,7 +528,7 @@ def try_parse_tuplet_begin (str, state): dig = str[1] str = str[2:] prev_tuplet_state = state.parsing_tuplet - state.parsing_tuplet = string.atoi (dig[0]) + state.parsing_tuplet = string.atoi (dig[0]) if prev_tuplet_state: voices_append ("}") voices_append ("\\times %s {" % tup_lookup[dig]) @@ -625,7 +617,7 @@ def fix_lyric(str): def slyrics_append(a): a = re.sub ( '_', ' _ ', a) # _ to ' _ ' - a = re.sub ( '-', '- ', a) # split words with - + a = re.sub ( '([^-])-([^-])', '\\1- \\2', a) # split words with "-" unless was originally "--" a = re.sub ( '\\\\- ', '-', a) # unless \- a = re.sub ( '~', '_', a) # ~ to space('_') a = re.sub ( '\*', '_ ', a) # * to to space @@ -898,6 +890,8 @@ artic_tbl = { '~' : '^"~" ', 'J' : '', # ignore slide 'R' : '', # ignore roll + 'S' : '^\\segno', + 'O' : '^\\coda', 'v' : '^\\downbow' } @@ -1271,7 +1265,7 @@ def try_parse_comment (str): #convention, such as most music written before 1700, or ethnic music in #non-western scales, it is necessary to be able to tell a translator that #the barlines should not affect its interpretation of the pitch. - if (string.find(str,'nobarlines') > 0): + if 'nobarlines' in str: nobarlines = 1 elif str[0:3] == '%LY': p = string.find(str, 'voices')