2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2010--2015 Joe Neeman <joeneeman@gmail.com>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
21 #include "dispatcher.hh"
22 #include "engraver.hh"
24 #include "grob-array.hh"
26 #include "translator.icc"
28 class Keep_alive_together_engraver: public Engraver
30 vector<Grob *> group_spanners_;
33 TRANSLATOR_DECLARATIONS (Keep_alive_together_engraver);
34 void acknowledge_hara_kiri_group_spanner (Grob_info);
36 virtual void finalize ();
39 Keep_alive_together_engraver::Keep_alive_together_engraver ()
44 Keep_alive_together_engraver::acknowledge_hara_kiri_group_spanner (Grob_info i)
46 group_spanners_.push_back (i.grob ());
50 Keep_alive_together_engraver::finalize ()
52 for (vsize i = 0; i < group_spanners_.size (); ++i)
54 SCM this_layer = group_spanners_[i]->get_property ("remove-layer");
55 if (scm_is_false (this_layer))
58 SCM live_scm = Grob_array::make_array ();
59 Grob_array *live = unsmob<Grob_array> (live_scm);
60 SCM dead_scm = Grob_array::make_array ();
61 Grob_array *dead = unsmob<Grob_array> (dead_scm);
63 for (vsize j = 0; j < group_spanners_.size (); ++j)
67 SCM that_layer = group_spanners_[j]->get_property ("remove-layer");
68 if (scm_is_false (that_layer))
70 if (!scm_is_integer (this_layer))
72 // Unspecified layers are kept alive by anything else
73 live->add (group_spanners_[j]);
76 // an explicit layer is only affected by explicit layers
77 if (!scm_is_integer (that_layer))
79 if (scm_is_true (scm_num_eq_p (that_layer, this_layer)))
80 live->add (group_spanners_[j]);
81 else if (scm_is_true (scm_less_p (that_layer, this_layer)))
82 dead->add (group_spanners_[j]);
85 group_spanners_[i]->set_object ("keep-alive-with", live_scm);
87 group_spanners_[i]->set_object ("make-dead-when", dead_scm);
93 Keep_alive_together_engraver::boot ()
95 ADD_ACKNOWLEDGER (Keep_alive_together_engraver, hara_kiri_group_spanner);
98 ADD_TRANSLATOR (Keep_alive_together_engraver,
100 "This engraver collects all @code{Hara_kiri_group_spanner}s "
101 "that are created in contexts at or below its own. "
102 "These spanners are then tied together so that one will "
103 "be removed only if all are removed. For example, "
104 "if a @code{StaffGroup} uses this engraver, then the staves "
105 "in the group will all be visible as long as there is a note "
106 "in at least one of them.",