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