From 6faae8735988dec671fcf8a67a4e09a0b74325eb Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Thu, 2 Mar 2006 10:50:40 +0000 Subject: [PATCH] * scripts/midi2ly.py (Key.dump): pychecker cleanups. * python/lilylib.py (underscore): remove identify() , warranty() * ps/music-drawing-routines.ps: change Border routine for GSView compatibility. * lily/stem.cc (height): use quantize-positions. This triggers set_stem_lengths, so scripts on beamed stems are handled correctly. * lily/side-position-interface.cc (aligned_side): check if edges of script are inside staff. Fixes accent of edge of the staff. * input/regression/staccato-pos.ly: more examples. --- ChangeLog | 15 ++++ THANKS | 2 + input/regression/staccato-pos.ly | 28 ++++--- lily/side-position-interface.cc | 4 +- lily/stem.cc | 3 +- ps/music-drawing-routines.ps | 2 +- python/lilylib.py | 15 ---- scm/script.scm | 2 +- scripts/convert-ly.py | 44 ++++++++--- scripts/lilypond-book.py | 21 ++++- scripts/midi2ly.py | 131 +++++++++++++++---------------- 11 files changed, 154 insertions(+), 113 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2219c732ae..55c6613fff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,20 @@ 2006-03-02 Han-Wen Nienhuys + * scripts/midi2ly.py (Key.dump): pychecker cleanups. + + * python/lilylib.py (underscore): remove identify() , warranty() + + * ps/music-drawing-routines.ps: change Border routine for GSView + compatibility. + + * lily/stem.cc (height): use quantize-positions. This triggers + set_stem_lengths, so scripts on beamed stems are handled correctly. + + * lily/side-position-interface.cc (aligned_side): check if edges + of script are inside staff. Fixes accent of edge of the staff. + + * input/regression/staccato-pos.ly: more examples. + * stepmake/aclocal.m4 (depth): fix bashism. * lily/lyric-combine-music-iterator.cc: move from diff --git a/THANKS b/THANKS index 21078903a6..a600fa9b9c 100644 --- a/THANKS +++ b/THANKS @@ -63,6 +63,7 @@ Darius Blasband David Bobroff Donald Axel Don Blaheta +Dunstan Vavasour Edward Neeman Eduardo Vieira Ernesto Gancedo @@ -89,6 +90,7 @@ Ralph Little Richard Schoeller Robert Vlatasy Roman Kurakin +Russell Lang Scott Russell Sean Reed Seng Liang diff --git a/input/regression/staccato-pos.ly b/input/regression/staccato-pos.ly index 322b8a0886..a1ccc13477 100644 --- a/input/regression/staccato-pos.ly +++ b/input/regression/staccato-pos.ly @@ -3,10 +3,10 @@ \header{ - texidoc=" The staccato dot (and all scripts with follow-into-staff -set) must not be on staff lines. The staccato dot is close to the -notehead. If the head is in a space, then the dot is in the space next -to it. " + texidoc=" Some scripts must have quantized postions. VErtical + position descend monotonously for a descending scale. The staccato + dot is close to the notehead. If the head is in a space, then the dot + is in the space next to it. " } @@ -14,12 +14,16 @@ to it. " ragged-right = ##t } - -\context Voice \relative c' { - e'4-. f-. g-. d-. c-. b-. - \stemDown - e,-. d-. c-. b-. a-. g-. +\context Voice { + \relative c' { + e'4-. f-. g-. d-. c-. b-. + \stemDown + e,-. d-. c-. b-. a-. g-. + } + \relative c'' { + \stemUp + d-> c-> b-> a-> g-> f-> e-> d-> + d' + d-. c-. b-. a-. g-. f-. e-. d-. + } } - - - diff --git a/lily/side-position-interface.cc b/lily/side-position-interface.cc index 8836e30d24..3dfe6eb900 100644 --- a/lily/side-position-interface.cc +++ b/lily/side-position-interface.cc @@ -179,8 +179,8 @@ Side_position_interface::aligned_side (Grob *me, Axis a) Real position = 2 * (my_off + o - staff_off) / ss; Real rounded = directed_round (position, dir); Grob *head = me->get_parent (X_AXIS); - - if (fabs (rounded) <= 2 * Staff_symbol_referencer::staff_radius (me) + + if (fabs (position) <= 2 * Staff_symbol_referencer::staff_radius (me) + 1 || (Note_head::has_interface (head) && sign (Staff_symbol_referencer::get_position (head)) == - dir)) { diff --git a/lily/stem.cc b/lily/stem.cc index accada587d..8a59a4909c 100644 --- a/lily/stem.cc +++ b/lily/stem.cc @@ -509,7 +509,8 @@ Stem::height (SCM smob) Grob *beam = get_beam (me); if (beam) { - beam->get_property ("positions"); + /* trigger set-stem-lengths. */ + beam->get_property ("quantized-positions"); } /* diff --git a/ps/music-drawing-routines.ps b/ps/music-drawing-routines.ps index b8f36aa208..bc875b448d 100644 --- a/ps/music-drawing-routines.ps +++ b/ps/music-drawing-routines.ps @@ -62,7 +62,7 @@ /llx exch def [ /Rect [ llx lly urx ury ] - /Border [ 0 0 0 0 ] + /Border [ 0 0 0 ] /Action << diff --git a/python/lilylib.py b/python/lilylib.py index 10c05656c7..d4772286e5 100644 --- a/python/lilylib.py +++ b/python/lilylib.py @@ -57,21 +57,6 @@ except: return s underscore = _ -def identify (port): - port.write ('%s (GNU LilyPond) %s\n' % (__main__.program_name, __main__.program_version)) - -def warranty (): - identify (sys.stdout) - sys.stdout.write ('\n') - sys.stdout.write (_ ("Copyright (c) %s by") % '1998--2006') - sys.stdout.write ('\n') - map (lambda x: sys.stdout.write (' %s\n' % x), __main__.copyright) - sys.stdout.write ('\n') - sys.stdout.write (_ ("Distributed under terms of the GNU General Public License.")) - sys.stdout.write ('\n') - sys.stdout.write (_ ("It comes with NO WARRANTY.")) - sys.stdout.write ('\n') - def progress (s): sys.stderr.write (s) diff --git a/scm/script.scm b/scm/script.scm index 3c8c9aebf0..18f39cc7a5 100644 --- a/scm/script.scm +++ b/scm/script.scm @@ -13,7 +13,7 @@ ((avoid-slur . around) (quantize-position . #t) (script-stencil . (feta . ("sforzato" . "sforzato"))) - (side-relative-direction . -1))) + (side-relative-direction . -1))) ("espressivo" . ((avoid-slur . around) (quantize-position . #t) diff --git a/scripts/convert-ly.py b/scripts/convert-ly.py index 3202f53b5f..149b913041 100644 --- a/scripts/convert-ly.py +++ b/scripts/convert-ly.py @@ -12,8 +12,6 @@ import os import sys -import __main__ -import getopt import string import re @@ -39,7 +37,6 @@ for p in ['share', 'lib']: sys.path.insert (0, datadir) import lilylib as ly -import fontextract global _;_=ly._ from convertrules import * @@ -66,6 +63,30 @@ program_version = '@TOPLEVEL_VERSION@' add_version = 1 +def warning (s): + sys.stderr.write (program_name + ": " + _ ("warning: %s") % s + '\n') + +def error (s): + sys.stderr.write (program_name + ": " + _ ("error: %s") % s + '\n') + +def identify (port=sys.stderr): + port.write ('%s (GNU LilyPond) %s\n' % (program_name, program_version)) + +def warranty (): + identify () + sys.stdout.write (''' +Copyright (c) %s by + + Han-Wen Nienhuys + Jan Nieuwenhuizen + +%s +%s +''' ( '2001--2006', + _('Distributed under terms of the GNU General Public License.'), + _('It comes with NO WARRANTY.'))) + + def get_option_parser (): p = ly.get_option_parser (usage='lilypond-book [OPTIONS] FILE', @@ -107,7 +128,7 @@ def get_option_parser (): def str_to_tuple (s): - return tuple (map (string.atoi, string.split (s, '.'))) + return tuple (map (int, string.split (s, '.'))) def tup_to_str (t): return string.join (map (lambda x: '%s' % x, list (t)), '.') @@ -179,12 +200,9 @@ class UnknownVersion: def do_one_file (infile_name): sys.stderr.write (_ ("Processing `%s\'... ") % infile_name) sys.stderr.write ('\n') - outfile_name = '' - if global_options.edit: - outfile_name = infile_name + '.NEW' - elif global_options.outfile_name: - outfile_name = global_options.outfile_name + from_version = None + to_version = None if global_options.from_version: from_version = global_options.from_version else: @@ -258,23 +276,23 @@ def main (): # should parse files[] to read \version? if global_options.show_rules: - show_rules (sys.stdout, from_version, to_version) + show_rules (sys.stdout, global_options.from_version, global_options.to_version) sys.exit (0) - ly.identify (sys.stderr) + identify (sys.stderr) for f in files: if f == '-': f = '' elif not os.path.isfile (f): - ly.error (_ ("can't open file: `%s'") % f) + error (_ ("can't open file: `%s'") % f) if len (files) == 1: sys.exit (1) continue try: do_one_file (f) except UnknownVersion: - ly.error (_ ("can't determine version for `%s'. Skipping") % f) + error (_ ("can't determine version for `%s'. Skipping") % f) sys.stderr.write ('\n') diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py index 7b79c9e204..2d2328672f 100644 --- a/scripts/lilypond-book.py +++ b/scripts/lilypond-book.py @@ -95,9 +95,28 @@ Example usage: lilypond-book --process='lilypond -I include' BOOK ''') -copyright = ('Jan Nieuwenhuizen ', +authors = ('Jan Nieuwenhuizen ', 'Han-Wen Nienhuys ') + +def identify (): + sys.stdout.write ('%s (GNU LilyPond) %s\n' % (program_name, program_version)) + +def warranty (): + identify () + sys.stdout.write (''' +%s + +%s + +%s +%s +''' ( _('Copyright (c) %s by') % '2001--2006', + authors + _('Distributed under terms of the GNU General Public License.'), + _('It comes with NO WARRANTY.'))) + + def get_option_parser (): p = ly.get_option_parser (usage='lilypond-book [OPTIONS] FILE', version="@TOPLEVEL_VERSION@", diff --git a/scripts/midi2ly.py b/scripts/midi2ly.py index 798f3efe41..c61cce84ed 100644 --- a/scripts/midi2ly.py +++ b/scripts/midi2ly.py @@ -10,23 +10,22 @@ ''' TODO: - * test on weird and unquantised midi input (lily-devel) - * update doc and manpage - - * simply insert clef changes whenever too many ledger lines - [to avoid tex capacity exceeded] - * do not ever quant skips - * better lyrics handling - * [see if it is feasible to] move ly-classes to library for use in - other converters, while leaving midi specific stuff here + * test on weird and unquantised midi input (lily-devel) + * update doc and manpage + + * simply insert clef changes whenever too many ledger lines + [to avoid tex capacity exceeded] + * do not ever quant skips + * better lyrics handling + * [see if it is feasible to] move ly-classes to library for use in + other converters, while leaving midi specific stuff here ''' -import getopt import os import string import sys - + ################################################################ # Users of python modules should include this snippet. # @@ -44,16 +43,17 @@ if os.environ.has_key ('LILYPONDPREFIX'): if os.path.exists (os.path.join (datadir, 'lib/lilypond/@TOPLEVEL_VERSION@/')): libdir = os.path.join (libdir, 'lib/lilypond/@TOPLEVEL_VERSION@/') - + if os.path.exists (os.path.join (datadir, 'lib/lilypond/current/')): libdir = os.path.join (libdir, 'lib/lilypond/current/') - + sys.path.insert (0, os.path.join (libdir, 'python')) # dynamic relocation, for GUB binaries. bindir = os.path.split (sys.argv[0])[0] -for p in ['share', 'lib']: - datadir = os.path.abspath (bindir + '/../%s/lilypond/current/python/' % p) + +for prefix_component in ['share', 'lib']: + datadir = os.path.abspath (bindir + '/../%s/lilypond/current/python/' % prefix_component) sys.path.insert (0, datadir) import midi @@ -299,8 +299,7 @@ class Note: ## FIXME: compile fix --jcn if dump_dur and (global_options.explicit_durations \ - or Duration.compare (self.duration, - reference_note.duration)): + or self.duration.compare (reference_note.duration)): s = s + self.duration.dump () reference_note = self @@ -362,8 +361,7 @@ class Key: self.minor = minor def dump (self): - global key - key = self + global_options.key = self s = '' if self.sharps and self.flats: @@ -425,8 +423,7 @@ class Text: s = '"%s"' % self.text d = Duration (self.clocks) if global_options.explicit_durations \ - or Duration.compare (d, - reference_note.duration): + or d.compare (reference_note.duration): s = s + Duration (self.clocks).dump () s = s + ' ' else: @@ -556,8 +553,7 @@ def events_on_channel (channel): # ugh, must set key while parsing # because Note init uses key # Better do Note.calc () at dump time? - global key - key = k + global_options.key = k elif e[1][1] == midi.LYRIC \ or (global_options.text_lyrics and e[1][1] == midi.TEXT_EVENT): @@ -636,8 +632,8 @@ def gcd (a,b): def dump_skip (skip, clocks): return skip + Duration (clocks).dump () + ' ' -def dump (self): - return self.dump () +def dump (d): + return d.dump () def dump_chord (ch): s = '' @@ -679,9 +675,9 @@ def dump_bar_line (last_bar_t, t, bar_count): def dump_channel (thread, skip): - global key, reference_note, time + global reference_note, time - key = Key (0, 0, 0) + global_options.key = Key (0, 0, 0) time = Time (4, 4) # urg LilyPond doesn't start at c4, but # remembers from previous tracks! @@ -844,14 +840,14 @@ def convert_midi (in_file, out_file): allowed_tuplet_clocks = [] for (dur, num, den) in global_options.allowed_tuplets: - allowed_tuplet_clocks.append (clocks_per_1 * num / (dur * den)) + allowed_tuplet_clocks.append (clocks_per_1 / den) tracks = [] for t in midi_dump[1]: - key = Key (0, 0, 0) + global_options.key = Key (0, 0, 0) tracks.append (split_track (t)) - tag = '%% Lily was here -- automatically converted by %s from %s' % ( program_name, f) + tag = '%% Lily was here -- automatically converted by %s from %s' % ( program_name, in_file) s = '' @@ -874,9 +870,9 @@ def convert_midi (in_file, out_file): i += 1 s = s + ' >>\n}\n' - progress (_ ("%s output to `%s'...") % ('LY', o)) + progress (_ ("%s output to `%s'...") % ('LY', out_file)) - if o == '-': + if out_file == '-': handle = sys.stdout else: handle = open (out_file, 'w') @@ -913,10 +909,10 @@ def get_option_parser (): dest="allowed_tuplets", help=_ ("allow tuplet durations DUR*NUM/DEN"), default=[]) - p.add_option ('-V', '--verbose', help=_ ("be verbose"), - action='store_true', + p.add_option ('-V', '--verbose', help=_("be verbose"), + action='store_true' ), - p.add_option ('-w', '--warranty', help=_ ("show warranty"), + p.add_option ('-w', '--warranty', help=_("show warranty"), action='store_true', ), p.add_option ('-x', '--text-lyrics', help=_("treat every text as a lyric"), @@ -947,13 +943,13 @@ def do_options (): sys.exit (2) if options.duration_quant: - options.duration_quant = string.atoi (options.duration_quant) + options.duration_quant = int (options.duration_quant) if options.warranty: warranty () sys.exit (0) if 1: - (alterations, minor) = map (string.atoi, string.split (options.key + ':0', ':'))[0:2] + (alterations, minor) = map (int, string.split (options.key + ':0', ':'))[0:2] sharps = 0 flats = 0 if alterations >= 0: @@ -965,9 +961,9 @@ def do_options (): if options.start_quant: - options.start_quant = string.atoi (a) + options.start_quant = int (options.start_quant) - options.allowed_tuplets = [map (string.atoi, a.replace ('/','*').split ('*')) + options.allowed_tuplets = [map (int, a.replace ('/','*').split ('*')) for a in options.allowed_tuplets] global global_options @@ -975,33 +971,34 @@ def do_options (): return args +def main(): + files = do_options() + + 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) -files = do_options() - -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 != '.' and outdir != '': - try: - os.mkdir (outdir, 0777) - except OSError: - pass - - convert_midi (f, o) + if outdir != '.' and outdir != '': + try: + os.mkdir (outdir, 0777) + except OSError: + pass + convert_midi (f, o) +if __name__ == '__main__': + main() -- 2.39.5