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