]> git.donarmstrong.com Git - lilypond.git/blob - lily/separating-line-group-engraver.cc
fe2d011a5a67a3e6c8c7f9e50ec3aec272fbfb14
[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 process_music ();
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::process_music ()
73 {
74
75   if (!sep_span_)
76     {
77       sep_span_ = make_spanner ("SeparatingGroupSpanner");
78
79       announce_grob(sep_span_, SCM_EOL);
80       sep_span_->set_bound (LEFT, unsmob_grob (get_property ("currentCommandColumn")));
81     }
82 }
83 void
84 Separating_line_group_engraver::finalize ()
85 {
86   if (!sep_span_)
87     return ;
88   
89   SCM ccol = get_property ("currentCommandColumn");
90   Grob *column = unsmob_grob (ccol);
91   
92   sep_span_->set_bound (RIGHT, unsmob_grob (ccol));
93   typeset_grob (sep_span_);
94   sep_span_ =0;
95
96   for  (int i= 0 ; i < last_spacings_.note_spacings_.size(); i++)
97     {
98       Pointer_group_interface::add_grob (last_spacings_.note_spacings_[i],
99                                          ly_symbol2scm ("right-items" ),
100                                          column);
101     }
102    
103   if(last_spacings_.staff_spacing_
104      && last_spacings_.staff_spacing_->get_column () == column)
105     {
106       last_spacings_.staff_spacing_->suicide ();
107     }
108 }
109
110 void
111 Separating_line_group_engraver::acknowledge_grob (Grob_info i)
112 {
113   Item * it = dynamic_cast <Item *> (i.grob_);
114   if (!it)
115     return;
116   if (it->get_parent (X_AXIS)
117       && it->get_parent (X_AXIS)
118       ->has_extent_callback_b(Axis_group_interface::group_extent_callback_proc, X_AXIS))
119     return;
120
121   
122   if (to_boolean (it->get_grob_property ("no-spacing-rods")))
123     return ;
124
125   if (Note_spacing::has_interface (it)) 
126     {
127       current_spacings_.note_spacings_.push (it);
128       return ;
129     }
130   
131   bool ib =Item::breakable_b (it);
132   Item *&p_ref_ (ib ? break_item_
133                  : musical_item_);
134
135   if (!p_ref_)
136     {
137       p_ref_ = make_item ("SeparationItem");
138
139       if (ib)
140         {
141           p_ref_->set_grob_property ("breakable", SCM_BOOL_T);
142           daddy_trans_->set_property ("breakableSeparationItem", p_ref_->self_scm ());
143         }
144       announce_grob(p_ref_, SCM_EOL);
145
146       if (p_ref_ == break_item_)
147         {
148           Item *it  = make_item ("StaffSpacing");
149           current_spacings_.staff_spacing_ = it;
150           it->set_grob_property ("left-items", gh_cons (break_item_->self_scm (), SCM_EOL));
151           
152           announce_grob(it, SCM_EOL);
153
154           if (int i = last_spacings_.note_spacings_.size ())
155             {
156               for (; i--;)
157                 Pointer_group_interface::add_grob (last_spacings_.note_spacings_[i],
158                                                    ly_symbol2scm ("right-items"),
159                                                    break_item_);
160                                      
161             }
162           else if (last_spacings_.staff_spacing_)
163             {
164               
165               last_spacings_.staff_spacing_->set_grob_property ("right-items",
166                                                                 gh_cons (break_item_->self_scm(), SCM_EOL));
167             }
168         }
169     }
170
171   if (Accidental_placement::has_interface (it))
172     Separation_item::add_conditional_item (p_ref_, it);
173   else
174     Separation_item::add_item (p_ref_,it);
175 }
176
177 void
178 Separating_line_group_engraver::start_translation_timestep ()
179 {
180   if (break_item_)
181     daddy_trans_->unset_property (ly_symbol2scm ("breakableSeparationItem"));
182   break_item_ =0;
183 }
184
185 void
186 Separating_line_group_engraver::stop_translation_timestep ()
187 {
188   if (break_item_)
189     {
190       Separating_group_spanner::add_spacing_unit (sep_span_, break_item_);
191       typeset_grob (break_item_);
192     }
193   
194   if (Item * sp = current_spacings_.staff_spacing_)
195     {
196       /*
197         TODO: should really look at the left-items of following
198         note-spacing grobs.
199        */
200       if (musical_item_)
201         Pointer_group_interface::add_grob (sp, ly_symbol2scm ("right-items"),
202                                            musical_item_);
203
204       typeset_grob (sp);
205     }
206
207   
208   if (!current_spacings_.empty ())
209     {
210       last_spacings_ = current_spacings_;
211     }
212
213   current_spacings_.clear ();
214   
215   if (musical_item_)
216     {
217       Separating_group_spanner::add_spacing_unit (sep_span_, musical_item_);
218       typeset_grob (musical_item_);
219     }
220   
221   musical_item_ =0;
222 }
223
224
225 ENTER_DESCRIPTION(Separating_line_group_engraver,
226 /* descr */       "Generates objects for computing spacing parameters.",
227 /* creats*/       "SeparationItem SeparatingGroupSpanner",
228 /* accepts */     "",
229 /* acks  */      "item-interface",
230 /* reads */       "",
231 /* write */       "breakableSeparationItem");