]> git.donarmstrong.com Git - lilypond.git/blob - lily/encompass-info.cc
02f5b2868601e85913ab1ec1e376c626161c8050
[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
20 Encompass_info::Encompass_info ()
21 {
22   assert (0);
23 }
24
25 Encompass_info::Encompass_info (Note_column const* note, Direction dir, Slur const* slur_l)
26 {
27   interstaff_f_ = 0;
28   
29   Paper_def* paper = note->paper_l ();
30   
31   // UGH
32   Real notewidth = paper->note_width () * 0.8;
33   
34
35   Stem* stem_l = note->stem_l_;
36   Real internote = stem_l-> staff_line_leading_f ()/2.;
37
38   /* 
39     set o_.x () to middle of notehead or on the exact position of stem,
40     according to slur direction
41    */
42   o_.x () = stem_l->hpos_f ();
43
44   /*
45      stem_l->dir == dir
46                       ________
47            |   |     /        \
48           x|  x|       |x  |x
49         \________/     |   |
50
51    */
52
53   if (stem_l->dir_ != dir)
54     o_.x () -= 0.5 * notewidth * stem_l->dir_;
55
56   o_.y () = stem_l->extent (Y_AXIS)[dir];
57   /*
58    leave a gap: slur mustn't touch head/stem
59    */
60   o_.y () += 2.5 * internote * dir;
61
62   if (stem_l->dir_ != dir)
63     o_.y () += 1.0 * internote * dir;
64
65   if (slur_l->encompass_arr_.size ()
66       && stem_l->staff_symbol_l () != slur_l->encompass_arr_[0]->stem_l_->staff_symbol_l ())
67     {
68       if (slur_l->vertical_align_drul_[MIN] != 
69           slur_l->vertical_align_drul_[MAX])
70         warning (_ ("minVerticalAlign != maxVerticalAlign: interstaff slurs may be broken"));
71       interstaff_f_ = slur_l->vertical_align_drul_[MIN];
72       /* urg, guess staff order */
73       int d = note->head_l_arr_.top ()->position_i_
74         - slur_l->encompass_arr_[0]->head_l_arr_[0]->position_i_;
75       if (abs (d > 3))
76         interstaff_f_ *= sign (d);
77       else if (stem_l->chord_start_f () >
78                slur_l->encompass_arr_[0]->stem_l_->chord_start_f ())
79         interstaff_f_ *= -1;
80       o_.y () += interstaff_f_;
81     }
82 }