]> git.donarmstrong.com Git - lilypond.git/blob - lily/axis-group-engraver.cc
2003 -> 2004
[lilypond.git] / lily / axis-group-engraver.cc
1 /*   
2   axis-group-engraver.cc --  implement Axis_group_engraver
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1999--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7  */
8
9 #include "spanner.hh"
10 #include "paper-column.hh"
11 #include "axis-group-interface.hh"
12 #include "engraver.hh"
13 #include "engraver-group-engraver.hh"
14 #include "warn.hh"
15
16 /**
17    Put stuff in a Spanner with an Axis_group_interface.
18    Use as last element of a context. 
19  */
20 class Axis_group_engraver : public Engraver
21 {
22 protected:
23   Spanner *staffline_;
24   Link_array<Grob> elts_;
25   virtual void process_music ();
26   virtual void finalize ();
27   virtual void acknowledge_grob (Grob_info);
28   virtual void process_acknowledged_grobs ();
29   virtual Spanner* get_spanner () ;
30   virtual void add_element (Grob*) ;
31 public:  
32   TRANSLATOR_DECLARATIONS(Axis_group_engraver);
33 };
34
35 Axis_group_engraver::Axis_group_engraver ()
36 {
37   staffline_ = 0;
38 }
39
40 void
41 Axis_group_engraver::process_music ()
42 {
43   if (!staffline_)
44     {
45       staffline_ = get_spanner ();
46
47       Grob *  it = unsmob_grob (get_property ("currentCommandColumn"));
48
49       staffline_->set_bound (LEFT,it);
50
51       announce_grob(staffline_, SCM_EOL);
52     }
53
54
55 Spanner*
56 Axis_group_engraver::get_spanner () 
57 {
58   return make_spanner ("VerticalAxisGroup");
59 }
60
61 /*
62   TODO: should we junk minimumVerticalExtent/extraVerticalExtent ?  
63  */
64
65 void
66 Axis_group_engraver::finalize ()
67 {
68   if (!staffline_)
69     return ;
70   
71   String type = get_daddy_grav ()->context_name ();
72   SCM dims = get_property ("verticalExtent");
73   
74   if (gh_pair_p (dims) && gh_number_p (ly_car (dims))
75       && gh_number_p (ly_cdr (dims)))
76     {
77       staffline_->set_extent (Grob::preset_extent_proc, Y_AXIS);
78       staffline_->set_grob_property ("Y-extent", dims);
79     }
80
81   dims = get_property ("minimumVerticalExtent");
82   if (gh_pair_p (dims) && gh_number_p (ly_car (dims))
83       && gh_number_p (ly_cdr (dims)))
84     staffline_->set_grob_property ("minimum-Y-extent", dims);
85
86   dims = get_property ("extraVerticalExtent");
87   if (gh_pair_p (dims) && gh_number_p (ly_car (dims))
88       && gh_number_p (ly_cdr (dims)))
89     staffline_->set_grob_property ("extra-Y-extent", dims);
90
91   Grob *  it = unsmob_grob (get_property ("currentCommandColumn"));
92
93
94   staffline_->set_bound (RIGHT,it);
95
96   typeset_grob (staffline_);
97   staffline_ = 0;
98 }
99
100 void
101 Axis_group_engraver::acknowledge_grob (Grob_info i)
102 {
103   elts_.push (i.grob_);
104 }
105
106 /*
107   maybe should check if our parent is set, because we now get a
108   cyclic parent relationship if we have two Axis_group_engravers in
109   the context.  */
110 void
111 Axis_group_engraver::process_acknowledged_grobs ()
112 {
113   /* UGH UGH UGH */
114   for (int i=0; i < elts_.size (); i++)
115     {
116       Grob *par = elts_[i]->get_parent (Y_AXIS);
117
118       if (!par || !Axis_group_interface::has_interface (par))
119         if (elts_[i]->is_empty (Y_AXIS))
120           {
121             /*
122               We have to do _something_, otherwise staff objects will
123               end up with System as parent.  
124               
125              */
126             elts_[i]->set_parent (staffline_, Y_AXIS);
127           }
128         else
129           add_element (elts_[i]);
130     }
131   elts_.clear ();
132 }
133
134 void
135 Axis_group_engraver::add_element (Grob*e)
136 {
137   Axis_group_interface::add_element (staffline_, e);
138 }
139
140 /****************************************************************/
141
142 /*
143   
144  maybenot such a good idea after all., to put class declarations in
145  .cc
146  
147 */
148
149 #include "hara-kiri-group-spanner.hh"
150 #include "rhythmic-head.hh"
151
152 class Hara_kiri_engraver : public Axis_group_engraver
153 {
154 protected:
155   virtual Spanner*get_spanner ();
156   virtual void acknowledge_grob (Grob_info);
157   virtual void add_element (Grob *e);
158 public:
159   TRANSLATOR_DECLARATIONS(Hara_kiri_engraver);
160 };
161
162 void
163 Hara_kiri_engraver::add_element (Grob*e)
164 {
165   Hara_kiri_group_spanner::add_element (staffline_, e);
166 }
167
168
169 Spanner*
170 Hara_kiri_engraver::get_spanner () 
171 {
172   Spanner * sp = make_spanner ("RemoveEmptyVerticalGroup");
173   
174   return sp;
175 }
176
177 void
178 Hara_kiri_engraver::acknowledge_grob (Grob_info i)
179 {
180   Axis_group_engraver::acknowledge_grob (i);
181   if (i.grob_->internal_has_interface (ly_symbol2scm ("rhythmic-grob-interface"))
182       || i.grob_->internal_has_interface (ly_symbol2scm ("lyric-interface"))
183       )
184     {
185       Hara_kiri_group_spanner::add_interesting_item (staffline_, i.grob_);
186     }
187 }
188
189
190 Hara_kiri_engraver::Hara_kiri_engraver()
191 {
192 }
193
194 ENTER_DESCRIPTION(Hara_kiri_engraver,
195 /* descr */       "Like Axis_group_engraver, but make a hara kiri spanner, and add "
196 "interesting items (ie. note heads, lyric syllables and normal rests) ",
197 /* creats*/       "RemoveEmptyVerticalGroup",
198 /* accepts */     "",
199 /* acks  */      "grob-interface",
200 /* reads */       "",
201 /* write */       "");
202
203 ENTER_DESCRIPTION(Axis_group_engraver,
204 /* descr */       "Group all objects created in this context in a VerticalAxisGroup spanner.",
205 /* creats*/       "VerticalAxisGroup",
206 /* accepts */     "",
207 /* acks  */      "grob-interface",
208 /* reads */       "verticalExtent minimumVerticalExtent extraVerticalExtent",
209 /* write */       "");