]> git.donarmstrong.com Git - lilypond.git/blob - lily/pure-from-neighbor-engraver.cc
Improves horizontal spacing of vertical axis groups that span bars traverse.
[lilypond.git] / lily / pure-from-neighbor-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2011 Mike Solomon <mike@apollinemike.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 <map>
21 #include <algorithm>
22
23 #include "grob.hh"
24 #include "item.hh"
25 #include "pointer-group-interface.hh"
26 #include "pure-from-neighbor-interface.hh"
27 #include "engraver.hh"
28
29 class Pure_from_neighbor_engraver : public Engraver
30 {
31   vector<Grob *> items_then_;
32   vector<Grob *> items_now_;
33   vector<Grob *> pures_then_;
34   vector<Grob *> pures_now_;
35
36 public:
37   TRANSLATOR_DECLARATIONS (Pure_from_neighbor_engraver);
38 protected:
39   DECLARE_ACKNOWLEDGER (pure_from_neighbor);
40   DECLARE_ACKNOWLEDGER (item);
41   void stop_translation_timestep ();
42 };
43
44 Pure_from_neighbor_engraver::Pure_from_neighbor_engraver ()
45 {
46 }
47
48 void
49 Pure_from_neighbor_engraver::acknowledge_item (Grob_info i)
50 {
51   SCM pure_relevant_p = ly_lily_module_constant ("pure-relevant?");
52   if (!Pure_from_neighbor_interface::has_interface (i.grob ())
53       && to_boolean (scm_call_1 (pure_relevant_p, i.item ()->self_scm ())))
54     items_now_.push_back (i.item ());
55 }
56
57 // note that this can get out of hand if there are lots of vertical axis groups...
58
59 void
60 Pure_from_neighbor_engraver::acknowledge_pure_from_neighbor (Grob_info i)
61 {
62   pures_now_.push_back (i.item ());
63 }
64
65 void
66 Pure_from_neighbor_engraver::stop_translation_timestep ()
67 {
68   if (pures_now_.size ())
69     {
70       for (vsize i = 0; i < pures_now_.size (); i++)
71         for (vsize j = 0; j < items_then_.size (); j++)
72           Pointer_group_interface::add_grob (pures_now_[i], ly_symbol2scm ("elements"), items_then_[j]);
73
74       for (vsize i = 0; i < pures_then_.size (); i++)
75         for (vsize j = 0; j < items_now_.size (); j++)
76           Pointer_group_interface::add_grob (pures_then_[i], ly_symbol2scm ("elements"), items_now_[j]);
77
78       items_then_.clear ();
79       items_then_.insert (items_then_.end (), items_now_.begin (), items_now_.end ());
80       items_now_.clear ();
81
82       pures_then_.clear ();
83       pures_then_.insert (pures_then_.end (), pures_now_.begin (), pures_now_.end ());
84       pures_now_.clear ();
85     }
86 }
87
88 #include "translator.icc"
89
90 ADD_ACKNOWLEDGER (Pure_from_neighbor_engraver, item);
91 ADD_ACKNOWLEDGER (Pure_from_neighbor_engraver, pure_from_neighbor);
92 ADD_TRANSLATOR (Pure_from_neighbor_engraver,
93                 /* doc */
94                 "Coordinates items that get their pure heights from their neighbors.",
95
96                 /* create */
97                 "",
98
99                 /* read */
100                 "",
101
102                 /* write */
103                 ""
104                );