+2006-03-29 Han-Wen Nienhuys <hanwen@lilypond.org>
+
+ * input/regression/stem-tremolo-position.ly: new file.
+
+ * lily/stem-tremolo.cc: remove Stem_tremolo::dim_callback
+
+2006-03-28 Joe Neeman <joeneeman@gmail.com>
+
+ * lily/stem-tremolo.cc (print): position
+ the tremolo depending only on the end of the stem
+ and not on the notehead
+ (raw_stencil): center, on the middle staff line, the
+ flag that is closest to the end of the stem (previously
+ the bottom flag)
+ (calc_width): add this callback to shorten a tremolo when
+ it is beamed or it is stemup with a flag
+ (style): add this callback to make a tremolo rectangular when
+ it is beamed or it is stemup with a flag
+ (rotated_box): this is like Lookup::beam but makes a rotated
+ rectangle instead of a parallelogram
+
+ * lily/stem.cc (calc_stem_info): make sure the stem
+ is long enough to fit the tremolo
+ (calc-length): reduce the length of tremolo stems since the
+ tremolo code is now capable of better positioning
+
+ * scm/define-grobs.scm: make calc_width the default beam-width
+ callback for stem-tremolo and add the style callback
+
2006-03-29 Han-Wen Nienhuys <hanwen@lilypond.org>
* lily/tuplet-bracket.cc (calc_control_points): handle suicide
#include "stem.hh"
#include "warn.hh"
-/* TODO: lengthen stem if necessary */
-
-MAKE_SCHEME_CALLBACK (Stem_tremolo, dim_callback, 1);
-
-/* todo: init with cons. */
-SCM
-Stem_tremolo::dim_callback (SCM e)
-{
- Grob *se = unsmob_grob (e);
-
- Real space = Staff_symbol_referencer::staff_space (se);
- return ly_interval2scm (Interval (-space, space));
-}
-
-
MAKE_SCHEME_CALLBACK (Stem_tremolo, calc_slope, 1)
SCM
Stem_tremolo::calc_slope (SCM smob)
return scm_from_double (dx ? dy / dx : 0);
}
else
- return scm_from_double (0.25);
+ /* down stems with flags should have more sloped trems (helps avoid
+ flag/stem collisions without making the stem very long) */
+ return scm_from_double (
+ (Stem::duration_log (stem) >= 3 && get_grob_direction (stem) == DOWN) ?
+ 0.40 : 0.25);
+}
+
+MAKE_SCHEME_CALLBACK (Stem_tremolo, calc_width, 1)
+SCM
+Stem_tremolo::calc_width (SCM smob)
+{
+ Grob *me = unsmob_grob (smob);
+ Grob *stem = unsmob_grob (me->get_object ("stem"));
+ Direction stemdir = get_grob_direction (stem);
+ bool beam = Stem::get_beam (stem);
+ bool flag = Stem::duration_log (stem) >= 3 && !beam;
+
+ /* beamed stems and up-stems with flags have shorter tremolos */
+ return scm_from_double (((stemdir == UP && flag) || beam)? 1.0 : 1.5);
+}
+
+MAKE_SCHEME_CALLBACK (Stem_tremolo, calc_style, 1)
+SCM
+Stem_tremolo::calc_style (SCM smob)
+{
+ Grob *me = unsmob_grob (smob);
+ Grob *stem = unsmob_grob (me->get_object ("stem"));
+ Direction stemdir = get_grob_direction (stem);
+ bool beam = Stem::get_beam (stem);
+ bool flag = Stem::duration_log (stem) >= 3 && !beam;
+
+ return ly_symbol2scm (((stemdir == UP && flag) || beam) ? "rectangle" : "default");
}
Real
return beam ? Beam::get_beam_translation (beam) : 0.81;
}
+/* FIXME: move to Lookup? */
+Stencil
+Stem_tremolo::rotated_box (Real slope, Real width, Real thick, Real blot)
+{
+ vector<Offset> pts;
+ Offset rot (1, slope);
+
+ thick -= 2*blot;
+ width -= 2*blot;
+ rot /= sqrt (1 + slope*slope);
+ pts.push_back (Offset (0, -thick / 2) * rot);
+ pts.push_back (Offset (width, -thick / 2) * rot);
+ pts.push_back (Offset (width, thick / 2) * rot);
+ pts.push_back (Offset (0, thick / 2) * rot);
+ return Lookup::round_filled_polygon (pts, blot);
+}
+
Stencil
-Stem_tremolo::raw_stencil (Grob *me, Real slope)
+Stem_tremolo::raw_stencil (Grob *me, Real slope, Direction stemdir)
{
Real ss = Staff_symbol_referencer::staff_space (me);
Real thick = robust_scm2double (me->get_property ("beam-thickness"), 1);
Real width = robust_scm2double (me->get_property ("beam-width"), 1);
Real blot = me->layout ()->get_dimension (ly_symbol2scm ("blot-diameter"));
+ SCM style = me->get_property ("style");
+ if (!scm_is_symbol (style))
+ style = ly_symbol2scm ("default");
width *= ss;
thick *= ss;
- Stencil a (Lookup::beam (slope, width, thick, blot));
- a.translate (Offset (-width * 0.5, width * 0.5 * slope));
+ Stencil a = style == ly_symbol2scm ("rectangle") ?
+ rotated_box (slope, width, thick, blot) :
+ Lookup::beam (slope, width, thick, blot);
+ a.align_to (X_AXIS, CENTER);
+ a.align_to (Y_AXIS, CENTER);
int tremolo_flags = robust_scm2int (me->get_property ("flag-count"), 0);
if (!tremolo_flags)
return Stencil ();
}
- /* Who the fuck is 0.81 ? --hwn. */
Real beam_translation = get_beam_translation(me);
Stencil mol;
for (int i = 0; i < tremolo_flags; i++)
{
Stencil b (a);
- b.translate_axis (beam_translation * i, Y_AXIS);
+ b.translate_axis (beam_translation * i * stemdir * -1, Y_AXIS);
mol.add_stencil (b);
}
return mol;
/*
Cannot use the real slope, since it looks at the Beam.
*/
- Stencil s1 (raw_stencil (me, 0.35));
+ Stencil s1 (raw_stencil (me, 0.35, UP));
return ly_interval2scm (s1.extent (Y_AXIS));
}
: 0.81;
Stencil mol = raw_stencil (me, robust_scm2double (me->get_property ("slope"),
- 0.25));
+ 0.25), stemdir);
+
Interval mol_ext = mol.extent (Y_AXIS);
Real ss = Staff_symbol_referencer::staff_space (me);
Real end_y
= Stem::stem_end_position (stem) * ss / 2
- - stemdir * (beam_count * beamthickness
- + (max (beam_count -1, 0) * beam_translation));
-
- /* FIXME: the 0.33 ss is to compensate for the size of the note head. */
- Real chord_start_y = Stem::chord_start_y (stem) + 0.33 * ss * stemdir;
-
- Real padding = beam_translation;
+ - stemdir * max (beam_count, 1) * beam_translation;
- /* if there is a flag, just above/below the notehead.
- if there is not enough space, center on remaining space,
- else one beamspace away from stem end. */
if (!beam && Stem::duration_log (stem) >= 3)
{
- mol.align_to (Y_AXIS, -stemdir);
- mol.translate_axis (chord_start_y + 0.5 * stemdir, Y_AXIS);
+ end_y -= stemdir * (Stem::duration_log (stem) - 2) * beam_translation;
+ if (stemdir == UP)
+ end_y -= stemdir * beam_translation * 0.5;
}
- else if (stemdir * (end_y - chord_start_y) - 2 * padding - mol_ext.length ()
- < 0.0)
- mol.translate_axis (0.5 * (end_y + chord_start_y) - mol_ext.center (),
- Y_AXIS);
- else
- mol.translate_axis (end_y - stemdir * beam_translation -mol_ext [stemdir],
- Y_AXIS);
+ mol.translate_axis (end_y, Y_AXIS);
return mol.smobbed_copy ();
}
ADD_INTERFACE (Stem_tremolo, "stem-tremolo-interface",
"A beam slashing a stem to indicate a tremolo.",
+
+ "beam-thickness "
+ "beam-width "
+ "flag-count "
"stem "
+ "style "
"slope "
- "beam-width "
- "beam-thickness "
- "flag-count");
+ );
+ 2 * t_flag->extent (t_flag, Y_AXIS).length ()
/ ss;
+ /* We don't want to add the whole extent of the flag because the trem
+ and the flag can overlap partly. beam_translation gives a good
+ approximation */
if (durlog >= 3)
- {
- Interval flag_ext = flag (me).extent (Y_AXIS);
- if (!flag_ext.is_empty ())
- minlen += 2 * flag_ext.length () / ss;
-
- /* The clash is smaller for down stems (since the tremolo is
- angled up.) */
- if (dir == DOWN)
- minlen -= 1.0;
- }
+ {
+ Real beam_trans = Stem_tremolo::get_beam_translation (t_flag);
+ /* the obvious choice is (durlog - 2) here, but we need a bit more space. */
+ minlen += 2 * (durlog - 1.5) * beam_trans;
+
+ /* up-stems need even a little more space to avoid collisions. This
+ needs to be in sync with the tremolo positioning code in
+ Stem_tremolo::print */
+ if (dir == UP)
+ minlen += beam_trans;
+ }
length = max (length, minlen + 1.0);
}
return si;
}
-/* TODO: add extra space for tremolos! */
MAKE_SCHEME_CALLBACK(Stem, calc_stem_info, 1);
SCM
Stem::calc_stem_info (SCM smob)
* staff_space
* length_fraction;
+ Real height_of_my_trem = 0.0;
+ Grob *trem = unsmob_grob (me->get_object ("tremolo-flag"));
+ if (trem)
+ height_of_my_trem = trem->extent (trem, Y_AXIS).length ()
+ /* hack a bit of space around the trem. */
+ + beam_translation;
+
/* UGH
It seems that also for ideal minimum length, we must use
the maximum beam count (for this direction):
Real ideal_minimum_length = ideal_minimum_free
+ height_of_my_beams
+ + height_of_my_trem
/* stem only extends to center of beam */
- 0.5 * beam_thickness;
* staff_space
* length_fraction;
- Real minimum_length = minimum_free
+ Real minimum_length = max (minimum_free, height_of_my_trem)
+ height_of_my_beams
/* stem only extends to center of beam */
- 0.5 * beam_thickness;
- if (Grob *tremolo = unsmob_grob (me->get_object ("tremolo-flag")))
- {
- Interval y_ext = tremolo->extent (tremolo, Y_AXIS);
- y_ext.widen (0.5); // FIXME. Should be tunable?
- minimum_length = max (minimum_length, y_ext.length ());
- }
-
ideal_y *= my_dir;
Real minimum_y = note_start + minimum_length;
Real shortest_y = minimum_y * my_dir;