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