]> git.donarmstrong.com Git - lilypond.git/blob - lily/collision-engraver.cc
Issue 4550 (1/2) Avoid "using namespace std;" in included files
[lilypond.git] / lily / 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 "engraver.hh"
21 #include "note-column.hh"
22 #include "note-collision.hh"
23 #include "axis-group-interface.hh"
24 #include "item.hh"
25
26 #include "translator.icc"
27
28 using std::vector;
29
30 class Collision_engraver : public Engraver
31 {
32   Item *col_;
33   vector<Grob *> note_columns_;
34
35 protected:
36   DECLARE_ACKNOWLEDGER (note_column);
37   void process_acknowledged ();
38   void stop_translation_timestep ();
39 public:
40   TRANSLATOR_DECLARATIONS (Collision_engraver);
41 };
42
43 void
44 Collision_engraver::process_acknowledged ()
45 {
46   if (col_ || note_columns_.size () < 2)
47     return;
48   if (!col_)
49     col_ = make_item ("NoteCollision", SCM_EOL);
50
51   for (vsize i = 0; i < note_columns_.size (); i++)
52     Note_collision_interface::add_column (col_, note_columns_[i]);
53 }
54
55 void
56 Collision_engraver::acknowledge_note_column (Grob_info i)
57 {
58   if (has_interface<Note_column> (i.grob ()))
59     {
60       /*should check Y axis? */
61       if (Note_column::has_rests (i.grob ()) || i.grob ()->get_parent (X_AXIS))
62         return;
63
64       if (to_boolean (i.grob ()->get_property ("ignore-collision")))
65         return;
66
67       note_columns_.push_back (i.grob ());
68     }
69 }
70
71 void
72 Collision_engraver::stop_translation_timestep ()
73 {
74   col_ = 0;
75   note_columns_.clear ();
76 }
77
78 Collision_engraver::Collision_engraver ()
79 {
80   col_ = 0;
81 }
82
83 ADD_ACKNOWLEDGER (Collision_engraver, note_column);
84
85 ADD_TRANSLATOR (Collision_engraver,
86                 /* doc */
87                 "Collect @code{NoteColumns}, and as soon as there are two or"
88                 " more, put them in a @code{NoteCollision} object.",
89
90                 /* create */
91                 "NoteCollision ",
92
93                 /* read */
94                 "",
95
96                 /* write */
97                 ""
98                );