]> git.donarmstrong.com Git - lilypond.git/blob - lily/rest-collision-engraver.cc
Merge branch 'master' of carldsorensen@git.sv.gnu.org:/srv/git/lilypond into ralph
[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--2008 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "warn.hh"
10 #include "engraver.hh"
11 #include "rest-collision.hh"
12 #include "note-column.hh"
13 #include "item.hh"
14
15 class Rest_collision_engraver : public Engraver
16 {
17   Item *rest_collision_;
18   vsize rest_count_;
19   vector<Grob*> note_columns_;
20 protected:
21   DECLARE_ACKNOWLEDGER (note_column);
22   void process_acknowledged ();
23   void stop_translation_timestep ();
24 public:
25   TRANSLATOR_DECLARATIONS (Rest_collision_engraver);
26 };
27
28 Rest_collision_engraver::Rest_collision_engraver ()
29 {
30   rest_collision_ = 0;
31   rest_count_ = 0;
32 }
33
34 void
35 Rest_collision_engraver::process_acknowledged ()
36 {
37   if (rest_collision_
38       || note_columns_.empty ()
39       || !rest_count_
40       || (note_columns_.size () == rest_count_
41           && rest_count_ < 2))
42     return;
43
44   rest_collision_ = make_item ("RestCollision", SCM_EOL);
45
46   for (vsize i = 0; i < note_columns_.size (); i++)
47     Rest_collision::add_column (rest_collision_, note_columns_[i]);
48 }
49
50 void
51 Rest_collision_engraver::acknowledge_note_column (Grob_info i)
52 {
53   note_columns_.push_back (i.grob ());
54   if (Note_column::has_rests (i.grob ()))
55     rest_count_++;
56 }
57
58 void
59 Rest_collision_engraver::stop_translation_timestep ()
60 {
61   rest_collision_ = 0;
62   note_columns_.clear ();
63   rest_count_ = 0;
64 }
65
66 #include "translator.icc"
67
68 ADD_ACKNOWLEDGER (Rest_collision_engraver, note_column);
69 ADD_TRANSLATOR (Rest_collision_engraver,
70                 /* doc */
71                 "Handle collisions of rests.",
72
73                 /* create */
74                 "RestCollision ",
75
76                 /* read */
77                 "",
78
79                 /* write */
80                 ""
81                 );