2 stem-tremolo.cc -- implement Stem_tremolo
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "stem-tremolo.hh"
13 #include "directional-element-interface.hh"
16 #include "output-def.hh"
17 #include "staff-symbol-referencer.hh"
21 /* TODO: lengthen stem if necessary */
23 MAKE_SCHEME_CALLBACK (Stem_tremolo, dim_callback, 2);
25 /* todo: init with cons. */
27 Stem_tremolo::dim_callback (SCM e, SCM)
29 Grob *se = unsmob_grob (e);
31 Real space = Staff_symbol_referencer::staff_space (se);
32 return ly_interval2scm (Interval (-space, space));
35 MAKE_SCHEME_CALLBACK (Stem_tremolo, height, 2);
37 Stem_tremolo::height (SCM smob, SCM ax)
39 Axis a = (Axis)scm_to_int (ax);
40 Grob *me = unsmob_grob (smob);
44 /* TODO: fixme. uncached? */
45 return ly_interval2scm (me->get_stencil ()
46 ? me->get_stencil ()->extent (a)
51 Stem_tremolo::raw_stencil (Grob *me)
53 Grob *stem = unsmob_grob (me->get_object ("stem"));
54 Spanner *beam = Stem::get_beam (stem);
56 SCM slope = me->get_property ("slope");
58 if (scm_is_number (slope))
60 dydx = robust_scm2double (slope, 0.0);
67 SCM s = beam->get_property ("positions");
68 if (is_number_pair (s))
69 dy = - scm_to_double (scm_car (s)) + scm_to_double (scm_cdr (s));
71 Real dx = Beam::last_visible_stem (beam)->relative_coordinate (0, X_AXIS)
72 - Beam::first_visible_stem (beam)->relative_coordinate (0, X_AXIS);
73 dydx = dx ? dy / dx : 0;
76 Real ss = Staff_symbol_referencer::staff_space (me);
77 Real thick = robust_scm2double (me->get_property ("beam-thickness"), 1);
78 Real width = robust_scm2double (me->get_property ("beam-width"), 1);
79 Real blot = me->get_layout ()->get_dimension (ly_symbol2scm ("blotdiameter"));
84 Stencil a (Lookup::beam (dydx, width, thick, blot));
85 a.translate (Offset (-width * 0.5, width * 0.5 * dydx));
87 int tremolo_flags = 0;
88 SCM s = me->get_property ("flag-count");
89 if (scm_is_number (s))
90 tremolo_flags = scm_to_int (s);
94 programming_error ("no tremolo flags");
100 /* Who the fuck is 0.81 ? --hwn. */
101 Real beam_translation = beam ? Beam::get_beam_translation (beam) : 0.81;
104 for (int i = 0; i < tremolo_flags; i++)
107 b.translate_axis (beam_translation * i, Y_AXIS);
113 MAKE_SCHEME_CALLBACK (Stem_tremolo, print, 1);
115 Stem_tremolo::print (SCM grob)
117 Grob *me = unsmob_grob (grob);
118 Grob *stem = unsmob_grob (me->get_object ("stem"));
121 programming_error ("no stem for stem-tremolo");
125 Spanner *beam = Stem::get_beam (stem);
126 Direction stemdir = get_grob_direction (stem);
130 Real beam_translation
131 = (beam && beam->is_live ())
132 ? Beam::get_beam_translation (beam)
135 Stencil mol = raw_stencil (me);
136 Interval mol_ext = mol.extent (Y_AXIS);
137 Real ss = Staff_symbol_referencer::staff_space (me);
139 // ugh, rather calc from Stem_tremolo_req
140 int beam_count = beam ? (Stem::beam_multiplicity (stem).length () + 1) : 0;
142 Real beamthickness = 0.0;
143 SCM sbt = (beam) ? beam->get_property ("thickness") : SCM_EOL;
144 if (scm_is_number (sbt))
145 beamthickness = scm_to_double (sbt) * ss;
148 = Stem::stem_end_position (stem) * ss / 2
149 - stemdir * (beam_count * beamthickness
150 + (max (beam_count -1, 0) * beam_translation));
152 /* FIXME: the 0.33 ss is to compensate for the size of the note head. */
153 Real chord_start_y = Stem::chord_start_y (stem) + 0.33 * ss * stemdir;
155 Real padding = beam_translation;
157 /* if there is a flag, just above/below the notehead.
158 if there is not enough space, center on remaining space,
159 else one beamspace away from stem end. */
160 if (!beam && Stem::duration_log (stem) >= 3)
162 mol.align_to (Y_AXIS, -stemdir);
163 mol.translate_axis (chord_start_y + 0.5 * stemdir, Y_AXIS);
165 else if (stemdir * (end_y - chord_start_y) - 2 * padding - mol_ext.length ()
167 mol.translate_axis (0.5 * (end_y + chord_start_y) - mol_ext.center (),
170 mol.translate_axis (end_y - stemdir * beam_translation -mol_ext [stemdir],
173 return mol.smobbed_copy ();
176 ADD_INTERFACE (Stem_tremolo, "stem-tremolo-interface",
177 "A beam slashing a stem to indicate a tremolo.",