2 item.cc -- implement Item
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
11 #include "axis-group-interface.hh"
12 #include "paper-score.hh"
14 #include "paper-column.hh"
15 #include "lily-guile.hh"
17 #include "pointer-group-interface.hh"
25 return new Item (*this);
31 broken_to_drul_[LEFT] = broken_to_drul_[RIGHT] = 0;
35 Item copy ctor. Copy nothing: everything should be a elt property
36 or a special purpose pointer (such as broken_to_drul_[]) */
37 Item::Item (Item const &s)
40 broken_to_drul_[LEFT] = broken_to_drul_[RIGHT] = 0;
44 Item::is_non_musical (Grob *me)
49 Item *i = dynamic_cast<Item *> (me->get_parent (X_AXIS));
50 return i ? Item::is_non_musical (i) : to_boolean (me->get_property ("non-musical"));
54 Item::get_column () const
56 Item *parent = dynamic_cast<Item *> (get_parent (X_AXIS));
57 return parent ? parent->get_column () : 0;
61 Item::get_system () const
63 Grob *g = get_parent (X_AXIS);
64 return g ? g->get_system () : 0;
68 Item::copy_breakable_items ()
70 Drul_array<Item *> new_copies;
74 Grob *dolly = clone ();
75 Item *item = dynamic_cast<Item *> (dolly);
76 get_root_system (this)->typeset_grob (item);
79 while (flip (&i) != LEFT);
81 broken_to_drul_ = new_copies;
85 Item::is_broken () const
87 return broken_to_drul_[LEFT] || broken_to_drul_[RIGHT];
91 Generate items for begin and end-of line.
94 Item::discretionary_processing ()
99 if (Item::is_non_musical (this))
100 copy_breakable_items ();
104 Item::find_broken_piece (System *l) const
106 if (get_system () == l)
107 return (Item *) (this);
112 Grob *s = broken_to_drul_[d];
113 if (s && s->get_system () == l)
116 while (flip (&d) != LEFT);
122 Item::find_prebroken_piece (Direction d) const
124 Item *me = (Item *) (this);
127 return dynamic_cast<Item *> (broken_to_drul_[d]);
131 Item::break_status_dir () const
135 Item *i = dynamic_cast<Item *> (original ());
137 return (i->broken_to_drul_[LEFT] == this) ? LEFT : RIGHT;
144 Item::handle_prebroken_dependencies ()
146 Grob::handle_prebroken_dependencies ();
149 Can't do this earlier, because try_visibility_lambda () might set
150 the elt property transparent, which would then be copied.
152 if (!Item::break_visible (this))
157 Item::break_visible (Grob *g)
159 Item *it = dynamic_cast<Item*> (g);
160 SCM vis = g->get_property ("break-visibility");
161 if (scm_is_vector (vis))
162 return to_boolean (scm_c_vector_ref (vis, it->break_status_dir () + 1));
167 Item::pure_is_visible (int start, int end) const
169 SCM vis = get_property ("break-visibility");
170 if (scm_is_vector (vis))
173 int pc_rank = Paper_column::get_rank (get_column ());
174 if (pc_rank == start)
176 else if (pc_rank == end)
178 return to_boolean (scm_vector_ref (vis, scm_from_int (pos)));
184 Item::spanned_rank_interval () const
186 int c = get_column ()->get_rank ();
187 return Interval_t<int> (c, c);
191 spanned_time_interval (Item *l, Item *r)
193 Drul_array<Item*> bounds (l, r);
194 Interval_t<Moment> iv;
199 if (bounds[d] && bounds[d]->get_column ())
200 iv[d] = robust_scm2moment (bounds[d]->get_column ()->get_property ("when"),
203 while (flip (&d) != LEFT);
207 if (!bounds[d] || !bounds[d]->get_column ())
210 while (flip (&d) != LEFT);
218 Item::derived_mark () const
220 if (broken_to_drul_[LEFT])
221 scm_gc_mark (broken_to_drul_[LEFT]->self_scm ());
222 if (broken_to_drul_[RIGHT])
223 scm_gc_mark (broken_to_drul_[RIGHT]->self_scm ());
229 return dynamic_cast<Item *> (unsmob_grob (s));
234 "Grobs can be distinguished in their role in the horizontal spacing.\n"
235 "Many grobs define constraints on the spacing by their sizes. For\n"
236 "example, note heads, clefs, stems, and all other symbols with a fixed\n"
237 "shape. These grobs form a subtype called @code{Item}.\n"
240 "Some items need special treatment for line breaking. For example, a\n"
241 "clef is normally only printed at the start of a line (i.e. after a\n"
242 "line break). To model this, `breakable' items (clef, key signature,\n"
243 "bar lines, etc.) are copied twice. Then we have three versions of each\n"
244 "breakable item: one version if there is no line break, one version\n"
245 "that is printed before the line break (at the end of a system), one\n"
246 "version that is printed after the line break.\n"
248 "Whether these versions are visible and take up space, is determined by\n"
249 "the outcome of the @code{break-visibility}. This grob property is a\n"
250 "function taking a direction (-1, 0 or 1) as argument. It returns a\n"
251 "cons of booleans, signifying whether this grob should be transparent\n"
252 "and have no extent.\n"
254 "The following variables for break-visibility are predefined:\n"
256 " grob will show: before no after\n"
257 " break break break\n"
258 " all-invisible no no no\n"
259 " begin-of-line-visible no no yes\n"
260 " end-of-line-visible yes no no\n"
261 " all-visible yes yes yes\n"
262 " begin-of-line-invisible yes yes no\n"
263 " end-of-line-invisible no yes yes\n"
264 " center-invisible yes no yes\n"
269 "extra-spacing-width "
270 "infinite-spacing-height "