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