]> git.donarmstrong.com Git - lilypond.git/blob - lily/separating-line-group-engraver.cc
release: 1.5.27
[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--2001 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
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_, 0);
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   sep_span_p_->set_bound (RIGHT, unsmob_grob (ccol));
81   typeset_grob (sep_span_p_);
82   sep_span_p_ =0;
83
84   for  (int i= 0 ; i < last_spacings_.note_spacings_.size(); i++)
85     {
86       last_spacings_.note_spacings_[i]->set_grob_property ("right-items", gh_cons (ccol, SCM_EOL));
87     }
88
89   if(last_spacings_.staff_spacing_
90      && last_spacings_.staff_spacing_->column_l () == unsmob_grob (ccol))
91     {
92       last_spacings_.staff_spacing_->suicide ();
93     }
94 }
95
96 void
97 Separating_line_group_engraver::acknowledge_grob (Grob_info i)
98 {
99   Item * it = dynamic_cast <Item *> (i.grob_l_);
100   if (!it)
101     return;
102   if (it->get_parent (X_AXIS)
103       && it->get_parent (X_AXIS)
104       ->has_extent_callback_b(Axis_group_interface::group_extent_callback_proc, X_AXIS))
105     return;
106
107   if (Note_spacing::has_interface (it)) 
108     {
109       current_spacings_.note_spacings_.push (it);
110       return ;
111     }
112   
113   bool ib =Item::breakable_b (it);
114   Item *&p_ref_ (ib ? break_malt_p_
115                  : musical_malt_p_);
116
117   if (!p_ref_)
118     {
119       p_ref_ = new Item (get_property ("SeparationItem"));
120
121       if (ib)
122         p_ref_->set_grob_property ("breakable", SCM_BOOL_T);
123       announce_grob (p_ref_, 0);
124
125       if (p_ref_ == break_malt_p_)
126         {
127           Item *it  = new Item (get_property ("StaffSpacing"));
128           current_spacings_.staff_spacing_ = it;
129           it->set_grob_property ("left-items", gh_cons (break_malt_p_->self_scm (), SCM_EOL));
130           
131           announce_grob (it, 0);
132
133           if (int i = last_spacings_.note_spacings_.size ())
134             {
135               SCM break_malt = gh_cons (break_malt_p_->self_scm (), SCM_EOL);
136               for (; i--;)
137                 last_spacings_.note_spacings_[i]
138                   ->set_grob_property ("right-items",break_malt);
139                                      
140             }
141           else if (last_spacings_.staff_spacing_)
142             {
143               
144               last_spacings_.staff_spacing_->set_grob_property ("right-items",
145                                                                 gh_cons (break_malt_p_->self_scm(), SCM_EOL));
146             }
147         }
148     }
149
150   Separation_item::add_item (p_ref_,it);
151 }
152
153 void
154 Separating_line_group_engraver::start_translation_timestep ()
155 {
156
157 }
158
159 void
160 Separating_line_group_engraver::stop_translation_timestep ()
161 {
162   if (break_malt_p_)
163     {
164       Separating_group_spanner::add_spacing_unit (sep_span_p_, break_malt_p_);
165       typeset_grob (break_malt_p_);
166
167       break_malt_p_ =0;
168     }
169
170   if (Item * sp = current_spacings_.staff_spacing_)
171     {
172       /*
173         TODO: should really look at the left-items of following
174         note-spacing grobs.
175        */
176       if (musical_malt_p_)
177         sp->set_grob_property ("right-items", musical_malt_p_->self_scm());
178
179       typeset_grob (sp);
180     }
181
182   if (!current_spacings_.empty ())
183     {
184       last_spacings_ = current_spacings_;
185     }
186
187   current_spacings_.clear ();
188   
189   if (musical_malt_p_)
190     {
191       Separating_group_spanner::add_spacing_unit (sep_span_p_, musical_malt_p_);
192       typeset_grob (musical_malt_p_);
193     }
194   
195   musical_malt_p_ =0;
196 }
197
198
199
200
201
202 ENTER_DESCRIPTION(Separating_line_group_engraver,
203 /* descr */       "Generates objects for computing spacing parameters.",
204 /* creats*/       "SeparationItem SeparatingGroupSpanner",
205 /* acks  */       "grob-interface",
206 /* reads */       "",
207 /* write */       "");