Real dx = last_visible_stem (me)->relative_coordinate (0, X_AXIS) - x0;
Real dy = dydx * dx;
+ me->set_grob_property ("least-squares-dy", gh_double2scm (dy * dir));
+
pos = Interval (y*dir, (y+dy) * dir);
}
Interval pos = ly_scm2interval (me->get_grob_property ("positions"));
Real r = pos.linear_combination (0);
me->set_grob_property ("positions", ly_interval2scm (Interval (r, r)));
+ me->remove_grob_property ("least-squares-dy");
}
return SCM_UNSPECIFIED;
Real staff_space = Staff_symbol_referencer::staff_space (me);
Real thick = me->paper_l ()->get_var ("stafflinethickness");
-
- /* TODO:
-
- - left and right should be different, depending on direction and
- multiplicity
-
- -use different left-position-quant-function,
- right-position-quant-function for handier slope quanting? */
- SCM proc = me->get_grob_property ("vertical-position-quant-function");
- SCM quants = scm_apply (proc,
- me->self_scm (),
- scm_list_n (gh_int2scm (multiplicity),
- gh_double2scm (1), /* junkme */
- gh_double2scm (thick / staff_space),
- /* HUH? */
- SCM_EOL,
- SCM_UNDEFINED));
-
- Array<Real> a;
- for (SCM i = quants; gh_pair_p (i); i = ly_cdr (i))
- a.push (gh_scm2double (ly_car (i)));
-
- if (a.size () <= 1)
- return pos;
-
Direction dir = Directional_element_interface::get (me);
- Interval left = quantise_iv (a, pos[LEFT]*dir/staff_space) * staff_space;
- Interval right = quantise_iv (a, pos[RIGHT]*dir/staff_space) * staff_space;
-
Real dy = pos.delta ();
+
+ Drul_array<Interval> bounds;
+ Direction d = LEFT;
+ do
+ {
+ SCM proc = d == LEFT
+ ? me->get_grob_property ("left-position-quant-function")
+ : me->get_grob_property ("right-position-quant-function");
+
+ SCM quants = scm_apply (proc,
+ me->self_scm (),
+ scm_list_n (gh_int2scm (multiplicity),
+ gh_double2scm (dir),
+ gh_double2scm (dy),
+ gh_double2scm (thick / staff_space),
+ /* HUH? */
+ SCM_EOL,
+ SCM_UNDEFINED));
+
+ Array<Real> a;
+ for (SCM i = quants; gh_pair_p (i); i = ly_cdr (i))
+ a.push (gh_scm2double (ly_car (i)));
+
+ if (a.size () <= 1)
+ return pos;
+
+ bounds[d] = quantise_iv (a, pos[d]*dir/staff_space) * staff_space;
+ }
+ while (flip (&d) != LEFT);
+
Real ady = abs (dy);
// quant direction hints disabled for now
(save that value?)
Slope should never be reduced to zero.
*/
- Interval qpos (0, 20.0 *sign (dy));
+ SCM s = me->get_grob_property ("least-squares-dy");
+ Real lsdy = gh_number_p (s) ? gh_scm2double (s) : 0;
+
+ // Interval qpos (0, 1000 * sign (dy));
+ Interval qpos;
+ Real epsilon = staff_space / 10;
Direction ldir = LEFT;
do
{
Direction rdir = LEFT;
do
{
- Interval i (left[ldir]*dir, right[rdir]*dir);
- if ((abs (abs (i.delta ()) - ady) <= abs (abs (qpos.delta ()) - ady)
- && sign (i.delta ()) == sign (pos.delta ())
- && (!q
- || (i[LEFT]*q >= pos[LEFT]*q && i[RIGHT]*q >= pos[RIGHT]*q))))
+ Interval i (bounds[LEFT][ldir]*dir, bounds[RIGHT][rdir]*dir);
+ if ((!lsdy
+ || (abs (i.delta ()) <= abs (lsdy) + epsilon
+ && sign (i.delta ()) == sign (lsdy)))
+ && (abs (abs (i.delta ()) - ady)
+ <= abs (abs (qpos.delta ()) - ady))
+ && sign (i.delta ()) == sign (pos.delta ())
+ && (!q
+ || (i[LEFT]*q >= pos[LEFT]*q && i[RIGHT]*q
+ >= pos[RIGHT]*q)))
qpos = i;
}
while (flip (&rdir) != LEFT);
Interval pos = ly_scm2interval (me->get_grob_property ("positions"));
Real y_shift = check_stem_length_f (me, pos);
pos += y_shift;
- pos = quantise_interval (me, pos, CENTER);
+ Real staff_space = Staff_symbol_referencer::staff_space (me);
+
+ Direction dir = Directional_element_interface::get (me);
+ for (int i = 0; i < 10; i++)
+ {
+ Interval qpos = quantise_interval (me, pos, CENTER);
+ // how to check for uninitised interval, (inf, -inf)?
+ if (qpos[LEFT] < 1000)
+ {
+ y_shift = check_stem_length_f (me, qpos);
+ if (y_shift * dir < staff_space / 2)
+ {
+ pos = qpos;
+ break;
+ }
+ }
+ pos += ((i + 1) * ((i % 2) * -2 + 1)) * dir * staff_space / 4;
+ }
+
me->set_grob_property ("positions", ly_interval2scm (pos));
set_stem_lengths (me);
+#if 0
pos = ly_scm2interval (me->get_grob_property ("positions"));
y_shift = check_stem_length_f (me, pos);
}
me->set_grob_property ("positions", ly_interval2scm (pos));
-
+#endif
+
return SCM_UNSPECIFIED;
}
if (info.idealy_f_ - stem_y > 0)
{
+#if 0
ideal_lengthen += info.idealy_f_ - stem_y;
ideal_lengthen_count++;
+#else
+ ideal_lengthen = ideal_lengthen >? info.idealy_f_ - stem_y;
+ ideal_lengthen_count = 1;
+#endif
}
else if (info.idealy_f_ - stem_y < 0)
{
+#if 0
ideal_shorten += info.idealy_f_ - stem_y;
ideal_shorten_count++;
+#else
+ ideal_shorten = ideal_shorten <? info.idealy_f_ - stem_y;
+ ideal_shorten_count = 1;
+#endif
}
}
;; period: 1 (staff-space)
(append quants (list (+ 1 (car quants))))))
+(define (default-left-beam-pos-quants beam multiplicity dir dy staff-line)
+ (default-beam-pos-quants beam multiplicity 1 staff-line))
+
+(define (foo beam multiplicity dir dy staff-line)
+ (let* ((beam-straddle 0)
+ (thick (ly-get-grob-property beam 'thickness))
+ (beam-sit (/ (- thick staff-line) 2))
+ (beam-hang (- 1 (/ (- thick staff-line) 2)))
+ (quants '())
+ )
+
+ (if (or (<= multiplicity 1)
+ (and (not (equal? dir 1))
+ (not (< dy 0))))
+ (set! quants (cons beam-sit quants)))
+ (if (or (<= multiplicity 1)
+ (and (not (equal? dir -1))
+ (not (> dy 0))))
+ (set! quants (cons beam-hang quants)))
+ (if (or (<= multiplicity 2) (>= (abs dy) (/ staff-line 2)))
+ (set! quants (cons beam-straddle quants)))
+ ;; period: 1 (staff-space)
+ (append quants (list (+ 1 (car quants))))))
+
+(define (default-right-beam-pos-quants beam multiplicity dir dy staff-line)
+ (default-beam-pos-quants beam multiplicity 1 staff-line))
+
+(define (foo beam multiplicity dir dy staff-line)
+ (let* ((beam-straddle 0)
+ (thick (ly-get-grob-property beam 'thickness))
+ (beam-sit (/ (- thick staff-line) 2))
+ (beam-hang (- 1 (/ (- thick staff-line) 2)))
+ (quants '())
+ )
+
+
+ (if (or (<= multiplicity 1)
+ (and (not (equal? dir 1))
+ (not (> dy 0))))
+ (set! quants (cons beam-sit quants)))
+ (if (or (<= multiplicity 1)
+ (and (not (equal? dir -1))
+ (not (< dy 0))))
+ (set! quants (cons beam-hang quants)))
+ (if (or (<= multiplicity 2) (>= (abs dy) (/ staff-line 2)))
+ (set! quants (cons beam-straddle quants)))
+ ;; period: 1 (staff-space)
+ (append quants (list (+ 1 (car quants))))))
+
(define (beam-traditional-pos-quants beam multiplicity dy staff-line)
(let* ((beam-straddle 0)
(thick (ly-get-grob-property beam 'thickness))