]> git.donarmstrong.com Git - lilypond.git/blob - lily/collision-engraver.cc
*** empty log message ***
[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--2004 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 class Collision_engraver : public Engraver
16 {
17   Item * col_;
18   Link_array<Grob> note_columns_;
19
20 protected:
21   virtual void acknowledge_grob (Grob_info);
22   virtual void process_acknowledged_grobs ();
23   virtual void stop_translation_timestep ();
24 public:
25   TRANSLATOR_DECLARATIONS (Collision_engraver);
26 };
27
28
29 void
30 Collision_engraver::process_acknowledged_grobs ()
31 {
32   if (col_ || note_columns_.size () < 2)
33     return ;
34   if (!col_) 
35     {
36       col_ = make_item ("NoteCollision", SCM_EOL);
37       
38     }
39   
40   for (int i = 0; i< note_columns_.size (); i++)
41     Note_collision_interface::add_column (col_,note_columns_[i]);
42 }
43
44 void
45 Collision_engraver::acknowledge_grob (Grob_info i)
46 {
47   if (Note_column::has_interface (i.grob_))
48     {
49       /*should check Y axis? */
50       if (Note_column::has_rests (i.grob_) || i.grob_->get_parent (X_AXIS))
51         return ;
52
53       note_columns_.push (i.grob_);
54     }
55 }
56
57 void
58 Collision_engraver::stop_translation_timestep ()
59 {
60   col_ = 0;
61   note_columns_.clear ();
62 }
63
64 Collision_engraver::Collision_engraver ()
65 {
66   col_ = 0;
67 }
68
69
70
71
72 ENTER_DESCRIPTION (Collision_engraver,
73 /* descr */       "Collect NoteColumns, and as soon as there are two or more, put them in a NoteCollision object.",
74 /* creats*/       "NoteCollision",
75 /* accepts */     "",
76 /* acks  */      "note-column-interface",
77 /* reads */       "",
78 /* write */       "");