]> git.donarmstrong.com Git - lilypond.git/blob - lily/separating-line-group-engraver.cc
* lily/separating-line-group-engraver.cc (acknowledge_grob):
[lilypond.git] / lily / separating-line-group-engraver.cc
1 /*   
2 '  separating-line-group-engraver.cc --  implement Separating_line_group_engraver
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1998--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "separating-group-spanner.hh"
11 #include "separation-item.hh"
12 #include "paper-column.hh"
13 #include "paper-def.hh"
14 #include "engraver.hh"
15 #include "axis-group-interface.hh"
16 #include "note-spacing.hh"
17 #include "group-interface.hh"
18 #include "accidental-placement.hh"
19 #include "translator-group.hh"
20
21
22 struct Spacings
23 {
24   Item * staff_spacing_;
25   Link_array<Item> note_spacings_;
26
27   Spacings ()
28   {
29     staff_spacing_ = 0;
30   }
31
32   bool empty( )const
33   {
34     return !staff_spacing_ && !note_spacings_.size (); 
35   }
36   void clear () {
37     staff_spacing_ = 0;
38     note_spacings_.clear();
39   }
40 };
41
42
43 class Separating_line_group_engraver : public Engraver
44 {
45 protected:
46   Item * break_item_;
47   Item * musical_item_;
48   Item * last_musical_item_;
49
50   Spacings current_spacings_;
51   Spacings last_spacings_;
52   
53   Spanner * sep_span_;
54   
55   virtual void acknowledge_grob (Grob_info);
56   virtual void initialize ();
57   virtual void finalize ();
58   virtual void stop_translation_timestep ();
59   virtual void start_translation_timestep ();  
60 public:
61   TRANSLATOR_DECLARATIONS(Separating_line_group_engraver);
62 };
63
64 Separating_line_group_engraver::Separating_line_group_engraver ()
65 {
66   sep_span_ = 0;
67   break_item_ = 0;
68   musical_item_ =0;
69 }
70
71 void
72 Separating_line_group_engraver::initialize ()
73 {
74   sep_span_ = new Spanner (get_property ("SeparatingGroupSpanner"));
75
76   announce_grob(sep_span_, SCM_EOL);
77   sep_span_->set_bound (LEFT, unsmob_grob (get_property ("currentCommandColumn")));
78 }
79
80 void
81 Separating_line_group_engraver::finalize ()
82 {
83   SCM ccol = get_property ("currentCommandColumn");
84   Grob *column = unsmob_grob (ccol);
85   
86   sep_span_->set_bound (RIGHT, unsmob_grob (ccol));
87   typeset_grob (sep_span_);
88   sep_span_ =0;
89
90   for  (int i= 0 ; i < last_spacings_.note_spacings_.size(); i++)
91     {
92       Pointer_group_interface::add_grob (last_spacings_.note_spacings_[i],
93                                          ly_symbol2scm ("right-items" ),
94                                          column);
95     }
96    
97   if(last_spacings_.staff_spacing_
98      && last_spacings_.staff_spacing_->get_column () == column)
99     {
100       last_spacings_.staff_spacing_->suicide ();
101     }
102 }
103
104 void
105 Separating_line_group_engraver::acknowledge_grob (Grob_info i)
106 {
107   Item * it = dynamic_cast <Item *> (i.grob_);
108   if (!it)
109     return;
110   if (it->get_parent (X_AXIS)
111       && it->get_parent (X_AXIS)
112       ->has_extent_callback_b(Axis_group_interface::group_extent_callback_proc, X_AXIS))
113     return;
114
115   
116   if (to_boolean (it->get_grob_property ("no-spacing-rods")))
117     return ;
118
119   if (Note_spacing::has_interface (it)) 
120     {
121       current_spacings_.note_spacings_.push (it);
122       return ;
123     }
124   
125   bool ib =Item::breakable_b (it);
126   Item *&p_ref_ (ib ? break_item_
127                  : musical_item_);
128
129   if (!p_ref_)
130     {
131       p_ref_ = new Item (get_property ("SeparationItem"));
132
133       if (ib)
134         {
135           p_ref_->set_grob_property ("breakable", SCM_BOOL_T);
136           daddy_trans_->set_property ("breakableSeparationItem", p_ref_->self_scm ());
137         }
138       announce_grob(p_ref_, SCM_EOL);
139
140       if (p_ref_ == break_item_)
141         {
142           Item *it  = new Item (get_property ("StaffSpacing"));
143           current_spacings_.staff_spacing_ = it;
144           it->set_grob_property ("left-items", gh_cons (break_item_->self_scm (), SCM_EOL));
145           
146           announce_grob(it, SCM_EOL);
147
148           if (int i = last_spacings_.note_spacings_.size ())
149             {
150               for (; i--;)
151                 Pointer_group_interface::add_grob (last_spacings_.note_spacings_[i],
152                                                    ly_symbol2scm ("right-items"),
153                                                    break_item_);
154                                      
155             }
156           else if (last_spacings_.staff_spacing_)
157             {
158               
159               last_spacings_.staff_spacing_->set_grob_property ("right-items",
160                                                                 gh_cons (break_item_->self_scm(), SCM_EOL));
161             }
162         }
163     }
164
165   if (Accidental_placement::has_interface (it))
166     Separation_item::add_conditional_item (p_ref_, it);
167   else
168     Separation_item::add_item (p_ref_,it);
169 }
170
171 void
172 Separating_line_group_engraver::start_translation_timestep ()
173 {
174   if (break_item_)
175     daddy_trans_->unset_property (ly_symbol2scm ("breakableSeparationItem"));
176   break_item_ =0;
177 }
178
179 void
180 Separating_line_group_engraver::stop_translation_timestep ()
181 {
182   if (break_item_)
183     {
184       Separating_group_spanner::add_spacing_unit (sep_span_, break_item_);
185       typeset_grob (break_item_);
186     }
187   
188   if (Item * sp = current_spacings_.staff_spacing_)
189     {
190       /*
191         TODO: should really look at the left-items of following
192         note-spacing grobs.
193        */
194       if (musical_item_)
195         Pointer_group_interface::add_grob (sp, ly_symbol2scm ("right-items"),
196                                            musical_item_);
197
198       typeset_grob (sp);
199     }
200
201   
202   if (!current_spacings_.empty ())
203     {
204       last_spacings_ = current_spacings_;
205     }
206
207   current_spacings_.clear ();
208   
209   if (musical_item_)
210     {
211       Separating_group_spanner::add_spacing_unit (sep_span_, musical_item_);
212       typeset_grob (musical_item_);
213     }
214   
215   musical_item_ =0;
216 }
217
218
219 ENTER_DESCRIPTION(Separating_line_group_engraver,
220 /* descr */       "Generates objects for computing spacing parameters.",
221 /* creats*/       "SeparationItem SeparatingGroupSpanner",
222 /* accepts */     "",
223 /* acks  */      "item-interface",
224 /* reads */       "",
225 /* write */       "breakableSeparationItem");