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 MAKE_SCHEME_CALLBACK (Stem_tremolo, calc_slope, 1)
23 Stem_tremolo::calc_slope (SCM smob)
25 Grob *me = unsmob_grob (smob);
26 Grob *stem = unsmob_grob (me->get_object ("stem"));
27 Spanner *beam = Stem::get_beam (stem);
32 SCM s = beam->get_property ("quantized-positions");
33 if (is_number_pair (s))
34 dy = - scm_to_double (scm_car (s)) + scm_to_double (scm_cdr (s));
36 Grob *s2 = Beam::last_visible_stem (beam);
37 Grob *s1 = Beam::first_visible_stem (beam);
39 Grob *common = s1->common_refpoint (s2, X_AXIS);
40 Real dx = s2->relative_coordinate (common, X_AXIS) -
41 s1->relative_coordinate (common, X_AXIS);
43 return scm_from_double (dx ? dy / dx : 0);
46 /* down stems with flags should have more sloped trems (helps avoid
47 flag/stem collisions without making the stem very long) */
48 return scm_from_double (
49 (Stem::duration_log (stem) >= 3 && get_grob_direction (stem) == DOWN) ?
53 MAKE_SCHEME_CALLBACK (Stem_tremolo, calc_width, 1)
55 Stem_tremolo::calc_width (SCM smob)
57 Grob *me = unsmob_grob (smob);
58 Grob *stem = unsmob_grob (me->get_object ("stem"));
59 Direction stemdir = get_grob_direction (stem);
60 bool beam = Stem::get_beam (stem);
61 bool flag = Stem::duration_log (stem) >= 3 && !beam;
63 /* beamed stems and up-stems with flags have shorter tremolos */
64 return scm_from_double (((stemdir == UP && flag) || beam)? 1.0 : 1.5);
67 MAKE_SCHEME_CALLBACK (Stem_tremolo, calc_style, 1)
69 Stem_tremolo::calc_style (SCM smob)
71 Grob *me = unsmob_grob (smob);
72 Grob *stem = unsmob_grob (me->get_object ("stem"));
73 Direction stemdir = get_grob_direction (stem);
74 bool beam = Stem::get_beam (stem);
75 bool flag = Stem::duration_log (stem) >= 3 && !beam;
77 return ly_symbol2scm (((stemdir == UP && flag) || beam) ? "rectangle" : "default");
81 Stem_tremolo::get_beam_translation (Grob *me)
83 Grob *stem = unsmob_grob (me->get_object ("stem"));
84 Spanner *beam = Stem::get_beam (stem);
86 return beam ? Beam::get_beam_translation (beam) : 0.81;
90 Stem_tremolo::raw_stencil (Grob *me, Real slope, Direction stemdir)
92 Real ss = Staff_symbol_referencer::staff_space (me);
93 Real thick = robust_scm2double (me->get_property ("beam-thickness"), 1);
94 Real width = robust_scm2double (me->get_property ("beam-width"), 1);
95 Real blot = me->layout ()->get_dimension (ly_symbol2scm ("blot-diameter"));
96 SCM style = me->get_property ("style");
97 if (!scm_is_symbol (style))
98 style = ly_symbol2scm ("default");
104 if (style == ly_symbol2scm ("rectangle"))
105 a = Lookup::rotated_box (slope, width, thick, blot);
107 a = Lookup::beam (slope, width, thick, blot);
109 a.align_to (X_AXIS, CENTER);
110 a.align_to (Y_AXIS, CENTER);
112 int tremolo_flags = robust_scm2int (me->get_property ("flag-count"), 0);
115 programming_error ("no tremolo flags");
121 Real beam_translation = get_beam_translation(me);
124 for (int i = 0; i < tremolo_flags; i++)
127 b.translate_axis (beam_translation * i * stemdir * -1, Y_AXIS);
135 MAKE_SCHEME_CALLBACK (Stem_tremolo, height, 1);
137 Stem_tremolo::height (SCM smob)
139 Grob *me = unsmob_grob (smob);
142 Cannot use the real slope, since it looks at the Beam.
144 Stencil s1 (raw_stencil (me, 0.35, UP));
146 return ly_interval2scm (s1.extent (Y_AXIS));
150 MAKE_SCHEME_CALLBACK (Stem_tremolo, print, 1);
152 Stem_tremolo::print (SCM grob)
154 Grob *me = unsmob_grob (grob);
155 Grob *stem = unsmob_grob (me->get_object ("stem"));
158 programming_error ("no stem for stem-tremolo");
162 Spanner *beam = Stem::get_beam (stem);
163 Direction stemdir = get_grob_direction (stem);
164 bool whole_note = Stem::duration_log (stem) <= 0;
168 Real beam_translation
169 = (beam && beam->is_live ())
170 ? Beam::get_beam_translation (beam)
173 /* for a whole note, we position relative to the notehead, so we want the
174 stencil aligned on the flag closest to the head */
175 Direction stencil_dir = whole_note ? -stemdir : stemdir;
176 Stencil mol = raw_stencil (me, robust_scm2double (me->get_property ("slope"),
179 Interval mol_ext = mol.extent (Y_AXIS);
180 Real ss = Staff_symbol_referencer::staff_space (me);
182 // ugh, rather calc from Stem_tremolo_req
183 int beam_count = beam ? (Stem::beam_multiplicity (stem).length () + 1) : 0;
185 Real beamthickness = 0.0;
186 SCM sbt = (beam) ? beam->get_property ("thickness") : SCM_EOL;
187 if (scm_is_number (sbt))
188 beamthickness = scm_to_double (sbt) * ss;
191 = Stem::stem_end_position (stem) * ss / 2
192 - stemdir * max (beam_count, 1) * beam_translation;
194 if (!beam && Stem::duration_log (stem) >= 3)
196 end_y -= stemdir * (Stem::duration_log (stem) - 2) * beam_translation;
198 end_y -= stemdir * beam_translation * 0.5;
202 /* we shouldn't position relative to the end of the stem since the stem
204 vector<int> nhp = Stem::note_head_positions (stem);
205 Real note_head = (stemdir == UP ? nhp.back () : nhp[0]) * ss / 2;
206 end_y = note_head + stemdir * 1.5;
208 mol.translate_axis (end_y, Y_AXIS);
210 return mol.smobbed_copy ();
213 ADD_INTERFACE (Stem_tremolo, "stem-tremolo-interface",
214 "A beam slashing a stem to indicate a tremolo.",