2 item.cc -- implement Item
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "paper-score.hh"
12 #include "paper-column.hh"
14 #include "lily-guile.hh"
16 #include "group-interface.hh"
20 Item::clone (int count) const
22 return new Item (*this, count);
26 Item::Item (SCM s, Object_key const *key)
29 broken_to_drul_[LEFT] = broken_to_drul_[RIGHT]=0;
30 Group_interface::add_thing (this, ly_symbol2scm ("interfaces"), ly_symbol2scm ("item-interface"));
34 Item copy ctor. Copy nothing: everything should be a elt property
35 or a special purpose pointer (such as broken_to_drul_[]) */
36 Item::Item (Item const &s, int copy_count)
37 : Grob (s, copy_count)
39 broken_to_drul_[LEFT] = broken_to_drul_[RIGHT] =0;
44 Item::is_breakable (Grob*me)
49 if (!dynamic_cast<Item*> (me))
50 me->programming_error ("only items can be breakable.");
52 Item * i = dynamic_cast<Item*> (me->get_parent (X_AXIS));
53 return (i) ? Item::is_breakable (i) : to_boolean (me->get_property ("breakable"));
57 Item::get_column () const
59 Item *parent = dynamic_cast<Item*> (get_parent (X_AXIS));
60 return parent ? parent->get_column () : 0;
64 Item::get_system () const
66 Grob *g = get_parent (X_AXIS);
67 return g ? g->get_system () : 0;
72 Item::copy_breakable_items ()
74 Drul_array<Item *> new_copies;
79 Grob * dolly = clone (count ++);
80 Item * item = dynamic_cast<Item*> (dolly);
81 pscore_->system_->typeset_grob (item);
84 while (flip (&i) != LEFT);
85 broken_to_drul_= new_copies;
90 Item::is_broken () const
92 return broken_to_drul_[LEFT] || broken_to_drul_[RIGHT];
97 Generate items for begin and end-of line.
100 Item::discretionary_processing ()
105 if (Item::is_breakable (this))
106 copy_breakable_items ();
110 Item::find_broken_piece (System*l) const
112 if (get_system () == l)
113 return (Item*) (this);
117 Grob *s = broken_to_drul_[d];
118 if (s && s->get_system () == l)
121 while (flip (&d) != LEFT);
128 Item::find_prebroken_piece (Direction d) const
130 Item * me = (Item *) (this);
133 return dynamic_cast<Item*> (broken_to_drul_[d]);
138 Item::break_status_dir () const
142 Item * i = dynamic_cast<Item*> (original_);
144 return (i->broken_to_drul_[LEFT] == this) ? LEFT : RIGHT;
151 Item::handle_prebroken_dependencies ()
153 Grob::handle_prebroken_dependencies ();
156 Can't do this earlier, because try_visibility_lambda () might set
157 the elt property transparent, which would then be copied.
161 give the item to break-visibility itself, so the function can do
162 more complicated things.
164 SCM vis = get_property ("break-visibility");
165 if (ly_c_procedure_p (vis))
167 SCM args = scm_list_n (scm_int2num (break_status_dir ()), SCM_UNDEFINED);
168 SCM result = scm_apply_0 (vis, args);
169 bool trans = ly_scm2bool (scm_car (result));
170 bool empty = ly_scm2bool (scm_cdr (result));
176 set_extent (SCM_EOL, X_AXIS);
177 set_extent (SCM_EOL, Y_AXIS);
180 set_property ("print-function", SCM_EOL);
185 Item::do_derived_mark ()const
187 if (broken_to_drul_[LEFT])
188 scm_gc_mark (broken_to_drul_[LEFT]->self_scm ());
189 if (broken_to_drul_[RIGHT])
190 scm_gc_mark (broken_to_drul_[RIGHT]->self_scm ());
197 return dynamic_cast<Item*> (unsmob_grob (s));
206 "Grobs can be distinguished in their role in the horizontal spacing.\n"
207 "Many grobs define constraints on the spacing by their sizes. For\n"
208 "example, note heads, clefs, stems, and all other symbols with a fixed\n"
209 "shape. These grobs form a subtype called @code{Item}.\n"
212 "Some items need special treatment for line breaking. For example, a\n"
213 "clef is normally only printed at the start of a line (i.e. after a\n"
214 "line break). To model this, `breakable' items (clef, key signature,\n"
215 "bar lines, etc.) are copied twice. Then we have three versions of each\n"
216 "breakable item: one version if there is no line break, one version\n"
217 "that is printed before the line break (at the end of a system), one\n"
218 "version that is printed after the line break.\n"
220 "Whether these versions are visible and take up space, is determined by\n"
221 "the outcome of the @code{break-visibility}. This grob property is a\n"
222 "function taking a direction (-1, 0 or 1) as argument. It returns a\n"
223 "cons of booleans, signifying whether this grob should be transparent\n"
224 "and have no extent.\n"
226 "The following variables for break-visibility are predefined:\n"
228 " grob will show: before no after\n"
229 " break break break\n"
230 " all-invisible no no no\n"
231 " begin-of-line-visible no no yes\n"
232 " end-of-line-visible yes no no\n"
233 " all-visible yes yes yes\n"
234 " begin-of-line-invisible yes yes no\n"
235 " end-of-line-invisible no yes yes\n"
238 "no-spacing-rods break-visibility breakable")