]> git.donarmstrong.com Git - lilypond.git/blob - lily/rest-collision-engraver.cc
af3d0ecc8903c03a8a1d5e05e7c009abe2981e5f
[lilypond.git] / lily / rest-collision-engraver.cc
1 /*
2   rest-collision-reg.cc -- implement Rest_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 "warn.hh"
10 #include "rest-collision.hh"
11 #include "engraver.hh"
12 #include "note-collision.hh"
13 #include "note-column.hh"
14
15 class Rest_collision_engraver : public Engraver
16 {
17   Item* rest_collision_;
18   int rest_count_; 
19   Link_array<Grob> note_columns_;
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(Rest_collision_engraver);  
26 };
27
28
29
30 Rest_collision_engraver::Rest_collision_engraver ()
31 {
32   rest_collision_ =0;
33   rest_count_ = 0;
34 }
35
36 void
37 Rest_collision_engraver::process_acknowledged_grobs ()
38 {
39   if (rest_collision_
40       || note_columns_.is_empty ()
41       || !rest_count_)
42     return;
43
44   rest_collision_ = make_item ("RestCollision");
45
46   announce_grob(rest_collision_, SCM_EOL);
47   for (int i=0; i < note_columns_.size (); i++)
48     Rest_collision::add_column (rest_collision_,note_columns_[i]);
49 }
50
51 void
52 Rest_collision_engraver::acknowledge_grob (Grob_info i)
53 {
54   if (Note_column::has_interface (i.grob_))
55     {
56       note_columns_.push (i.grob_);
57       if (Note_column::has_rests (i.grob_))
58         rest_count_ ++;
59     }
60 }
61
62 void
63 Rest_collision_engraver::stop_translation_timestep ()
64 {
65   if (rest_collision_) 
66     {
67       typeset_grob (rest_collision_);
68       rest_collision_ = 0;
69     }
70   note_columns_.clear ();
71   rest_count_ = 0;
72 }
73
74 ENTER_DESCRIPTION(Rest_collision_engraver,
75 /* descr */       "Handles collisions of rests.",
76 /* creats*/       "RestCollision",
77 /* accepts */     "",
78 /* acks  */      "note-column-interface",
79 /* reads */       "",
80 /* write */       "");