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,1);
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::get (me))
88 Directional_element_interface::set (me, get_default_dir (me));
91 set_stem_directions (me);
92 set_stem_shorten (me);
98 Beam::get_default_dir (Score_element*me)
100 Drul_array<int> total;
101 total[UP] = total[DOWN] = 0;
102 Drul_array<int> count;
103 count[UP] = count[DOWN] = 0;
106 Link_array<Item> stems=
107 Pointer_group_interface__extract_elements (me, (Item*)0, "stems");
109 for (int i=0; i <stems.size (); i++)
110 do { // HUH -- waar slaat dit op?
111 Score_element *s = stems[i];
112 Direction sd = Directional_element_interface::get (s);
113 int current = sd ? (1 + d * sd)/2
114 : Stem::get_center_distance (s, (Direction)-d);
122 } while (flip(&d) != DOWN);
124 SCM func = me->get_elt_property ("dir-function");
125 SCM s = gh_call2 (func,
126 gh_cons (gh_int2scm (count[UP]),
127 gh_int2scm (count[DOWN])),
128 gh_cons (gh_int2scm (total[UP]),
129 gh_int2scm (total[DOWN])));
131 if (gh_number_p (s) && gh_scm2int (s))
135 If dir is not determined: get default
137 return to_dir (me->get_elt_property ("default-neutral-direction"));
142 Set all stems with non-forced direction to beam direction.
143 Urg: non-forced should become `without/with unforced' direction,
144 once stem gets cleaned-up.
147 Beam::set_stem_directions (Score_element*me)
149 Link_array<Item> stems
150 =Pointer_group_interface__extract_elements (me, (Item*) 0, "stems");
151 Direction d = Directional_element_interface::get (me);
153 for (int i=0; i <stems.size (); i++)
155 Score_element *s = stems[i];
156 SCM force = s->remove_elt_property ("dir-forced");
157 if (!gh_boolean_p (force) || !gh_scm2bool (force))
158 Directional_element_interface ::set (s,d);
163 Beam::auto_knees (Score_element*me)
165 if (!auto_knee (me,"auto-interstaff-knee-gap", true))
166 auto_knee (me, "auto-knee-gap", false);
170 Simplistic auto-knees; only consider vertical gap between two
173 `Forced' stem directions are ignored. If you don't want auto-knees,
174 don't set, or unset autoKneeGap/autoInterstaffKneeGap.
177 Beam::auto_knee (Score_element*me, String gap_str, bool interstaff_b)
181 SCM gap = me->get_elt_property (gap_str.ch_C());
183 Direction d = Directional_element_interface::get (me);
184 Link_array<Item> stems=
185 Pointer_group_interface__extract_elements (me, (Item*)0, "stems");
187 if (gh_number_p (gap))
189 Spanner*sp = dynamic_cast<Spanner*> (me);
190 int auto_gap_i = gh_scm2int (gap);
191 for (int i=1; i < stems.size (); i++)
193 bool is_b = (bool)(calc_interstaff_dist (stems[i], sp)
194 - calc_interstaff_dist (stems[i-1], sp));
195 int l_y = (int)(Stem::head_positions(stems[i-1])[d])
196 + (int)calc_interstaff_dist (stems[i-1], sp);
197 int r_y = (int)(Stem::head_positions(stems[i])[d])
198 + (int)calc_interstaff_dist (stems[i], sp);
199 int gap_i = r_y - l_y;
201 if ((abs (gap_i) >= auto_gap_i) && (!interstaff_b || is_b))
203 knee_y = (r_y + l_y) / 2;
211 for (int i=0; i < stems.size (); i++)
214 int y = (int)(Stem::head_positions(s)[d])
215 + (int)calc_interstaff_dist (s, dynamic_cast<Spanner*> (me));
217 Directional_element_interface::set (s,y < knee_y ? UP : DOWN);
218 s->set_elt_property ("dir-forced", SCM_BOOL_T);
225 Set stem's shorten property if unset.
227 take some y-position (chord/beam/nearest?) into account
228 scmify forced-fraction
231 Beam::set_stem_shorten (Score_element*m)
233 Spanner*me = dynamic_cast<Spanner*> (m);
234 if (!visible_stem_count (me))
237 Real forced_fraction = forced_stem_count (me) / visible_stem_count (me);
238 if (forced_fraction < 0.5)
241 int multiplicity = get_multiplicity (me);
243 SCM shorten = me->get_elt_property ("beamed-stem-shorten");
244 if (shorten == SCM_EOL)
247 int sz = scm_ilength (shorten);
249 Real staff_space = Staff_symbol_referencer::staff_space (me);
250 SCM shorten_elt = scm_list_ref (shorten, gh_int2scm (multiplicity <? (sz - 1)));
251 Real shorten_f = gh_scm2double (shorten_elt) * staff_space;
253 /* cute, but who invented me -- how to customise ? */
254 if (forced_fraction < 1)
257 Link_array<Item> stems=
258 Pointer_group_interface__extract_elements (me, (Item*)0, "stems");
260 for (int i=0; i < stems.size (); i++)
263 if (Stem::invisible_b (s))
265 if (gh_number_p (s->get_elt_property ("shorten")))
266 s->set_elt_property ("shorten", gh_double2scm (shorten_f));
271 Set elt properties height and y-position if not set.
272 Adjust stem lengths to reach beam.
274 MAKE_SCHEME_CALLBACK(Beam,after_line_breaking,1);
276 Beam::after_line_breaking (SCM smob)
278 Score_element * me = unsmob_element (smob);
280 /* first, calculate y, dy */
282 calc_default_position_and_height (me, &y, &dy);
283 if (visible_stem_count (me))
285 if (suspect_slope_b (me, y, dy))
288 Real damped_dy = calc_slope_damping_f (me, dy);
289 Real quantised_dy = quantise_dy_f (me, damped_dy);
291 y += (dy - quantised_dy) / 2;
295 until here, we used only stem_info, which acts as if dir=up
297 y *= Directional_element_interface::get (me);
298 dy *= Directional_element_interface::get (me);
301 Real half_space = Staff_symbol_referencer::staff_space (me) / 2;
303 /* weird: why do we do calc_position_and_height () ? regardless of
307 /* check for user-override of dy */
308 SCM s = me->remove_elt_property ("height-hs");
311 dy = gh_scm2double (s) * half_space;
313 me->set_elt_property ("height", gh_double2scm (dy));
315 /* check for user-override of y */
316 s = me->remove_elt_property ("y-position-hs");
319 y = gh_scm2double (s) * half_space;
323 /* we can modify y, so we should quantise y */
324 Real y_shift = check_stem_length_f (me, y, dy);
326 y = quantise_y_f (me,y, dy, 0);
327 set_stem_length (me, y, dy);
328 y_shift = check_stem_length_f (me, y, dy);
330 if (y_shift > half_space / 4)
335 for significantly lengthened or shortened stems,
336 request quanting the other way.
339 if (abs (y_shift) > half_space / 2)
340 quant_dir = sign (y_shift) * Directional_element_interface::get (me);
341 y = quantise_y_f (me, y, dy, quant_dir);
344 // UGH. Y is not in staff position unit?
345 // Ik dacht datwe daar juist van weg wilden?
346 set_stem_length (me, y, dy);
347 me->set_elt_property ("y-position", gh_double2scm (y));
349 return SCM_UNSPECIFIED;
353 See Documentation/tex/fonts.doc
356 Beam::calc_default_position_and_height (Score_element*me,Real* y, Real* dy)
360 if (visible_stem_count (me) <= 1)
363 Real first_ideal = Stem::calc_stem_info (first_visible_stem (me)).idealy_f_;
364 if (first_ideal == Stem::calc_stem_info (last_visible_stem (me)).idealy_f_)
371 Array<Offset> ideals;
373 // ugh -> use commonx
374 Real x0 = first_visible_stem (me)->relative_coordinate (0, X_AXIS);
375 Link_array<Item> stems=
376 Pointer_group_interface__extract_elements (me, (Item*)0, "stems");
378 for (int i=0; i < stems.size (); i++)
381 if (Stem::invisible_b (s))
383 ideals.push (Offset (s->relative_coordinate (0, X_AXIS) - x0,
384 Stem::calc_stem_info (s).idealy_f_));
387 minimise_least_squares (&dydx, y, ideals); // duh, takes references
389 Real dx = last_visible_stem (me)->relative_coordinate (0, X_AXIS) - x0;
394 Beam::suspect_slope_b (Score_element*me, Real y, Real dy)
396 /* first, calculate y, dy */
398 steep slope running against lengthened stem is suspect
400 Real ss = me->paper_l ()->get_var ("staffspace");
401 Real first_ideal = Stem::calc_stem_info (first_visible_stem (me)).idealy_f_;
402 Real last_ideal = Stem::calc_stem_info (last_visible_stem (me)).idealy_f_;
403 Real lengthened = gh_scm2double (me->get_elt_property ("outer-stem-length-limit")) * ss;
404 Real steep = gh_scm2double (me->get_elt_property ("slope-limit"));
406 // ugh -> use commonx
407 Real dx = last_visible_stem (me)->relative_coordinate (0, X_AXIS) - first_visible_stem (me)->relative_coordinate (0, X_AXIS);
408 Real dydx = dy && dx ? dy/dx : 0;
410 if (((y - first_ideal > lengthened) && (dydx > steep))
411 || ((y + dy - last_ideal > lengthened) && (dydx < -steep)))
419 This neat trick is by Werner Lemberg,
420 damped = tanh (slope)
421 corresponds with some tables in [Wanske]
424 Beam::calc_slope_damping_f (Score_element*me,Real dy)
426 SCM damp = me->get_elt_property ("damping");
427 int damping = gh_scm2int (damp);
431 // ugh -> use commonx
432 Real dx = last_visible_stem (me)->relative_coordinate (0, X_AXIS)
433 - first_visible_stem (me)->relative_coordinate (0, X_AXIS);
434 Real dydx = dy && dx ? dy/dx : 0;
435 dydx = 0.6 * tanh (dydx) / damping;
442 Beam::calc_stem_y_f (Score_element*me,Item* s, Real y, Real dy)
444 int beam_multiplicity = get_multiplicity (me);
445 int stem_multiplicity = (Stem::flag_i (s) - 2) >? 0;
447 Real staffspace = me->paper_l ()->get_var ("staffspace");
449 SCM space_proc = me->get_elt_property ("space-function");
450 SCM space = gh_call1 (space_proc, gh_int2scm (beam_multiplicity));
452 Real thick = gh_scm2double (me->get_elt_property ("thickness")) *staffspace;
453 Real interbeam_f = gh_scm2double (space) * staffspace;
455 // ugh -> use commonx
456 Real x0 = first_visible_stem (me)->relative_coordinate (0, X_AXIS);
457 Real dx = last_visible_stem (me)->relative_coordinate (0, X_AXIS) - x0;
458 Real stem_y = (dy && dx ? (s->relative_coordinate (0, X_AXIS) - x0) / dx * dy : 0) + y;
461 Direction dir = Directional_element_interface::get (me);
462 Direction sdir = Directional_element_interface::get (s);
468 * (thick / 2 + (beam_multiplicity - 1) * interbeam_f);
472 // huh, why not for first visible?
473 if (Staff_symbol_referencer::staff_symbol_l (s)
474 != Staff_symbol_referencer::staff_symbol_l (last_visible_stem (me)))
475 stem_y += Directional_element_interface::get (me)
476 * (beam_multiplicity - stem_multiplicity) * interbeam_f;
483 Beam::check_stem_length_f (Score_element*me,Real y, Real dy)
487 Direction dir = Directional_element_interface::get (me);
489 Link_array<Item> stems=
490 Pointer_group_interface__extract_elements (me, (Item*)0, "stems");
492 for (int i=0; i < stems.size(); i++)
495 if (Stem::invisible_b (s))
498 Real stem_y = calc_stem_y_f (me, s, y, dy);
501 Stem_info info = Stem::calc_stem_info (s);
503 // if (0 > info.maxy_f_ - stem_y)
504 shorten = shorten <? info.maxy_f_ - stem_y;
505 // if (0 < info.miny_f_ - stem_y)
506 lengthen = lengthen >? info.miny_f_ - stem_y;
509 if (lengthen && shorten)
510 warning (_ ("weird beam vertical offset"));
512 /* when all stems are too short, normal stems win */
513 return dir * ((shorten) ? shorten : lengthen);
517 Hmm. At this time, beam position and slope are determined. Maybe,
518 stem directions and length should set to relative to the chord's
519 position of the beam. */
521 Beam::set_stem_length (Score_element*me,Real y, Real dy)
523 Real half_space = Staff_symbol_referencer::staff_space (me)/2;
524 Link_array<Item> stems=
525 Pointer_group_interface__extract_elements (me, (Item*)0, "stems");
528 for (int i=0; i < stems.size (); i++)
531 if (Stem::invisible_b (s))
534 Real stem_y = calc_stem_y_f (me, s, y, dy);
536 /* caution: stem measures in staff-positions */
537 Stem::set_stemend (s,(stem_y + calc_interstaff_dist (s, dynamic_cast<Spanner*> (me))) / half_space);
542 [Ross] (simplification of)
543 Set dy complying with:
545 - thick / 2 + staffline_f / 2
546 - thick + staffline_f
550 Beam::quantise_dy_f (Score_element*me,Real dy)
554 SCM proc = me->get_elt_property ("height-quants");
555 SCM quants = gh_call2 (proc, me->self_scm (),
556 gh_double2scm (me->paper_l ()->get_var ("stafflinethickness")
557 / me->paper_l ()->get_var ("staffspace")));
560 for (SCM s = quants; gh_pair_p (s); s = gh_cdr (s))
561 a.push (gh_scm2double (gh_car (s)));
566 Real staff_space = Staff_symbol_referencer::staff_space (me);
568 Interval iv = quantise_iv (a, abs (dy)/staff_space) * staff_space;
569 Real q = (abs (dy) - iv[SMALLER] <= iv[BIGGER] - abs (dy))
573 return q * sign (dy);
577 Prevent interference from stafflines and beams.
578 See Documentation/tex/fonts.doc
580 We only need to quantise the (left) y-position of the beam,
581 since dy is quantised too.
582 if extend_b then stems must *not* get shorter
585 Beam::quantise_y_f (Score_element*me,Real y, Real dy, int quant_dir)
587 int multiplicity = get_multiplicity (me);
589 Real staff_space = Staff_symbol_referencer::staff_space (me);
590 Real thick = me->paper_l ()->get_var ("stafflinethickness");
593 SCM proc = me->get_elt_property ("vertical-position-quant-function");
594 SCM quants = scm_apply (proc,
596 gh_list (gh_int2scm (multiplicity),
597 gh_double2scm (dy/staff_space),
598 gh_double2scm (thick/staff_space),
599 SCM_EOL, SCM_UNDEFINED));
603 for (; gh_pair_p (quants); quants = gh_cdr (quants))
604 a.push (gh_scm2double (gh_car (quants)));
609 Real up_y = Directional_element_interface::get (me) * y;
610 Interval iv = quantise_iv (a, up_y/staff_space) * staff_space;
612 Real q = up_y - iv[SMALLER] <= iv[BIGGER] - up_y
613 ? iv[SMALLER] : iv[BIGGER];
615 q = iv[(Direction)quant_dir];
617 return q * Directional_element_interface::get (me);
621 Beam::set_beaming (Score_element*me,Beaming_info_list *beaming)
623 Link_array<Score_element> stems=
624 Pointer_group_interface__extract_elements (me, (Score_element*)0, "stems");
627 for (int i=0; i < stems.size(); i++)
631 if (Stem::beam_count (stems[i], d) == 0)
632 Stem::set_beaming ( stems[i], beaming->infos_.elem (i).beams_i_drul_[d],d);
634 while (flip (&d) != LEFT);
641 beams to go with one stem.
646 Beam::stem_beams (Score_element*me,Item *here, Item *next, Item *prev)
648 // ugh -> use commonx
649 if ((next && !(next->relative_coordinate (0, X_AXIS) > here->relative_coordinate (0, X_AXIS))) ||
650 (prev && !(prev->relative_coordinate (0, X_AXIS) < here->relative_coordinate (0, X_AXIS))))
651 programming_error ("Beams are not left-to-right");
653 Real staffline_f = me->paper_l ()->get_var ("stafflinethickness");
654 int multiplicity = get_multiplicity (me);
655 Real staffspace =me->paper_l ()->get_var ("staffspace");
657 SCM space_proc = me->get_elt_property ("space-function");
658 SCM space = gh_call1 (space_proc, gh_int2scm (multiplicity));
660 Real thick = gh_scm2double (me->get_elt_property ("thickness")) *staffspace;
661 Real interbeam_f = gh_scm2double (space) * staffspace;
663 Real bdy = interbeam_f;
664 Real stemdx = staffline_f;
666 // ugh -> use commonx
667 Real dx = visible_stem_count (me) ?
668 last_visible_stem (me)->relative_coordinate (0, X_AXIS) - first_visible_stem (me)->relative_coordinate (0, X_AXIS)
670 Real dy = gh_scm2double (me->get_elt_property ("height"));
671 Real dydx = dy && dx ? dy/dx : 0;
677 if (!Stem::first_head (here))
680 int t = Stem::type_i (here);
682 SCM proc = me->get_elt_property ("flag-width-function");
683 SCM result = gh_call1 (proc, gh_int2scm (t));
684 nw_f = gh_scm2double (result) * staffspace;
688 Direction dir = Directional_element_interface::get (me);
690 /* half beams extending to the left. */
693 int lhalfs= lhalfs = Stem::beam_count (here,LEFT) - Stem::beam_count (prev,RIGHT);
694 int lwholebeams= Stem::beam_count (here,LEFT) <? Stem::beam_count (prev,RIGHT) ;
696 Half beam should be one note-width,
697 but let's make sure two half-beams never touch
699 Real w = here->relative_coordinate (0, X_AXIS) - prev->relative_coordinate (0, X_AXIS);
702 if (lhalfs) // generates warnings if not
703 a = me->lookup_l ()->beam (dydx, w, thick);
704 a.translate (Offset (-w, -w * dydx));
705 for (int j = 0; j < lhalfs; j++)
708 b.translate_axis (-dir * bdy * (lwholebeams+j), Y_AXIS);
709 leftbeams.add_molecule (b);
715 int rhalfs = Stem::beam_count (here,RIGHT) - Stem::beam_count (next,LEFT);
716 int rwholebeams= Stem::beam_count (here,RIGHT) <? Stem::beam_count (next,LEFT) ;
718 Real w = next->relative_coordinate (0, X_AXIS) - here->relative_coordinate (0, X_AXIS);
719 Molecule a = me->lookup_l ()->beam (dydx, w + stemdx, thick);
720 a.translate_axis( - stemdx/2, X_AXIS);
724 SCM gap = me->get_elt_property ("gap");
725 if (gh_number_p (gap))
727 int gap_i = gh_scm2int ( (gap));
728 int nogap = rwholebeams - gap_i;
730 for (; j < nogap; j++)
733 b.translate_axis (-dir * bdy * j, Y_AXIS);
734 rightbeams.add_molecule (b);
736 // TODO: notehead widths differ for different types
739 a = me->lookup_l ()->beam (dydx, w + stemdx, thick);
742 for (; j < rwholebeams; j++)
745 b.translate (Offset (Stem::invisible_b (here) ? 0 : gap_f, -dir * bdy * j));
746 rightbeams.add_molecule (b);
751 a = me->lookup_l ()->beam (dydx, w, thick);
753 for (; j < rwholebeams + rhalfs; j++)
756 b.translate_axis (- dir * bdy * j, Y_AXIS);
757 rightbeams.add_molecule (b);
761 leftbeams.add_molecule (rightbeams);
764 Does beam quanting think of the asymetry of beams?
765 Refpoint is on bottom of symbol. (FIXTHAT) --hwn.
770 MAKE_SCHEME_CALLBACK(Beam,brew_molecule,1);
772 Beam::brew_molecule (SCM smob)
774 Score_element * me =unsmob_element (smob);
777 if (!gh_pair_p (me->get_elt_property ("stems")))
780 Link_array<Item>stems =
781 Pointer_group_interface__extract_elements (me, (Item*) 0, "stems");
782 if (visible_stem_count (me))
784 // ugh -> use commonx
785 x0 = first_visible_stem (me)->relative_coordinate (0, X_AXIS);
786 dx = last_visible_stem (me)->relative_coordinate (0, X_AXIS) - x0;
790 x0 = stems[0]->relative_coordinate (0, X_AXIS);
791 dx = stems.top()->relative_coordinate (0, X_AXIS) - x0;
795 Real dy = gh_scm2double (me->get_elt_property ("height"));
796 Real dydx = dy && dx ? dy/dx : 0;
797 Real y = gh_scm2double (me->get_elt_property ("y-position"));
800 for (int j=0; j <stems.size (); j++)
803 Item * prev = (j > 0)? stems[j-1] : 0;
804 Item * next = (j < stems.size()-1) ? stems[j+1] :0;
806 Molecule sb = stem_beams (me, i, next, prev);
807 Real x = i->relative_coordinate (0, X_AXIS)-x0;
808 sb.translate (Offset (x, x * dydx + y));
809 mol.add_molecule (sb);
811 mol.translate_axis (x0
812 - dynamic_cast<Spanner*> (me)->get_bound (LEFT)->relative_coordinate (0, X_AXIS), X_AXIS);
814 return mol.create_scheme ();
818 Beam::forced_stem_count (Score_element*me)
820 Link_array<Item>stems =
821 Pointer_group_interface__extract_elements ( me, (Item*) 0, "stems");
823 for (int i=0; i < stems.size (); i++)
827 if (Stem::invisible_b (s))
830 if (((int)Stem::chord_start_f (s))
831 && (Stem::get_direction (s ) != Stem::get_default_dir (s )))
841 use filter and standard list functions.
844 Beam::visible_stem_count (Score_element*me)
846 Link_array<Item>stems =
847 Pointer_group_interface__extract_elements (me, (Item*) 0, "stems");
849 for (int i = stems.size (); i--;)
851 if (!Stem::invisible_b (stems[i]))
858 Beam::first_visible_stem(Score_element*me)
860 Link_array<Item>stems =
861 Pointer_group_interface__extract_elements ( me, (Item*) 0, "stems");
863 for (int i = 0; i < stems.size (); i++)
865 if (!Stem::invisible_b (stems[i]))
872 Beam::last_visible_stem(Score_element*me)
874 Link_array<Item>stems =
875 Pointer_group_interface__extract_elements ( me, (Item*) 0, "stems");
876 for (int i = stems.size (); i--;)
878 if (!Stem::invisible_b (stems[i]))
887 handle rest under beam (do_post: beams are calculated now)
888 what about combination of collisions and rest under beam.
892 rest -> stem -> beam -> interpolate_y_position ()
894 MAKE_SCHEME_CALLBACK(Beam,rest_collision_callback,1);
896 Beam::rest_collision_callback (SCM element_smob, SCM axis)
898 Score_element *rest = unsmob_element (element_smob);
899 Axis a = (Axis) gh_scm2int (axis);
901 assert (a == Y_AXIS);
903 Score_element * st = unsmob_element (rest->get_elt_property ("stem"));
904 Score_element * stem = st;
906 return gh_double2scm (0.0);
907 Score_element * beam = unsmob_element (stem->get_elt_property ("beam"));
908 if (!beam || !Beam::has_interface (beam) || !Beam::visible_stem_count (beam))
909 return gh_double2scm (0.0);
911 // make callback for rest from this.
916 // todo: make sure this calced already.
917 SCM s = beam->get_elt_property ("height");
919 beam_dy = gh_scm2double (s);
921 s = beam->get_elt_property ("y-position");
923 beam_y = gh_scm2double (s);
925 // ugh -> use commonx
926 Real x0 = first_visible_stem(beam)->relative_coordinate (0, X_AXIS);
927 Real dx = last_visible_stem(beam)->relative_coordinate (0, X_AXIS) - x0;
928 Real dydx = beam_dy && dx ? beam_dy/dx : 0;
930 Direction d = Stem::get_direction (stem);
931 Real beamy = (stem->relative_coordinate (0, X_AXIS) - x0) * dydx + beam_y;
933 Real staff_space = Staff_symbol_referencer::staff_space (rest);
934 Real rest_dim = rest->extent (Y_AXIS)[d]*2.0 / staff_space ;
937 = gh_scm2double (rest->get_elt_property ("minimum-beam-collision-distance"));
939 minimum_dist + -d * (beamy - rest_dim) >? 0;
941 int stafflines = Staff_symbol_referencer::line_count (rest);
943 // move discretely by half spaces.
944 int discrete_dist = int (ceil (dist));
946 // move by whole spaces inside the staff.
947 if (discrete_dist < stafflines+1)
948 discrete_dist = int (ceil (discrete_dist / 2.0)* 2.0);
950 return (-d * discrete_dist);
955 Beam::has_interface (Score_element*me)
957 return me->has_interface (ly_symbol2scm ("beam-interface"));
961 Beam::set_interface (Score_element*me)
963 Pointer_group_interface g (me, "stems");
967 why the init? No way to tell difference between default and user
969 me->set_elt_property ("height", gh_int2scm (0)); // ugh.
970 me->set_elt_property ("y-position" ,gh_int2scm (0));
971 me->set_interface (ly_symbol2scm("beam-interface"));