]> git.donarmstrong.com Git - lilypond.git/blob - lily/keep-alive-together-engraver.cc
f6ba297ccfe4b5bd8fd84776e9d62c3799a5bc8e
[lilypond.git] / lily / keep-alive-together-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2010--2012 Joe Neeman <joeneeman@gmail.com>
5
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.
10
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.
15
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/>.
18 */
19
20 #include "context.hh"
21 #include "dispatcher.hh"
22 #include "engraver.hh"
23 #include "grob.hh"
24 #include "grob-array.hh"
25
26 #include "translator.icc"
27
28 class Keep_alive_together_engraver: public Engraver
29 {
30   vector<Grob *> group_spanners_;
31
32 public:
33   TRANSLATOR_DECLARATIONS (Keep_alive_together_engraver);
34   DECLARE_ACKNOWLEDGER (hara_kiri_group_spanner);
35
36   virtual void finalize ();
37 };
38
39 Keep_alive_together_engraver::Keep_alive_together_engraver ()
40 {
41 }
42
43 void
44 Keep_alive_together_engraver::acknowledge_hara_kiri_group_spanner (Grob_info i)
45 {
46   group_spanners_.push_back (i.grob ());
47 }
48
49 void
50 Keep_alive_together_engraver::finalize ()
51 {
52   for (vsize i = 0; i < group_spanners_.size (); ++i)
53     {
54       SCM grob_array_scm = Grob_array::make_array ();
55       Grob_array *ga = unsmob_grob_array (grob_array_scm);
56
57       // It would make Hara_kiri_group_spanner::request_suicide a _little_
58       // faster if we removed each grob from its own array. It seems
59       // unnecessary for now, though.
60       ga->set_array (group_spanners_);
61       group_spanners_[i]->set_object ("keep-alive-with", grob_array_scm);
62     }
63 }
64
65 ADD_ACKNOWLEDGER (Keep_alive_together_engraver, hara_kiri_group_spanner);
66
67 ADD_TRANSLATOR (Keep_alive_together_engraver,
68                 /* doc */
69                 "This engraver collects all @code{Hara_kiri_group_spanner}s "
70                 "that are created in contexts at or below its own.  "
71                 "These spanners are then tied together so that one will "
72                 "be removed only if all are removed.  For example, "
73                 "if a @code{StaffGroup} uses this engraver, then the staves "
74                 "in the group will all be visible as long as there is a note "
75                 "in at least one of them.",
76
77                 /* create */
78                 "",
79
80                 /* read */
81                 "",
82
83                 /* write */
84                 ""
85                );