]> git.donarmstrong.com Git - lilypond.git/blob - lily/rest-collision-engraver.cc
* flower
[lilypond.git] / lily / rest-collision-engraver.cc
1 /*
2   rest-collision-engraver.cc -- implement Rest_collision_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "warn.hh"
10 #include "engraver.hh"
11 #include "rest-collision.hh"
12 #include "note-column.hh"
13
14 class Rest_collision_engraver : public Engraver
15 {
16   Item *rest_collision_;
17   int rest_count_;
18   Link_array<Grob> note_columns_;
19 protected:
20   virtual void acknowledge_grob (Grob_info);
21   virtual void process_acknowledged_grobs ();
22   virtual void stop_translation_timestep ();
23 public:
24   TRANSLATOR_DECLARATIONS (Rest_collision_engraver);
25 };
26
27 Rest_collision_engraver::Rest_collision_engraver ()
28 {
29   rest_collision_ = 0;
30   rest_count_ = 0;
31 }
32
33 void
34 Rest_collision_engraver::process_acknowledged_grobs ()
35 {
36   if (rest_collision_
37       || note_columns_.is_empty ()
38       || !rest_count_
39       || (note_columns_.size () == rest_count_
40           && rest_count_ < 2))
41     return;
42
43   rest_collision_ = make_item ("RestCollision", SCM_EOL);
44
45   for (int i = 0; i < note_columns_.size (); i++)
46     Rest_collision::add_column (rest_collision_, note_columns_[i]);
47 }
48
49 void
50 Rest_collision_engraver::acknowledge_grob (Grob_info i)
51 {
52   if (Note_column::has_interface (i.grob_))
53     {
54       note_columns_.push (i.grob_);
55       if (Note_column::has_rests (i.grob_))
56         rest_count_++;
57     }
58 }
59
60 void
61 Rest_collision_engraver::stop_translation_timestep ()
62 {
63   rest_collision_ = 0;
64   note_columns_.clear ();
65   rest_count_ = 0;
66 }
67
68 ADD_TRANSLATOR (Rest_collision_engraver,
69                 /* descr */ "Handles collisions of rests.",
70                 /* creats*/ "RestCollision",
71                 /* accepts */ "",
72                 /* acks  */ "note-column-interface",
73                 /* reads */ "",
74                 /* write */ "");