]> git.donarmstrong.com Git - lilypond.git/blob - lily/cross-staff.cc
release: 1.3.37
[lilypond.git] / lily / cross-staff.cc
1 #include "cross-staff.hh"
2 #include "item.hh"
3 #include "align-interface.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_interface align(common);
13
14   if (align.has_interface_b () && align.axis() == Y_AXIS)
15     {
16       SCM threshold = common->get_elt_property ("threshold");
17       if (!gh_pair_p (threshold)
18           || !scm_equal_p (gh_car (threshold), gh_cdr (threshold)))
19         warning (_ ("minVerticalAlign != maxVerticalAlign: cross staff spanners may be broken"));
20
21       interstaff = 0.0;
22       if (gh_pair_p (threshold))
23         interstaff =  gh_scm2double (gh_car (threshold));
24
25       Score_element const * span_refpoint = span;
26       while (span_refpoint->parent_l  (Y_AXIS) != common)
27         span_refpoint = span_refpoint->parent_l (Y_AXIS);
28
29       Score_element const * note_refpoint = item;
30       while (note_refpoint->parent_l (Y_AXIS) != common)
31         note_refpoint = note_refpoint->parent_l (Y_AXIS);
32
33       int span_prio =
34         align.get_count ((Score_element*) dynamic_cast<Score_element const*> (span_refpoint));
35       int item_prio =
36         align.get_count ((Score_element*) dynamic_cast<Score_element  const *> (note_refpoint));
37
38       /*
39         our staff is lower -> interstaff *= -1
40        */
41
42       if (span_prio < item_prio)
43         interstaff *= -1;
44       return interstaff;
45     }
46   else return 0.0;
47 }
48