]> git.donarmstrong.com Git - lilypond.git/blob - lily/cross-staff.cc
ca44c30e9d19c35a9c6f765b477a2a840b2debd7
[lilypond.git] / lily / cross-staff.cc
1 #include "cross-staff.hh"
2 #include "item.hh"
3 #include "align-element.hh"
4 #include "spanner.hh"
5 #include "warn.hh"
6
7 Real
8 calc_interstaff_dist (Item const *item, Spanner const *span)
9 {
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)
14     {
15       if (align->threshold_interval_[MIN] != 
16           align->threshold_interval_[MAX])
17         warning (_ ("minVerticalAlign != maxVerticalAlign: cross staff spanners may be broken"));
18
19       interstaff = align->threshold_interval_[MIN];
20
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);
24
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);
28
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));
33
34       /*
35         our staff is lower -> interstaff *= -1
36        */
37
38       if (span_prio < item_prio)
39         interstaff *= -1;
40       return interstaff;
41     }
42   else return 0.0;
43 }
44