]> git.donarmstrong.com Git - lilypond.git/blob - lily/encompass-info.cc
b5fbcf56fee0af6136a908a75310ca618b182a7c
[lilypond.git] / lily / encompass-info.cc
1 /*
2   encompass-info.cc -- implement Encompass_info
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1998--1999 Jan Nieuwenhuizen <janneke@gnu.org>
7
8 */
9
10 #include "proto.hh"
11 #include "stem.hh"
12 #include "note-column.hh"
13 #include "paper-def.hh"
14 #include "encompass-info.hh"
15 #include "slur.hh"
16 #include "staff-symbol.hh"
17 #include "note-head.hh"
18 #include "debug.hh"
19 #include "align-element.hh"
20
21 Encompass_info::Encompass_info ()
22 {
23 }
24
25 Encompass_info::Encompass_info (Note_column const* note_column, Direction dir, Slur const* slur_l)
26 {
27   interstaff_f_ = 0;
28   
29   Stem* stem_l = note_column->stem_l_;
30   if (!stem_l)
31     {
32       warning (_ ("Slur over rest?"));
33       o_[X_AXIS] = note_column->hpos_f ();
34       return; 
35     }
36   
37   o_[X_AXIS] = stem_l->hpos_f ();
38
39   /*
40     Simply set x to middle of notehead
41    */
42
43   o_[X_AXIS] -= 0.5 * stem_l->dir_ * note_column->extent (X_AXIS).length ();
44
45   if (stem_l->dir_ == dir)
46     {
47       o_[Y_AXIS] = stem_l->extent (Y_AXIS)[dir];
48     }
49   else
50     {
51       o_[Y_AXIS] = note_column->extent (Y_AXIS)[dir];
52     }
53
54   /*
55    leave a gap: slur mustn't touch head/stem
56    */
57   o_[Y_AXIS] += dir * slur_l->paper_l ()->get_var ("slur_y_free");
58
59   Dimension_cache *common = stem_l->common_group (slur_l, Y_AXIS);
60   Align_element * align = dynamic_cast<Align_element*> (common->element_l ());
61   if (align && align->axis() == Y_AXIS)
62     {
63       if (align->threshold_interval_[MIN] != 
64           align->threshold_interval_[MAX])
65         warning (_ ("minVerticalAlign != maxVerticalAlign: interstaff beams/slurs may be broken"));
66
67       interstaff_f_ = align->threshold_interval_[MIN];
68
69       Dimension_cache * slur_refpoint = slur_l->dim_cache_[Y_AXIS];
70       Dimension_cache * note_refpoint = note_column->dim_cache_[Y_AXIS];
71
72       while (slur_refpoint->parent_l_ != common)
73         slur_refpoint = slur_refpoint->parent_l_;
74       while (note_refpoint->parent_l_ != common)
75         note_refpoint = note_refpoint->parent_l_;
76
77
78       int slur_prio =
79         align->get_priority (dynamic_cast<Score_element*> (slur_refpoint->element_l ()));
80       int stem_prio =
81         align->get_priority (dynamic_cast<Score_element*> (note_refpoint->element_l ()));
82
83       /*
84         our staff is lower -> interstaff_f_ *= -1
85        */
86
87       if (slur_prio < stem_prio)
88         interstaff_f_ *= -1;
89       o_[Y_AXIS] += interstaff_f_;
90     }
91 }