]> git.donarmstrong.com Git - lilypond.git/blob - lily/separating-line-group-engraver.cc
release: 1.5.24
[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 class Separating_line_group_engraver : public Engraver
19 {
20 protected:
21   Item * break_malt_p_;
22   Item * musical_malt_p_;
23   Item * last_musical_malt_p_;
24
25   Grob * last_note_spacing_;
26   Grob * current_note_spacing_;
27   Grob * staff_spacing_;
28   
29   Spanner * sep_span_p_;
30   
31   virtual void acknowledge_grob (Grob_info);
32   virtual void initialize ();
33   virtual void finalize ();
34   virtual void stop_translation_timestep ();
35 public:
36   TRANSLATOR_DECLARATIONS(Separating_line_group_engraver);
37 };
38
39 Separating_line_group_engraver::Separating_line_group_engraver ()
40 {
41   last_note_spacing_ = 0;
42   current_note_spacing_ = 0;
43   staff_spacing_ =0;
44   
45   sep_span_p_ = 0;
46   break_malt_p_ = 0;
47   musical_malt_p_ =0;
48 }
49
50 void
51 Separating_line_group_engraver::initialize ()
52 {
53   sep_span_p_ = new Spanner (get_property ("SeparatingGroupSpanner"));
54
55   announce_grob (sep_span_p_, 0);
56   sep_span_p_->set_bound (LEFT, unsmob_grob (get_property ("currentCommandColumn")));
57 }
58
59 void
60 Separating_line_group_engraver::finalize ()
61 {
62   sep_span_p_->set_bound (RIGHT, unsmob_grob (get_property ("currentCommandColumn")));
63   typeset_grob (sep_span_p_);
64   sep_span_p_ =0;
65 }
66
67 void
68 Separating_line_group_engraver::acknowledge_grob (Grob_info i)
69 {
70   Item * it = dynamic_cast <Item *> (i.grob_l_);
71   if (!it)
72     return;
73   if (it->get_parent (X_AXIS)
74       && it->get_parent (X_AXIS)
75       ->has_extent_callback_b(Axis_group_interface::group_extent_callback_proc, X_AXIS))
76     return;
77
78   if (Note_spacing::has_interface (it)) 
79     {
80       current_note_spacing_ =  it;
81       return ;
82     }
83   
84   bool ib =Item::breakable_b (it);
85   Item *&p_ref_ (ib ? break_malt_p_
86                  : musical_malt_p_);
87
88   if (!p_ref_)
89     {
90       p_ref_ = new Item (get_property ("SeparationItem"));
91
92       if (ib)
93         p_ref_->set_grob_property ("breakable", SCM_BOOL_T);
94       announce_grob (p_ref_, 0);
95
96       if (p_ref_ == break_malt_p_)
97         {
98           staff_spacing_ = new Item (get_property ("StaffSpacing"));
99           staff_spacing_->set_grob_property ("left-item", break_malt_p_->self_scm ());
100           announce_grob (staff_spacing_, 0);
101
102           if (last_note_spacing_)
103             last_note_spacing_->set_grob_property ("right-item",
104                                                    break_malt_p_->self_scm ());
105         }
106     }
107
108   Separation_item::add_item (p_ref_,it);
109 }
110
111 void
112 Separating_line_group_engraver::stop_translation_timestep ()
113 {
114   if (break_malt_p_)
115     {
116       Separating_group_spanner::add_spacing_unit (sep_span_p_, break_malt_p_);
117       typeset_grob (break_malt_p_);
118
119       break_malt_p_ =0;
120     }
121
122   if (staff_spacing_)
123     {
124       if (musical_malt_p_)
125         staff_spacing_->set_grob_property ("right-item", musical_malt_p_->self_scm());
126
127       typeset_grob (staff_spacing_);
128       staff_spacing_ = 0;
129     }
130   
131   if (musical_malt_p_)
132     {
133       Separating_group_spanner::add_spacing_unit (sep_span_p_, musical_malt_p_);
134       typeset_grob (musical_malt_p_);
135     }
136
137   last_note_spacing_ = current_note_spacing_ ;
138   current_note_spacing_ =0 ;
139   
140   musical_malt_p_ =0;
141 }
142
143
144
145
146
147 ENTER_DESCRIPTION(Separating_line_group_engraver,
148 /* descr */       "Generates objects for computing spacing parameters.",
149 /* creats*/       "SeparationItem SeparatingGroupSpanner",
150 /* acks  */       "grob-interface",
151 /* reads */       "",
152 /* write */       "");