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