Release: update news.
[lilypond/patrick.git] / lily / rest-collision-engraver.cc
blobd1f1640cf3bcfd926c772411055296733755275f
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
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/>.
20 #include <set>
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"
35 class Rest_collision_engraver : public Engraver
37 protected:
38 Grob *rest_collision_;
40 void process_acknowledged ();
41 void stop_translation_timestep ();
42 public:
43 TRANSLATOR_DECLARATIONS (Rest_collision_engraver);
46 Rest_collision_engraver::Rest_collision_engraver ()
48 rest_collision_ = 0;
51 void
52 Rest_collision_engraver::process_acknowledged ()
54 vsize rest_count = 0;
55 set<Grob*> columns;
56 Moment now = now_mom ();
58 for (SCM s = get_property ("busyGrobs"); scm_is_pair (s); s = scm_cdr (s))
60 Grob *g = unsmob_grob (scm_cdar (s));
61 Moment *m = unsmob_moment (scm_caar (s));
62 if (!g || !m)
63 continue;
65 if (Rhythmic_head::has_interface (g) && (*m) > now)
67 Grob *column = g->get_parent (X_AXIS);
68 if (!column)
70 g->warning (_ ("rhythmic head is not part of a rhythmic column"));
71 continue;
74 // Only include rests that start now. Include notes that started any time.
75 Paper_column *paper_column = dynamic_cast<Item*> (column)->get_column ();
76 if (!Rest::has_interface (g) || !paper_column || Paper_column::when_mom (paper_column) == now)
78 columns.insert (column);
79 rest_count += Note_column::has_rests (column);
84 if (!rest_collision_ && rest_count && columns.size () > 1)
86 rest_collision_ = make_item ("RestCollision", SCM_EOL);
87 for (set<Grob*>::iterator i = columns.begin (); i != columns.end (); ++i)
88 Rest_collision::add_column (rest_collision_, *i);
92 void
93 Rest_collision_engraver::stop_translation_timestep ()
95 rest_collision_ = 0;
98 #include "translator.icc"
100 ADD_TRANSLATOR (Rest_collision_engraver,
101 /* doc */
102 "Handle collisions of rests.",
104 /* create */
105 "RestCollision ",
107 /* read */
108 "busyGrobs ",
110 /* write */