2 stem-tremolo.cc -- implement Stem_tremolo
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2002 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
26 MAKE_SCHEME_CALLBACK (Stem_tremolo,dim_callback,2);
32 Stem_tremolo::dim_callback (SCM e, SCM)
34 Grob * se = unsmob_grob (e);
36 Real space = Staff_symbol_referencer::staff_space (se);
37 return ly_interval2scm (Interval (-space, space));
43 MAKE_SCHEME_CALLBACK (Stem_tremolo, height, 2);
45 Stem_tremolo::height (SCM smob, SCM ax)
47 Axis a = (Axis)gh_scm2int (ax);
48 Grob * me = unsmob_grob (smob);
51 SCM mol = me->get_uncached_molecule ();
52 return ly_interval2scm (unsmob_molecule (mol)->extent (a));
56 MAKE_SCHEME_CALLBACK (Stem_tremolo,brew_molecule,1);
58 Stem_tremolo::brew_molecule (SCM smob)
60 Grob *me= unsmob_grob (smob);
61 Grob * stem = unsmob_grob (me->get_grob_property ("stem"));
62 Grob * beam = Stem::beam_l (stem);
68 SCM s = beam->get_grob_property ("positions");
71 dy = -gh_scm2double (gh_car (s)) +gh_scm2double (gh_cdr (s));
73 Real dx = Beam::last_visible_stem (beam)->relative_coordinate (0, X_AXIS)
74 - Beam::first_visible_stem (beam)->relative_coordinate (0, X_AXIS);
75 dydx = dx ? dy/dx : 0;
81 Real ss = Staff_symbol_referencer::staff_space (stem);
82 Real thick = gh_scm2double (me->get_grob_property ("beam-thickness"));
83 Real width = gh_scm2double (me->get_grob_property ("beam-width"));
87 Molecule a (Lookup::beam (dydx, width, thick));
88 a.translate (Offset (-width/2, width / 2 * dydx));
91 SCM s = me->get_grob_property ("flag-count");
93 tremolo_flags = gh_scm2int (s);
98 Real interbeam = beam ? Beam::get_interbeam (beam) : 0.81;
101 for (int i = 0; i < tremolo_flags; i++)
104 b.translate_axis (interbeam * i, Y_AXIS);
105 mol.add_molecule (b);
108 mol.translate_axis (-mol.extent (Y_AXIS).center (), Y_AXIS);
111 // ugh, rather calc from Stem_tremolo_req
112 int beams_i = Stem::beam_count (stem, RIGHT)
113 >? Stem::beam_count (stem, LEFT);
114 mol.translate (Offset (stem->relative_coordinate (0, X_AXIS)
115 - me->relative_coordinate (0, X_AXIS),
116 Stem::stem_end_position (stem) * ss / 2 -
117 Directional_element_interface::get (beam)
118 * beams_i * interbeam));
123 Beams should intersect one beamthickness below stem end
125 Real dy = Stem::stem_end_position (stem) * ss / 2;
126 dy -= mol.extent (Y_AXIS).length () / 2 * Stem::get_direction (stem);
129 uhg. Should use relative coords and placement
131 Real whole_note_correction;
132 if (Stem::invisible_b (stem))
134 Grob *hed = Stem::support_head (stem);
135 whole_note_correction = -Stem::get_direction (stem)
136 *hed->extent (hed, X_AXIS).length () / 2;
139 whole_note_correction = 0;
141 mol.translate (Offset (stem->relative_coordinate (0, X_AXIS)
142 - me->relative_coordinate (0, X_AXIS) +
143 whole_note_correction, dy));
146 return mol.smobbed_copy ();
151 Stem_tremolo::set_stem (Grob*me,Grob *s)
153 me->set_grob_property ("stem", s->self_scm ());
157 ADD_INTERFACE (Stem_tremolo,"stem-tremolo-interface",
159 "stem beam-width beam-thickness flag-count");