#include "note-spacing.hh"
+#include "grob-array.hh"
#include "paper-column.hh"
#include "moment.hh"
#include "note-column.hh"
#include "staff-spacing.hh"
#include "accidental-placement.hh"
#include "output-def.hh"
+#include "pointer-group-interface.hh"
+
/*
TODO: detect hshifts due to collisions, and account for them in
Note_spacing::get_spacing (Grob *me, Item *right_col,
Real base_space, Real increment, Real *space, Real *fixed)
{
-
- Drul_array<SCM> props (me->get_property ("left-items"),
- me->get_property ("right-items"));
+ Drul_array<SCM> props (me->get_object ("left-items"),
+ me->get_object ("right-items"));
Direction d = LEFT;
Direction col_dir = right_col->break_status_dir ();
Drul_array<Interval> extents;
Interval left_head_wid;
do
{
- for (SCM s = props[d]; scm_is_pair (s); s = scm_cdr (s))
+ Link_array<Grob> const &items (ly_scm2link_array (props [d]));
+ for (int i = items.size (); i--;)
{
- Item *it = dynamic_cast<Item *> (unsmob_grob (scm_car (s)));
+ Item *it = dynamic_cast<Item *> (items[i]);
if (d == RIGHT && it->break_status_dir () != col_dir)
{
if (d == LEFT)
{
- SCM r = it->get_property ("rest");
+ SCM r = it->get_object ("rest");
Grob *g = unsmob_grob (r);
if (!g)
g = Note_column::first_head (it);
if (!me->is_live ())
return 0;
- SCM right = me->get_property ("right-items");
+ Grob_array * a = unsmob_grob_array (me->get_object ("right-items"));
Item *mincol = 0;
int min_rank = INT_MAX;
bool prune = false;
- for (SCM s = right; scm_is_pair (s); s = scm_cdr (s))
+ for (int i = 0; a && i < a->size (); i++)
{
- Item *ri = unsmob_item (scm_car (s));
-
+ Item *ri = a->item (i);
Item *col = ri->get_column ();
+
int rank = Paper_column::get_rank (col);
if (rank < min_rank)
}
}
- if (prune)
+ if (prune && a)
{
- // I'm a lazy bum. We could do this in-place.
- SCM newright = SCM_EOL;
- for (SCM s = right; scm_is_pair (s); s = scm_cdr (s))
+ Link_array<Grob> & right = a->array_reference ();
+ for (int i = right.size(); i--;)
{
- if (unsmob_item (scm_car (s))->get_column () == mincol)
- newright = scm_cons (scm_car (s), newright);
+ if (dynamic_cast<Item*> (right[i])->get_column () != mincol)
+ right.del (i);
}
-
- me->set_property ("right-items", newright);
}
if (!mincol)
{
- /*
- int r = Paper_column::get_rank (dynamic_cast<Item*>(me)->get_column ());
- programming_error (_f ("Spacing wish column %d has no right item.", r));
- */
-
return 0;
}
Drul_array<Direction> stem_dirs (CENTER, CENTER);
Drul_array<Interval> stem_posns;
Drul_array<Interval> head_posns;
- Drul_array<SCM> props (me->get_property ("left-items"),
- me->get_property ("right-items"));
+ Drul_array<SCM> props (me->get_object ("left-items"),
+ me->get_object ("right-items"));
Drul_array<Spanner *> beams_drul (0, 0);
Drul_array<Grob *> stems_drul (0, 0);
do
{
- for (SCM s = props[d]; scm_is_pair (s); s = scm_cdr (s))
+ Link_array<Grob> const &items (ly_scm2link_array (props [d]));
+ for (int i = 0; i < items.size(); i++)
{
- Item *it = dynamic_cast<Item *> (unsmob_grob (scm_car (s)));
+ Item *it = dynamic_cast<Item *> (items[i]);
if (d == RIGHT)
acc_right = acc_right || Note_column::accidentals (it);
Real chord_start = hp[sd];
Real stem_end = Stem::stem_end_position (stem);
- stem_posns[d] = Interval (chord_start <? stem_end, chord_start>? stem_end);
+ stem_posns[d] = Interval (min (chord_start, stem_end), max (chord_start, stem_end));
head_posns[d].unite (hp);
}
}
/*
Ugh. 7 is hardcoded.
*/
- correction = (correction / 7) <? 1.0;
+ correction = min (correction / 7, 1.0);
correction *= stem_dirs[LEFT];
correction
*= robust_scm2double (me->get_property ("stem-spacing-correction"), 0);
= (head_posns[LEFT][DOWN] > head_posns[RIGHT][UP]) ? RIGHT : LEFT;
Real delta = head_posns[-lowest][DOWN] - head_posns[lowest][UP];
- Real corr = robust_scm2double (me->get_property ("stem-spacing-correction"), 0);
- corr = (delta <= 1) ? 0.0 : 0.25;
-
- correction = -lowest * corr;
+ Real corr = robust_scm2double (me->get_property ("same-direction-correction"), 0);
+
+ if (delta > 1)
+ correction = -lowest * corr;
}
*space += correction;
ADD_INTERFACE (Note_spacing, "note-spacing-interface",
"This object calculates spacing wishes for individual voices.",
- "left-items right-items stem-spacing-correction knee-spacing-correction");
+ "left-items right-items stem-spacing-correction same-direction-correction knee-spacing-correction");