]> git.donarmstrong.com Git - lilypond.git/blob - lily/script-column-engraver.cc
* lily/include/translator.icc (ADD_ACKNOWLEDGER): new macro.
[lilypond.git] / lily / script-column-engraver.cc
1 /*
2   script-column-engraver.cc -- implement Script_column_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1999--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "engraver.hh"
10 #include "script-column.hh"
11 #include "side-position-interface.hh"
12
13 #include "translator.icc"
14
15
16 /**
17    Find potentially colliding scripts, and put them in a
18    Script_column, that will fix the collisions.  */
19 class Script_column_engraver : public Engraver
20 {
21   Grob *scol_;
22   Link_array<Item> scripts_;
23
24 public:
25   TRANSLATOR_DECLARATIONS (Script_column_engraver);
26 protected:
27   DECLARE_ACKNOWLEDGER(side_position);
28   PRECOMPUTED_VIRTUAL void process_acknowledged ();
29   PRECOMPUTED_VIRTUAL void stop_translation_timestep ();
30 };
31
32 Script_column_engraver::Script_column_engraver ()
33 {
34   scol_ = 0;
35 }
36
37 void
38 Script_column_engraver::stop_translation_timestep ()
39 {
40   scol_ = 0;
41   scripts_.clear ();
42 }
43
44 void
45 Script_column_engraver::acknowledge_side_position (Grob_info inf)
46 {
47   Item *thing = dynamic_cast<Item *> (inf.grob ());
48   if (thing)
49     {
50       if (!Item::is_breakable (thing)
51           && Side_position_interface::get_axis (inf.grob ()) == Y_AXIS)
52         {
53           scripts_.push (thing);
54         }
55     }
56 }
57
58 void
59 Script_column_engraver::process_acknowledged ()
60 {
61   if (!scol_ && scripts_.size () > 1)
62     {
63       scol_ = make_item ("ScriptColumn", SCM_EOL);
64     }
65
66   if (scol_)
67     {
68       for (int i = 0; i < scripts_.size (); i++)
69         Script_column::add_staff_sided (scol_, scripts_[i]);
70       scripts_.clear ();
71     }
72 }
73 ADD_ACKNOWLEDGER(Script_column_engraver, side_position);
74 ADD_TRANSLATOR (Script_column_engraver,
75                 /* descr */ "",
76                 /* creats*/ "ScriptColumn",
77                 /* accepts */ "",
78                 /* acks  */ "",
79                 /* reads */ "",
80                 /* write */ "");