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>
10 #include "stem-tremolo.hh"
13 #include "paper-def.hh"
17 #include "staff-symbol-referencer.hh"
18 #include "directional-element-interface.hh"
22 lengthen stem if necessary
24 MAKE_SCHEME_CALLBACK (Stem_tremolo,dim_callback,2);
30 Stem_tremolo::dim_callback (SCM e, SCM)
32 Grob * se = unsmob_grob (e);
34 Real space = Staff_symbol_referencer::staff_space (se);
35 return ly_interval2scm (Interval (-space, space));
41 MAKE_SCHEME_CALLBACK (Stem_tremolo, height, 2);
43 Stem_tremolo::height (SCM smob, SCM ax)
45 Axis a = (Axis)ly_scm2int (ax);
46 Grob * me = unsmob_grob (smob);
49 SCM mol = me->get_uncached_stencil ();
51 if (Stencil *m = unsmob_stencil (mol))
52 return ly_interval2scm (m->extent (a));
54 return ly_interval2scm (Interval ());
59 Stem_tremolo::raw_stencil (Grob *me)
61 Grob *stem = unsmob_grob (me->get_property ("stem"));
62 Grob *beam = Stem::get_beam (stem);
68 SCM s = beam->get_property ("positions");
69 if (is_number_pair (s))
71 dy = -ly_scm2double (ly_car (s)) +ly_scm2double (ly_cdr (s));
74 Real dx = Beam::last_visible_stem (beam)->relative_coordinate (0, X_AXIS)
75 - Beam::first_visible_stem (beam)->relative_coordinate (0, X_AXIS);
76 dydx = dx ? dy/dx : 0;
82 Real ss = Staff_symbol_referencer::staff_space (me);
83 Real thick = robust_scm2double (me->get_property ("beam-thickness"),1);
84 Real width = robust_scm2double (me->get_property ("beam-width"),1);
85 Real blot = me->get_paper ()->get_dimension (ly_symbol2scm ("blotdiameter"));
90 Stencil a (Lookup::beam (dydx, width, thick, blot));
91 a.translate (Offset (-width/2, width / 2 * dydx));
93 int tremolo_flags = 0;
94 SCM s = me->get_property ("flag-count");
95 if (ly_c_number_p (s))
96 tremolo_flags = ly_scm2int (s);
100 programming_error ("No tremolo flags?");
107 Who the fuck is 0.81 ?
111 Real beam_translation = beam ? Beam::get_beam_translation (beam) : 0.81;
114 for (int i = 0; i < tremolo_flags; i++)
117 b.translate_axis (beam_translation * i, Y_AXIS);
124 MAKE_SCHEME_CALLBACK (Stem_tremolo,print,1);
126 Stem_tremolo::print (SCM grob)
128 Grob *me = unsmob_grob (grob);
129 Grob *stem = unsmob_grob (me->get_property ("stem"));
132 programming_error ("No stem for stem-tremolo");
136 Grob *beam = Stem::get_beam (stem);
137 Direction stemdir = Stem::get_direction (stem);
138 Real beam_translation
139 = (beam && beam->live ())
140 ? Beam::get_beam_translation (beam)
143 Stencil mol = raw_stencil (me);
144 Interval mol_ext = mol.extent (Y_AXIS);
145 Real ss = Staff_symbol_referencer::staff_space (me);
147 // ugh, rather calc from Stem_tremolo_req
148 int beam_count = (beam) ? (Stem::beam_multiplicity (stem).length () + 1): 0;
151 Real beamthickness = 0.0;
152 SCM sbt = (beam) ? beam->get_property ("thickness") : SCM_EOL ;
153 if (ly_c_number_p (sbt))
155 beamthickness = ly_scm2double (sbt) * ss;
159 = Stem::stem_end_position (stem) *ss/2
160 - stemdir * (beam_count * beamthickness
161 + ((beam_count -1) >? 0) * beam_translation);
164 the 0.33 ss is to compensate for the size of the note head
166 Real chord_start_y = Stem::chord_start_y (stem) +
169 Real padding = beam_translation;
172 if there is a flag, just above/below the notehead.
173 if there is not enough space, center on remaining space,
174 else one beamspace away from stem end.
176 if (!beam && Stem::duration_log (stem) >= 3)
178 mol.align_to (Y_AXIS, -stemdir);
179 mol.translate_axis (chord_start_y + .5 * stemdir, Y_AXIS);
181 else if (stemdir * (end_y - chord_start_y) - 2*padding - mol_ext.length () < 0.0)
183 mol.translate_axis (0.5 * (end_y + chord_start_y) - mol_ext.center (),Y_AXIS);
187 mol.translate_axis (end_y - stemdir * beam_translation
192 return mol.smobbed_copy ();
197 ADD_INTERFACE (Stem_tremolo,"stem-tremolo-interface",
198 "A beam slashing a stem to indicate a tremolo.",
199 "stem beam-width beam-thickness flag-count");