2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "stem-tremolo.hh"
24 #include "directional-element-interface.hh"
27 #include "output-def.hh"
28 #include "staff-symbol-referencer.hh"
32 MAKE_SCHEME_CALLBACK (Stem_tremolo
, calc_slope
, 1)
34 Stem_tremolo::calc_slope (SCM smob
)
36 Grob
*me
= unsmob_grob (smob
);
37 Grob
*stem
= unsmob_grob (me
->get_object ("stem"));
38 Spanner
*beam
= Stem::get_beam (stem
);
43 SCM s
= beam
->get_property ("quantized-positions");
44 if (is_number_pair (s
))
45 dy
= - scm_to_double (scm_car (s
)) + scm_to_double (scm_cdr (s
));
47 Grob
*s2
= Beam::last_normal_stem (beam
);
48 Grob
*s1
= Beam::first_normal_stem (beam
);
50 Grob
*common
= s1
->common_refpoint (s2
, X_AXIS
);
51 Real dx
= s2
->relative_coordinate (common
, X_AXIS
) -
52 s1
->relative_coordinate (common
, X_AXIS
);
54 return scm_from_double (dx
? dy
/ dx
: 0);
57 /* down stems with flags should have more sloped trems (helps avoid
58 flag/stem collisions without making the stem very long) */
59 return scm_from_double (
60 (Stem::duration_log (stem
) >= 3 && get_grob_direction (stem
) == DOWN
) ?
64 MAKE_SCHEME_CALLBACK (Stem_tremolo
, calc_width
, 1)
66 Stem_tremolo::calc_width (SCM smob
)
68 Grob
*me
= unsmob_grob (smob
);
69 Grob
*stem
= unsmob_grob (me
->get_object ("stem"));
70 Direction stemdir
= get_grob_direction (stem
);
71 bool beam
= Stem::get_beam (stem
);
72 bool flag
= Stem::duration_log (stem
) >= 3 && !beam
;
74 /* beamed stems and up-stems with flags have shorter tremolos */
75 return scm_from_double (((stemdir
== UP
&& flag
) || beam
)? 1.0 : 1.5);
78 MAKE_SCHEME_CALLBACK (Stem_tremolo
, calc_style
, 1)
80 Stem_tremolo::calc_style (SCM smob
)
82 Grob
*me
= unsmob_grob (smob
);
83 Grob
*stem
= unsmob_grob (me
->get_object ("stem"));
84 Direction stemdir
= get_grob_direction (stem
);
85 bool beam
= Stem::get_beam (stem
);
86 bool flag
= Stem::duration_log (stem
) >= 3 && !beam
;
88 return ly_symbol2scm (((stemdir
== UP
&& flag
) || beam
) ? "rectangle" : "default");
92 Stem_tremolo::get_beam_translation (Grob
*me
)
94 Grob
*stem
= unsmob_grob (me
->get_object ("stem"));
95 Spanner
*beam
= Stem::get_beam (stem
);
97 return (beam
&& beam
->is_live ())
98 ? Beam::get_beam_translation (beam
)
99 : (Staff_symbol_referencer::staff_space (me
)
100 * robust_scm2double (me
->get_property ("length-fraction"), 1.0) * 0.81);
104 Stem_tremolo::raw_stencil (Grob
*me
, Real slope
, Direction stemdir
)
106 Real ss
= Staff_symbol_referencer::staff_space (me
);
107 Real thick
= robust_scm2double (me
->get_property ("beam-thickness"), 1);
108 Real width
= robust_scm2double (me
->get_property ("beam-width"), 1);
109 Real blot
= me
->layout ()->get_dimension (ly_symbol2scm ("blot-diameter"));
110 SCM style
= me
->get_property ("style");
111 if (!scm_is_symbol (style
))
112 style
= ly_symbol2scm ("default");
118 if (style
== ly_symbol2scm ("rectangle"))
119 a
= Lookup::rotated_box (slope
, width
, thick
, blot
);
121 a
= Lookup::beam (slope
, width
, thick
, blot
);
123 a
.align_to (X_AXIS
, CENTER
);
124 a
.align_to (Y_AXIS
, CENTER
);
126 int tremolo_flags
= robust_scm2int (me
->get_property ("flag-count"), 0);
129 programming_error ("no tremolo flags");
135 Real beam_translation
= get_beam_translation (me
);
138 for (int i
= 0; i
< tremolo_flags
; i
++)
141 b
.translate_axis (beam_translation
* i
* stemdir
* -1, Y_AXIS
);
149 MAKE_SCHEME_CALLBACK (Stem_tremolo
, height
, 1);
151 Stem_tremolo::height (SCM smob
)
153 Grob
*me
= unsmob_grob (smob
);
156 Cannot use the real slope, since it looks at the Beam.
158 Stencil
s1 (translated_stencil (me
, 0.35));
160 return ly_interval2scm (s1
.extent (Y_AXIS
));
163 MAKE_SCHEME_CALLBACK (Stem_tremolo
, width
, 1);
165 Stem_tremolo::width (SCM smob
)
167 Grob
*me
= unsmob_grob (smob
);
170 Cannot use the real slope, since it looks at the Beam.
172 Stencil
s1 (untranslated_stencil (me
, 0.35));
174 return ly_interval2scm (s1
.extent (X_AXIS
));
178 Stem_tremolo::vertical_length (Grob
*me
)
180 return untranslated_stencil (me
, 0.35).extent (Y_AXIS
).length ();
184 Stem_tremolo::untranslated_stencil (Grob
*me
, Real slope
)
186 Grob
*stem
= unsmob_grob (me
->get_object ("stem"));
189 programming_error ("no stem for stem-tremolo");
193 Direction stemdir
= get_grob_direction (stem
);
197 bool whole_note
= Stem::duration_log (stem
) <= 0;
199 /* for a whole note, we position relative to the notehead, so we want the
200 stencil aligned on the flag closest to the head */
201 Direction stencil_dir
= whole_note
? -stemdir
: stemdir
;
202 return raw_stencil (me
, slope
, stencil_dir
);
207 Stem_tremolo::translated_stencil (Grob
*me
, Real slope
)
209 Stencil mol
= untranslated_stencil (me
, slope
);
211 Grob
*stem
= unsmob_grob (me
->get_object ("stem"));
215 Direction stemdir
= get_grob_direction (stem
);
219 Spanner
*beam
= Stem::get_beam (stem
);
220 Real beam_translation
= get_beam_translation (me
);
222 int beam_count
= beam
? (Stem::beam_multiplicity (stem
).length () + 1) : 0;
223 Real ss
= Staff_symbol_referencer::staff_space (me
);
226 = Stem::stem_end_position (stem
) * ss
/ 2
227 - stemdir
* max (beam_count
, 1) * beam_translation
;
229 if (!beam
&& Stem::duration_log (stem
) >= 3)
231 end_y
-= stemdir
* (Stem::duration_log (stem
) - 2) * beam_translation
;
233 end_y
-= stemdir
* beam_translation
* 0.5;
236 bool whole_note
= Stem::duration_log (stem
) <= 0;
239 /* we shouldn't position relative to the end of the stem since the stem
241 vector
<int> nhp
= Stem::note_head_positions (stem
);
242 Real note_head
= (stemdir
== UP
? nhp
.back () : nhp
[0]) * ss
/ 2;
243 end_y
= note_head
+ stemdir
* 1.5;
245 mol
.translate_axis (end_y
, Y_AXIS
);
250 MAKE_SCHEME_CALLBACK (Stem_tremolo
, print
, 1);
252 Stem_tremolo::print (SCM grob
)
254 Grob
*me
= unsmob_grob (grob
);
256 Stencil s
= translated_stencil (me
, robust_scm2double (me
->get_property ("slope"), 0.25));
257 return s
.smobbed_copy ();
260 ADD_INTERFACE (Stem_tremolo
,
261 "A beam slashing a stem to indicate a tremolo. The property"
262 " @code{style} can be @code{default} or @code{rectangle}.",