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