]> git.donarmstrong.com Git - lilypond.git/blob - lily/encompass-info.cc
452d825aa6473c364d94c3e6bce842d4802098d2
[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   assert (0);
24 }
25
26 Encompass_info::Encompass_info (Note_column const* note, Direction dir, Slur const* slur_l)
27 {
28   interstaff_f_ = 0;
29   
30   Paper_def* paper = note->paper_l ();
31   
32   // UGH
33   Real notewidth = paper->note_width () * 0.8;
34   
35
36   Stem* stem_l = note->stem_l_;
37   Real internote = stem_l-> staff_line_leading_f ()/2.;
38
39   /* 
40     set o_.x () to middle of notehead or on the exact position of stem,
41     according to slur direction
42    */
43   o_.x () = stem_l->hpos_f ();
44
45   /*
46      stem_l->dir == dir
47                       ________
48            |   |     /        \
49           x|  x|       |x  |x
50         \________/     |   |
51
52    */
53
54   if (stem_l->dir_ != dir)
55     o_.x () -= 0.5 * notewidth * stem_l->dir_;
56
57   o_.y () = stem_l->extent (Y_AXIS)[dir];
58   /*
59    leave a gap: slur mustn't touch head/stem
60    */
61   o_.y () += 2.5 * internote * dir;
62
63   if (stem_l->dir_ != dir)
64     o_.y () += 1.0 * internote * dir;
65
66
67   Dimension_cache *common = note->common_group (slur_l, Y_AXIS);
68   Align_element * align = dynamic_cast<Align_element*> (common->element_l ());
69   if (align && align->axis() == Y_AXIS)
70     {
71       if (align->threshold_interval_[MIN] != 
72           align->threshold_interval_[MAX])
73         warning (_ ("minVerticalAlign != maxVerticalAlign: interstaff beams/slurs may be broken"));
74
75       interstaff_f_ = align->threshold_interval_[MIN];
76
77       Dimension_cache * slur_refpoint = &slur_l->dim_cache_[Y_AXIS];
78       Dimension_cache * note_refpoint = &note->dim_cache_[Y_AXIS];
79
80       while (slur_refpoint->parent_l_ != common)
81         slur_refpoint = slur_refpoint->parent_l_;
82       while (note_refpoint->parent_l_ != common)
83         note_refpoint = note_refpoint->parent_l_;
84
85
86       int slur_prio =
87         align->get_priority (dynamic_cast<Score_element*> (slur_refpoint->element_l ()));
88       int stem_prio =
89         align->get_priority (dynamic_cast<Score_element*> (note_refpoint->element_l ()));
90
91       /*
92         our staff is lower -> interstaff_f_ *= -1
93        */
94       // ? Is this OK?
95       if (slur_prio < stem_prio)
96         interstaff_f_ *= -1;
97       o_.y () += interstaff_f_;
98     }
99 }