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