]> git.donarmstrong.com Git - lilypond.git/blob - lily/encompass-info.cc
release: 1.1.60
[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 }
24
25 Encompass_info::Encompass_info (Note_column const* note_column, Direction dir, Slur const* slur_l)
26 {
27   interstaff_f_ = 0;
28   
29   Stem* stem_l = note_column->stem_l_;
30   if (!stem_l)
31     {
32       warning (_ ("Slur over rest?"));
33       o_[X_AXIS] = note_column->hpos_f ();
34       o_[Y_AXIS] = note_column->extent (Y_AXIS)[dir];
35       return; 
36     }
37   
38   o_[X_AXIS] = stem_l->hpos_f ();
39
40   /*
41     Simply set x to middle of notehead
42    */
43
44   o_[X_AXIS] -= 0.5 * stem_l->dir_ * note_column->extent (X_AXIS).length ();
45
46   if ((stem_l->dir_ == dir)
47       && !stem_l->extent (Y_AXIS).empty_b ())
48     {
49       o_[Y_AXIS] = stem_l->extent (Y_AXIS)[dir];
50       // URG URG.
51       // some slur in choral.ly returns -inf here
52       if (abs (o_[Y_AXIS]) > 1000)
53         o_[Y_AXIS] = 0;
54     }
55   else
56     {
57       o_[Y_AXIS] = note_column->extent (Y_AXIS)[dir];
58     }
59
60   /*
61    leave a gap: slur mustn't touch head/stem
62    */
63   o_[Y_AXIS] += dir * slur_l->paper_l ()->get_var ("slur_y_free");
64
65   Dimension_cache *common = stem_l->common_group (slur_l, Y_AXIS);
66   Align_element * align = dynamic_cast<Align_element*> (common->element_l ());
67   if (align && align->axis() == Y_AXIS)
68     {
69       if (align->threshold_interval_[MIN] != 
70           align->threshold_interval_[MAX])
71         warning (_ ("minVerticalAlign != maxVerticalAlign: interstaff beams/slurs may be broken"));
72
73       interstaff_f_ = align->threshold_interval_[MIN];
74
75       Dimension_cache * slur_refpoint = slur_l->dim_cache_[Y_AXIS];
76       Dimension_cache * note_refpoint = note_column->dim_cache_[Y_AXIS];
77
78       while (slur_refpoint->parent_l_ != common)
79         slur_refpoint = slur_refpoint->parent_l_;
80       while (note_refpoint->parent_l_ != common)
81         note_refpoint = note_refpoint->parent_l_;
82
83
84       int slur_prio =
85         align->get_priority (dynamic_cast<Score_element*> (slur_refpoint->element_l ()));
86       int stem_prio =
87         align->get_priority (dynamic_cast<Score_element*> (note_refpoint->element_l ()));
88
89       /*
90         our staff is lower -> interstaff_f_ *= -1
91        */
92
93       if (slur_prio < stem_prio)
94         interstaff_f_ *= -1;
95       o_[Y_AXIS] += interstaff_f_;
96     }
97 }