lilypond-1.4.4
[lilypond.git] / lily / rest-collision-engraver.cc
blob1443d70790c8f7a8c63af9f4bf0b66dfcee551c7
1 /*
2 rest-collision-reg.cc -- implement Rest_collision_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
9 #include "debug.hh"
10 #include "rest-collision.hh"
11 #include "engraver.hh"
12 #include "collision.hh"
13 #include "note-column.hh"
15 class Rest_collision_engraver : public Engraver
17 Item* rest_collision_p_;
19 Link_array<Grob> note_column_l_arr_;
20 protected:
21 virtual void acknowledge_grob (Grob_info);
22 virtual void create_grobs ();
23 virtual void stop_translation_timestep ();
24 public:
25 VIRTUAL_COPY_CONS (Translator);
26 Rest_collision_engraver ();
30 ADD_THIS_TRANSLATOR (Rest_collision_engraver);
32 Rest_collision_engraver::Rest_collision_engraver ()
34 rest_collision_p_ =0;
37 void
38 Rest_collision_engraver::create_grobs ()
40 if (rest_collision_p_ || note_column_l_arr_.size () < 2)
41 return;
43 rest_collision_p_ = new Item (get_property ("RestCollision"));
44 Rest_collision::set_interface (rest_collision_p_);
45 announce_grob (rest_collision_p_, 0);
46 for (int i=0; i< note_column_l_arr_.size (); i++)
47 Rest_collision::add_column (rest_collision_p_,note_column_l_arr_[i]);
50 void
51 Rest_collision_engraver::acknowledge_grob (Grob_info i)
53 if (Note_column::has_interface (i.elem_l_))
54 note_column_l_arr_.push (i.elem_l_);
57 void
58 Rest_collision_engraver::stop_translation_timestep ()
60 if (rest_collision_p_)
62 typeset_grob (rest_collision_p_);
63 rest_collision_p_ = 0;
65 note_column_l_arr_.clear ();