X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fhara-kiri-group-spanner.cc;h=f477cd22e4cad5be5db83b3c701f99125d874410;hb=4f5b668a1d61ca95adb60d56f1c771748b5a6446;hp=25680db3ef26eca41d0d08886515c6dfb4bf1530;hpb=51f16c19ef686979a6a36709226ec6022eb86c0a;p=lilypond.git diff --git a/lily/hara-kiri-group-spanner.cc b/lily/hara-kiri-group-spanner.cc index 25680db3ef..f477cd22e4 100644 --- a/lily/hara-kiri-group-spanner.cc +++ b/lily/hara-kiri-group-spanner.cc @@ -3,55 +3,45 @@ source file of the GNU LilyPond music typesetter - (c) 1998--2000 Jan Nieuwenhuizen + (c) 1998--2004 Jan Nieuwenhuizen Han-Wen Nienhuys */ #include "axis-group-interface.hh" #include "spanner.hh" #include "hara-kiri-group-spanner.hh" -#include "debug.hh" +#include "warn.hh" #include "item.hh" -void -Hara_kiri_group_spanner::set_interface (Score_element*me) -{ - me->set_elt_property ("items-worth-living", SCM_EOL); - me->add_offset_callback (force_hara_kiri_callback, Y_AXIS); - me->set_interface (ly_symbol2scm ("hara-kiri-spanner-interface")); - me->set_extent_callback (Hara_kiri_group_spanner::y_extent, Y_AXIS); -} -Interval -Hara_kiri_group_spanner::y_extent(Score_element*me, Axis a) +MAKE_SCHEME_CALLBACK (Hara_kiri_group_spanner,y_extent,2); +SCM +Hara_kiri_group_spanner::y_extent (SCM element_smob, SCM scm_axis) { + Grob *me = unsmob_grob (element_smob); + Axis a = (Axis) scm_to_int (scm_axis); + assert (a == Y_AXIS); consider_suicide (me); - return Axis_group_interface::group_extent_callback (me, a); + return Axis_group_interface::group_extent_callback (me->self_scm (), scm_axis); } -bool -Hara_kiri_group_spanner::has_interface (Score_element*me) -{ - return me->has_interface (ly_symbol2scm ("hara-kiri-spanner-interface")); -} - -void -Hara_kiri_group_spanner::add_interesting_item (Score_element* me,Score_element* n) -{ - me->add_dependency (n); - Pointer_group_interface (me, "items-worth-living").add_element (n); -} - void -Hara_kiri_group_spanner::consider_suicide(Score_element*me) +Hara_kiri_group_spanner::consider_suicide (Grob*me) { - SCM worth = me->get_elt_property ("items-worth-living"); - if (gh_pair_p (worth)) + Spanner*sp = dynamic_cast (me); + SCM worth = me->get_property ("items-worth-living"); + if (scm_is_pair (worth)) return ; - Link_array childs = Axis_group_interface::get_children (me); + if (!to_boolean (me->get_property ("remove-first")) + && broken_spanner_index (sp) == 0) + { + return ; + } + + Link_array childs = Axis_group_interface::get_children (me); for (int i = 0; i < childs.size (); i++) childs[i]->suicide (); @@ -68,26 +58,52 @@ Hara_kiri_group_spanner::consider_suicide(Score_element*me) We can't rely on offsets and dimensions of elements in a hara-kiri group. Use a callback to make sure that hara-kiri has been done before asking for offsets. */ -Real -Hara_kiri_group_spanner::force_hara_kiri_callback (Score_element *elt, Axis a) +MAKE_SCHEME_CALLBACK (Hara_kiri_group_spanner,force_hara_kiri_callback,2); +SCM +Hara_kiri_group_spanner::force_hara_kiri_callback (SCM element_smob, SCM axis) { + Grob *me = unsmob_grob (element_smob); + Axis a = (Axis) scm_to_int (axis); assert (a == Y_AXIS); - consider_suicide (elt); - return 0.0; + consider_suicide (me); + return scm_make_real (0.0); } -Real -Hara_kiri_group_spanner::force_hara_kiri_in_parent_callback (Score_element*daughter, Axis a) +MAKE_SCHEME_CALLBACK (Hara_kiri_group_spanner,force_hara_kiri_in_parent_callback,2); +SCM +Hara_kiri_group_spanner::force_hara_kiri_in_parent_callback (SCM element_smob, SCM axis) { + Grob *daughter = unsmob_grob (element_smob); + Axis a = (Axis) scm_to_int (axis); assert (a == Y_AXIS); - force_hara_kiri_callback (daughter->parent_l (a), Y_AXIS); - return 0.0; + force_hara_kiri_callback (daughter->get_parent (a)->self_scm (), axis); + return scm_make_real (0.0); } void -Hara_kiri_group_spanner::add_element (Score_element * me, Score_element *e) +Hara_kiri_group_spanner::add_element (Grob * me, Grob *e) { // e->add_offset_callback (force_hara_kiri_in_parent_callback, Y_AXIS); Axis_group_interface::add_element (me, e); } + + + + + +void +Hara_kiri_group_spanner::add_interesting_item (Grob* me,Grob* n) +{ + me->add_dependency (n); + Pointer_group_interface::add_grob (me, ly_symbol2scm ("items-worth-living"),n); +} + + +ADD_INTERFACE (Hara_kiri_group_spanner,"hara-kiri-group-interface", + "A group spanner that keeps track of interesting items. If it " + "doesn't contain any after linebreaking, then it " + "will remove itself and all its children." + , + "items-worth-living remove-first"); +