From 587ac05cab69ae4877614e4ebc0e8784cb2cbe71 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Thu, 8 Apr 2004 12:02:29 +0000 Subject: [PATCH] (parse_file): Strip \r from lines. Fixes DOS flavour abc files. Really ignore unknown keys (backportme). --- ChangeLog | 2 +- scripts/abc2ly.py | 32 ++++++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4bcb4ef14b..4b7432eff2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,7 @@ 2004-04-08 Jan Nieuwenhuizen * scripts/abc2ly.py (parse_file): Strip \r from lines. Fixes DOS - flavour abc files (backportme). + flavour abc files. Really ignore unknown keys (backportme). 2004-04-08 Han-Wen Nienhuys diff --git a/scripts/abc2ly.py b/scripts/abc2ly.py index 534c6a8b7f..881935f443 100644 --- a/scripts/abc2ly.py +++ b/scripts/abc2ly.py @@ -50,6 +50,10 @@ #TODO: # +# * lilylib +# * GNU style messages: warning:FILE:LINE: +# * l10n +# # Convert to new chord styles. # # UNDEF -> None @@ -388,8 +392,11 @@ key_lookup = { # abc to lilypond key mode names } def lily_key (k): + orig = "" + k + # UGR k = string.lower (k) key = k[0] + #UGH k = k[1:] if k and k[0] == '#': key = key + 'is' @@ -401,10 +408,13 @@ def lily_key (k): return '%s \\major' % key type = k[0:3] - if key_lookup.has_key (type): - return ("%s \\%s" % ( key, key_lookup[type])) - sys.stderr.write ("Unknown key type `%s' ignored\n" % type) - return "" + if not key_lookup.has_key (type): + #ugh, use lilylib, say WARNING:FILE:LINE: + sys.stderr.write ("abc2ly:warning:") + sys.stderr.write ("ignoring unknown key: `%s'" % orig) + sys.stderr.write ('\n') + return 0 + return ("%s \\%s" % ( key, key_lookup[type])) def shift_key (note, acc , shift): s = semitone_pitch((note, acc)) @@ -632,12 +642,16 @@ def try_parse_header_line (ln, state): else: key_info = m.group(1) clef_info = m.group(2) - __main__.global_key = compute_key (key_info)# ugh. - voices_append ('\\key %s' % lily_key(key_info)) + __main__.global_key = compute_key (key_info) + k = lily_key (key_info) + if k: + voices_append ('\\key %s' % k) check_clef(clef_info) else: - __main__.global_key = compute_key (a)# ugh. - voices_append ('\\key %s \\major' % lily_key(a)) + __main__.global_key = compute_key (a) + k = lily_key (a) + if k: + voices_append ('\\key %s \\major' % k) if g == 'N': # Notes header ['footnotes'] = header['footnotes'] + '\\\\\\\\' + a if g == 'O': # Origin @@ -1205,6 +1219,7 @@ def try_parse_comment (str): #write other kinds of appending if we ever need them. return str +lineno = 0 happy_count = 100 def parse_file (fn): f = open (fn) @@ -1212,6 +1227,7 @@ def parse_file (fn): ls = map (lambda x: re.sub ("\r$", '', x), ls) select_voice('default', '') + global lineno lineno = 0 sys.stderr.write ("Line ... ") sys.stderr.flush () -- 2.39.5