(process_acknowledged_grobs):
[lilypond.git] / lily / staff-symbol.cc
blobc8db2f48122f84123aea00d952b8e0aada756856
1 /*
2 staff-symbol.cc -- implement Staff_symbol
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
9 #include "lookup.hh"
10 #include "dimensions.hh"
11 #include "paper-def.hh"
12 #include "molecule.hh"
13 #include "warn.hh"
14 #include "item.hh"
15 #include "staff-symbol.hh"
16 #include "staff-symbol-referencer.hh"
17 #include "spanner.hh"
21 MAKE_SCHEME_CALLBACK (Staff_symbol,brew_molecule,1);
23 SCM
24 Staff_symbol::brew_molecule (SCM smob)
26 Grob *me = unsmob_grob (smob);
27 Spanner* sp = dynamic_cast<Spanner*> (me);
28 Grob * common
29 = sp->get_bound (LEFT)->common_refpoint (sp->get_bound (RIGHT), X_AXIS);
31 Real width = 0.0;
34 For raggedright without ragged staffs, simply set width to the linewidth.
36 (ok -- lousy UI, since width is in staff spaces)
38 --hwn.
40 SCM width_scm = me->get_grob_property ("width");
41 if (gh_number_p (width_scm))
45 don't multiply by Staff_symbol_referencer::staff_space (me),
46 since that would make aligning staff symbols of different sizes to
47 one right margin hell.
48 */
49 width = gh_scm2double (width_scm);
51 else
53 width = sp->get_bound (RIGHT)->relative_coordinate (common , X_AXIS);
56 // respect indentation, if any
57 width -= sp->get_bound (LEFT)->relative_coordinate (common, X_AXIS);
59 if (width < 0)
61 warning (_f ("staff symbol: indentation yields beyond end of line"));
62 width = 0;
65 Real t = me->get_paper ()->get_realvar (ly_symbol2scm ("linethickness"));
66 SCM my_thick = me->get_grob_property("thickness");
67 if (gh_number_p (my_thick))
68 t *= gh_scm2double (my_thick);
70 int l = Staff_symbol::line_count (me);
72 Real height = (l-1) * staff_space (me) /2;
73 Molecule m;
74 for (int i=0; i < l; i++)
76 Molecule a =
77 Lookup::horizontal_line (Interval (0,width), t);
79 a.translate_axis (height - i * staff_space (me), Y_AXIS);
80 m.add_molecule (a);
83 return m.smobbed_copy ();
86 int
87 Staff_symbol::get_steps (Grob*me)
89 return line_count (me) * 2;
92 int
93 Staff_symbol::line_count (Grob*me)
95 SCM c = me->get_grob_property ("line-count");
96 if (gh_number_p (c))
97 return gh_scm2int (c);
98 else
99 return 0;
102 Real
103 Staff_symbol::staff_space (Grob*me)
105 Real ss = 1.0;
107 SCM s = me->get_grob_property ("staff-space");
108 if (gh_number_p (s))
109 ss *= gh_scm2double (s);
110 return ss;
116 ADD_INTERFACE (Staff_symbol,"staff-symbol-interface",
117 "This spanner draws the lines of a staff. The center (i.e. middle line "
118 "or space) is position 0. The length of the symbol may be set by hand "
119 "through the @code{width} property. ",
121 "width staff-space thickness line-count");