]> git.donarmstrong.com Git - lilypond.git/blob - lily/script-column-engraver.cc
2003 -> 2004
[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--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "engraver.hh"
11 #include "script-column.hh"
12 #include "item.hh"
13 #include "side-position-interface.hh"
14
15 /**
16    Find potentially colliding scripts, and put them in a
17    Script_column, that will fix the collisions.  */
18 class Script_column_engraver : public Engraver
19 {
20   Grob *scol_;
21   Link_array<Item> scripts_;
22
23 public:
24   TRANSLATOR_DECLARATIONS(Script_column_engraver);
25 protected:
26   virtual void acknowledge_grob (Grob_info);
27   virtual void process_acknowledged_grobs ();
28   virtual void stop_translation_timestep ();
29 };
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   if (scol_)
41     {
42       typeset_grob (scol_);
43       scol_ =0;
44     }
45   scripts_.clear ();
46 }
47
48 void
49 Script_column_engraver::acknowledge_grob (Grob_info inf) 
50 {
51   Item *thing = dynamic_cast<Item*> (inf.grob_);
52   if (thing && Side_position_interface::has_interface (inf.grob_)) // ugh FIXME
53     {
54       if (!Item::breakable_b (thing)
55           && Side_position_interface::get_axis (inf.grob_) == Y_AXIS)
56         {
57           scripts_.push (thing);
58         }
59     }
60 }
61
62 void
63 Script_column_engraver::process_acknowledged_grobs ()
64 {
65   if (!scol_ && scripts_.size () > 1)
66     {
67       scol_ = make_item ("ScriptColumn");
68       announce_grob(scol_, SCM_EOL);
69     }
70
71   if (scol_)
72     {
73       for (int i=0; i < scripts_.size (); i++)
74         Script_column::add_staff_sided (scol_, scripts_[i]);
75       scripts_.clear ();
76     }
77
78 }
79
80 ENTER_DESCRIPTION(Script_column_engraver,
81 /* descr */       "",
82 /* creats*/       "ScriptColumn",
83 /* accepts */     "",
84 /* acks  */      "side-position-interface",
85 /* reads */       "",
86 /* write */       "");