]> git.donarmstrong.com Git - lilypond.git/blob - lily/rest-collision-engraver.cc
Issue 4961/6: Let make_partial_ellipse_boxes use degrees
[lilypond.git] / lily / rest-collision-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
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 <set>
21
22 #include "duration.hh"
23 #include "engraver.hh"
24 #include "international.hh"
25 #include "item.hh"
26 #include "moment.hh"
27 #include "note-column.hh"
28 #include "paper-column.hh"
29 #include "rest.hh"
30 #include "rest-collision.hh"
31 #include "rhythmic-head.hh"
32 #include "stream-event.hh"
33 #include "warn.hh"
34
35 #include "translator.icc"
36
37 class Rest_collision_engraver : public Engraver
38 {
39 protected:
40   Grob *rest_collision_;
41
42   void process_acknowledged ();
43   void stop_translation_timestep ();
44 public:
45   TRANSLATOR_DECLARATIONS (Rest_collision_engraver);
46 };
47
48 Rest_collision_engraver::Rest_collision_engraver ()
49 {
50   rest_collision_ = 0;
51 }
52
53 void
54 Rest_collision_engraver::process_acknowledged ()
55 {
56   vsize rest_count = 0;
57   set<Grob *> columns;
58   Moment now = now_mom ();
59
60   for (SCM s = get_property ("busyGrobs"); scm_is_pair (s); s = scm_cdr (s))
61     {
62       Grob *g = unsmob<Grob> (scm_cdar (s));
63       Moment *m = unsmob<Moment> (scm_caar (s));
64       if (!g || !m)
65         continue;
66
67       if (has_interface<Rhythmic_head> (g) && (*m) > now)
68         {
69           Grob *column = g->get_parent (X_AXIS);
70           if (!column)
71               continue;
72
73           // Only include rests that start now. Include notes that started any time.
74           Paper_column *paper_column = dynamic_cast<Item *> (column)->get_column ();
75           if (!has_interface<Rest> (g) || !paper_column || Paper_column::when_mom (paper_column) == now)
76             {
77               columns.insert (column);
78               rest_count += Note_column::has_rests (column);
79             }
80         }
81     }
82
83   if (!rest_collision_ && rest_count && columns.size () > 1)
84     {
85       rest_collision_ = make_item ("RestCollision", SCM_EOL);
86       for (set<Grob *>::iterator i = columns.begin (); i != columns.end (); ++i)
87         Rest_collision::add_column (rest_collision_, *i);
88     }
89 }
90
91 void
92 Rest_collision_engraver::stop_translation_timestep ()
93 {
94   rest_collision_ = 0;
95 }
96
97 void
98 Rest_collision_engraver::boot ()
99 {
100
101 }
102
103 ADD_TRANSLATOR (Rest_collision_engraver,
104                 /* doc */
105                 "Handle collisions of rests.",
106
107                 /* create */
108                 "RestCollision ",
109
110                 /* read */
111                 "busyGrobs ",
112
113                 /* write */
114                 ""
115                );