+ assert (beam_l ());
+
+ Direction beam_dir = directional_element (beam_l ()).get ();
+ if (!beam_dir)
+ {
+ programming_error ("Beam dir not set.");
+ beam_dir = UP;
+ }
+
+ Staff_symbol_referencer_interface st (this);
+ Real staff_space = st.staff_space ();
+ Real half_space = staff_space / 2;
+ Real interbeam_f = paper_l ()->interbeam_f (beam_l ()->get_multiplicity ());
+ Real thick = gh_scm2double (beam_l ()->get_elt_property ("beam-thickness"));
+ int multiplicity = beam_l ()->get_multiplicity ();
+
+ Stem_info info;
+ info.idealy_f_ = chord_start_f ();
+
+ // for simplicity, we calculate as if dir == UP
+ info.idealy_f_ *= beam_dir;
+ SCM grace_prop = get_elt_property ("grace");
+
+ bool grace_b = to_boolean (grace_prop);
+
+ Array<Real> a;
+ SCM s;
+ String type_str = grace_b ? "grace-" : "";
+
+ s = scm_eval (ly_symbol2scm ((type_str + "beamed-stem-minimum-length").ch_C()));
+ a.clear ();
+ for (SCM q = s; q != SCM_EOL; q = gh_cdr (q))
+ a.push (gh_scm2double (gh_car (q)));
+
+
+ Real minimum_length = a[multiplicity <? (a.size () - 1)] * staff_space;
+ s = scm_eval (ly_symbol2scm ((type_str + "beamed-stem-length").ch_C()));
+
+ a.clear();
+ for (SCM q = s; q != SCM_EOL; q = gh_cdr (q))
+ a.push (gh_scm2double (gh_car (q)));
+
+ Real stem_length = a[multiplicity <? (a.size () - 1)] * staff_space;
+
+ if (!beam_dir || (beam_dir == directional_element (this).get ()))
+ /* normal beamed stem */
+ {
+ if (multiplicity)
+ {
+ info.idealy_f_ += thick + (multiplicity - 1) * interbeam_f;
+ }
+ info.miny_f_ = info.idealy_f_;
+ info.maxy_f_ = INT_MAX;
+
+ info.idealy_f_ += stem_length;
+ info.miny_f_ += minimum_length;
+
+ /*
+ lowest beam of (UP) beam must never be lower than second staffline
+
+ Hmm, reference (Wanske?)
+
+ 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.
+
+ */
+ bool no_extend_b = to_boolean (get_elt_property ("no-stem-extend"));
+ if (!grace_b && !no_extend_b)
+ {
+ /* highest beam of (UP) beam must never be lower than middle
+ staffline
+ lowest beam of (UP) beam must never be lower than second staffline
+ */
+ info.miny_f_ =
+ info.miny_f_ >? 0
+ >? (- 2 * half_space - thick
+ + (multiplicity > 0) * thick
+ + interbeam_f * (multiplicity - 1));
+ }
+ }
+ else
+ /* knee */
+ {
+ info.idealy_f_ -= thick;
+ info.maxy_f_ = info.idealy_f_;
+ info.miny_f_ = -INT_MAX;
+
+ info.idealy_f_ -= stem_length;
+ info.maxy_f_ -= minimum_length;
+ }
+
+ info.idealy_f_ = (info.maxy_f_ <? info.idealy_f_) >? info.miny_f_;
+
+ s = beam_l ()->get_elt_property ("shorten");
+ if (gh_number_p (s))
+ info.idealy_f_ -= gh_double2scm (s);
+
+ Real interstaff_f = -beam_dir* calc_interstaff_dist (this, beam_l ());
+
+ info.idealy_f_ += interstaff_f;
+ info.miny_f_ += interstaff_f;
+ info.maxy_f_ += interstaff_f ;
+
+ return info;