From 696a2d33ac542bf19aabca540a572fef686a6478 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Fri, 10 Feb 2006 01:05:05 +0000 Subject: [PATCH] (get_beam_translation): new function. (calc_slope): new function. (height): don't use real slope. --- ChangeLog | 6 +++ lily/include/stem-tremolo.hh | 4 +- lily/stem-tremolo.cc | 91 ++++++++++++++++++++-------------- lily/stem.cc | 2 +- scm/define-grobs.scm | 1 + scm/define-markup-commands.scm | 1 + scripts/convert-ly.py | 2 + 7 files changed, 68 insertions(+), 39 deletions(-) diff --git a/ChangeLog b/ChangeLog index cda828adfb..831ca7f495 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-02-10 Han-Wen Nienhuys + + * lily/stem-tremolo.cc (get_beam_translation): new function. + (calc_slope): new function. + (height): don't use real slope. + 2006-02-10 Jürgen Reuter * scm/define-grobs.scm (LigatureBracket): Maintenance bugfix: add diff --git a/lily/include/stem-tremolo.hh b/lily/include/stem-tremolo.hh index aa323ab09f..41d504a8c7 100644 --- a/lily/include/stem-tremolo.hh +++ b/lily/include/stem-tremolo.hh @@ -18,9 +18,11 @@ public: static bool has_interface (Grob *); DECLARE_SCHEME_CALLBACK (dim_callback, (SCM smob)); + DECLARE_SCHEME_CALLBACK (calc_slope, (SCM)); DECLARE_SCHEME_CALLBACK (print, (SCM)); DECLARE_SCHEME_CALLBACK (height, (SCM)); - static Stencil raw_stencil (Grob *); + static Stencil raw_stencil (Grob *, Real); + static Real get_beam_translation (Grob *me); }; #endif /* ABBREV_HH */ diff --git a/lily/stem-tremolo.cc b/lily/stem-tremolo.cc index f515f95908..03019d0237 100644 --- a/lily/stem-tremolo.cc +++ b/lily/stem-tremolo.cc @@ -32,44 +32,47 @@ Stem_tremolo::dim_callback (SCM e) return ly_interval2scm (Interval (-space, space)); } -MAKE_SCHEME_CALLBACK (Stem_tremolo, height, 1); + +MAKE_SCHEME_CALLBACK (Stem_tremolo, calc_slope, 1) SCM -Stem_tremolo::height (SCM smob) +Stem_tremolo::calc_slope (SCM smob) { Grob *me = unsmob_grob (smob); + Grob *stem = unsmob_grob (me->get_object ("stem")); + Spanner *beam = Stem::get_beam (stem); - /* TODO: fixme. uncached? */ - return ly_interval2scm (me->get_stencil () - ? me->get_stencil ()->extent (Y_AXIS) - : Interval()); + if (beam) + { + Real dy = 0; + SCM s = beam->get_property ("quantized-positions"); + if (is_number_pair (s)) + dy = - scm_to_double (scm_car (s)) + scm_to_double (scm_cdr (s)); + + Grob *s2 = Beam::last_visible_stem (beam); + Grob *s1 = Beam::first_visible_stem (beam); + + Grob *common = s1->common_refpoint (s2, X_AXIS); + Real dx = s2->relative_coordinate (common, X_AXIS) - + s1->relative_coordinate (common, X_AXIS); + + return scm_from_double (dx ? dy / dx : 0); + } + else + return scm_from_double (0.25); } -Stencil -Stem_tremolo::raw_stencil (Grob *me) +Real +Stem_tremolo::get_beam_translation (Grob *me) { Grob *stem = unsmob_grob (me->get_object ("stem")); Spanner *beam = Stem::get_beam (stem); - SCM slope = me->get_property ("slope"); - Real dydx = 0.25; - if (scm_is_number (slope)) - { - dydx = robust_scm2double (slope, 0.0); - } - else - { - if (beam) - { - Real dy = 0; - SCM s = beam->get_property ("positions"); - if (is_number_pair (s)) - dy = - scm_to_double (scm_car (s)) + scm_to_double (scm_cdr (s)); - - Real dx = Beam::last_visible_stem (beam)->relative_coordinate (0, X_AXIS) - - Beam::first_visible_stem (beam)->relative_coordinate (0, X_AXIS); - dydx = dx ? dy / dx : 0; - } - } + return beam ? Beam::get_beam_translation (beam) : 0.81; +} + +Stencil +Stem_tremolo::raw_stencil (Grob *me, Real slope) +{ Real ss = Staff_symbol_referencer::staff_space (me); Real thick = robust_scm2double (me->get_property ("beam-thickness"), 1); Real width = robust_scm2double (me->get_property ("beam-width"), 1); @@ -78,14 +81,10 @@ Stem_tremolo::raw_stencil (Grob *me) width *= ss; thick *= ss; - Stencil a (Lookup::beam (dydx, width, thick, blot)); - a.translate (Offset (-width * 0.5, width * 0.5 * dydx)); - - int tremolo_flags = 0; - SCM s = me->get_property ("flag-count"); - if (scm_is_number (s)) - tremolo_flags = scm_to_int (s); + Stencil a (Lookup::beam (slope, width, thick, blot)); + a.translate (Offset (-width * 0.5, width * 0.5 * slope)); + int tremolo_flags = robust_scm2int (me->get_property ("flag-count"), 0); if (!tremolo_flags) { programming_error ("no tremolo flags"); @@ -95,7 +94,7 @@ Stem_tremolo::raw_stencil (Grob *me) } /* Who the fuck is 0.81 ? --hwn. */ - Real beam_translation = beam ? Beam::get_beam_translation (beam) : 0.81; + Real beam_translation = get_beam_translation(me); Stencil mol; for (int i = 0; i < tremolo_flags; i++) @@ -107,6 +106,23 @@ Stem_tremolo::raw_stencil (Grob *me) return mol; } + + +MAKE_SCHEME_CALLBACK (Stem_tremolo, height, 1); +SCM +Stem_tremolo::height (SCM smob) +{ + Grob *me = unsmob_grob (smob); + + /* + Cannot use the real slope, since it looks at the Beam. + */ + Stencil s1 (raw_stencil (me, 0.35)); + + return ly_interval2scm (s1.extent (Y_AXIS)); +} + + MAKE_SCHEME_CALLBACK (Stem_tremolo, print, 1); SCM Stem_tremolo::print (SCM grob) @@ -129,7 +145,8 @@ Stem_tremolo::print (SCM grob) ? Beam::get_beam_translation (beam) : 0.81; - Stencil mol = raw_stencil (me); + Stencil mol = raw_stencil (me, robust_scm2double (me->get_property ("slope"), + 0.25)); Interval mol_ext = mol.extent (Y_AXIS); Real ss = Staff_symbol_referencer::staff_space (me); diff --git a/lily/stem.cc b/lily/stem.cc index 0f42976d32..c50b976310 100644 --- a/lily/stem.cc +++ b/lily/stem.cc @@ -331,7 +331,7 @@ Stem::calc_length (SCM smob) (Stem_tremolo::raw_stencil () looks at the beam.) --hwn */ Real minlen = 1.0 - + 2 * Stem_tremolo::raw_stencil (t_flag).extent (Y_AXIS).length () + + 2 * t_flag->extent (t_flag, Y_AXIS).length () / ss; if (durlog >= 3) diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm index 09bddf34d3..660eacd0a5 100644 --- a/scm/define-grobs.scm +++ b/scm/define-grobs.scm @@ -1543,6 +1543,7 @@ (Y-extent . ,ly:stem-tremolo::height) (stencil . ,ly:stem-tremolo::print) (X-extent . #f) + (slope . ,ly:stem-tremolo::calc-slope) (beam-width . 1.6) ; staff-space (beam-thickness . 0.48) ; staff-space (meta . ((class . Item) diff --git a/scm/define-markup-commands.scm b/scm/define-markup-commands.scm index 9f6ff63259..899e2c26f3 100644 --- a/scm/define-markup-commands.scm +++ b/scm/define-markup-commands.scm @@ -568,6 +568,7 @@ of the @code{#'direction} layout property." "Put @code{args} in a centered column. " (let* ((mols (map (lambda (x) (interpret-markup layout props x)) args)) (cmols (map (lambda (x) (ly:stencil-aligned-to x X CENTER)) mols))) + (stack-lines -1 0.0 (chain-assoc-get 'baseline-skip props) cmols))) (def-markup-command (vcenter layout props arg) (markup?) diff --git a/scripts/convert-ly.py b/scripts/convert-ly.py index b9cac64f59..d660dfd201 100644 --- a/scripts/convert-ly.py +++ b/scripts/convert-ly.py @@ -26,6 +26,8 @@ if os.environ.has_key ('LILYPONDPREFIX'): if os.path.exists (os.path.join (datadir, 'share/lilypond/@TOPLEVEL_VERSION@/')): datadir = os.path.join (datadir, 'share/lilypond/@TOPLEVEL_VERSION@/') +elif os.path.exists (os.path.join (datadir, 'share/lilypond/current/')): + datadir = os.path.join (datadir, 'share/lilypond/current/') sys.path.insert (0, os.path.join (datadir, 'python')) -- 2.39.5