+ /* Tab notation feature: make stem end extend out of staff. */
+ SCM up_to_staff = me->get_grob_property ("up-to-staff");
+ if (to_boolean (up_to_staff))
+ {
+ int line_count = Staff_symbol_referencer::line_count (me);
+ Direction dir = get_direction (me);
+ Real ideal_y = dir * (line_count + 1.5);
+ Real shortest_y = ideal_y;
+
+ me->set_grob_property ("stem-info",
+ scm_list_n (gh_double2scm (ideal_y),
+ gh_double2scm (shortest_y),
+ SCM_UNDEFINED));
+ return;
+ }
+
+ Direction my_dir = Directional_element_interface::get (me);
+ Real staff_space = Staff_symbol_referencer::staff_space (me);
+ Grob *beam = get_beam (me);
+ Real beam_translation = Beam::get_beam_translation (beam);
+ Real beam_thickness = gh_scm2double (beam->get_grob_property ("thickness"));
+ int beam_count = Beam::get_direction_beam_count (beam, my_dir);
+
+
+ /* Simple standard stem length */
+ Real ideal_length =
+ gh_scm2double (robust_list_ref
+ (beam_count - 1,
+ me->get_grob_property ("beamed-lengths")))
+ * staff_space
+ /* stem only extends to center of beam */
+ - 0.5 * beam_thickness;
+
+
+ /* Condition: sane minimum free stem length (chord to beams) */
+ Real ideal_minimum_free =
+ gh_scm2double (robust_list_ref
+ (beam_count - 1,
+ me->get_grob_property ("beamed-minimum-free-lengths")))
+ * staff_space;
+
+
+ /* UGH
+ It seems that also for ideal minimum length, we must use
+ the maximum beam count (for this direction):
+
+ \score{ \notes\relative c''{ [a8 a32] }}
+
+ must be horizontal. */
+ Real height_of_my_beams = beam_thickness
+ + (beam_count - 1) * beam_translation;
+
+ Real ideal_minimum_length = ideal_minimum_free
+ + height_of_my_beams
+ /* stem only extends to center of beam */
+ - 0.5 * beam_thickness;
+
+ ideal_length = ideal_length >? ideal_minimum_length;
+
+
+ /* Convert to Y position, calculate for dir == UP */
+ Real note_start =
+ /* staff positions */
+ head_positions (me)[my_dir] * 0.5
+ * my_dir;
+ Real ideal_y = note_start + ideal_length;
+
+
+ /* Conditions for Y position */
+
+ /* Lowest beam of (UP) beam must never be lower than second staffline
+
+ Reference?
+
+ Although this (additional) rule is probably correct,
+ I expect that highest beam (UP) should also never be lower
+ than middle staffline, just as normal stems.
+
+ Reference?
+
+ Obviously not for grace beams.
+
+ Also, not for knees. Seems to be a good thing. */
+ SCM grace = me->get_grob_property ("grace");
+ bool grace_b = to_boolean (grace);
+ bool no_extend_b = to_boolean (me->get_grob_property ("no-stem-extend"));
+ bool knee_b = to_boolean (beam->get_grob_property ("knee"));
+ if (!grace_b && !no_extend_b && !knee_b)