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