From 73d087a6589038ac21efe802fe6d51cafa411749 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Tue, 3 Oct 2006 12:00:17 +0000 Subject: [PATCH] * lily/slur.cc (outside_slur_callback): make offset_scm optional. * lily/beam.cc (rest_collision_callback): make prev_offset optional. * lily/grob-closure.cc (chain_offset_callback): don't pass 0 but SCM_UNDEFINED for non-existent data. * lily/side-position-interface.cc (general_side_position): allow optional current_offset argument for chaining, so combinations of side-position and outside slur callback don't add up. Fixes issue #92. --- ChangeLog | 16 ++++- lily/beam.cc | 2 +- lily/context.cc | 9 ++- lily/dot-column.cc | 2 +- lily/grob-closure.cc | 11 ++- lily/include/lily-guile-macros.hh | 8 +-- lily/include/side-position-interface.hh | 9 +-- lily/music-function.cc | 2 - lily/prob.cc | 6 +- lily/rest-collision.cc | 5 +- lily/side-position-interface.cc | 90 ++++++++++++++++--------- lily/simple-closure.cc | 2 +- lily/slur.cc | 8 +-- lily/smobs.cc | 2 + 14 files changed, 110 insertions(+), 62 deletions(-) diff --git a/ChangeLog b/ChangeLog index 617631eda3..2d7d3e60cf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,20 @@ 2006-10-03 Han-Wen Nienhuys - * lily/pango-font.cc (pango_item_string_stencil): use - logical_rect. This prevents spaces after words from disappearing. + * lily/slur.cc (outside_slur_callback): make offset_scm optional. + + * lily/beam.cc (rest_collision_callback): make prev_offset optional. + + * lily/grob-closure.cc (chain_offset_callback): don't pass 0 but + SCM_UNDEFINED for non-existent data. + * lily/side-position-interface.cc (general_side_position): allow + optional current_offset argument for chaining, so combinations of side-position + and outside slur callback don't add up. Fixes issue #92. + + * lily/pango-font.cc (pango_item_string_stencil): use + logical_rect. This prevents spaces after words from disappearing, + issue #72. + * VERSION: release 2.9.20 2006-10-02 Han-Wen Nienhuys diff --git a/lily/beam.cc b/lily/beam.cc index c52b6f14f9..4a59a069be 100644 --- a/lily/beam.cc +++ b/lily/beam.cc @@ -1301,7 +1301,7 @@ Beam::last_visible_stem (Grob *me) rest -> stem -> beam -> interpolate_y_position () */ -MAKE_SCHEME_CALLBACK (Beam, rest_collision_callback, 2); +MAKE_SCHEME_CALLBACK_WITH_OPTARGS (Beam, rest_collision_callback, 2, 1); SCM Beam::rest_collision_callback (SCM smob, SCM prev_offset) { diff --git a/lily/context.cc b/lily/context.cc index d8e5b7bfba..629dfadc4f 100644 --- a/lily/context.cc +++ b/lily/context.cc @@ -469,15 +469,14 @@ Context::add_alias (SCM sym) } void +Context::internal_set_property (SCM sym, SCM val #ifndef NDEBUG -Context::internal_set_property (SCM sym, SCM val, char const *file, int line, char const *fun) + , char const *file, int line, char const *fun +#endif + ) { if (do_internal_type_checking_global) assert (type_check_assignment (sym, val, ly_symbol2scm ("translation-type?"))); -#else -Context::internal_set_property (SCM sym, SCM val) -{ -#endif properties_dict ()->set (sym, val); } diff --git a/lily/dot-column.cc b/lily/dot-column.cc index ac76bd4a16..a4b13be79f 100644 --- a/lily/dot-column.cc +++ b/lily/dot-column.cc @@ -51,7 +51,7 @@ Dot_column::side_position (SCM smob) } } - return Side_position_interface::x_aligned_side (smob); + return Side_position_interface::x_aligned_side (smob, SCM_EOL); } struct Dot_position diff --git a/lily/grob-closure.cc b/lily/grob-closure.cc index 9dddc0616f..5e4035f7e8 100644 --- a/lily/grob-closure.cc +++ b/lily/grob-closure.cc @@ -75,9 +75,14 @@ chain_offset_callback (Grob *g, SCM proc, Axis a) data = ly_make_simple_closure (scm_list_1 (data)); else if (is_simple_closure (data)) data = simple_closure_expression (data); - else if (!scm_is_number (data)) - data = scm_from_int (0); - + else + /* + Data may be nonnumber. In that case, it is assumed to be + undefined. + */ + + data = SCM_UNDEFINED; + SCM expr = scm_list_2 (proc, data); g->set_property (axis_offset_symbol (a), diff --git a/lily/include/lily-guile-macros.hh b/lily/include/lily-guile-macros.hh index 77c4597364..3f72caddc4 100644 --- a/lily/include/lily-guile-macros.hh +++ b/lily/include/lily-guile-macros.hh @@ -21,11 +21,12 @@ #define SCM_UNPACK(x) (x) #endif -#if (__GNUC__ > 2) /* Unreliable with gcc-2.x FIXME: should add check for x86 as well? */ #define CACHE_SYMBOLS -#endif + + + #ifdef CACHE_SYMBOLS @@ -41,8 +42,7 @@ scm_or_str2symbol (SCM s) { return s; } "fooo" is a constant string. This is done at the cost of one static variable per ly_symbol2scm() use, and one boolean evaluation for every call. - - The overall speedup of lily is about 5% on a run of wtk1-fugue2. */ + */ #define ly_symbol2scm(x) \ ({ \ static SCM cached; \ diff --git a/lily/include/side-position-interface.hh b/lily/include/side-position-interface.hh index ea7655fa62..36b1e8fdf5 100644 --- a/lily/include/side-position-interface.hh +++ b/lily/include/side-position-interface.hh @@ -23,13 +23,14 @@ public: DECLARE_SCHEME_CALLBACK (y_aligned_on_support_refpoints, (SCM element)); DECLARE_SCHEME_CALLBACK (pure_y_aligned_on_support_refpoints, (SCM element, SCM start, SCM end)); - DECLARE_SCHEME_CALLBACK (x_aligned_side, (SCM element)); - DECLARE_SCHEME_CALLBACK (y_aligned_side, (SCM element)); + DECLARE_SCHEME_CALLBACK (x_aligned_side, (SCM element, SCM current)); + DECLARE_SCHEME_CALLBACK (y_aligned_side, (SCM element, SCM current)); DECLARE_SCHEME_CALLBACK (pure_y_aligned_side, (SCM element, SCM start, SCM end)); - static SCM aligned_side (Grob*me, Axis a, bool pure, int start, int end); + static SCM aligned_side (Grob*me, Axis a, bool pure, int start, int end, Real *current_off_ptr); - static SCM general_side_position (Grob *, Axis, bool, bool pure, int start, int end); + static SCM general_side_position (Grob *, Axis, bool, bool my_extents, + bool pure, int start, int end, Real *current_off); static Axis get_axis (Grob *); static void set_axis (Grob *, Axis); static bool has_interface (Grob *); diff --git a/lily/music-function.cc b/lily/music-function.cc index c9b9a07658..6795ca67d4 100644 --- a/lily/music-function.cc +++ b/lily/music-function.cc @@ -33,8 +33,6 @@ LY_DEFINE (ly_make_music_function, "ly:make-music-function", 2, 0, 0, "Its arguments. @code{signature} is a list containing either " "@code{ly:music?} predicates or other type predicates.") { - extern SCM ly_music_p_proc; - scm_set_object_property_x (func, ly_symbol2scm ("music-function-signature"), signature); diff --git a/lily/prob.cc b/lily/prob.cc index eecd1a4446..bff24e5ade 100644 --- a/lily/prob.cc +++ b/lily/prob.cc @@ -99,11 +99,11 @@ Prob::internal_get_property (SCM sym) const } void +Prob::internal_set_property (SCM sym, SCM val #ifndef NDEBUG -Prob::internal_set_property (SCM sym, SCM val, char const *file, int line, char const *fun) -#else -Prob::internal_set_property (SCM sym, SCM val) + , char const *file, int line, char const *fun #endif + ) { if (do_internal_type_checking_global) type_check_assignment (sym, val); diff --git a/lily/rest-collision.cc b/lily/rest-collision.cc index a2c9fa63c0..959bf2156b 100644 --- a/lily/rest-collision.cc +++ b/lily/rest-collision.cc @@ -40,7 +40,7 @@ Rest_collision::force_shift_callback (SCM smob) return scm_from_double (0.0); } -MAKE_SCHEME_CALLBACK (Rest_collision, force_shift_callback_rest, 2); +MAKE_SCHEME_CALLBACK_WITH_OPTARGS (Rest_collision, force_shift_callback_rest, 2, 1); SCM Rest_collision::force_shift_callback_rest (SCM rest, SCM offset) { @@ -51,7 +51,8 @@ Rest_collision::force_shift_callback_rest (SCM rest, SCM offset) translate REST; we need the result of this translation later on, while the offset probably still is 0/calculation-in-progress. */ - rest_grob->translate_axis (scm_to_double (offset), Y_AXIS); + if (scm_is_number (offset)) + rest_grob->translate_axis (scm_to_double (offset), Y_AXIS); if (Note_column::has_interface (parent)) force_shift_callback (parent->self_scm ()); diff --git a/lily/side-position-interface.cc b/lily/side-position-interface.cc index 52e9ba5221..38880cb52e 100644 --- a/lily/side-position-interface.cc +++ b/lily/side-position-interface.cc @@ -46,10 +46,15 @@ Side_position_interface::get_direction (Grob *me) } /* Put the element next to the support, optionally taking in - account the extent of the support. */ + account the extent of the support. + + Does not take into account the extent of ME. +*/ SCM Side_position_interface::general_side_position (Grob *me, Axis a, bool use_extents, - bool pure, int start, int end) + bool include_my_extent, + bool pure, int start, int end, + Real *current_offset) { Real ss = Staff_symbol_referencer::staff_space (me); @@ -102,6 +107,25 @@ Side_position_interface::general_side_position (Grob *me, Axis a, bool use_exten && dir && total_off * dir < minimum_space) total_off = minimum_space * dir; + + if (include_my_extent) + { + Interval iv = me->maybe_pure_extent (me, a, pure, start, end); + if (!iv.is_empty ()) + { + if (!dir) + { + programming_error ("direction unknown, but aligned-side wanted"); + dir = DOWN; + } + total_off += -iv[-dir]; + } + } + + if (current_offset) + total_off = dir * max (dir * total_off, + dir * (*current_offset)); + /* FIXME: 1000 should relate to paper size. */ if (fabs (total_off) > 1000) @@ -122,60 +146,64 @@ MAKE_SCHEME_CALLBACK (Side_position_interface, y_aligned_on_support_refpoints, 1 SCM Side_position_interface::y_aligned_on_support_refpoints (SCM smob) { - return general_side_position (unsmob_grob (smob), Y_AXIS, false, false, 0, 0); + return general_side_position (unsmob_grob (smob), Y_AXIS, false, false, false, 0, 0, 0); } MAKE_SCHEME_CALLBACK (Side_position_interface, pure_y_aligned_on_support_refpoints, 3); SCM Side_position_interface::pure_y_aligned_on_support_refpoints (SCM smob, SCM start, SCM end) { - return general_side_position (unsmob_grob (smob), Y_AXIS, false, - true, scm_to_int (start), scm_to_int (end)); + return general_side_position (unsmob_grob (smob), Y_AXIS, false, false, + true, scm_to_int (start), scm_to_int (end), 0); } /* Position next to support, taking into account my own dimensions and padding. */ +SCM +axis_aligned_side_helper (SCM smob, Axis a, bool pure, int start, int end, SCM current_off_scm) +{ + Real r; + Real *current_off_ptr = 0; + if (scm_is_number (current_off_scm)) + { + r = scm_to_double (current_off_scm); + current_off_ptr = &r; + } + + return Side_position_interface::aligned_side (unsmob_grob (smob), a, pure, start, end, current_off_ptr); +} + -MAKE_SCHEME_CALLBACK (Side_position_interface, x_aligned_side, 1); +MAKE_SCHEME_CALLBACK_WITH_OPTARGS (Side_position_interface, x_aligned_side, 2, 1); SCM -Side_position_interface::x_aligned_side (SCM smob) +Side_position_interface::x_aligned_side (SCM smob, SCM current_off) { - return aligned_side (unsmob_grob (smob), X_AXIS, false, 0, 0); + return axis_aligned_side_helper (smob, X_AXIS, false, 0, 0, current_off); } -MAKE_SCHEME_CALLBACK (Side_position_interface, y_aligned_side, 1); +MAKE_SCHEME_CALLBACK_WITH_OPTARGS (Side_position_interface, y_aligned_side, 2, 1); SCM -Side_position_interface::y_aligned_side (SCM smob) +Side_position_interface::y_aligned_side (SCM smob, SCM current_off) { - return aligned_side (unsmob_grob (smob), Y_AXIS, false, 0, 0); + return axis_aligned_side_helper (smob, Y_AXIS, false, 0, 0, current_off); } MAKE_SCHEME_CALLBACK (Side_position_interface, pure_y_aligned_side, 3); SCM Side_position_interface::pure_y_aligned_side (SCM smob, SCM start, SCM end) { - return aligned_side (unsmob_grob (smob), Y_AXIS, true, scm_to_int (start), scm_to_int (end)); + return aligned_side (unsmob_grob (smob), Y_AXIS, true, scm_to_int (start), scm_to_int (end), 0); } SCM -Side_position_interface::aligned_side (Grob *me, Axis a, bool pure, int start, int end) +Side_position_interface::aligned_side (Grob *me, Axis a, bool pure, int start, int end, + Real *current_off) { Direction dir = get_grob_direction (me); - Real o = scm_to_double (general_side_position (me, a, true, pure, start, end)); - Interval iv = me->maybe_pure_extent (me, a, pure, start, end); - - if (!iv.is_empty ()) - { - if (!dir) - { - programming_error ("direction unknown, but aligned-side wanted"); - dir = DOWN; - } - o += -iv[-dir]; - } + Real o = scm_to_double (general_side_position (me, a, true, true, pure, start, end, current_off)); /* Maintain a minimum distance to the staff. This is similar to side @@ -206,6 +234,8 @@ Side_position_interface::aligned_side (Grob *me, Axis a, bool pure, int start, i } else if (scm_is_number (me->get_property ("staff-padding"))) { + Interval iv = me->maybe_pure_extent (me, a, pure, start, end); + Real padding = Staff_symbol_referencer::staff_space (me) * scm_to_double (me->get_property ("staff-padding")); @@ -226,11 +256,11 @@ Side_position_interface::set_axis (Grob *me, Axis a) if (!scm_is_number (me->get_property ("side-axis"))) { me->set_property ("side-axis", scm_from_int (a)); - add_offset_callback (me, - (a==X_AXIS) - ? x_aligned_side_proc - : y_aligned_side_proc, - a); + chain_offset_callback (me, + (a==X_AXIS) + ? x_aligned_side_proc + : y_aligned_side_proc, + a); } } Axis diff --git a/lily/simple-closure.cc b/lily/simple-closure.cc index db19cfc38c..77764b2bc6 100644 --- a/lily/simple-closure.cc +++ b/lily/simple-closure.cc @@ -63,7 +63,7 @@ evaluate_with_simple_closure (SCM delayed_argument, } else // ugh. deviation from standard. Should print error? - return evaluate_args (delayed_argument, scm_cdr (expr)); + return evaluate_args (delayed_argument, scm_cdr (expr)); assert (false); return SCM_EOL; diff --git a/lily/slur.cc b/lily/slur.cc index c78a066d06..d8c81f7836 100644 --- a/lily/slur.cc +++ b/lily/slur.cc @@ -186,7 +186,7 @@ Slur::add_extra_encompass (Grob *me, Grob *n) } -MAKE_SCHEME_CALLBACK (Slur, outside_slur_callback, 2); +MAKE_SCHEME_CALLBACK_WITH_OPTARGS (Slur, outside_slur_callback, 2, 1); SCM Slur::outside_slur_callback (SCM grob, SCM offset_scm) { @@ -216,8 +216,8 @@ Slur::outside_slur_callback (SCM grob, SCM offset_scm) Interval yext = robust_relative_extent (script, cy, Y_AXIS); Interval xext = robust_relative_extent (script, cx, X_AXIS); - yext.translate (robust_scm2double (offset_scm, 0)); - + Real offset = robust_scm2double (offset_scm, 0); + yext.translate (offset); /* FIXME: slur property, script property? */ Real slur_padding = robust_scm2double (script->get_property ("slur-padding"), @@ -258,7 +258,7 @@ Slur::outside_slur_callback (SCM grob, SCM offset_scm) avoidance_offset = dir * (max (dir * avoidance_offset, dir * (ys[k] - yext[-dir] + dir * slur_padding))); - return scm_from_double (scm_to_double (offset_scm) + avoidance_offset); + return scm_from_double (offset + avoidance_offset); } /* diff --git a/lily/smobs.cc b/lily/smobs.cc index 9629ed45ee..fff178ccb2 100644 --- a/lily/smobs.cc +++ b/lily/smobs.cc @@ -44,6 +44,7 @@ protect_smob (SCM smob, SCM *prot_cons) prot); *prot_cons = prot; #else + (void) prot_cons; scm_gc_protect_object (smob); #endif } @@ -52,6 +53,7 @@ void unprotect_smob (SCM smob, SCM *prot_cons) { #if 1 + (void) prot_cons; scm_gc_unprotect_object (smob); #else SCM next = scm_cdr (*prot_cons); -- 2.39.2