lilypond-1.3.28
[lilypond.git] / lily / cross-staff.cc
blobca44c30e9d19c35a9c6f765b477a2a840b2debd7
1 #include "cross-staff.hh"
2 #include "item.hh"
3 #include "align-element.hh"
4 #include "spanner.hh"
5 #include "warn.hh"
7 Real
8 calc_interstaff_dist (Item const *item, Spanner const *span)
10 Real interstaff = 0.0;
11 Score_element *common = item->common_refpoint (span, Y_AXIS);
12 Align_element * align = dynamic_cast<Align_element*> (common);
13 if (align && align->axis() == Y_AXIS)
15 if (align->threshold_interval_[MIN] !=
16 align->threshold_interval_[MAX])
17 warning (_ ("minVerticalAlign != maxVerticalAlign: cross staff spanners may be broken"));
19 interstaff = align->threshold_interval_[MIN];
21 Score_element const * span_refpoint = span;
22 while (span_refpoint->parent_l (Y_AXIS) != common)
23 span_refpoint = span_refpoint->parent_l (Y_AXIS);
25 Score_element const * note_refpoint = item;
26 while (note_refpoint->parent_l (Y_AXIS) != common)
27 note_refpoint = note_refpoint->parent_l (Y_AXIS);
29 int span_prio =
30 align->get_count ((Score_element*) dynamic_cast<Score_element const*> (span_refpoint));
31 int item_prio =
32 align->get_count ((Score_element*) dynamic_cast<Score_element const *> (note_refpoint));
35 our staff is lower -> interstaff *= -1
38 if (span_prio < item_prio)
39 interstaff *= -1;
40 return interstaff;
42 else return 0.0;