From 69d35384f8bb79751fa9923501c6bb9e51065aad Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Wed, 17 Oct 2001 00:52:54 +0200 Subject: [PATCH] patch::: 1.5.17.jcn3 1.5.17.jcn3 --- CHANGES | 8 +- VERSION | 2 +- buildscripts/GNUmakefile | 4 +- buildscripts/lilylib.py.in | 202 +++++++++++++++++++++++++ scripts/ly2dvi.py | 248 ++++--------------------------- scripts/midi2ly.py | 293 +++++++++++++++++++++++++++++++------ scripts/mup2ly.py | 223 +++++----------------------- scripts/update-lily.py | 244 +++++++----------------------- 8 files changed, 581 insertions(+), 643 deletions(-) create mode 100644 buildscripts/lilylib.py.in diff --git a/CHANGES b/CHANGES index 4fa070cebc..e31ac27c36 100644 --- a/CHANGES +++ b/CHANGES @@ -1,7 +1,11 @@ -1.5.17.jcn2 +1.5.17.jcn3 =========== -* Some more random hacking at midi2ly.py. +* Some more random hacking at midi2ly.py: + - handle keys and note names + - simple quantising + - options and stuff: moved to library for ly2dvi, midi2ly, mup2ly, + update-lily. * Bugfix: Key_change_req::transpose: don't deliver reversed list. diff --git a/VERSION b/VERSION index fdee57d419..43df50ac49 100644 --- a/VERSION +++ b/VERSION @@ -2,7 +2,7 @@ PACKAGE_NAME=LilyPond MAJOR_VERSION=1 MINOR_VERSION=5 PATCH_LEVEL=17 -MY_PATCH_LEVEL=jcn2 +MY_PATCH_LEVEL=jcn3 # use the above to send patches: MY_PATCH_LEVEL is always empty for a # released version. diff --git a/buildscripts/GNUmakefile b/buildscripts/GNUmakefile index d75ba0987b..c8f569c25b 100755 --- a/buildscripts/GNUmakefile +++ b/buildscripts/GNUmakefile @@ -3,7 +3,7 @@ depth = .. #STEPMAKE_TEMPLATES=script install install-out po STEPMAKE_TEMPLATES=script install po -INSTALLATION_FILES=$(outdir)/gettext.py +INSTALLATION_FILES=$(outdir)/gettext.py $(outdir)/lilylib.py INSTALLATION_DIR=$(datadir)/python include $(depth)/make/stepmake.make @@ -14,5 +14,5 @@ include $(depth)/make/stepmake.make #INSTALLATION_OUT_DIR1=$(datadir)/scripts #INSTALLATION_OUT_FILES1=$(outdir)/lilypond-login $(outdir)/lilypond-profile -all: $(outdir)/gettext.py +all: $(INSTALLATION_FILES) diff --git a/buildscripts/lilylib.py.in b/buildscripts/lilylib.py.in new file mode 100644 index 0000000000..fea6ffda23 --- /dev/null +++ b/buildscripts/lilylib.py.in @@ -0,0 +1,202 @@ +# lilylib.py -- options and stuff +# +# source file of the GNU LilyPond music typesetter + +import os +from __main__ import * + +try: + import gettext + gettext.bindtextdomain ('lilypond', '@localedir@') + gettext.textdomain ('lilypond') + _ = gettext.gettext +except: + def _ (s): + return s + +program_version = '@TOPLEVEL_VERSION@' +if program_version == '@' + 'TOPLEVEL_VERSION' + '@': + program_version = '1.5.17' + + +original_dir = os.getcwd () +temp_dir = os.path.join (original_dir, '%s.dir' % program_name) + +errorport = sys.stderr +keep_temp_dir_p = 0 +verbose_p = 0 + + +def identify (): + sys.stdout.write ('%s (GNU LilyPond) %s\n' % (program_name, program_version)) + +def warranty (): + identify () + sys.stdout.write ('\n') + sys.stdout.write (_ ('Copyright (c) %s by' % ' 2001')) + sys.stdout.write ('\n') + sys.stdout.write (' Han-Wen Nienhuys') + sys.stdout.write (' Jan Nieuwenhuizen') + sys.stdout.write ('\n') + sys.stdout.write (_ (r''' +Distributed under terms of the GNU General Public License. It comes with +NO WARRANTY.''')) + sys.stdout.write ('\n') + +def progress (s): + errorport.write (s + '\n') + +def warning (s): + progress (_ ("warning: ") + s) + +def error (s): + + + '''Report the error S. Exit by raising an exception. Please + do not abuse by trying to catch this error. If you do not want + a stack trace, write to the output directly. + + RETURN VALUE + + None + + ''' + + progress (_ ("error: ") + s) + raise _ ("Exiting ... ") + +def getopt_args (opts): + '''Construct arguments (LONG, SHORT) for getopt from list of options.''' + short = '' + long = [] + for o in opts: + if o[1]: + short = short + o[1] + if o[0]: + short = short + ':' + if o[2]: + l = o[2] + if o[0]: + l = l + '=' + long.append (l) + return (short, long) + +def option_help_str (o): + '''Transform one option description (4-tuple ) into neatly formatted string''' + sh = ' ' + if o[1]: + sh = '-%s' % o[1] + + sep = ' ' + if o[1] and o[2]: + sep = ',' + + long = '' + if o[2]: + long= '--%s' % o[2] + + arg = '' + if o[0]: + if o[2]: + arg = '=' + arg = arg + o[0] + return ' ' + sh + sep + long + arg + + +def options_help_str (opts): + '''Convert a list of options into a neatly formatted string''' + w = 0 + strs =[] + helps = [] + + for o in opts: + s = option_help_str (o) + strs.append ((s, o[3])) + if len (s) > w: + w = len (s) + + str = '' + for s in strs: + str = str + '%s%s%s\n' % (s[0], ' ' * (w - len(s[0]) + 3), s[1]) + return str + +def help (): + ls = [(_ ("Usage: %s [OPTION]... FILE") % program_name), + ('\n\n'), + (help_summary), + ('\n\n'), + (_ ("Options:")), + ('\n'), + (options_help_str (option_definitions)), + ('\n\n'), + (_ ("Report bugs to %s") % 'bug-lilypond@gnu.org'), + ('\n')] + map (sys.stdout.write, ls) + +def setup_temp (): + """ + Create a temporary directory, and return its name. + """ + global temp_dir + if not keep_temp_dir_p: + temp_dir = tempfile.mktemp (program_name) + try: + os.mkdir (temp_dir, 0777) + except OSError: + pass + + return temp_dir + + +def system (cmd, ignore_error = 0): + """Run CMD. If IGNORE_ERROR is set, don't complain when CMD returns non zero. + + RETURN VALUE + + Exit status of CMD + """ + + if verbose_p: + progress (_ ("Invoking `%s\'") % cmd) + st = os.system (cmd) + if st: + name = re.match ('[ \t]*([^ \t]*)', cmd).group (1) + msg = name + ': ' + _ ("command exited with value %d") % st + if ignore_error: + warning (msg + ' ' + _ ("(ignored)") + ' ') + else: + error (msg) + + return st + + +def cleanup_temp (): + if not keep_temp_dir_p: + if verbose_p: + progress (_ ("Cleaning %s...") % temp_dir) + shutil.rmtree (temp_dir) + + +#what a name. +def set_setting (dict, key, val): + try: + val = string.atof (val) + except ValueError: + #warning (_ ("invalid value: %s") % `val`) + pass + + try: + dict[key].append (val) + except KeyError: + warning (_ ("no such setting: %s") % `key`) + dict[key] = [val] + + +def strip_extension (f, ext): + (p, e) = os.path.splitext (f) + if e == ext: + e = '' + return p + e + +# END Library + diff --git a/scripts/ly2dvi.py b/scripts/ly2dvi.py index e67d6988a3..77ebe9808c 100644 --- a/scripts/ly2dvi.py +++ b/scripts/ly2dvi.py @@ -68,11 +68,13 @@ import tempfile import traceback datadir = '@datadir@' -sys.path.append (datadir + '/python') +sys.path.append ('@datadir@/python') +sys.path.append ('@datadir@/buildscripts/out') + try: import gettext gettext.bindtextdomain ('lilypond', '@localedir@') - gettext.textdomain('lilypond') + gettext.textdomain ('lilypond') _ = gettext.gettext except: def _ (s): @@ -83,10 +85,33 @@ except: # is available on UNIX. try: import resource - resource.setrlimit(resource.RLIMIT_STACK, (-1,-1)) + resource.setrlimit (resource.RLIMIT_STACK, (-1, -1)) except: pass +program_name = 'ly2dvi' +package_name = 'lilypond' +help_summary = _ ("Generate .dvi with LaTeX for LilyPond") + +option_definitions = [ + ('', 'd', 'dependencies', _ ("write Makefile dependencies for every input file")), + ('', 'h', 'help', _ ("this help")), + (_ ("DIR"), 'I', 'include', _ ("add DIR to LilyPond's search path")), + ('', 'k', 'keep', _ ("keep all output, and name the directory %s.dir") % program_name), + ('', '', 'no-lily', _ ("don't run LilyPond")), + ('', 'm', 'no-paper', _ ("produce MIDI output only")), + (_ ("FILE"), 'o', 'output', _ ("write ouput to FILE")), + (_ ("FILE"), 'f', 'find-pfa', _ ("find pfa fonts used in FILE")), + # why capital P? + ('', 'P', 'postscript', _ ("generate PostScript output")), + (_ ("KEY=VAL"), 's', 'set', _ ("change global setting KEY to VAL")), + ('', 'V', 'verbose', _ ("verbose")), + ('', 'v', 'version', _ ("print version number")), + ('', 'w', 'warranty', _ ("show warranty and copyright")), + ] + +from lilylib import * + layout_fields = ['dedication', 'title', 'subtitle', 'subsubtitle', 'footer', 'head', 'composer', 'arranger', 'instrument', @@ -109,10 +134,7 @@ extra_init = { } extra_fields = extra_init.keys () - fields = layout_fields + extra_fields -program_name = 'ly2dvi' -help_summary = _ ("Generate .dvi with LaTeX for LilyPond") include_path = ['.'] lily_p = 1 @@ -133,24 +155,6 @@ track_dependencies_p = 0 dependency_files = [] -# lily_py.py -- options and stuff -# -# source file of the GNU LilyPond music typesetter - -# BEGIN Library for these? -# cut-n-paste from ly2dvi - -program_version = '@TOPLEVEL_VERSION@' -if program_version == '@' + 'TOPLEVEL_VERSION' + '@': - program_version = '1.3.148' - - -original_dir = os.getcwd () -temp_dir = os.path.join (original_dir, '%s.dir' % program_name) - -keep_temp_dir_p = 0 -verbose_p = 0 - # # Try to cater for bad installations of LilyPond, that have # broken TeX setup. Just hope this doesn't hurt good TeX @@ -173,198 +177,6 @@ def setup_environment (): val = os.environ[key] + os.pathsep + val os.environ[key] = val -def identify (): - sys.stdout.write ('%s (GNU LilyPond) %s\n' % (program_name, program_version)) - -def warranty (): - identify () - sys.stdout.write ('\n') - sys.stdout.write (_ ('Copyright (c) %s by' % ' 2001')) - sys.stdout.write ('\n') - sys.stdout.write (' Han-Wen Nienhuys') - sys.stdout.write (' Jan Nieuwenhuizen') - sys.stdout.write ('\n') - sys.stdout.write (_ (r''' -Distributed under terms of the GNU General Public License. It comes with -NO WARRANTY.''')) - sys.stdout.write ('\n') - -errorport=sys.stderr - -def progress (s): - errorport.write (s + '\n') - -def warning (s): - progress (_ ("warning: ") + s) - -def error (s): - - - '''Report the error S. Exit by raising an exception. Please - do not abuse by trying to catch this error. If you do not want - a stack trace, write to the output directly. - - RETURN VALUE - - None - - ''' - - progress (_ ("error: ") + s) - raise _ ("Exiting ... ") - -def getopt_args (opts): - '''Construct arguments (LONG, SHORT) for getopt from list of options.''' - short = '' - long = [] - for o in opts: - if o[1]: - short = short + o[1] - if o[0]: - short = short + ':' - if o[2]: - l = o[2] - if o[0]: - l = l + '=' - long.append (l) - return (short, long) - -def option_help_str (o): - '''Transform one option description (4-tuple ) into neatly formatted string''' - sh = ' ' - if o[1]: - sh = '-%s' % o[1] - - sep = ' ' - if o[1] and o[2]: - sep = ',' - - long = '' - if o[2]: - long= '--%s' % o[2] - - arg = '' - if o[0]: - if o[2]: - arg = '=' - arg = arg + o[0] - return ' ' + sh + sep + long + arg - - -def options_help_str (opts): - '''Convert a list of options into a neatly formatted string''' - w = 0 - strs =[] - helps = [] - - for o in opts: - s = option_help_str (o) - strs.append ((s, o[3])) - if len (s) > w: - w = len (s) - - str = '' - for s in strs: - str = str + '%s%s%s\n' % (s[0], ' ' * (w - len(s[0]) + 3), s[1]) - return str - -def help (): - ls = [(_ ("Usage: %s [OPTION]... FILE") % program_name), - ('\n\n'), - (help_summary), - ('\n\n'), - (_ ("Options:")), - ('\n'), - (options_help_str (option_definitions)), - ('\n\n'), - (_ ("Report bugs to %s") % 'bug-gnu-music@gnu.org'), - ('\n')] - map (sys.stdout.write, ls) - -def setup_temp (): - """ - Create a temporary directory, and return its name. - """ - global temp_dir - if not keep_temp_dir_p: - temp_dir = tempfile.mktemp (program_name) - try: - os.mkdir (temp_dir, 0777) - except OSError: - pass - - return temp_dir - - -def system (cmd, ignore_error = 0): - """Run CMD. If IGNORE_ERROR is set, don't complain when CMD returns non zero. - - RETURN VALUE - - Exit status of CMD - """ - - if verbose_p: - progress (_ ("Invoking `%s\'") % cmd) - st = os.system (cmd) - if st: - name = re.match ('[ \t]*([^ \t]*)', cmd).group (1) - msg = name + ': ' + _ ("command exited with value %d") % st - if ignore_error: - warning (msg + ' ' + _ ("(ignored)") + ' ') - else: - error (msg) - - return st - - -def cleanup_temp (): - if not keep_temp_dir_p: - if verbose_p: - progress (_ ("Cleaning %s...") % temp_dir) - shutil.rmtree (temp_dir) - - -#what a name. -def set_setting (dict, key, val): - try: - val = string.atof (val) - except ValueError: - #warning (_ ("invalid value: %s") % `val`) - pass - - try: - dict[key].append (val) - except KeyError: - warning (_ ("no such setting: %s") % `key`) - dict[key] = [val] - - -def strip_extension (f, ext): - (p, e) = os.path.splitext (f) - if e == ext: - e = '' - return p + e - -# END Library - -option_definitions = [ - ('', 'd', 'dependencies', _ ("write Makefile dependencies for every input file")), - ('', 'h', 'help', _ ("this help")), - (_ ("DIR"), 'I', 'include', _ ("add DIR to LilyPond's search path")), - ('', 'k', 'keep', _ ("keep all output, and name the directory %s.dir") % program_name), - ('', '', 'no-lily', _ ("don't run LilyPond")), - ('', 'm', 'no-paper', _ ("produce MIDI output only")), - (_ ("FILE"), 'o', 'output', _ ("write ouput to FILE")), - (_ ("FILE"), 'f', 'find-pfa', _ ("find pfa fonts used in FILE")), - # why capital P? - ('', 'P', 'postscript', _ ("generate PostScript output")), - (_ ("KEY=VAL"), 's', 'set', _ ("change global setting KEY to VAL")), - ('', 'V', 'verbose', _ ("verbose")), - ('', 'v', 'version', _ ("print version number")), - ('', 'w', 'warranty', _ ("show warranty and copyright")), - ] - def run_lilypond (files, outbase, dep_prefix): opts = '' # opts = opts + '--output=%s.tex' % outbase @@ -657,7 +469,7 @@ try: (options, files) = getopt.getopt(sys.argv[1:], sh, long) except getopt.error, s: errorport.write ('\n') - errorport.write (_( "error: ") + _ ("getopt says: `%s\'" % s)) + errorport.write (_ ("error: ") + _ ("getopt says: `%s\'" % s)) errorport.write ('\n') errorport.write ('\n') help () @@ -850,7 +662,7 @@ if files and files[0] != '-': else: # FIXME: read from stdin when files[0] = '-' help () - errorport.write ("ly2dvi: " + _ ("error: ") + _ ("no files specified on command line.") + '\n') + errorport.write (program_name + ":" + _ ("error: ") + _ ("no files specified on command line.") + '\n') sys.exit (2) diff --git a/scripts/midi2ly.py b/scripts/midi2ly.py index 9c5ff18452..b49386be11 100644 --- a/scripts/midi2ly.py +++ b/scripts/midi2ly.py @@ -1,42 +1,71 @@ #!@PYTHON@ +# +# midi2ly.py -- LilyPond midi import script +# +# source file of the GNU LilyPond music typesetter +# +# convert MIDI to LilyPond source +# -import midi + +''' +TODO: + + * fix duration bug for lily input: a4*3/5 + * handle all notes off + * recognise (note-on, volume = 0) as note-off + * don't ever quant skips + * handle lyrics and other text events + +''' + +import getopt +import __main__ import sys import string -LINE_BELL = 60 -scale_steps = [0,2,4,5,7,9,11] +sys.path.append ('@datadir@/python') +sys.path.append ('@datadir@/buildscripts/out') +sys.path.append ('@datadir@/modules/out') -clocks_per_1 = 1536 +import midi +try: + import gettext + gettext.bindtextdomain ('lilypond', '@localedir@') + gettext.textdomain ('lilypond') + _ = gettext.gettext +except: + def _ (s): + return s -program_name = 'midi2ly.py [experimental]' +# Attempt to fix problems with limited stack size set by Python! +# Sets unlimited stack size. Note that the resource module only +# is available on UNIX. +try: + import resource + resource.setrlimit (resource.RLIMIT_STACK, (-1, -1)) +except: + pass -def split_track (track): - chs = {} - for i in range(16): - chs[i] = [] - - for e in track: - data = list (e[1]) - if data[0] > 0x7f and data[0] < 0xf0: - c = data[0] & 0x0f - e = (e[0], tuple ([data[0] & 0xf0] + data[1:])) - chs[c].append (e) - else: - chs[0].append (e) +program_name = 'midi2ly [experimental]' +package_name = 'lilypond' +help_summary = _ ("Convert MIDI to LilyPond source") + +option_definitions = [ + ('', 'h', 'help', _ ("this help")), + (_ ("DUR"), 'd', 'duration-quant', _ ("quantise note durations on DUR")), + (_ ("ACC[:MINOR]"), 'k', 'key', _ ("set key: ACC=+sharps|-flats; MINOR=1")), + (_ ("FILE"), 'o', 'output', _ ("write ouput to FILE")), + (_ ("DUR"), 's', 'start-quant', _ ("quantise note starts on DUR")), + (_ ("DUR*NUM/DEN"), 't', 'allow-tuplet', _ ("allow tuplet durations DUR*NUM/DEN")), + ('', 'v', 'version', _ ("print version number")), + ('', 'w', 'warranty', _ ("show warranty and copyright")), + ] + +from lilylib import * - for i in range (16): - if chs[i] == []: - del chs[i] - threads = [] - for v in chs.values (): - events = events_on_channel (v) - thread = unthread_notes (events) - if len (thread): - threads.append (thread) - return threads class Note: @@ -228,6 +257,57 @@ class Text: def dump (self): return '\n % [' + self.text_types[self.type] + '] ' + self.text + '\n ' + +output_name = '' +LINE_BELL = 60 +scale_steps = [0,2,4,5,7,9,11] + +clocks_per_1 = 1536 +key = 0 +start_quant = 0 +start_quant_clocks = 0 +duration_quant = 0 +duration_quant_clocks = 0 +allowed_tuplets = [] +allowed_tuplet_clocks = [] + +def split_track (track): + chs = {} + for i in range(16): + chs[i] = [] + + for e in track: + data = list (e[1]) + if data[0] > 0x7f and data[0] < 0xf0: + c = data[0] & 0x0f + e = (e[0], tuple ([data[0] & 0xf0] + data[1:])) + chs[c].append (e) + else: + chs[0].append (e) + + for i in range (16): + if chs[i] == []: + del chs[i] + + threads = [] + for v in chs.values (): + events = events_on_channel (v) + thread = unthread_notes (events) + if len (thread): + threads.append (thread) + return threads + + +def quantise_clocks (clocks, quant): + q = int (clocks / quant) * quant + if q != clocks: + for tquant in allowed_tuplet_clocks: + if int (clocks / tquant) * tquant == clocks: + return clocks + if 2 * (clocks - q) > quant: + q = q + quant + return q + def events_on_channel (channel): pitches = {} @@ -236,6 +316,10 @@ def events_on_channel (channel): for e in channel: t = e[0] + if start_quant_clocks: + t = quantise_clocks (t, start_quant_clocks) + + if e[1][0] == midi.NOTE_ON: if not pitches.has_key (e[1][1]): pitches[e[1][1]] = (t, e[1][2]) @@ -250,8 +334,14 @@ def events_on_channel (channel): i = i -1 else: break + d = t - lt + if duration_quant_clocks: + d = quantise_clocks (d, duration_quant_clocks) + if not d: + d = duration_quant_clocks + notes.insert (i + 1, - (lt, Note (t-lt, e[1][1], vel))) + (lt, Note (d, e[1][1], vel))) except KeyError: pass @@ -330,14 +420,23 @@ def dump_skip (clocks): return 's' + dump_duration (clocks) + ' ' def dump_duration (clocks): + for i in range (len (allowed_tuplet_clocks)): + if clocks == allowed_tuplet_clocks[i]: + (dur, num, den) = allowed_tuplets[i] + s = '%d*%d/%d' % (dur, num, den) + return s + g = gcd (clocks, clocks_per_1) - (d, n) = (clocks_per_1/ g, clocks / g) - if n == 1: - s = '%d' % d - elif n == 3 and d != 1: - s = '%d.' % (d / 2) + if g: + (d, n) = (clocks_per_1 / g, clocks / g) + if n == 1: + s = '%d' % d + elif n == 3 and d != 1: + s = '%d.' % (d / 2) + else: + s = '%d*%d' % (d, n) else: - s = '%d*%d' % (d, n) + s = '1*%d/%d' % (clocks, clocks_per_1) return s def dump (self): @@ -426,8 +525,7 @@ def dump_track (channels, n): s = s + '>\n\n' return s - -def convert_midi (f): +def convert_midi (f, o): global clocks_per_1 str = open (f).read () @@ -435,6 +533,19 @@ def convert_midi (f): clocks_per_1 = midi_dump[0][1] + global start_quant, start_quant_clocks + if start_quant: + start_quant_clocks = clocks_per_1 / start_quant + + global duration_quant, duration_quant_clocks + if duration_quant: + duration_quant_clocks = clocks_per_1 / duration_quant + + global allowed_tuplet_clocks + allowed_tuplet_clocks = [] + for (dur, num, den) in allowed_tuplets: + allowed_tuplet_clocks.append (clocks_per_1 * num / (dur * den)) + tracks = [] for t in midi_dump[1]: tracks.append (split_track (t)) @@ -451,9 +562,109 @@ def convert_midi (f): track = track_name (i) s = s + ' \\context Staff=%s \\%s\n' % (track, track) s = s + ' >\n}\n' + + progress (_ ("%s output to `%s'...") % ('LY', o)) + + if o == '-': + h = sys.stdout + else: + h = open (o, 'w') + + h.write (s) + h.close () + + +(sh, long) = getopt_args (__main__.option_definitions) +try: + (options, files) = getopt.getopt(sys.argv[1:], sh, long) +except getopt.error, s: + errorport.write ('\n') + errorport.write (_ ("error: ") + _ ("getopt says: `%s\'" % s)) + errorport.write ('\n') + errorport.write ('\n') + help () + sys.exit (2) - sys.stdout.write (s) - +for opt in options: + o = opt[0] + a = opt[1] + + if 0: + pass + elif o == '--help' or o == '-h': + help () + errorport.write ('\n') + errorport.write (_ ("Example:")) + errorport.write (r''' + midi2ly --key=-2:1 --duration-quant=32 \ + --allow-tuplet=4*2/3 --allow-tuplet=2*4/3 foo.midi +''') + sys.exit (0) + elif o == '--output' or o == '-o': + output_name = a + elif o == '--verbose' or o == '-V': + verbose_p = 1 + elif o == '--version' or o == '-v': + identify () + sys.exit (0) + elif o == '--warranty' or o == '-w': + status = system ('lilypond -w', ignore_error = 1) + if status: + warranty () + sys.exit (0) + elif o == '--key' or o == '-k': + (accidentals, minor) = map (string.atoi, string.split (a + ':0', ':'))[0:2] + sharps = 0 + flats = 0 + if accidentals >= 0: + sharps = accidentals + else: + flats = - accidentals + global key + key = Key (sharps, flats, minor) + elif o == '--duration-quant' or o == '-d': + global duration_quant + duration_quant = string.atoi (a) + elif o == '--start-quant' or o == '-s': + global start_quant, start_quant_clocks + start_quant = string.atoi (a) + elif o == '--allow-tuplet' or o == '-t': + global allowed_tuplets + a = string.replace (a, '/', '*') + tuplet = map (string.atoi, string.split (a, '*')) + allowed_tuplets.append (tuplet) + + +if not files or files[0] == '-': + + # FIXME: read from stdin when files[0] = '-' + help () + errorport.write (program_name + ":" + _ ("error: ") + _ ("no files specified on command line.") + '\n') + sys.exit (2) + + +for f in files: + + g = f + g = strip_extension (g, '.midi') + g = strip_extension (g, '.mid') + g = strip_extension (g, '.MID') + (outdir, outbase) = ('','') + + if not output_name: + outdir = '.' + outbase = os.path.basename (g) + o = os.path.join (outdir, outbase + '-midi.ly') + elif output_name[-1] == os.sep: + outdir = output_name + outbase = os.path.basename (g) + os.path.join (outdir, outbase + '-gen.ly') + else: + o = output_name + (outdir, outbase) = os.path.split (o) + + if outdir != '.': + mkdir_p (outdir, 0777) + + convert_midi (f, o) -for f in sys.argv[1:]: - convert_midi (f) diff --git a/scripts/mup2ly.py b/scripts/mup2ly.py index 208aa76ae3..f7b7da1eff 100644 --- a/scripts/mup2ly.py +++ b/scripts/mup2ly.py @@ -34,194 +34,49 @@ import __main__ import operator import tempfile -# let's not yet clutter lily's po with this mup converter junk -def _ (s): - return s - -#sys.path.append ('@datadir@/python') -#import gettext -#gettext.bindtextdomain ('lilypond', '@localedir@') -#gettext.textdomain('lilypond') -#_ = gettext.gettext - +sys.path.append ('@datadir@/python') +sys.path.append ('@datadir@/buildscripts/out') +sys.path.append ('@datadir@/modules/out') +try: + import gettext + gettext.bindtextdomain ('lilypond', '@localedir@') + gettext.textdomain ('lilypond') + _ = gettext.gettext +except: + def _ (s): + return s +# Attempt to fix problems with limited stack size set by Python! +# Sets unlimited stack size. Note that the resource module only +# is available on UNIX. +try: + import resource + resource.setrlimit (resource.RLIMIT_STACK, (-1, -1)) +except: + pass program_name = 'mup2ly' -help_summary = _("Convert mup to ly") -output = 0 - -# lily_py.py -- options and stuff -# -# source file of the GNU LilyPond music typesetter - -# BEGIN Library for these? -# cut-n-paste from ly2dvi - -program_version = '@TOPLEVEL_VERSION@' -if program_version == '@' + 'TOPLEVEL_VERSION' + '@': - program_version = '1.3.142' - - -original_dir = os.getcwd () -temp_dir = '%s.dir' % program_name -keep_temp_dir_p = 0 -verbose_p = 0 - -def identify (): - sys.stdout.write ('%s (GNU LilyPond) %s\n' % (program_name, program_version)) - -def warranty (): - identify () - sys.stdout.write ('\n') - sys.stdout.write (_ ('Copyright (c) %s by' % ' 2001')) - sys.stdout.write ('\n') - sys.stdout.write (' Han-Wen Nienhuys') - sys.stdout.write (' Jan Nieuwenhuizen') - sys.stdout.write ('\n') - sys.stdout.write (_ (r''' -Distributed under terms of the GNU General Public License. It comes with -absolutely NO WARRANTY.''')) - sys.stdout.write ('\n') - -def progress (s): - if s[-1] != '\n': - s = s + '\n' - sys.stderr.write (s) - -def warning (s): - sys.stderr.write (_ ("warning: ") + s) - sys.stderr.write ('\n') - - -def error (s): - sys.stderr.write (_ ("error: ") + s) - sys.stderr.write ('\n') - raise _ ("Exiting ... ") - -def getopt_args (opts): - '''Construct arguments (LONG, SHORT) for getopt from list of options.''' - short = '' - long = [] - for o in opts: - if o[1]: - short = short + o[1] - if o[0]: - short = short + ':' - if o[2]: - l = o[2] - if o[0]: - l = l + '=' - long.append (l) - return (short, long) - -def option_help_str (o): - '''Transform one option description (4-tuple ) into neatly formatted string''' - sh = ' ' - if o[1]: - sh = '-%s' % o[1] - - sep = ' ' - if o[1] and o[2]: - sep = ',' - - long = '' - if o[2]: - long= '--%s' % o[2] - - arg = '' - if o[0]: - if o[2]: - arg = '=' - arg = arg + o[0] - return ' ' + sh + sep + long + arg - - -def options_help_str (opts): - '''Convert a list of options into a neatly formatted string''' - w = 0 - strs =[] - helps = [] - - for o in opts: - s = option_help_str (o) - strs.append ((s, o[3])) - if len (s) > w: - w = len (s) - - str = '' - for s in strs: - str = str + '%s%s%s\n' % (s[0], ' ' * (w - len(s[0]) + 3), s[1]) - return str - -def help (): - sys.stdout.write (_ ("Usage: %s [OPTION]... FILE") % program_name) - sys.stdout.write ('\n\n') - sys.stdout.write (help_summary) - sys.stdout.write ('\n\n') - sys.stdout.write (_ ("Options:")) - sys.stdout.write ('\n') - sys.stdout.write (options_help_str (option_definitions)) - sys.stdout.write ('\n') - warning (_ ("%s is far from completed. Not all constructs are recognised.") % program_name) - sys.stdout.write ('\n') - sys.stdout.write (_ ("Report bugs to %s") % 'bug-gnu-music@gnu.org') - sys.stdout.write ('\n') - sys.exit (0) - - -def setup_temp (): - global temp_dir - if not keep_temp_dir_p: - temp_dir = tempfile.mktemp (program_name) - try: - os.mkdir (temp_dir, 0777) - except OSError: - pass - - -def system (cmd, ignore_error = 0): - if verbose_p: - progress (_ ("Invoking `%s\'") % cmd) - st = os.system (cmd) - if st: - msg = ( _ ("error: ") + _ ("command exited with value %d") % st) - if ignore_error: - sys.stderr.write (msg + ' ' + _ ("(ignored)") + ' ') - else: - error (msg) - - return st - - -def cleanup_temp (): - if not keep_temp_dir_p: - if verbose_p: - progress (_ ('Cleaning up `%s\'') % temp_dir) - system ('rm -rf %s' % temp_dir) +package_name = 'lilypond' +help_summary = _ ("Convert mup to LilyPond source") +option_definitions = [ + ('', 'd', 'debug', _ ("debug")), + ('NAME[=EXP]', 'D', 'define', _ ("define macro NAME [optional expansion EXP]")), + ('', 'h', 'help', _ ("this help")), + ('FILE', 'o', 'output', _ ("write output to FILE")), + ('', 'E', 'pre-process', _ ("only pre-process")), + ('', 'V', 'verbose', _ ("verbose")), + ('', 'v', 'version', _ ("print version number")), + ('', 'w', 'warranty', _ ("show warranty and copyright")), + ] -def set_setting (dict, key, val): - try: - val = string.atof (val) - except ValueError: - #warning (_ ("invalid value: %s") % `val`) - pass - try: - dict[key].append (val) - except KeyError: - warning (_ ("no such setting: %s") % `key`) - dict[key] = [val] +from lilylib import * -def strip_extension (f, ext): - (p, e) = os.path.splitext (f) - if e == ext: - e = '' - return p + e -# END Library +output = 0 # # PMX cut and paste @@ -1110,18 +965,6 @@ class Pre_processor: s = '' - -option_definitions = [ - ('', 'd', 'debug', _ ("debug")), - ('NAME[=EXP]', 'D', 'define', _ ("define macro NAME [optional expansion EXP]")), - ('', 'h', 'help', _ ("this help")), - ('FILE', 'o', 'output', _ ("write output to FILE")), - ('', 'E', 'pre-process', _ ("only pre-process")), - ('', 'V', 'verbose', _ ("verbose")), - ('', 'v', 'version', _ ("print version number")), - ('', 'w', 'warranty', _ ("show warranty and copyright")), - ] - debug_p = 0 only_pre_process_p = 0 def debug (s): diff --git a/scripts/update-lily.py b/scripts/update-lily.py index 79f8040fc6..e60de66dba 100644 --- a/scripts/update-lily.py +++ b/scripts/update-lily.py @@ -31,208 +31,46 @@ import string import sys import __main__ + +url = 'file:/home/ftp/pub/gnu/LilyPond/development/lilypond-*.tar.gz' +url = 'ftp://appel.lilypond.org/pub/gnu/LilyPond/development/lilypond-*.tar.gz' +url = 'ftp://ftp.cs.uu.nl/pub/GNU/LilyPond/development/lilypond-*.tar.gz' + +remove_previous_p = 0 + + sys.path.append ('@datadir@/python') +sys.path.append ('@datadir@/buildscripts/out') + try: import gettext gettext.bindtextdomain ('lilypond', '@localedir@') - gettext.textdomain('lilypond') + gettext.textdomain ('lilypond') _ = gettext.gettext except: def _ (s): return s +# Attempt to fix problems with limited stack size set by Python! +# Sets unlimited stack size. Note that the resource module only +# is available on UNIX. +try: + import resource + resource.setrlimit (resource.RLIMIT_STACK, (-1, -1)) +except: + pass + + program_name = 'build-lily' package_name = 'lilypond' -help_summary = _("Fetch and rebuild from latest source package") +help_summary = _ ("Fetch and rebuild from latest source package") + build_root = os.path.join (os.environ ['HOME'], 'usr', 'src') release_dir = build_root + '/releases' patch_dir = build_root + '/patches' -notify = 0 - -build_command = ''' -set -x -cd %b && -[ -d %n-%v ] && exit 1 || true; -mkdir -p %n-%v -( -tar xzf %r/%t && -rm -f building && -ln -s %n-%v building && -cd %n-%v && -./configure --prefix=$HOME/usr && make all web -) >> %n-%v/log.txt 2>&1 && -rm -f %n && -ln -s %n-%v %n -''' - - -url = 'file:/home/ftp/pub/gnu/LilyPond/development/lilypond-*.tar.gz' -url = 'ftp://appel.lilypond.org/pub/gnu/LilyPond/development/lilypond-*.tar.gz' -url = 'ftp://ftp.cs.uu.nl/pub/GNU/LilyPond/development/lilypond-*.tar.gz' - -remove_previous_p = 0 - - -# lily_py.py -- options and stuff -# -# source file of the GNU LilyPond music typesetter - -# BEGIN Library for these? -# cut-n-paste from ly2dvi - -program_version = '@TOPLEVEL_VERSION@' -if program_version == '@' + 'TOPLEVEL_VERSION' + '@': - program_version = '1.3.142' - - original_dir = os.getcwd () -temp_dir = '%s.dir' % program_name -keep_temp_dir_p = 0 -verbose_p = 0 - -def identify (): - sys.stdout.write ('%s (GNU LilyPond) %s\n' % (program_name, program_version)) - -def warranty (): - identify () - sys.stdout.write ('\n') - sys.stdout.write (_ ('Copyright (c) %s by' % ' 2001')) - sys.stdout.write ('\n') - sys.stdout.write (' Han-Wen Nienhuys') - sys.stdout.write (' Jan Nieuwenhuizen') - sys.stdout.write ('\n') - sys.stdout.write (_ (r''' -Distributed under terms of the GNU General Public License. It comes with -NO WARRANTY.''')) - sys.stdout.write ('\n') - -def progress (s): - sys.stderr.write (s + '\n') - -def warning (s): - sys.stderr.write (_ ("warning: ") + s) - sys.stderr.write ('\n') - - -def error (s): - sys.stderr.write (_ ("error: ") + s) - sys.stderr.write ('\n') - raise _ ("Exiting ... ") - -def getopt_args (opts): - '''Construct arguments (LONG, SHORT) for getopt from list of options.''' - short = '' - long = [] - for o in opts: - if o[1]: - short = short + o[1] - if o[0]: - short = short + ':' - if o[2]: - l = o[2] - if o[0]: - l = l + '=' - long.append (l) - return (short, long) - -def option_help_str (o): - '''Transform one option description (4-tuple ) into neatly formatted string''' - sh = ' ' - if o[1]: - sh = '-%s' % o[1] - - sep = ' ' - if o[1] and o[2]: - sep = ',' - - long = '' - if o[2]: - long= '--%s' % o[2] - - arg = '' - if o[0]: - if o[2]: - arg = '=' - arg = arg + o[0] - return ' ' + sh + sep + long + arg - - -def options_help_str (opts): - '''Convert a list of options into a neatly formatted string''' - w = 0 - strs =[] - helps = [] - - for o in opts: - s = option_help_str (o) - strs.append ((s, o[3])) - if len (s) > w: - w = len (s) - - str = '' - for s in strs: - str = str + '%s%s%s\n' % (s[0], ' ' * (w - len(s[0]) + 3), s[1]) - return str - -def help (): - sys.stdout.write (_ ("Usage: %s [OPTION]... FILE") % program_name) - sys.stdout.write ('\n\n') - sys.stdout.write (help_summary) - sys.stdout.write ('\n\n') - sys.stdout.write (_ ("Options:")) - sys.stdout.write ('\n') - sys.stdout.write (options_help_str (option_definitions)) - sys.stdout.write ('\n\n') - sys.stdout.write (_ ("Report bugs to %s") % 'bug-gnu-music@gnu.org') - sys.stdout.write ('\n') - sys.exit (0) - - -def setup_temp (): - global temp_dir - if not keep_temp_dir_p: - temp_dir = tempfile.mktemp (program_name) - try: - os.mkdir (temp_dir, 0777) - except OSError: - pass - - -def system (cmd, ignore_error = 0): - if verbose_p: - progress (_ ("Invoking `%s\'") % cmd) - st = os.system (cmd) - if st: - msg = ( _ ("error: ") + _ ("command exited with value %d") % st) - if ignore_error: - sys.stderr.write (msg + ' ' + _ ("(ignored)") + ' ') - else: - error (msg) - - return st - +temp_dir = os.path.join (original_dir, '%s.dir' % program_name) -def cleanup_temp (): - if not keep_temp_dir_p: - if verbose_p: - progress (_ ("Cleaning `%s'...") % temp_dir) - system ('rm -rf %s' % temp_dir) - - -def set_setting (dict, key, val): - try: - val = string.atof (val) - except ValueError: - #warning (_ ("invalid value: %s") % `val`) - pass - - try: - dict[key].append (val) - except KeyError: - warning (_ ("no such setting: %s") % `key`) - dict[key] = [val] - -# END Library option_definitions = [ ('DIR', 'b', 'build-root', _ ("unpack and build in DIR [%s]") % build_root), @@ -253,6 +91,28 @@ option_definitions = [ ('', 'w', 'warranty', _ ("show warranty and copyright")), ] +from lilylib import * + + +notify = 0 + +build_command = ''' +set -x +cd %b && +[ -d %n-%v ] && exit 1 || true; +mkdir -p %n-%v +( +tar xzf %r/%t && +rm -f building && +ln -s %n-%v building && +cd %n-%v && +./configure --prefix=$HOME/usr && make all web +) >> %n-%v/log.txt 2>&1 && +rm -f %n && +ln -s %n-%v %n +''' + + def list_file (user, passwd, host, dir, file): match = [] for i in os.listdir (dir): @@ -379,13 +239,19 @@ def build (p): c = re.sub (i, expand[i], c) return system (c, 1) + + (sh, long) = getopt_args (__main__.option_definitions) try: - (options, files) = getopt.getopt (sys.argv[1:], sh, long) -except: + (options, files) = getopt.getopt(sys.argv[1:], sh, long) +except getopt.error, s: + errorport.write ('\n') + errorport.write (_ ("error: ") + _ ("getopt says: `%s\'" % s)) + errorport.write ('\n') + errorport.write ('\n') help () sys.exit (2) - + for opt in options: o = opt[0] a = opt[1] -- 2.39.5