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