]> git.donarmstrong.com Git - lilypond.git/blob - lily/encompass-info.cc
8dd95437d4d7cf1a78176fddd419517ff67b4d14
[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_column, Direction dir, Slur const* slur_l)
27 {
28   interstaff_f_ = 0;
29   
30   Stem* stem_l = note_column->stem_l_;
31   if (!stem_l)
32     {
33       warning (_ ("Slur over rest?"));
34       o_[X_AXIS] = note_column->hpos_f ();
35       return; 
36     }
37   
38   o_[X_AXIS] = stem_l->hpos_f ();
39
40 #if 0
41   /* 
42     Let's not do this; yields ugly assymetric slurs.
43
44     set o_[X_AXIS] to middle of notehead or on the exact position of stem,
45     according to slur direction
46
47     
48      stem_l->dir == dir
49                       ________
50            |   |     /        \
51           x|  x|       |x  |x
52         \________/     |   |
53
54    */
55
56   dx_f_drul_[d] = -d * spanned_drul_[d]->extent (X_AXIS).length ();
57
58   if (stem_l->dir_ != dir)
59     o_[X_AXIS] -= 0.5 * stem_l->dir_ * note_column->extent (X_AXIS).length ();
60
61 #else
62
63   /*
64     Instead; simply set x to middle of notehead
65    */
66
67   o_[X_AXIS] -= 0.5 * stem_l->dir_ * note_column->extent (X_AXIS).length ();
68
69 #endif
70
71   if (stem_l->dir_ == dir)
72     {
73       o_[Y_AXIS] = stem_l->extent (Y_AXIS)[dir];
74     }
75   else
76     {
77       o_[Y_AXIS] = note_column->extent (Y_AXIS)[dir];
78     }
79
80   /*
81    leave a gap: slur mustn't touch head/stem
82    */
83   o_[Y_AXIS] += dir * slur_l->paper_l ()->get_var ("slur_y_free");
84
85   Dimension_cache *common = stem_l->common_group (slur_l, Y_AXIS);
86   Align_element * align = dynamic_cast<Align_element*> (common->element_l ());
87   if (align && align->axis() == Y_AXIS)
88     {
89       if (align->threshold_interval_[MIN] != 
90           align->threshold_interval_[MAX])
91         warning (_ ("minVerticalAlign != maxVerticalAlign: interstaff beams/slurs may be broken"));
92
93       interstaff_f_ = align->threshold_interval_[MIN];
94
95       Dimension_cache * slur_refpoint = slur_l->dim_cache_[Y_AXIS];
96       Dimension_cache * note_refpoint = note_column->dim_cache_[Y_AXIS];
97
98       while (slur_refpoint->parent_l_ != common)
99         slur_refpoint = slur_refpoint->parent_l_;
100       while (note_refpoint->parent_l_ != common)
101         note_refpoint = note_refpoint->parent_l_;
102
103
104       int slur_prio =
105         align->get_priority (dynamic_cast<Score_element*> (slur_refpoint->element_l ()));
106       int stem_prio =
107         align->get_priority (dynamic_cast<Score_element*> (note_refpoint->element_l ()));
108
109       /*
110         our staff is lower -> interstaff_f_ *= -1
111        */
112
113       if (slur_prio < stem_prio)
114         interstaff_f_ *= -1;
115       o_[Y_AXIS] += interstaff_f_;
116     }
117 }