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