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