2 beam.cc -- implement Beam
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
13 * shorter! (now +- 1000 lines)
15 * move paper vars to scm
17 remove *-hs variables, and do all y-position stuff in staff-space.
21 #include <math.h> // tanh.
24 #include "directional-element-interface.hh"
28 #include "least-squares.hh"
30 #include "paper-def.hh"
32 #include "group-interface.hh"
33 #include "staff-symbol-referencer.hh"
34 #include "cross-staff.hh"
40 Beam::add_stem (Score_element*me, Score_element*s)
42 Pointer_group_interface gi (me, "stems");
45 s->add_dependency (me);
47 assert (!Stem::beam_l (s));
48 s->set_elt_property ("beam", me->self_scm ());
50 add_bound_item (dynamic_cast<Spanner*> (me), dynamic_cast<Item*> (s));
54 Beam::get_multiplicity (Score_element*me)
57 for (SCM s = me->get_elt_property ("stems"); gh_pair_p (s); s = gh_cdr (s))
59 Score_element * sc = unsmob_element (gh_car (s));
61 if (Stem::has_interface (sc))
62 m = m >? Stem::beam_count (sc,LEFT) >? Stem::beam_count (sc,RIGHT);
68 After pre-processing all directions should be set.
69 Several post-processing routines (stem, slur, script) need stem/beam
71 Currenly, this means that beam has set all stem's directions.
72 [Alternatively, stems could set its own directions, according to
73 their beam, during 'final-pre-processing'.]
75 MAKE_SCHEME_CALLBACK(Beam,before_line_breaking);
77 Beam::before_line_breaking (SCM smob)
79 Score_element * me = unsmob_element (smob);
82 if (visible_stem_count (me) < 2)
84 warning (_ ("beam has less than two stems"));
87 if (!Directional_element_interface (me).get ())
88 Directional_element_interface (me).set (get_default_dir (me));
91 set_stem_directions (me);
92 set_stem_shorten (me);
101 Beam::get_default_dir (Score_element*me)
103 Drul_array<int> total;
104 total[UP] = total[DOWN] = 0;
105 Drul_array<int> count;
106 count[UP] = count[DOWN] = 0;
109 Link_array<Item> stems=
110 Pointer_group_interface__extract_elements (me, (Item*)0, "stems");
112 for (int i=0; i <stems.size (); i++)
113 do { // HUH -- waar slaat dit op?
114 Score_element *s = stems[i];
115 Direction sd = Directional_element_interface (s).get ();
116 int current = sd ? (1 + d * sd)/2
117 : Stem::get_center_distance (s, (Direction)-d);
125 } while (flip(&d) != DOWN);
128 SCM s = scm_eval2 (gh_list (ly_symbol2scm ("beam-dir-algorithm"),
129 ly_quote_scm (gh_cons (gh_int2scm (count[UP]),
130 gh_int2scm (count[DOWN]))),
131 ly_quote_scm (gh_cons (gh_int2scm (total[UP]),
132 gh_int2scm (total[DOWN]))),
135 if (gh_number_p (s) && gh_scm2int (s))
139 If dir is not determined: get default
141 return to_dir (me->get_elt_property ("default-neutral-direction"));
146 Set all stems with non-forced direction to beam direction.
147 Urg: non-forced should become `without/with unforced' direction,
148 once stem gets cleaned-up.
151 Beam::set_stem_directions (Score_element*me)
153 Link_array<Item> stems
154 =Pointer_group_interface__extract_elements (me, (Item*) 0, "stems");
155 Direction d = Directional_element_interface (me).get ();
157 for (int i=0; i <stems.size (); i++)
159 Score_element *s = stems[i];
160 SCM force = s->remove_elt_property ("dir-forced");
161 if (!gh_boolean_p (force) || !gh_scm2bool (force))
162 Directional_element_interface (s).set (d);
167 Beam::auto_knees (Score_element*me)
169 if (!auto_knee (me,"auto-interstaff-knee-gap", true))
170 auto_knee (me, "auto-knee-gap", false);
174 Simplistic auto-knees; only consider vertical gap between two
177 `Forced' stem directions are ignored. If you don't want auto-knees,
178 don't set, or unset autoKneeGap/autoInterstaffKneeGap.
181 Beam::auto_knee (Score_element*me, String gap_str, bool interstaff_b)
185 SCM gap = me->get_elt_property (gap_str.ch_C());
187 Direction d = Directional_element_interface (me).get ();
188 Link_array<Item> stems=
189 Pointer_group_interface__extract_elements (me, (Item*)0, "stems");
191 if (gh_number_p (gap))
193 Spanner*sp = dynamic_cast<Spanner*> (me);
194 int auto_gap_i = gh_scm2int (gap);
195 for (int i=1; i < stems.size (); i++)
197 bool is_b = (bool)(calc_interstaff_dist (stems[i], sp)
198 - calc_interstaff_dist (stems[i-1], sp));
199 int l_y = (int)(Stem::head_positions(stems[i-1])[d])
200 + (int)calc_interstaff_dist (stems[i-1], sp);
201 int r_y = (int)(Stem::head_positions(stems[i])[d])
202 + (int)calc_interstaff_dist (stems[i], sp);
203 int gap_i = r_y - l_y;
205 if ((abs (gap_i) >= auto_gap_i) && (!interstaff_b || is_b))
207 knee_y = (r_y + l_y) / 2;
215 for (int i=0; i < stems.size (); i++)
218 int y = (int)(Stem::head_positions(s)[d])
219 + (int)calc_interstaff_dist (s, dynamic_cast<Spanner*> (me));
221 Directional_element_interface (s).set (y < knee_y ? UP : DOWN);
222 s->set_elt_property ("dir-forced", SCM_BOOL_T);
229 Set stem's shorten property if unset.
231 take some y-position (chord/beam/nearest?) into account
232 scmify forced-fraction
235 Beam::set_stem_shorten (Score_element*m)
237 Spanner*me = dynamic_cast<Spanner*> (m);
238 if (!visible_stem_count (me))
241 Real forced_fraction = forced_stem_count (me) / visible_stem_count (me);
242 if (forced_fraction < 0.5)
245 int multiplicity = get_multiplicity (me);
248 SCM shorten = scm_eval2 (ly_symbol2scm ("beamed-stem-shorten"), SCM_EOL);
250 if (shorten == SCM_EOL)
253 int sz = scm_ilength (shorten);
255 Real staff_space = Staff_symbol_referencer::staff_space (me);
256 SCM shorten_elt = scm_list_ref (shorten, gh_int2scm (multiplicity <? (sz - 1)));
257 Real shorten_f = gh_scm2double (shorten_elt) * staff_space;
259 /* cute, but who invented me -- how to customise ? */
260 if (forced_fraction < 1)
263 Link_array<Item> stems=
264 Pointer_group_interface__extract_elements (me, (Item*)0, "stems");
266 for (int i=0; i < stems.size (); i++)
269 if (Stem::invisible_b (s))
271 if (gh_number_p (s->get_elt_property ("shorten")))
272 s->set_elt_property ("shorten", gh_double2scm (shorten_f));
277 Set elt properties height and y-position if not set.
278 Adjust stem lengths to reach beam.
280 MAKE_SCHEME_CALLBACK(Beam,after_line_breaking);
282 Beam::after_line_breaking (SCM smob)
284 Score_element * me = unsmob_element (smob);
286 /* first, calculate y, dy */
288 calc_default_position_and_height (me, &y, &dy);
289 if (visible_stem_count (me))
291 if (suspect_slope_b (me, y, dy))
294 Real damped_dy = calc_slope_damping_f (me, dy);
295 Real quantised_dy = quantise_dy_f (me, damped_dy);
297 y += (dy - quantised_dy) / 2;
301 until here, we used only stem_info, which acts as if dir=up
303 y *= Directional_element_interface (me).get ();
304 dy *= Directional_element_interface (me).get ();
307 Real half_space = Staff_symbol_referencer::staff_space (me) / 2;
309 /* weird: why do we do calc_position_and_height () ? regardless of
313 /* check for user-override of dy */
314 SCM s = me->remove_elt_property ("height-hs");
317 dy = gh_scm2double (s) * half_space;
319 me->set_elt_property ("height", gh_double2scm (dy));
321 /* check for user-override of y */
322 s = me->remove_elt_property ("y-position-hs");
325 y = gh_scm2double (s) * half_space;
329 /* we can modify y, so we should quantise y */
330 Real y_shift = check_stem_length_f (me, y, dy);
332 y = quantise_y_f (me,y, dy, 0);
333 set_stem_length (me, y, dy);
334 y_shift = check_stem_length_f (me, y, dy);
336 if (y_shift > half_space / 4)
341 for significantly lengthened or shortened stems,
342 request quanting the other way.
345 if (abs (y_shift) > half_space / 2)
346 quant_dir = sign (y_shift) * Directional_element_interface (me).get ();
347 y = quantise_y_f (me, y, dy, quant_dir);
350 // UGH. Y is not in staff position unit?
351 // Ik dacht datwe daar juist van weg wilden?
352 set_stem_length (me, y, dy);
353 me->set_elt_property ("y-position", gh_double2scm (y));
355 return SCM_UNSPECIFIED;
359 See Documentation/tex/fonts.doc
362 Beam::calc_default_position_and_height (Score_element*me,Real* y, Real* dy)
366 if (visible_stem_count (me) <= 1)
369 Real first_ideal = Stem::calc_stem_info (first_visible_stem (me)).idealy_f_;
370 if (first_ideal == Stem::calc_stem_info (last_visible_stem (me)).idealy_f_)
377 Array<Offset> ideals;
379 // ugh -> use commonx
380 Real x0 = first_visible_stem (me)->relative_coordinate (0, X_AXIS);
381 Link_array<Item> stems=
382 Pointer_group_interface__extract_elements (me, (Item*)0, "stems");
384 for (int i=0; i < stems.size (); i++)
387 if (Stem::invisible_b (s))
389 ideals.push (Offset (s->relative_coordinate (0, X_AXIS) - x0,
390 Stem::calc_stem_info (s).idealy_f_));
393 minimise_least_squares (&dydx, y, ideals); // duh, takes references
395 Real dx = last_visible_stem (me)->relative_coordinate (0, X_AXIS) - x0;
400 Beam::suspect_slope_b (Score_element*me, Real y, Real dy)
402 /* first, calculate y, dy */
404 steep slope running against lengthened stem is suspect
406 Real first_ideal = Stem::calc_stem_info (first_visible_stem (me)).idealy_f_;
407 Real last_ideal = Stem::calc_stem_info (last_visible_stem (me)).idealy_f_;
408 Real lengthened = me->paper_l ()->get_var ("beam_lengthened");
409 Real steep = me->paper_l ()->get_var ("beam_steep_slope");
411 // ugh -> use commonx
412 Real dx = last_visible_stem (me)->relative_coordinate (0, X_AXIS) - first_visible_stem (me)->relative_coordinate (0, X_AXIS);
413 Real dydx = dy && dx ? dy/dx : 0;
415 if (((y - first_ideal > lengthened) && (dydx > steep))
416 || ((y + dy - last_ideal > lengthened) && (dydx < -steep)))
424 This neat trick is by Werner Lemberg,
425 damped = tanh (slope)
426 corresponds with some tables in [Wanske]
429 Beam::calc_slope_damping_f (Score_element*me,Real dy)
431 SCM damp = me->get_elt_property ("damping");
432 int damping = gh_scm2int (damp);
436 // ugh -> use commonx
437 Real dx = last_visible_stem (me)->relative_coordinate (0, X_AXIS)
438 - first_visible_stem (me)->relative_coordinate (0, X_AXIS);
439 Real dydx = dy && dx ? dy/dx : 0;
440 dydx = 0.6 * tanh (dydx) / damping;
447 Beam::calc_stem_y_f (Score_element*me,Item* s, Real y, Real dy)
449 Real thick = gh_scm2double (me->get_elt_property ("beam-thickness"));
450 thick *= me->paper_l ()->get_var ("staffspace");
452 int beam_multiplicity = get_multiplicity (me);
453 int stem_multiplicity = (Stem::flag_i (s) - 2) >? 0;
455 Real interbeam_f = me->paper_l ()->interbeam_f (beam_multiplicity);
456 // ugh -> use commonx
457 Real x0 = first_visible_stem (me)->relative_coordinate (0, X_AXIS);
458 Real dx = last_visible_stem (me)->relative_coordinate (0, X_AXIS) - x0;
459 Real stem_y = (dy && dx ? (s->relative_coordinate (0, X_AXIS) - x0) / dx * dy : 0) + y;
462 Direction dir = Directional_element_interface(me).get ();
463 Direction sdir = Directional_element_interface (s).get ();
469 * (thick / 2 + (beam_multiplicity - 1) * interbeam_f);
473 // huh, why not for first visible?
474 if (Staff_symbol_referencer::staff_symbol_l (s)
475 != Staff_symbol_referencer::staff_symbol_l (last_visible_stem (me)))
476 stem_y += Directional_element_interface (me).get ()
477 * (beam_multiplicity - stem_multiplicity) * interbeam_f;
484 Beam::check_stem_length_f (Score_element*me,Real y, Real dy)
488 Direction dir = Directional_element_interface (me).get ();
490 Link_array<Item> stems=
491 Pointer_group_interface__extract_elements (me, (Item*)0, "stems");
493 for (int i=0; i < stems.size(); i++)
496 if (Stem::invisible_b (s))
499 Real stem_y = calc_stem_y_f (me, s, y, dy);
502 Stem_info info = Stem::calc_stem_info (s);
504 // if (0 > info.maxy_f_ - stem_y)
505 shorten = shorten <? info.maxy_f_ - stem_y;
506 // if (0 < info.miny_f_ - stem_y)
507 lengthen = lengthen >? info.miny_f_ - stem_y;
510 if (lengthen && shorten)
511 warning (_ ("weird beam vertical offset"));
513 /* when all stems are too short, normal stems win */
514 return dir * ((shorten) ? shorten : lengthen);
518 Hmm. At this time, beam position and slope are determined. Maybe,
519 stem directions and length should set to relative to the chord's
520 position of the beam. */
522 Beam::set_stem_length (Score_element*me,Real y, Real dy)
524 Real half_space = Staff_symbol_referencer::staff_space (me)/2;
525 Link_array<Item> stems=
526 Pointer_group_interface__extract_elements (me, (Item*)0, "stems");
529 for (int i=0; i < stems.size (); i++)
532 if (Stem::invisible_b (s))
535 Real stem_y = calc_stem_y_f (me, s, y, dy);
537 /* caution: stem measures in staff-positions */
538 Stem::set_stemend (s,(stem_y + calc_interstaff_dist (s, dynamic_cast<Spanner*> (me))) / half_space);
543 [Ross] (simplification of)
544 Set dy complying with:
546 - thick / 2 + staffline_f / 2
547 - thick + staffline_f
551 Beam::quantise_dy_f (Score_element*me,Real dy)
554 for (SCM s = scm_eval2 (ly_symbol2scm ("beam-height-quants"), SCM_EOL);
555 s !=SCM_EOL; s = gh_cdr (s))
556 a.push (gh_scm2double (gh_car (s)));
561 Real staff_space = Staff_symbol_referencer::staff_space (me);
563 Interval iv = quantise_iv (a, abs (dy)/staff_space) * staff_space;
564 Real q = (abs (dy) - iv[SMALLER] <= iv[BIGGER] - abs (dy))
568 return q * sign (dy);
572 Prevent interference from stafflines and beams.
573 See Documentation/tex/fonts.doc
575 We only need to quantise the (left) y-position of the beam,
576 since dy is quantised too.
577 if extend_b then stems must *not* get shorter
580 Beam::quantise_y_f (Score_element*me,Real y, Real dy, int quant_dir)
582 int multiplicity = get_multiplicity (me);
584 Real staff_space = Staff_symbol_referencer::staff_space (me);
585 SCM quants = scm_eval2 (gh_list (ly_symbol2scm ("beam-vertical-position-quants"),
586 gh_int2scm (multiplicity),
587 gh_double2scm (dy/staff_space),
593 for (; quants != SCM_EOL; quants = gh_cdr (quants))
594 a.push (gh_scm2double (gh_car (quants)));
599 Real up_y = Directional_element_interface (me).get () * y;
600 Interval iv = quantise_iv (a, up_y/staff_space) * staff_space;
602 Real q = up_y - iv[SMALLER] <= iv[BIGGER] - up_y
603 ? iv[SMALLER] : iv[BIGGER];
605 q = iv[(Direction)quant_dir];
607 return q * Directional_element_interface (me).get ();
611 Beam::set_beaming (Score_element*me,Beaming_info_list *beaming)
613 Link_array<Score_element> stems=
614 Pointer_group_interface__extract_elements (me, (Score_element*)0, "stems");
617 for (int i=0; i < stems.size(); i++)
621 if (Stem::beam_count (stems[i], d) == 0)
622 Stem::set_beaming ( stems[i], beaming->infos_.elem (i).beams_i_drul_[d],d);
624 while (flip (&d) != LEFT);
631 beams to go with one stem.
637 Beam::stem_beams (Score_element*me,Item *here, Item *next, Item *prev)
639 // ugh -> use commonx
640 if ((next && !(next->relative_coordinate (0, X_AXIS) > here->relative_coordinate (0, X_AXIS))) ||
641 (prev && !(prev->relative_coordinate (0, X_AXIS) < here->relative_coordinate (0, X_AXIS))))
642 programming_error ("Beams are not left-to-right");
644 Real staffline_f = me->paper_l ()->get_var ("stafflinethickness");
645 int multiplicity = get_multiplicity (me);
648 Real interbeam_f = me->paper_l ()->interbeam_f (multiplicity);
649 Real thick = gh_scm2double (me->get_elt_property ("beam-thickness"));
650 thick *= me->paper_l ()->get_var ("staffspace");
652 Real bdy = interbeam_f;
653 Real stemdx = staffline_f;
655 // ugh -> use commonx
656 Real dx = visible_stem_count (me) ?
657 last_visible_stem (me)->relative_coordinate (0, X_AXIS) - first_visible_stem (me)->relative_coordinate (0, X_AXIS)
659 Real dy = gh_scm2double (me->get_elt_property ("height"));
660 Real dydx = dy && dx ? dy/dx : 0;
667 if (!Stem::first_head (here))
669 else if (Stem::type_i (here)== 1)
670 nw_f = me->paper_l ()->get_var ("wholewidth");
671 else if (Stem::type_i (here) == 2)
672 nw_f = me->paper_l ()->get_var ("notewidth") * 0.8;
674 nw_f = me->paper_l ()->get_var ("quartwidth");
677 Direction dir = Directional_element_interface (me).get ();
679 /* half beams extending to the left. */
682 int lhalfs= lhalfs = Stem::beam_count (here,LEFT) - Stem::beam_count (prev,RIGHT);
683 int lwholebeams= Stem::beam_count (here,LEFT) <? Stem::beam_count (prev,RIGHT) ;
685 Half beam should be one note-width,
686 but let's make sure two half-beams never touch
688 Real w = here->relative_coordinate (0, X_AXIS) - prev->relative_coordinate (0, X_AXIS);
691 if (lhalfs) // generates warnings if not
692 a = me->lookup_l ()->beam (dydx, w, thick);
693 a.translate (Offset (-w, -w * dydx));
694 for (int j = 0; j < lhalfs; j++)
697 b.translate_axis (-dir * bdy * (lwholebeams+j), Y_AXIS);
698 leftbeams.add_molecule (b);
704 int rhalfs = Stem::beam_count (here,RIGHT) - Stem::beam_count (next,LEFT);
705 int rwholebeams= Stem::beam_count (here,RIGHT) <? Stem::beam_count (next,LEFT) ;
707 Real w = next->relative_coordinate (0, X_AXIS) - here->relative_coordinate (0, X_AXIS);
708 Molecule a = me->lookup_l ()->beam (dydx, w + stemdx, thick);
709 a.translate_axis( - stemdx/2, X_AXIS);
713 SCM gap = me->get_elt_property ("beam-gap");
714 if (gh_number_p (gap))
716 int gap_i = gh_scm2int ( (gap));
717 int nogap = rwholebeams - gap_i;
719 for (; j < nogap; j++)
722 b.translate_axis (-dir * bdy * j, Y_AXIS);
723 rightbeams.add_molecule (b);
725 // TODO: notehead widths differ for different types
728 a = me->lookup_l ()->beam (dydx, w + stemdx, thick);
731 for (; j < rwholebeams; j++)
734 b.translate (Offset (Stem::invisible_b (here) ? 0 : gap_f, -dir * bdy * j));
735 rightbeams.add_molecule (b);
740 a = me->lookup_l ()->beam (dydx, w, thick);
742 for (; j < rwholebeams + rhalfs; j++)
745 b.translate_axis (- dir * bdy * j, Y_AXIS);
746 rightbeams.add_molecule (b);
750 leftbeams.add_molecule (rightbeams);
753 Does beam quanting think of the asymetry of beams?
754 Refpoint is on bottom of symbol. (FIXTHAT) --hwn.
759 MAKE_SCHEME_CALLBACK(Beam,brew_molecule);
761 Beam::brew_molecule (SCM smob)
763 Score_element * me =unsmob_element (smob);
766 if (!gh_pair_p (me->get_elt_property ("stems")))
769 Link_array<Item>stems =
770 Pointer_group_interface__extract_elements (me, (Item*) 0, "stems");
771 if (visible_stem_count (me))
773 // ugh -> use commonx
774 x0 = first_visible_stem (me)->relative_coordinate (0, X_AXIS);
775 dx = last_visible_stem (me)->relative_coordinate (0, X_AXIS) - x0;
779 x0 = stems[0]->relative_coordinate (0, X_AXIS);
780 dx = stems.top()->relative_coordinate (0, X_AXIS) - x0;
784 Real dy = gh_scm2double (me->get_elt_property ("height"));
785 Real dydx = dy && dx ? dy/dx : 0;
786 Real y = gh_scm2double (me->get_elt_property ("y-position"));
789 for (int j=0; j <stems.size (); j++)
792 Item * prev = (j > 0)? stems[j-1] : 0;
793 Item * next = (j < stems.size()-1) ? stems[j+1] :0;
795 Molecule sb = stem_beams (me, i, next, prev);
796 Real x = i->relative_coordinate (0, X_AXIS)-x0;
797 sb.translate (Offset (x, x * dydx + y));
798 mol.add_molecule (sb);
800 mol.translate_axis (x0
801 - dynamic_cast<Spanner*> (me)->get_bound (LEFT)->relative_coordinate (0, X_AXIS), X_AXIS);
803 return mol.create_scheme ();
807 Beam::forced_stem_count (Score_element*me)
809 Link_array<Item>stems =
810 Pointer_group_interface__extract_elements ( me, (Item*) 0, "stems");
812 for (int i=0; i < stems.size (); i++)
816 if (Stem::invisible_b (s))
819 if (((int)Stem::chord_start_f (s))
820 && (Stem::get_direction (s ) != Stem::get_default_dir (s )))
830 use filter and standard list functions.
833 Beam::visible_stem_count (Score_element*me)
835 Link_array<Item>stems =
836 Pointer_group_interface__extract_elements (me, (Item*) 0, "stems");
838 for (int i = stems.size (); i--;)
840 if (!Stem::invisible_b (stems[i]))
847 Beam::first_visible_stem(Score_element*me)
849 Link_array<Item>stems =
850 Pointer_group_interface__extract_elements ( me, (Item*) 0, "stems");
852 for (int i = 0; i < stems.size (); i++)
854 if (!Stem::invisible_b (stems[i]))
861 Beam::last_visible_stem(Score_element*me)
863 Link_array<Item>stems =
864 Pointer_group_interface__extract_elements ( me, (Item*) 0, "stems");
865 for (int i = stems.size (); i--;)
867 if (!Stem::invisible_b (stems[i]))
876 handle rest under beam (do_post: beams are calculated now)
877 what about combination of collisions and rest under beam.
881 rest -> stem -> beam -> interpolate_y_position ()
884 Beam::rest_collision_callback (Score_element *rest, Axis a )
886 assert (a == Y_AXIS);
888 Score_element * st = unsmob_element (rest->get_elt_property ("stem"));
889 Score_element * stem = st;
892 Score_element * beam = unsmob_element (stem->get_elt_property ("beam"));
893 if (!beam || !Beam::has_interface (beam) || !Beam::visible_stem_count (beam))
896 // make callback for rest from this.
901 // todo: make sure this calced already.
902 SCM s = beam->get_elt_property ("height");
904 beam_dy = gh_scm2double (s);
906 s = beam->get_elt_property ("y-position");
908 beam_y = gh_scm2double (s);
910 // ugh -> use commonx
911 Real x0 = first_visible_stem(beam)->relative_coordinate (0, X_AXIS);
912 Real dx = last_visible_stem(beam)->relative_coordinate (0, X_AXIS) - x0;
913 Real dydx = beam_dy && dx ? beam_dy/dx : 0;
915 Direction d = Stem::get_direction (stem);
916 Real beamy = (stem->relative_coordinate (0, X_AXIS) - x0) * dydx + beam_y;
918 Real staff_space = Staff_symbol_referencer::staff_space (rest);
919 Real rest_dim = rest->extent (Y_AXIS)[d]*2.0 / staff_space ;
922 = gh_scm2double (rest->get_elt_property ("minimum-beam-collision-distance"));
924 minimum_dist + -d * (beamy - rest_dim) >? 0;
926 int stafflines = Staff_symbol_referencer::line_count (rest);
928 // move discretely by half spaces.
929 int discrete_dist = int (ceil (dist));
931 // move by whole spaces inside the staff.
932 if (discrete_dist < stafflines+1)
933 discrete_dist = int (ceil (discrete_dist / 2.0)* 2.0);
935 return (-d * discrete_dist);
940 Beam::has_interface (Score_element*me)
942 return me->has_interface (ly_symbol2scm ("beam-interface"));
946 Beam::set_interface (Score_element*me)
948 Pointer_group_interface g (me, "stems");
952 why the init? No way to tell difference between default and user
954 me->set_elt_property ("height", gh_int2scm (0)); // ugh.
955 me->set_elt_property ("y-position" ,gh_int2scm (0));
956 me->set_interface (ly_symbol2scm("beam-interface"));