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