]> git.donarmstrong.com Git - lilypond.git/blob - lily/collision-engraver.cc
release: 1.3.51
[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 /*
15   collect Note_column, and as soon as there are 2 or more, put them in
16   a collision object.  */
17 class Collision_engraver : public Engraver {
18   Collision* col_p_;
19   Link_array<Note_column> note_column_l_arr_;
20
21 protected:
22   virtual void acknowledge_element (Score_element_info);
23   virtual void process_acknowledged ();
24   virtual void do_pre_move_processing();
25 public:
26   VIRTUAL_COPY_CONS(Translator);
27   Collision_engraver();
28 };
29
30
31 void
32 Collision_engraver::process_acknowledged ()
33 {
34   if (col_p_ || note_column_l_arr_.size () < 2)
35     return ;
36   if (!col_p_) 
37     {
38       col_p_ = new Collision;
39       announce_element (Score_element_info (col_p_,0));
40     }
41   for (int i=0; i< note_column_l_arr_.size (); i++)
42     col_p_->add_column (note_column_l_arr_[i]);
43 }
44
45 void
46 Collision_engraver::acknowledge_element (Score_element_info i)
47 {
48   if (Note_column * c = dynamic_cast<Note_column *> (i.elem_l_))
49     {
50       /*should check Y axis? */
51       if (c->rest_b () || c->parent_l(X_AXIS))
52         return ;
53
54       note_column_l_arr_.push (c);
55     }
56 }
57
58 void
59 Collision_engraver::do_pre_move_processing()
60 {
61   if (col_p_) 
62     {
63       typeset_element (col_p_);
64       col_p_ =0;
65     }
66   note_column_l_arr_.clear ();
67 }
68
69 Collision_engraver::Collision_engraver()
70 {
71   col_p_ =0;
72 }
73
74
75
76 ADD_THIS_TRANSLATOR(Collision_engraver);