]> git.donarmstrong.com Git - lilypond.git/blob - lily/encompass-info.cc
release: 1.2.4
[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 #include "dimension-cache.hh"
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       o_[Y_AXIS] = note_column->extent (Y_AXIS)[dir];
35       return; 
36     }
37   
38   o_[X_AXIS] = stem_l->hpos_f ();
39
40   /*
41     Simply set x to middle of notehead
42    */
43
44   o_[X_AXIS] -= 0.5 * stem_l->dir_ * note_column->extent (X_AXIS).length ();
45
46   if ((stem_l->dir_ == dir)
47       && !stem_l->extent (Y_AXIS).empty_b ())
48     {
49       o_[Y_AXIS] = stem_l->extent (Y_AXIS)[dir];
50     }
51   else
52     {
53       o_[Y_AXIS] = note_column->extent (Y_AXIS)[dir];
54     }
55
56   /*
57    leave a gap: slur mustn't touch head/stem
58    */
59   o_[Y_AXIS] += dir * slur_l->paper_l ()->get_var ("slur_y_free");
60
61   Graphical_element *common = stem_l->common_refpoint (slur_l, Y_AXIS);
62   Align_element * align = dynamic_cast<Align_element*> (common);
63   if (align && align->axis() == Y_AXIS)
64     {
65       if (align->threshold_interval_[MIN] != 
66           align->threshold_interval_[MAX])
67         warning (_ ("minVerticalAlign != maxVerticalAlign: interstaff beams/slurs may be broken"));
68
69       interstaff_f_ = align->threshold_interval_[MIN];
70
71       Graphical_element const * slur_refpoint = slur_l;
72       while (slur_refpoint->parent_l  (Y_AXIS) != common)
73         slur_refpoint = slur_refpoint->parent_l (Y_AXIS);
74
75       Graphical_element const * note_refpoint = note_column;
76       while (note_refpoint->parent_l (Y_AXIS) != common)
77         note_refpoint = note_refpoint->parent_l (Y_AXIS);
78
79       int slur_prio =
80         align->get_priority ((Score_element*) dynamic_cast<Score_element const*> (slur_refpoint));
81       int stem_prio =
82         align->get_priority ((Score_element*) dynamic_cast<Score_element  const *> (note_refpoint));
83
84       /*
85         our staff is lower -> interstaff_f_ *= -1
86        */
87
88       if (slur_prio < stem_prio)
89         interstaff_f_ *= -1;
90       o_[Y_AXIS] += interstaff_f_;
91     }
92 }