Merge remote branch 'origin' into release/unstable
[lilypond/patrick.git] / lily / collision-engraver.cc
bloba92a2a71715adbb366e92b86741fd44f83ad220f
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 "engraver.hh"
21 #include "note-column.hh"
22 #include "note-collision.hh"
23 #include "axis-group-interface.hh"
24 #include "item.hh"
26 class Collision_engraver : public Engraver
28 Item *col_;
29 vector<Grob*> note_columns_;
31 protected:
32 DECLARE_ACKNOWLEDGER (note_column);
33 void process_acknowledged ();
34 void stop_translation_timestep ();
35 public:
36 TRANSLATOR_DECLARATIONS (Collision_engraver);
39 void
40 Collision_engraver::process_acknowledged ()
42 if (col_ || note_columns_.size () < 2)
43 return;
44 if (!col_)
45 col_ = make_item ("NoteCollision", SCM_EOL);
47 for (vsize i = 0; i < note_columns_.size (); i++)
48 Note_collision_interface::add_column (col_, note_columns_[i]);
51 void
52 Collision_engraver::acknowledge_note_column (Grob_info i)
54 if (Note_column::has_interface (i.grob ()))
56 /*should check Y axis? */
57 if (Note_column::has_rests (i.grob ()) || i.grob ()->get_parent (X_AXIS))
58 return;
60 if (to_boolean (i.grob ()->get_property ("ignore-collision")))
61 return;
63 note_columns_.push_back (i.grob ());
67 void
68 Collision_engraver::stop_translation_timestep ()
70 col_ = 0;
71 note_columns_.clear ();
74 Collision_engraver::Collision_engraver ()
76 col_ = 0;
79 #include "translator.icc"
81 ADD_ACKNOWLEDGER (Collision_engraver, note_column);
83 ADD_TRANSLATOR (Collision_engraver,
84 /* doc */
85 "Collect @code{NoteColumns}, and as soon as there are two or"
86 " more, put them in a @code{NoteCollision} object.",
88 /* create */
89 "NoteCollision ",
91 /* read */
92 "",
94 /* write */