]> git.donarmstrong.com Git - lilypond.git/blob - lily/hara-kiri-group-spanner.cc
patch::: 1.3.93.jcn2
[lilypond.git] / lily / hara-kiri-group-spanner.cc
1 /*
2   hara-kiri-vertical-group-spanner.cc -- implement Hara_kiri_group_spanner
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1998--2000 Jan Nieuwenhuizen <janneke@gnu.org>
7   Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
9
10 #include "axis-group-interface.hh"
11 #include "spanner.hh"
12 #include "hara-kiri-group-spanner.hh"
13 #include "debug.hh"
14 #include "item.hh"
15
16
17 Interval
18 Hara_kiri_group_spanner::y_extent(Score_element*me, Axis a)
19 {
20   assert (a == Y_AXIS);
21   consider_suicide (me);
22   return  Axis_group_interface::group_extent_callback (me, a);
23 }
24
25
26 bool
27 Hara_kiri_group_spanner::has_interface (Score_element*me)
28 {
29   return me->has_interface (ly_symbol2scm ("hara-kiri-spanner-interface"));
30 }
31
32 void 
33 Hara_kiri_group_spanner::add_interesting_item (Score_element* me,Score_element* n)
34 {
35   me->add_dependency (n);
36   Pointer_group_interface (me, "items-worth-living").add_element (n);
37 }
38
39 void
40 Hara_kiri_group_spanner::consider_suicide(Score_element*me)
41 {
42   SCM worth = me->get_elt_property ("items-worth-living");
43   if (gh_pair_p (worth))
44     return ;
45
46   Link_array<Score_element> childs = Axis_group_interface::get_children (me);
47   for (int i = 0; i < childs.size (); i++)
48     childs[i]->suicide ();
49
50
51   /*
52     very appropriate name here :-)
53    */
54   me->suicide ();
55 }
56
57
58
59 /*
60   We can't rely on offsets and dimensions of elements in a hara-kiri
61   group. Use a callback to make sure that hara-kiri has been done
62   before asking for offsets.  */
63 MAKE_SCHEME_CALLBACK(Hara_kiri_group_spanner,force_hara_kiri_callback,2);
64 SCM
65 Hara_kiri_group_spanner::force_hara_kiri_callback (SCM element_smob, SCM axis)
66 {
67   Score_element *me = unsmob_element (element_smob);
68   Axis a = (Axis) gh_scm2int (axis);
69   assert (a == Y_AXIS);
70   consider_suicide (me);
71   return gh_double2scm (0.0);
72 }
73
74
75 MAKE_SCHEME_CALLBACK(Hara_kiri_group_spanner,force_hara_kiri_in_parent_callback,2);
76 SCM
77 Hara_kiri_group_spanner::force_hara_kiri_in_parent_callback (SCM element_smob, SCM axis)
78 {
79   Score_element *daughter = unsmob_element (element_smob);
80   Axis a = (Axis) gh_scm2int (axis);
81   assert (a == Y_AXIS);
82   force_hara_kiri_callback (daughter->parent_l (a)->self_scm (), Y_AXIS);
83   return gh_double2scm ( 0.0);
84 }
85
86 void
87 Hara_kiri_group_spanner::add_element (Score_element * me, Score_element *e)
88 {
89   //  e->add_offset_callback (force_hara_kiri_in_parent_callback, Y_AXIS);
90   Axis_group_interface::add_element (me, e);
91 }
92
93
94 void
95 Hara_kiri_group_spanner::set_interface (Score_element*me)
96 {
97   me->add_offset_callback (Hara_kiri_group_spanner_force_hara_kiri_callback_proc, Y_AXIS);
98   me->set_interface (ly_symbol2scm ("hara-kiri-spanner-interface"));
99   me->set_extent_callback (Hara_kiri_group_spanner::y_extent, Y_AXIS);
100 }