2 stem-tremolo.cc -- implement Stem_tremolo
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "directional-element-interface.hh"
14 #include "output-def.hh"
15 #include "staff-symbol-referencer.hh"
16 #include "stem-tremolo.hh"
20 /* TODO: lengthen stem if necessary */
22 MAKE_SCHEME_CALLBACK (Stem_tremolo, dim_callback, 2);
24 /* todo: init with cons. */
26 Stem_tremolo::dim_callback (SCM e, SCM)
28 Grob *se = unsmob_grob (e);
30 Real space = Staff_symbol_referencer::staff_space (se);
31 return ly_interval2scm (Interval (-space, space));
34 /* ugh ? --from Slur */
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);
43 SCM mol = me->get_uncached_stencil ();
45 if (Stencil *m = unsmob_stencil (mol))
46 return ly_interval2scm (m->extent (a));
48 return ly_interval2scm (Interval ());
52 Stem_tremolo::raw_stencil (Grob *me)
54 Grob *stem = unsmob_grob (me->get_property ("stem"));
55 Spanner*beam = Stem::get_beam (stem);
60 SCM s = beam->get_property ("positions");
61 if (is_number_pair (s))
62 dy = -scm_to_double (ly_car (s)) +scm_to_double (ly_cdr (s));
64 Real dx = Beam::last_visible_stem (beam)->relative_coordinate (0, X_AXIS)
65 - Beam::first_visible_stem (beam)->relative_coordinate (0, X_AXIS);
66 dydx = dx ? dy/dx : 0;
72 Real ss = Staff_symbol_referencer::staff_space (me);
73 Real thick = robust_scm2double (me->get_property ("beam-thickness"),1);
74 Real width = robust_scm2double (me->get_property ("beam-width"),1);
75 Real blot = me->get_paper ()->get_dimension (ly_symbol2scm ("blotdiameter"));
80 Stencil a (Lookup::beam (dydx, width, thick, blot));
81 a.translate (Offset (-width * 0.5, width * 0.5 * dydx));
83 int tremolo_flags = 0;
84 SCM s = me->get_property ("flag-count");
85 if (scm_is_number (s))
86 tremolo_flags = scm_to_int (s);
90 programming_error ("No tremolo flags?");
96 /* Who the fuck is 0.81 ? --hwn. */
97 Real beam_translation = beam ? Beam::get_beam_translation (beam) : 0.81;
100 for (int i = 0; i < tremolo_flags; i++)
103 b.translate_axis (beam_translation * i, Y_AXIS);
109 MAKE_SCHEME_CALLBACK (Stem_tremolo,print,1);
111 Stem_tremolo::print (SCM grob)
113 Grob *me = unsmob_grob (grob);
114 Grob *stem = unsmob_grob (me->get_property ("stem"));
117 programming_error ("No stem for stem-tremolo");
121 Spanner *beam = Stem::get_beam (stem);
122 Direction stemdir = Stem::get_direction (stem);
126 Real beam_translation
127 = (beam && beam->is_live ())
128 ? Beam::get_beam_translation (beam)
131 Stencil mol = raw_stencil (me);
132 Interval mol_ext = mol.extent (Y_AXIS);
133 Real ss = Staff_symbol_referencer::staff_space (me);
135 // ugh, rather calc from Stem_tremolo_req
136 int beam_count = beam ? (Stem::beam_multiplicity (stem).length () + 1) : 0;
138 Real beamthickness = 0.0;
139 SCM sbt = (beam) ? beam->get_property ("thickness") : SCM_EOL ;
140 if (scm_is_number (sbt))
141 beamthickness = scm_to_double (sbt) * ss;
144 = Stem::stem_end_position (stem) * ss / 2
145 - stemdir * (beam_count * beamthickness
146 + ((beam_count -1) >? 0) * beam_translation);
148 /* FIXME: the 0.33 ss is to compensate for the size of the note head. */
149 Real chord_start_y = Stem::chord_start_y (stem) + 0.33 * ss * stemdir;
151 Real padding = beam_translation;
153 /* if there is a flag, just above/below the notehead.
154 if there is not enough space, center on remaining space,
155 else one beamspace away from stem end. */
156 if (!beam && Stem::duration_log (stem) >= 3)
158 mol.align_to (Y_AXIS, -stemdir);
159 mol.translate_axis (chord_start_y + 0.5 * stemdir, Y_AXIS);
161 else if (stemdir * (end_y - chord_start_y) - 2 * padding - mol_ext.length ()
163 mol.translate_axis (0.5 * (end_y + chord_start_y) - mol_ext.center (),
166 mol.translate_axis (end_y - stemdir * beam_translation -mol_ext [stemdir],
169 return mol.smobbed_copy ();
174 ADD_INTERFACE (Stem_tremolo,"stem-tremolo-interface",
175 "A beam slashing a stem to indicate a tremolo.",
176 "stem beam-width beam-thickness flag-count");