2 stem-tremolo.cc -- implement Stem_tremolo
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.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, 1);
25 /* todo: init with cons. */
27 Stem_tremolo::dim_callback (SCM e)
29 Grob *se = unsmob_grob (e);
31 Real space = Staff_symbol_referencer::staff_space (se);
32 return ly_interval2scm (Interval (-space, space));
36 MAKE_SCHEME_CALLBACK (Stem_tremolo, calc_slope, 1)
38 Stem_tremolo::calc_slope (SCM smob)
40 Grob *me = unsmob_grob (smob);
41 Grob *stem = unsmob_grob (me->get_object ("stem"));
42 Spanner *beam = Stem::get_beam (stem);
47 SCM s = beam->get_property ("quantized-positions");
48 if (is_number_pair (s))
49 dy = - scm_to_double (scm_car (s)) + scm_to_double (scm_cdr (s));
51 Grob *s2 = Beam::last_visible_stem (beam);
52 Grob *s1 = Beam::first_visible_stem (beam);
54 Grob *common = s1->common_refpoint (s2, X_AXIS);
55 Real dx = s2->relative_coordinate (common, X_AXIS) -
56 s1->relative_coordinate (common, X_AXIS);
58 return scm_from_double (dx ? dy / dx : 0);
61 return scm_from_double (0.25);
65 Stem_tremolo::get_beam_translation (Grob *me)
67 Grob *stem = unsmob_grob (me->get_object ("stem"));
68 Spanner *beam = Stem::get_beam (stem);
70 return beam ? Beam::get_beam_translation (beam) : 0.81;
74 Stem_tremolo::raw_stencil (Grob *me, Real slope)
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->layout ()->get_dimension (ly_symbol2scm ("blot-diameter"));
84 Stencil a (Lookup::beam (slope, width, thick, blot));
85 a.translate (Offset (-width * 0.5, width * 0.5 * slope));
87 int tremolo_flags = robust_scm2int (me->get_property ("flag-count"), 0);
90 programming_error ("no tremolo flags");
96 /* Who the fuck is 0.81 ? --hwn. */
97 Real beam_translation = get_beam_translation(me);
100 for (int i = 0; i < tremolo_flags; i++)
103 b.translate_axis (beam_translation * i, Y_AXIS);
111 MAKE_SCHEME_CALLBACK (Stem_tremolo, height, 1);
113 Stem_tremolo::height (SCM smob)
115 Grob *me = unsmob_grob (smob);
118 Cannot use the real slope, since it looks at the Beam.
120 Stencil s1 (raw_stencil (me, 0.35));
122 return ly_interval2scm (s1.extent (Y_AXIS));
126 MAKE_SCHEME_CALLBACK (Stem_tremolo, print, 1);
128 Stem_tremolo::print (SCM grob)
130 Grob *me = unsmob_grob (grob);
131 Grob *stem = unsmob_grob (me->get_object ("stem"));
134 programming_error ("no stem for stem-tremolo");
138 Spanner *beam = Stem::get_beam (stem);
139 Direction stemdir = get_grob_direction (stem);
143 Real beam_translation
144 = (beam && beam->is_live ())
145 ? Beam::get_beam_translation (beam)
148 Stencil mol = raw_stencil (me, robust_scm2double (me->get_property ("slope"),
150 Interval mol_ext = mol.extent (Y_AXIS);
151 Real ss = Staff_symbol_referencer::staff_space (me);
153 // ugh, rather calc from Stem_tremolo_req
154 int beam_count = beam ? (Stem::beam_multiplicity (stem).length () + 1) : 0;
156 Real beamthickness = 0.0;
157 SCM sbt = (beam) ? beam->get_property ("thickness") : SCM_EOL;
158 if (scm_is_number (sbt))
159 beamthickness = scm_to_double (sbt) * ss;
162 = Stem::stem_end_position (stem) * ss / 2
163 - stemdir * (beam_count * beamthickness
164 + (max (beam_count -1, 0) * beam_translation));
166 /* FIXME: the 0.33 ss is to compensate for the size of the note head. */
167 Real chord_start_y = Stem::chord_start_y (stem) + 0.33 * ss * stemdir;
169 Real padding = beam_translation;
171 /* if there is a flag, just above/below the notehead.
172 if there is not enough space, center on remaining space,
173 else one beamspace away from stem end. */
174 if (!beam && Stem::duration_log (stem) >= 3)
176 mol.align_to (Y_AXIS, -stemdir);
177 mol.translate_axis (chord_start_y + 0.5 * stemdir, Y_AXIS);
179 else if (stemdir * (end_y - chord_start_y) - 2 * padding - mol_ext.length ()
181 mol.translate_axis (0.5 * (end_y + chord_start_y) - mol_ext.center (),
184 mol.translate_axis (end_y - stemdir * beam_translation -mol_ext [stemdir],
187 return mol.smobbed_copy ();
190 ADD_INTERFACE (Stem_tremolo, "stem-tremolo-interface",
191 "A beam slashing a stem to indicate a tremolo.",