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>
11 #include "paper-score.hh"
13 #include "paper-column.hh"
14 #include "lily-guile.hh"
16 #include "group-interface.hh"
19 Item::clone (int count) const
21 return new Item (*this, count);
25 Item::Item (SCM s, Object_key const *key)
28 broken_to_drul_[LEFT] = broken_to_drul_[RIGHT]=0;
29 Group_interface::add_thing (this, ly_symbol2scm ("interfaces"), ly_symbol2scm ("item-interface"));
33 Item copy ctor. Copy nothing: everything should be a elt property
34 or a special purpose pointer (such as broken_to_drul_[]) */
35 Item::Item (Item const &s, int copy_count)
36 : Grob (s, copy_count)
38 broken_to_drul_[LEFT] = broken_to_drul_[RIGHT] =0;
43 Item::is_breakable (Grob*me)
48 if (!dynamic_cast<Item*> (me))
49 me->programming_error ("only items can be breakable.");
51 Item * i = dynamic_cast<Item*> (me->get_parent (X_AXIS));
52 return (i) ? Item::is_breakable (i) : to_boolean (me->get_property ("breakable"));
56 Item::get_column () const
58 Item *parent = dynamic_cast<Item*> (get_parent (X_AXIS));
59 return parent ? parent->get_column () : 0;
63 Item::get_system () const
65 Grob *g = get_parent (X_AXIS);
66 return g ? g->get_system () : 0;
71 Item::copy_breakable_items ()
73 Drul_array<Item *> new_copies;
78 Grob * dolly = clone (count ++);
79 Item * item = dynamic_cast<Item*> (dolly);
80 pscore_->system_->typeset_grob (item);
83 while (flip (&i) != LEFT);
84 broken_to_drul_= new_copies;
89 Item::is_broken () const
91 return broken_to_drul_[LEFT] || broken_to_drul_[RIGHT];
96 Generate items for begin and end-of line.
99 Item::discretionary_processing ()
104 if (Item::is_breakable (this))
105 copy_breakable_items ();
109 Item::find_broken_piece (System*l) const
111 if (get_system () == l)
112 return (Item*) (this);
116 Grob *s = broken_to_drul_[d];
117 if (s && s->get_system () == l)
120 while (flip (&d) != LEFT);
127 Item::find_prebroken_piece (Direction d) const
129 Item * me = (Item *) (this);
132 return dynamic_cast<Item*> (broken_to_drul_[d]);
137 Item::break_status_dir () const
141 Item * i = dynamic_cast<Item*> (original_);
143 return (i->broken_to_drul_[LEFT] == this) ? LEFT : RIGHT;
150 Item::handle_prebroken_dependencies ()
152 Grob::handle_prebroken_dependencies ();
155 Can't do this earlier, because try_visibility_lambda () might set
156 the elt property transparent, which would then be copied.
160 give the item to break-visibility itself, so the function can do
161 more complicated things.
163 SCM vis = get_property ("break-visibility");
164 if (ly_c_procedure_p (vis))
166 SCM args = scm_list_n (scm_int2num (break_status_dir ()), SCM_UNDEFINED);
167 SCM result = scm_apply_0 (vis, args);
168 bool trans = ly_scm2bool (scm_car (result));
169 bool empty = ly_scm2bool (scm_cdr (result));
175 set_extent (SCM_EOL, X_AXIS);
176 set_extent (SCM_EOL, Y_AXIS);
179 set_property ("print-function", SCM_EOL);
184 Item::do_derived_mark ()const
186 if (broken_to_drul_[LEFT])
187 scm_gc_mark (broken_to_drul_[LEFT]->self_scm ());
188 if (broken_to_drul_[RIGHT])
189 scm_gc_mark (broken_to_drul_[RIGHT]->self_scm ());
196 return dynamic_cast<Item*> (unsmob_grob (s));
205 "Grobs can be distinguished in their role in the horizontal spacing.\n"
206 "Many grobs define constraints on the spacing by their sizes. For\n"
207 "example, note heads, clefs, stems, and all other symbols with a fixed\n"
208 "shape. These grobs form a subtype called @code{Item}.\n"
211 "Some items need special treatment for line breaking. For example, a\n"
212 "clef is normally only printed at the start of a line (i.e. after a\n"
213 "line break). To model this, `breakable' items (clef, key signature,\n"
214 "bar lines, etc.) are copied twice. Then we have three versions of each\n"
215 "breakable item: one version if there is no line break, one version\n"
216 "that is printed before the line break (at the end of a system), one\n"
217 "version that is printed after the line break.\n"
219 "Whether these versions are visible and take up space, is determined by\n"
220 "the outcome of the @code{break-visibility}. This grob property is a\n"
221 "function taking a direction (-1, 0 or 1) as argument. It returns a\n"
222 "cons of booleans, signifying whether this grob should be transparent\n"
223 "and have no extent.\n"
225 "The following variables for break-visibility are predefined:\n"
227 " grob will show: before no after\n"
228 " break break break\n"
229 " all-invisible no no no\n"
230 " begin-of-line-visible no no yes\n"
231 " end-of-line-visible yes no no\n"
232 " all-visible yes yes yes\n"
233 " begin-of-line-invisible yes yes no\n"
234 " end-of-line-invisible no yes yes\n"
237 "no-spacing-rods break-visibility breakable")