From 0ada3837f91b0e14cf7c588351d020b88e50d604 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Wed, 2 Nov 2005 11:54:22 +0000 Subject: [PATCH] * lily/self-aligment-interface.cc (set_align_self): new function (set_center_parent): new function. * lily/side-position-interface.cc (set_axis): new function. * lily/new-fingering-engraver.cc (position_scripts): use drul for generic code. * scm/define-grob-properties.scm (all-user-grob-properties): remove [XY]-offset-callbacks add [YX]-offset --- ChangeLog | 8 +++ lily/beam.cc | 1 - lily/dynamic-engraver.cc | 3 +- lily/fingering-engraver.cc | 4 +- lily/grob-closure.cc | 87 +++++++++++++++++++++++ lily/grob-property.cc | 2 + lily/grob.cc | 89 +----------------------- lily/hara-kiri-engraver.cc | 2 +- lily/hara-kiri-group-spanner.cc | 6 -- lily/include/hara-kiri-group-spanner.hh | 1 - lily/include/self-alignment-interface.hh | 2 + lily/new-fingering-engraver.cc | 51 ++++++-------- lily/self-aligment-interface.cc | 26 +++++-- lily/side-position-interface.cc | 9 +-- lily/staff-symbol-referencer.cc | 2 + scm/define-grob-properties.scm | 3 + scm/define-grobs.scm | 1 + 17 files changed, 159 insertions(+), 138 deletions(-) create mode 100644 lily/grob-closure.cc diff --git a/ChangeLog b/ChangeLog index 4adb008565..1588f098f9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2005-11-02 Han-Wen Nienhuys + * lily/self-aligment-interface.cc (set_align_self): new function + (set_center_parent): new function. + + * lily/side-position-interface.cc (set_axis): new function. + + * lily/new-fingering-engraver.cc (position_scripts): use drul for + generic code. + * scm/define-grob-properties.scm (all-user-grob-properties): remove [XY]-offset-callbacks add [YX]-offset diff --git a/lily/beam.cc b/lily/beam.cc index 591af1a147..f779b2c87e 100644 --- a/lily/beam.cc +++ b/lily/beam.cc @@ -1403,7 +1403,6 @@ ADD_INTERFACE (Beam, "length-fraction " "least-squares-dy " "neutral-direction " - "position-callbacks " "positions " "quant-score " "shorten " diff --git a/lily/dynamic-engraver.cc b/lily/dynamic-engraver.cc index 3a0d5ba042..73cb94aaa8 100644 --- a/lily/dynamic-engraver.cc +++ b/lily/dynamic-engraver.cc @@ -398,8 +398,7 @@ Dynamic_engraver::acknowledge_note_column (Grob_info info) { Grob *head = heads[0]; script_->set_parent (head, X_AXIS); - script_->set_property ("self-X-offset", - Self_alignment_interface::centered_on_x_parent_proc); + Self_alignment_interface::set_center_parent (script_, X_AXIS); } } diff --git a/lily/fingering-engraver.cc b/lily/fingering-engraver.cc index 0997b19a0f..db90fd6801 100644 --- a/lily/fingering-engraver.cc +++ b/lily/fingering-engraver.cc @@ -90,8 +90,8 @@ Fingering_engraver::make_script (Direction d, Music *r, int i) fingerings for chords need different settings. */ Side_position_interface::set_axis (fingering, Y_AXIS); - fingering->set_property ("self-X-offset", Self_alignment_interface::x_aligned_on_self_proc); - fingering->set_property ("X-offset", Self_alignment_interface::centered_on_x_parent_proc); + Self_alignment_interface::set_align_self (fingering, X_AXIS); + Self_alignment_interface::set_center_parent (fingering, X_AXIS); // Hmm int priority = 200; diff --git a/lily/grob-closure.cc b/lily/grob-closure.cc new file mode 100644 index 0000000000..c1610e89d6 --- /dev/null +++ b/lily/grob-closure.cc @@ -0,0 +1,87 @@ +#include "grob.hh" +#include "simple-closure.hh" + +/* + UGH : todo -> to different file. + */ + +SCM +axis_offset_symbol (Axis a) +{ + return a == X_AXIS + ? ly_symbol2scm ("X-offset") + : ly_symbol2scm ("Y-offset"); +} + +SCM +axis_parent_positioning (Axis a) +{ + return (a == X_AXIS) + ? Grob::x_parent_positioning_proc + : Grob::y_parent_positioning_proc; +} + + + +/* + Replace + + (orig-proc GROB) + + by + + (+ (PROC GROB) (orig-proc GROB)) + +*/ +void +add_offset_callback (Grob *g, SCM proc, Axis a) +{ + SCM data = g->get_property_data (axis_offset_symbol (a)); + if (ly_is_procedure (data)) + 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)) + g->internal_set_property (axis_offset_symbol (a), + proc); + else + { + SCM plus = ly_lily_module_constant ("+"); + SCM expr = scm_list_3 (plus, + ly_make_simple_closure (scm_list_1 (proc)), + data); + g->internal_set_property (axis_offset_symbol (a), + ly_make_simple_closure (expr)); + } +} + + +/* + replace + + (orig-proc GROB) + + by + + (PROC GROB (orig-proc GROB)) + +*/ +void +chain_offset_callback (Grob *g, SCM proc, Axis a) +{ + SCM data = g->get_property_data (axis_offset_symbol (a)); + + if (ly_is_procedure (data)) + 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); + + SCM expr = scm_list_2 (proc, data); + g->internal_set_property (axis_offset_symbol (a), + + // twice: one as a wrapper for grob property routines, + // once for the actual delayed binding. + ly_make_simple_closure (ly_make_simple_closure (expr))); +} diff --git a/lily/grob-property.cc b/lily/grob-property.cc index 38306c536b..c9d0ea8aae 100644 --- a/lily/grob-property.cc +++ b/lily/grob-property.cc @@ -60,6 +60,7 @@ Grob::internal_set_property (SCM sym, SCM v) if (do_internal_type_checking_global) { if (!ly_is_procedure (v) + && !is_simple_closure (v) && !type_check_assignment (sym, v, ly_symbol2scm ("backend-type?"))) abort (); check_interfaces_for_property (this, sym); @@ -87,6 +88,7 @@ Grob::get_property_data (SCM sym) const { SCM val = scm_cdr (handle); if (!ly_is_procedure (val) + && !is_simple_closure (val) && !type_check_assignment (sym, val, ly_symbol2scm ("backend-type?"))) abort (); diff --git a/lily/grob.cc b/lily/grob.cc index 89be56aa19..7cbdac4a81 100644 --- a/lily/grob.cc +++ b/lily/grob.cc @@ -630,9 +630,9 @@ ADD_INTERFACE (Grob, "grob-interface", /* properties */ "X-extent " - "X-offset-callbacks " + "X-offset " "Y-extent " - "Y-offset-callbacks " + "Y-offset " "after-line-breaking " "axis-group-parent-X " "axis-group-parent-Y " @@ -653,88 +653,3 @@ ADD_INTERFACE (Grob, "grob-interface", "transparent " ); - -#include "simple-closure.hh" - -/* - UGH : todo -> to different file. - */ - -SCM -axis_offset_symbol (Axis a) -{ - return a == X_AXIS - ? ly_symbol2scm ("X-offset") - : ly_symbol2scm ("Y-offset"); -} - -SCM -axis_parent_positioning (Axis a) -{ - return (a == X_AXIS) - ? Grob::x_parent_positioning_proc - : Grob::y_parent_positioning_proc; -} - - - -/* - Replace - - (orig-proc GROB) - - by - - (+ (PROC GROB) (orig-proc GROB)) - -*/ -void -add_offset_callback (Grob *g, SCM proc, Axis a) -{ - SCM data = g->get_property_data (axis_offset_symbol (a)); - - if (ly_is_procedure (data)) - 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); - - SCM plus = ly_lily_module_constant ("+"); - SCM expr = scm_list_3 (plus, - ly_make_simple_closure (scm_list_1 (proc)), - data); - g->internal_set_property (axis_offset_symbol (a), - ly_make_simple_closure (expr)); -} - - -/* - replace - - (orig-proc GROB) - - by - - (PROC GROB (orig-proc GROB)) - -*/ -void -chain_offset_callback (Grob *g, SCM proc, Axis a) -{ - SCM data = g->get_property_data (axis_offset_symbol (a)); - - if (ly_is_procedure (data)) - 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); - - SCM expr = scm_list_2 (proc, data); - g->internal_set_property (axis_offset_symbol (a), - - // twice: one as a wrapper for grob property routines, - // once for the actual delayed binding. - ly_make_simple_closure (ly_make_simple_closure (expr))); -} diff --git a/lily/hara-kiri-engraver.cc b/lily/hara-kiri-engraver.cc index a704fa91f8..ea0356526d 100644 --- a/lily/hara-kiri-engraver.cc +++ b/lily/hara-kiri-engraver.cc @@ -46,7 +46,7 @@ Hara_kiri_engraver::start_translation_timestep () void Hara_kiri_engraver::add_element (Grob *e) { - Hara_kiri_group_spanner::add_element (staffline_, e); + Axis_group_engraver::add_element (e); } Spanner * diff --git a/lily/hara-kiri-group-spanner.cc b/lily/hara-kiri-group-spanner.cc index 3e2417f8eb..9a205ffd8e 100644 --- a/lily/hara-kiri-group-spanner.cc +++ b/lily/hara-kiri-group-spanner.cc @@ -81,12 +81,6 @@ Hara_kiri_group_spanner::force_hara_kiri_in_parent_callback (SCM smob, SCM axis) return scm_from_double (0.0); } -void -Hara_kiri_group_spanner::add_element (Grob *me, Grob *e) -{ - Axis_group_interface::add_element (me, e); -} - void Hara_kiri_group_spanner::add_interesting_item (Grob *me, Grob *n) { diff --git a/lily/include/hara-kiri-group-spanner.hh b/lily/include/hara-kiri-group-spanner.hh index a14f8feeac..ff4ddae2aa 100644 --- a/lily/include/hara-kiri-group-spanner.hh +++ b/lily/include/hara-kiri-group-spanner.hh @@ -18,7 +18,6 @@ public: DECLARE_SCHEME_CALLBACK (force_hara_kiri_callback, (SCM, SCM)); DECLARE_SCHEME_CALLBACK (y_extent, (SCM smob)); DECLARE_SCHEME_CALLBACK (force_hara_kiri_in_parent_callback, (SCM, SCM)); - static void add_element (Grob *me, Grob *e); static bool has_interface (Grob *); static void consider_suicide (Grob *me); static void add_interesting_item (Grob *me, Grob *n); diff --git a/lily/include/self-alignment-interface.hh b/lily/include/self-alignment-interface.hh index c9438a764b..bd1f1096c4 100644 --- a/lily/include/self-alignment-interface.hh +++ b/lily/include/self-alignment-interface.hh @@ -18,6 +18,8 @@ struct Self_alignment_interface static SCM aligned_on_self (Grob *me, Axis a); static SCM centered_on_parent (Grob *me, Axis a); static SCM aligned_on_parent (Grob *me, Axis a); + static void set_center_parent (Grob *me, Axis a); + static void set_align_self (Grob *me, Axis a); DECLARE_SCHEME_CALLBACK (x_aligned_on_self, (SCM element)); DECLARE_SCHEME_CALLBACK (y_aligned_on_self, (SCM element)); diff --git a/lily/new-fingering-engraver.cc b/lily/new-fingering-engraver.cc index 0285faec33..028febae81 100644 --- a/lily/new-fingering-engraver.cc +++ b/lily/new-fingering-engraver.cc @@ -267,43 +267,36 @@ New_fingering_engraver::position_scripts (SCM orientations, f->set_parent (ft.head_, X_AXIS); f->set_parent (ft.head_, Y_AXIS); - f->set_property ("self-Y-offset",Self_alignment_interface::y_aligned_on_self_proc); - f->set_property ("Y-offset", Self_alignment_interface::centered_on_y_parent_proc); - f->set_property ("X-offset", Side_position_interface::x_aligned_side_proc); + + Self_alignment_interface::set_align_self (f, Y_AXIS); + Self_alignment_interface::set_center_parent (f, Y_AXIS); + Side_position_interface::set_axis (f, X_AXIS); f->set_property ("direction", scm_from_int (hordir)); } int finger_prio = 200; - for (int i = 0; i < up.size (); i++) - { - Finger_tuple ft = up[i]; - Grob *f = ft.script_; - f->set_parent (ft.head_, X_AXIS); - f->set_property ("script-priority", - scm_from_int (finger_prio + ft.position_)); - - f->set_property ("self-X-offset", Self_alignment_interface::x_aligned_on_self_proc); - f->set_property ("Y-offset", Side_position_interface::y_aligned_side_proc); - f->set_property ("X-offset", Self_alignment_interface::centered_on_x_parent_proc); - - f->set_property ("direction", scm_from_int (UP)); - } - for (int i = 0; i < down.size (); i++) + Direction d = DOWN; + Drul_array< Array > vertical (down, up); + do { - Finger_tuple ft = down[i]; - Grob *f = ft.script_; - f->set_parent (ft.head_, X_AXIS); - f->set_property ("script-priority", - scm_from_int (finger_prio + down.size () - ft.position_)); - - f->set_property ("self-X-offset", Self_alignment_interface::x_aligned_on_self_proc); - f->set_property ("X-offset", Self_alignment_interface::centered_on_x_parent_proc); - f->set_property ("Y-offset", Side_position_interface::y_aligned_side_proc); - - f->set_property ("direction", scm_from_int (DOWN)); + for (int i = 0; i < vertical[d].size (); i++) + { + Finger_tuple ft = vertical[d][i]; + Grob *f = ft.script_; + f->set_parent (ft.head_, X_AXIS); + f->set_property ("script-priority", + scm_from_int (finger_prio + d * ft.position_)); + + Self_alignment_interface::set_align_self (f, X_AXIS); + Self_alignment_interface::set_center_parent (f, X_AXIS); + Side_position_interface::set_axis (f, Y_AXIS); + + f->set_property ("direction", scm_from_int (d)); + } } + while (flip (&d) != DOWN); } void diff --git a/lily/self-aligment-interface.cc b/lily/self-aligment-interface.cc index ed66d30ef1..17ec37b91f 100644 --- a/lily/self-aligment-interface.cc +++ b/lily/self-aligment-interface.cc @@ -110,23 +110,39 @@ Self_alignment_interface::aligned_on_parent (Grob *me, Axis a) return scm_from_double (x); } +void +Self_alignment_interface::set_center_parent (Grob *me, Axis a) +{ + add_offset_callback (me, + (a==X_AXIS) ? centered_on_x_parent_proc : centered_on_y_parent_proc, + a); +} + +void +Self_alignment_interface::set_align_self (Grob *me, Axis a) +{ + add_offset_callback (me, + (a==X_AXIS) ? x_aligned_on_self_proc : y_aligned_on_self_proc, + a); +} + ADD_INTERFACE (Self_alignment_interface, "self-alignment-interface", "Position this object on itself and/or on its parent. To this end, the following functions " " are provided: \n" "@table @code \n" - "@item Self_alignment_interface::aligned_on_self\n" + "@item Self_alignment_interface::[xy]_aligned_on_self\n" " Align self on reference point, using @code{self-alignment-X} and " "@code{self-alignment-Y}." - "@item Self_alignment_interface::aligned_on_parent\n" - "@item Self_alignment_interface::centered_on_parent\n" + "@item Self_alignment_interface::aligned_on_[xy]_parent\n" + "@item Self_alignment_interface::centered_on_[xy]_parent\n" " Shift the object so its own reference point is centered on the " " extent of the parent \n" - "@item Self_alignment_interface::centered_on_other_axis_parent\n" - " For X-axis, center on the Y-parent, and vice versa.\n " "@end table\n", /* porperties */ "self-alignment-X " + "self-X-offset " + "self-Y-offset " "self-alignment-Y "); diff --git a/lily/side-position-interface.cc b/lily/side-position-interface.cc index 498818f447..4543331568 100644 --- a/lily/side-position-interface.cc +++ b/lily/side-position-interface.cc @@ -212,10 +212,11 @@ Side_position_interface::aligned_side (Grob*me, Axis a) void Side_position_interface::set_axis (Grob *me, Axis a) { - me->internal_set_property (axis_offset_symbol (a), - (a==X_AXIS) - ? x_aligned_side_proc - : y_aligned_side_proc); + add_offset_callback (me, + (a==X_AXIS) + ? x_aligned_side_proc + : y_aligned_side_proc, + a); } // ugh. doesn't catch all variants. diff --git a/lily/staff-symbol-referencer.cc b/lily/staff-symbol-referencer.cc index 1a729e1e0f..22fb460ed1 100644 --- a/lily/staff-symbol-referencer.cc +++ b/lily/staff-symbol-referencer.cc @@ -169,5 +169,7 @@ ADD_INTERFACE (Staff_symbol_referencer, "staff-symbol-referencer-interface", "symbol. " "These usually have @code{Staff_symbol_referencer::callback} " "in their @code{Y-offset-callbacks}. ", + + /* properties */ "staff-position"); diff --git a/scm/define-grob-properties.scm b/scm/define-grob-properties.scm index b8c25f9bcd..4fcac63c7c 100644 --- a/scm/define-grob-properties.scm +++ b/scm/define-grob-properties.scm @@ -25,6 +25,8 @@ (X-offset ,number? "The horizontal amount that this object is moved relative to its X-parent") (Y-offset ,number? "The vertical amount that this object is moved relative to its X-parent") + (self-X-offset ,number? "") + (self-Y-offset ,number? "") (accidentals ,list? "List of alteration numbers") (alteration-alist ,list? "List of @code{(@var{pitch} . @var{accidental})} pairs for key signature.") @@ -539,6 +541,7 @@ entries @code{name} and @code{interfaces}.") (chord-tremolo ,boolean? "if set, this beam is a tremolo. ") (begin-of-line-visible ,boolean? "Used for marking ChordNames that should only show changes.") + (quantize-position ,boolean? "If set, a vertical alignment is aligned to be within staff spaces.") (quant-score ,string? "Beam quanting score -- can be stored for debugging") diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm index 0be194a4b3..8ae9054ac6 100644 --- a/scm/define-grobs.scm +++ b/scm/define-grobs.scm @@ -1840,6 +1840,7 @@ (X-extent . ,Axis_group_interface::width) (meta . ((class . Spanner) (interfaces . (axis-group-interface + hara-kiri-group-interface vertically-spaceable-interface)))))) (VocalName -- 2.39.5