From 8daeedc462234bd590eb15c70b090e84931e7dec Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Mon, 1 Jan 2007 14:22:39 +0100 Subject: [PATCH] Fix #184. Use new function Stem_tremolo::vertical_length() to determine stem length. Breaks Stem::length -> Stem_tremolo::extent -> Stem::stem_end -> Stem::length cycle. --- input/regression/stem-tremolo-forced-dir.ly | 8 ++++ lily/include/stem-tremolo.hh | 2 + lily/stem-tremolo.cc | 43 ++++++++++++++------- lily/stem.cc | 5 +-- 4 files changed, 41 insertions(+), 17 deletions(-) create mode 100644 input/regression/stem-tremolo-forced-dir.ly diff --git a/input/regression/stem-tremolo-forced-dir.ly b/input/regression/stem-tremolo-forced-dir.ly new file mode 100644 index 0000000000..146dd6241a --- /dev/null +++ b/input/regression/stem-tremolo-forced-dir.ly @@ -0,0 +1,8 @@ + +\version "2.10.2" +\layout { ragged-right = ##t } +\relative c +{ + \clef bass + \stemUp f4 : 32 +} diff --git a/lily/include/stem-tremolo.hh b/lily/include/stem-tremolo.hh index 49b5fd4c5c..9200b4e323 100644 --- a/lily/include/stem-tremolo.hh +++ b/lily/include/stem-tremolo.hh @@ -24,7 +24,9 @@ public: DECLARE_SCHEME_CALLBACK (calc_style, (SCM)); static Stencil raw_stencil (Grob *, Real slope, Direction stemdir); static Stencil translated_stencil (Grob*, Real slope); + static Stencil untranslated_stencil (Grob*, Real slope); static Real get_beam_translation (Grob *me); + static Real vertical_length (Grob *me); }; #endif /* ABBREV_HH */ diff --git a/lily/stem-tremolo.cc b/lily/stem-tremolo.cc index 6729aa934c..5ada4e5b32 100644 --- a/lily/stem-tremolo.cc +++ b/lily/stem-tremolo.cc @@ -147,8 +147,14 @@ Stem_tremolo::height (SCM smob) return ly_interval2scm (s1.extent (Y_AXIS)); } +Real +Stem_tremolo::vertical_length (Grob *me) +{ + return untranslated_stencil (me, 0.35).extent (Y_AXIS).length (); +} + Stencil -Stem_tremolo::translated_stencil (Grob *me, Real slope) +Stem_tremolo::untranslated_stencil (Grob *me, Real slope) { Grob *stem = unsmob_grob (me->get_object ("stem")); if (!stem) @@ -157,30 +163,37 @@ Stem_tremolo::translated_stencil (Grob *me, Real slope) return Stencil(); } - Spanner *beam = Stem::get_beam (stem); Direction stemdir = get_grob_direction (stem); - if (stemdir == 0) + if (!stemdir) stemdir = UP; bool whole_note = Stem::duration_log (stem) <= 0; - Real beam_translation = get_beam_translation (me); - /* for a whole note, we position relative to the notehead, so we want the stencil aligned on the flag closest to the head */ Direction stencil_dir = whole_note ? -stemdir : stemdir; - Stencil mol = raw_stencil (me, slope, stencil_dir); + return raw_stencil (me, slope, stencil_dir); +} - Interval mol_ext = mol.extent (Y_AXIS); - Real ss = Staff_symbol_referencer::staff_space (me); + +Stencil +Stem_tremolo::translated_stencil (Grob *me, Real slope) +{ + Stencil mol = untranslated_stencil (me, slope); - // ugh, rather calc from Stem_tremolo_req - int beam_count = beam ? (Stem::beam_multiplicity (stem).length () + 1) : 0; + Grob *stem = unsmob_grob (me->get_object ("stem")); + if (!stem) + return Stencil (); + + Direction stemdir = get_grob_direction (stem); + if (stemdir == 0) + stemdir = UP; - Real beamthickness = 0.0; - SCM sbt = (beam) ? beam->get_property ("thickness") : SCM_EOL; - if (scm_is_number (sbt)) - beamthickness = scm_to_double (sbt) * ss; + Spanner *beam = Stem::get_beam (stem); + Real beam_translation = get_beam_translation (me); + + int beam_count = beam ? (Stem::beam_multiplicity (stem).length () + 1) : 0; + Real ss = Staff_symbol_referencer::staff_space (me); Real end_y = Stem::stem_end_position (stem) * ss / 2 @@ -192,6 +205,8 @@ Stem_tremolo::translated_stencil (Grob *me, Real slope) if (stemdir == UP) end_y -= stemdir * beam_translation * 0.5; } + + bool whole_note = Stem::duration_log (stem) <= 0; if (whole_note) { /* we shouldn't position relative to the end of the stem since the stem diff --git a/lily/stem.cc b/lily/stem.cc index 69e7a15ce6..352c5ca419 100644 --- a/lily/stem.cc +++ b/lily/stem.cc @@ -316,7 +316,7 @@ Stem::calc_stem_end_position (SCM smob) return scm_from_double (stem_end); } - +/* Length is in half-spaces (or: positions) here. */ MAKE_SCHEME_CALLBACK (Stem, calc_length, 1) SCM Stem::calc_length (SCM smob) @@ -363,8 +363,7 @@ Stem::calc_length (SCM smob) (Stem_tremolo::raw_stencil () looks at the beam.) --hwn */ Real minlen = 1.0 - + 2 * t_flag->extent (t_flag, Y_AXIS).length () - / ss; + + 2 * Stem_tremolo::vertical_length (t_flag) / 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 -- 2.39.5