+ Grob *beam = Stem::get_beam (stem);
+ Direction stemdir = Stem::get_direction (stem);
+ if (stemdir == 0)
+ stemdir = UP;
+
+ Real beam_translation
+ = (beam && beam->is_live ())
+ ? Beam::get_beam_translation (beam)
+ : 0.81;
+
+ Stencil mol = raw_stencil (me);
+ Interval mol_ext = mol.extent (Y_AXIS);
+ Real ss = Staff_symbol_referencer::staff_space (me);
+
+ // ugh, rather calc from Stem_tremolo_req
+ int beam_count = beam ? (Stem::beam_multiplicity (stem).length () + 1) : 0;
+
+ Real beamthickness = 0.0;
+ SCM sbt = (beam) ? beam->get_property ("thickness") : SCM_EOL ;
+ if (ly_c_number_p (sbt))
+ beamthickness = ly_scm2double (sbt) * ss;
+
+ Real end_y
+ = Stem::stem_end_position (stem) * ss / 2
+ - stemdir * (beam_count * beamthickness
+ + ((beam_count -1) >? 0) * beam_translation);
+
+ /* FIXME: the 0.33 ss is to compensate for the size of the note head. */
+ Real chord_start_y = Stem::chord_start_y (stem) + 0.33 * ss * stemdir;
+
+ Real padding = beam_translation;
+
+ /* if there is a flag, just above/below the notehead.
+ if there is not enough space, center on remaining space,
+ else one beamspace away from stem end. */
+ if (!beam && Stem::duration_log (stem) >= 3)
+ {
+ mol.align_to (Y_AXIS, -stemdir);
+ mol.translate_axis (chord_start_y + 0.5 * stemdir, Y_AXIS);
+ }
+ else if (stemdir * (end_y - chord_start_y) - 2 * padding - mol_ext.length ()
+ < 0.0)
+ mol.translate_axis (0.5 * (end_y + chord_start_y) - mol_ext.center (),
+ Y_AXIS);
+ else
+ mol.translate_axis (end_y - stemdir * beam_translation -mol_ext [stemdir],
+ Y_AXIS);
+
+ return mol.smobbed_copy ();