]> git.donarmstrong.com Git - lilypond.git/blob - lily/collision-engraver.cc
Run grand-replace (issue 3765)
[lilypond.git] / lily / collision-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2014 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 "engraver.hh"
21 #include "note-column.hh"
22 #include "note-collision.hh"
23 #include "axis-group-interface.hh"
24 #include "item.hh"
25
26 class Collision_engraver : public Engraver
27 {
28   Item *col_;
29   vector<Grob *> note_columns_;
30
31 protected:
32   DECLARE_ACKNOWLEDGER (note_column);
33   void process_acknowledged ();
34   void stop_translation_timestep ();
35 public:
36   TRANSLATOR_DECLARATIONS (Collision_engraver);
37 };
38
39 void
40 Collision_engraver::process_acknowledged ()
41 {
42   if (col_ || note_columns_.size () < 2)
43     return;
44   if (!col_)
45     col_ = make_item ("NoteCollision", SCM_EOL);
46
47   for (vsize i = 0; i < note_columns_.size (); i++)
48     Note_collision_interface::add_column (col_, note_columns_[i]);
49 }
50
51 void
52 Collision_engraver::acknowledge_note_column (Grob_info i)
53 {
54   if (Note_column::has_interface (i.grob ()))
55     {
56       /*should check Y axis? */
57       if (Note_column::has_rests (i.grob ()) || i.grob ()->get_parent (X_AXIS))
58         return;
59
60       if (to_boolean (i.grob ()->get_property ("ignore-collision")))
61         return;
62
63       note_columns_.push_back (i.grob ());
64     }
65 }
66
67 void
68 Collision_engraver::stop_translation_timestep ()
69 {
70   col_ = 0;
71   note_columns_.clear ();
72 }
73
74 Collision_engraver::Collision_engraver ()
75 {
76   col_ = 0;
77 }
78
79 #include "translator.icc"
80
81 ADD_ACKNOWLEDGER (Collision_engraver, note_column);
82
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.",
87
88                 /* create */
89                 "NoteCollision ",
90
91                 /* read */
92                 "",
93
94                 /* write */
95                 ""
96                );