2 staff-symbol.cc -- implement Staff_symbol
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #include "staff-symbol.hh"
12 #include "dimensions.hh"
13 #include "output-def.hh"
16 #include "staff-symbol-referencer.hh"
19 MAKE_SCHEME_CALLBACK (Staff_symbol, print, 1);
22 Staff_symbol::print (SCM smob)
24 Grob *me = unsmob_grob (smob);
25 Spanner *sp = dynamic_cast<Spanner *> (me);
27 = sp->get_bound (LEFT)->common_refpoint (sp->get_bound (RIGHT), X_AXIS);
29 Interval span_points (0, 0);
32 For raggedright without ragged staffs, simply set width to the linewidth.
34 (ok -- lousy UI, since width is in staff spaces)
38 Real t = me->layout ()->get_dimension (ly_symbol2scm ("line-thickness"));
39 t *= robust_scm2double (me->get_property ("thickness"), 1.0);
44 SCM width_scm = me->get_property ("width");
45 if (d == RIGHT && scm_is_number (width_scm))
48 don't multiply by Staff_symbol_referencer::staff_space (me),
49 since that would make aligning staff symbols of different sizes to
50 one right margin hell.
52 span_points[RIGHT] = scm_to_double (width_scm);
56 Item *x = sp->get_bound (d);
58 span_points[d] = x->relative_coordinate (common, X_AXIS);
59 if (!x->break_status_dir ()
60 && !x->extent (x, X_AXIS).is_empty ())
61 span_points[d] += x->extent (x, X_AXIS)[d];
64 span_points[d] -= d* t / 2;
66 while (flip (&d) != LEFT);
70 SCM line_positions = me->get_property ("line-positions");
72 = Lookup::horizontal_line (span_points
73 -me->relative_coordinate (common, X_AXIS),
76 Real space = staff_space (me);
77 if (scm_is_pair (line_positions))
79 for (SCM s = line_positions; scm_is_pair (s);
83 b.translate_axis (scm_to_double (scm_car (s))
84 * 0.5 * space, Y_AXIS);
90 int l = Staff_symbol::line_count (me);
91 Real height = (l - 1) * staff_space (me) / 2;
92 for (int i = 0; i < l; i++)
95 b.translate_axis (height - i * space, Y_AXIS);
99 return m.smobbed_copy ();
104 Staff_symbol::get_steps (Grob *me)
106 return line_count (me) * 2;
110 Staff_symbol::line_count (Grob *me)
112 SCM c = me->get_property ("line-count");
113 if (scm_is_number (c))
114 return scm_to_int (c);
120 Staff_symbol::staff_space (Grob *me)
122 return robust_scm2double (me->get_property ("staff-space"), 1.0);
126 Staff_symbol::get_line_thickness (Grob *me)
128 Real lt = me->layout ()->get_dimension (ly_symbol2scm ("line-thickness"));
130 return robust_scm2double (me->get_property ("thickness"), 1.0) * lt;
134 Staff_symbol::get_ledger_line_thickness (Grob *me)
136 SCM lt_pair = me->get_property ("ledger-line-thickness");
137 Offset z = robust_scm2offset (lt_pair, Offset (1.0, 0.1));
139 return z[X_AXIS] * get_line_thickness (me) + z[Y_AXIS] * staff_space (me);
142 MAKE_SCHEME_CALLBACK(Staff_symbol,height,1);
144 Staff_symbol::height (SCM smob)
146 Grob *me = unsmob_grob (smob);
147 Real t = me->layout ()->get_dimension (ly_symbol2scm ("line-thickness"));
148 t *= robust_scm2double (me->get_property ("thickness"), 1.0);
150 SCM line_positions = me->get_property ("line-positions");
153 Real space = staff_space (me);
154 if (scm_is_pair (line_positions))
156 for (SCM s = line_positions; scm_is_pair (s);
158 y_ext.add_point (scm_to_double (scm_car (s)) * 0.5 * space);
162 int l = Staff_symbol::line_count (me);
163 Real height = (l - 1) * staff_space (me) / 2;
164 y_ext = Interval (-height, height);
167 return ly_interval2scm (y_ext);
173 ADD_INTERFACE (Staff_symbol, "staff-symbol-interface",
174 "This spanner draws the lines of a staff. "
175 "A staff symbol definines a vertical unit, the staff space. "
176 "Quantities that go by a half staff space are called positions "
177 "The center (i.e. middle line "
178 "or space) is position 0. The length of the symbol may be set by hand "
179 "through the @code{width} property. ",
183 "ledger-line-thickness "