]> git.donarmstrong.com Git - lilypond.git/blob - lily/collision-engraver.cc
release: 1.3.50
[lilypond.git] / lily / collision-engraver.cc
1 /*
2   collision-reg.cc -- implement Collision_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "note-column.hh"
10 #include "collision.hh"
11 #include "dimension-cache.hh"
12 #include "engraver.hh"
13
14 class Collision_engraver : public Engraver {
15   Collision* col_p_;
16   Link_array<Note_column> note_column_l_arr_;
17
18 protected:
19   virtual void acknowledge_element (Score_element_info);
20   virtual void process_acknowledged ();
21   virtual void do_pre_move_processing();
22 public:
23   VIRTUAL_COPY_CONS(Translator);
24   Collision_engraver();
25 };
26
27
28 void
29 Collision_engraver::process_acknowledged ()
30 {
31   if (col_p_ || note_column_l_arr_.size () < 2)
32     return ;
33   if (!col_p_) 
34     {
35       col_p_ = new Collision;
36       announce_element (Score_element_info (col_p_,0));
37     }
38   for (int i=0; i< note_column_l_arr_.size (); i++)
39     col_p_->add_column (note_column_l_arr_[i]);
40 }
41
42 void
43 Collision_engraver::acknowledge_element (Score_element_info i)
44 {
45   if (Note_column * c = dynamic_cast<Note_column *> (i.elem_l_))
46     {
47       /*should check Y axis? */
48       if (c->rest_b () || c->parent_l(X_AXIS))
49         return ;
50
51       note_column_l_arr_.push (c);
52     }
53 }
54
55 void
56 Collision_engraver::do_pre_move_processing()
57 {
58   if (col_p_) 
59     {
60       typeset_element (col_p_);
61       col_p_ =0;
62     }
63   note_column_l_arr_.clear ();
64 }
65
66 Collision_engraver::Collision_engraver()
67 {
68   col_p_ =0;
69 }
70
71
72
73 ADD_THIS_TRANSLATOR(Collision_engraver);