-
-
-/*
- beams to go with one stem.
-
- FIXME: clean me up:
-
- The beam should be constructed by one function that knows where the
- X and Y points are, and only inspects the stems to obtain
- multiplicity and stem directions.
-
- */
-Molecule
-Beam::stem_beams (Grob *me, Item *here, Item *next, Item *prev, Real dydx)
-{
- // ugh -> use commonx
- if ((next
- && ! (next->relative_coordinate (0, X_AXIS)
- > here->relative_coordinate (0, X_AXIS)))
- || (prev
- && ! (prev->relative_coordinate (0, X_AXIS)
- < here->relative_coordinate (0, X_AXIS))))
- programming_error ("Beams are not left-to-right");
-
- Real thick = gh_scm2double (me->get_grob_property ("thickness"));
- Real bdy = get_interbeam (me);
-
- Molecule leftbeams;
- Molecule rightbeams;
-
- Real nw_f;
- if (!Stem::first_head (here))
- nw_f = 0;
- else
- {
- int t = Stem::duration_log (here);
-
- SCM proc = me->get_grob_property ("flag-width-function");
- SCM result = gh_call1 (proc, gh_int2scm (t));
- nw_f = gh_scm2double (result);
- }
-
-
- /* [Tremolo] beams on whole notes may not have direction set? */
- Direction dir = Directional_element_interface::get (here);
-
- /* half beams extending to the left. */
- if (prev)
- {
- int lhalfs= lhalfs = Stem::beam_count (here, LEFT)
- - Stem::beam_count (prev, RIGHT);
- int lwholebeams= Stem::beam_count (here, LEFT)
- <? Stem::beam_count (prev, RIGHT);
-
- /* Half beam should be one note-width,
- but let's make sure two half-beams never touch */
-
- // FIXME: TODO (check) stem width / sloped beams
- Real w = here->relative_coordinate (0, X_AXIS)
- - prev->relative_coordinate (0, X_AXIS);
- Real stem_w = gh_scm2double (prev->get_grob_property ("thickness"))
- // URG
- * me->paper_l ()->get_var ("linethickness");
-
- w = w/2 <? nw_f;
- Molecule a;
- if (lhalfs) // generates warnings if not
- a = Lookup::beam (dydx, w + stem_w, thick);
- a.translate (Offset (-w, -w * dydx));
- a.translate_axis (-stem_w/2, X_AXIS);
- for (int j = 0; j < lhalfs; j++)
- {
- Molecule b (a);
- b.translate_axis (-dir * bdy * (lwholebeams+j), Y_AXIS);
- leftbeams.add_molecule (b);
- }
- }
-
- if (next)
- {
- int rhalfs = Stem::beam_count (here, RIGHT)
- - Stem::beam_count (next, LEFT);
- int rwholebeams= Stem::beam_count (here, RIGHT)
- <? Stem::beam_count (next, LEFT);
-
- Real w = next->relative_coordinate (0, X_AXIS)
- - here->relative_coordinate (0, X_AXIS);
-
- Real stem_w = gh_scm2double (next->get_grob_property ("thickness"))
- // URG
- * me->paper_l ()->get_var ("linethickness");
-
- Molecule a = Lookup::beam (dydx, w + stem_w, thick);
- a.translate_axis (- stem_w/2, X_AXIS);
- int j = 0;
- Real gap_f = 0;
-
- SCM gap = me->get_grob_property ("gap");
- if (gh_number_p (gap))
- {
- int gap_i = gh_scm2int ((gap));
- int nogap = rwholebeams - gap_i;
-
- for (; j < nogap; j++)
- {
- Molecule b (a);
- b.translate_axis (-dir * bdy * j, Y_AXIS);
- rightbeams.add_molecule (b);
- }
- if (Stem::invisible_b (here))
- gap_f = nw_f;
- else
- gap_f = nw_f / 2;
- w -= 2 * gap_f;
- a = Lookup::beam (dydx, w + stem_w, thick);
- }
-
- for (; j < rwholebeams; j++)
- {
- Molecule b (a);
- Real tx = 0;
- if (Stem::invisible_b (here))
- // ugh, see chord-tremolo.ly
- tx = (-dir + 1) / 2 * nw_f * 1.5 + gap_f/4;
- else
- tx = gap_f;
- b.translate (Offset (tx, -dir * bdy * j));
- rightbeams.add_molecule (b);
- }
-
- w = w/2 <? nw_f;
- if (rhalfs)
- a = Lookup::beam (dydx, w, thick);
-
- for (; j < rwholebeams + rhalfs; j++)
- {
- Molecule b (a);
- b.translate_axis (- dir * bdy * j, Y_AXIS);
- rightbeams.add_molecule (b);
- }
-
- }
- leftbeams.add_molecule (rightbeams);
-
- return leftbeams;
-}
-
-
-MAKE_SCHEME_CALLBACK (Beam, brew_molecule, 1);
-SCM
-Beam::brew_molecule (SCM smob)
-{
- Grob *me =unsmob_grob (smob);
-
- Molecule mol;
- if (!gh_pair_p (me->get_grob_property ("stems")))
- return SCM_EOL;
- Real x0, dx;
- Link_array<Item>stems =
- Pointer_group_interface__extract_grobs (me, (Item*) 0, "stems");
- if (visible_stem_count (me))
- {
- // ugh -> use commonx
- x0 = first_visible_stem (me)->relative_coordinate (0, X_AXIS);
- dx = last_visible_stem (me)->relative_coordinate (0, X_AXIS) - x0;
- }
- else
- {
- x0 = stems[0]->relative_coordinate (0, X_AXIS);
- dx = stems.top ()->relative_coordinate (0, X_AXIS) - x0;
- }
-
- SCM posns = me->get_grob_property ("positions");
- Interval pos;
- if (!ly_number_pair_p (posns))
- {
- programming_error ("No beam posns");
- pos = Interval (0,0);
- }
- else
- pos= ly_scm2interval (posns);
- Real dy = pos.delta ();
- Real dydx = dy && dx ? dy/dx : 0;
-
-
- for (int i=0; i < stems.size (); i++)
- {
- Item *item = stems[i];
- Item *prev = (i > 0)? stems[i-1] : 0;
- Item *next = (i < stems.size ()-1) ? stems[i+1] :0;
-
-
-
- Molecule sb = stem_beams (me, item, next, prev, dydx);
- Real x = item->relative_coordinate (0, X_AXIS) - x0;
- sb.translate (Offset (x, x * dydx + pos[LEFT]));
-
-
- mol.add_molecule (sb);
- }
-
- mol.translate_axis (x0
- - dynamic_cast<Spanner*> (me)
- ->get_bound (LEFT)->relative_coordinate (0, X_AXIS),
- X_AXIS);
-
-#if (DEBUG_QUANTING)
- {
- /*
- This code prints the demerits for each beam. Perhaps this
- should be switchable for those who want to twiddle with the
- parameters.
- */
- String str;
- if (1)
- {
- str += to_str (gh_scm2int (me->get_grob_property ("best-idx")));
- str += ":";
- }
- str += to_str (gh_scm2double (me->get_grob_property ("quant-score")),
- "%.2f");
-
- SCM properties = Font_interface::font_alist_chain (me);
-
-
- Molecule tm = Text_item::text2molecule (me, ly_str02scm (str.ch_C ()), properties);
- mol.add_at_edge (Y_AXIS, UP, tm, 5.0);
- }
-#endif
-
- return mol.smobbed_copy ();
-}
-