2006-02-17 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ * lily/beam.cc (get_default_dir): take extreme note head as input
+ for stem direction.
+
+ * lily/tie.cc (get_default_dir): only look directions for visible
+ stems.
+
* lily/side-position-interface.cc (aligned_side): oops. Don't
mutiply with direction. This fixes quantized (staccato, tenuto)
scripts below notes.
}
-/* After pre-processing all directions should be set.
- Several post-processing routines (stem, slur, script) need stem/beam
- direction.
- Currenly, this means that beam has set all stem's directions.
- [Alternatively, stems could set its own directions, according to
- their beam, during 'final-pre-processing'.] */
MAKE_SCHEME_CALLBACK (Beam, calc_direction, 1);
SCM
Beam::calc_direction (SCM smob)
return the_beam.smobbed_copy ();
}
+#define iterof(i,s) typeof((s).begin()) i((s).begin())
+
Direction
Beam::get_default_dir (Grob *me)
{
- Drul_array<int> total;
- total[UP] = total[DOWN] = 0;
- Drul_array<int> count;
- count[UP] = count[DOWN] = 0;
-
extract_grob_set (me, "stems", stems);
+ Drul_array<Real> extremes (0.0, 0.0);
+ for (iterof (s, stems); s != stems.end (); s++)
+ {
+ Interval positions = Stem::head_positions (*s);
+ Direction d = DOWN;
+ do
+ {
+ if (sign (positions[d]) == d)
+ extremes[d] = d * max (d * positions[d], d * extremes[d]);
+ }
+ while (flip (&d) != DOWN);
+ }
+
+ if (extremes[UP] > extremes[DOWN])
+ return DOWN;
+ else if (extremes[UP] < extremes[DOWN])
+ return UP;
+
+ Drul_array<int> total (0, 0);
+ Drul_array<int> count (0, 0);
+
for (vsize i = 0; i < stems.size (); i++)
{
Grob *s = stems[i];
Direction
Tie::get_default_dir (Grob *me)
{
- Item *sl = head (me, LEFT) ? Rhythmic_head::get_stem (head (me, LEFT)) : 0;
- Item *sr = head (me, RIGHT) ? Rhythmic_head::get_stem (head (me, RIGHT)) : 0;
- if (sl && sr)
+ Drul_array<Grob*> stems;
+ Direction d = LEFT;
+ do
+ {
+ Grob *stem = head (me, d) ? Rhythmic_head::get_stem (head (me, d)) : 0;
+ if (stem)
+ stem = Stem::is_invisible (stem) ? 0 : stem;
+
+ stems[d] = stem;
+ }
+ while (flip (&d)!= LEFT);
+
+ if (stems[LEFT] && stems[RIGHT])
{
- if (get_grob_direction (sl) == UP
- && get_grob_direction (sr) == UP)
+ if (get_grob_direction (stems[LEFT]) == UP
+ && get_grob_direction (stems[RIGHT]) == UP)
return DOWN;
}
- else if (sl || sr)
+ else if (stems[LEFT] || stems[RIGHT])
{
- Item *s = sl ? sl : sr;
+ Grob *s = stems[LEFT] ? stems[LEFT] : stems[RIGHT];
return -get_grob_direction (s);
}