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