]> git.donarmstrong.com Git - lilypond.git/blob - lily/collision-engraver.cc
``slikken kreng''
[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--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "note-column.hh"
10 #include "note-collision.hh"
11
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_;
20   Link_array<Grob> note_columns_;
21
22 protected:
23   virtual void acknowledge_grob (Grob_info);
24   virtual void process_acknowledged_grobs ();
25   virtual void stop_translation_timestep ();
26 public:
27   TRANSLATOR_DECLARATIONS(Collision_engraver);
28 };
29
30
31 void
32 Collision_engraver::process_acknowledged_grobs ()
33 {
34   if (col_ || note_columns_.size () < 2)
35     return ;
36   if (!col_) 
37     {
38       col_ = new Item (get_property ("NoteCollision"));
39       announce_grob (col_, SCM_EOL);
40     }
41   
42   for (int i=0; i< note_columns_.size (); i++)
43     Note_collision_interface::add_column (col_,note_columns_[i]);
44 }
45
46 void
47 Collision_engraver::acknowledge_grob (Grob_info i)
48 {
49   if (Note_column::has_interface (i.grob_))
50     {
51       /*should check Y axis? */
52       if (Note_column::rest_b (i.grob_) || i.grob_->get_parent (X_AXIS))
53         return ;
54
55       note_columns_.push (i.grob_);
56     }
57 }
58
59 void
60 Collision_engraver::stop_translation_timestep ()
61 {
62   if (col_) 
63     {
64       typeset_grob (col_);
65       col_ =0;
66     }
67   note_columns_.clear ();
68 }
69
70 Collision_engraver::Collision_engraver ()
71 {
72   col_ =0;
73 }
74
75
76
77
78 ENTER_DESCRIPTION(Collision_engraver,
79 /* descr */       "",
80 /* creats*/       "NoteCollision",
81 /* acks  */       "note-column-interface",
82 /* reads */       "",
83 /* write */       "");