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