lilypond-1.3.12
[lilypond.git] / lily / encompass-info.cc
blobaebad06539e91665595c6e9c6a2b1fb59ccdeb69
1 /*
2 encompass-info.cc -- implement Encompass_info
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--1999 Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9 #include "dimension-cache.hh"
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"
21 Encompass_info::Encompass_info ()
25 Encompass_info::Encompass_info (Note_column const* note_column, Direction dir, Slur const* slur_l)
27 interstaff_f_ = 0;
29 Stem* stem_l = note_column->stem_l_;
30 if (!stem_l)
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;
38 o_[X_AXIS] = stem_l->hpos_f ();
41 Simply set x to middle of notehead
44 o_[X_AXIS] -= 0.5 * stem_l->dir_ * note_column->extent (X_AXIS).length ();
46 if ((stem_l->dir_ == dir)
47 && !stem_l->extent (Y_AXIS).empty_b ())
49 o_[Y_AXIS] = stem_l->extent (Y_AXIS)[dir];
51 else
53 o_[Y_AXIS] = note_column->extent (Y_AXIS)[dir];
57 leave a gap: slur mustn't touch head/stem
59 o_[Y_AXIS] += dir * slur_l->paper_l ()->get_var ("slur_y_free");
61 Graphical_element *common = stem_l->common_refpoint (slur_l, Y_AXIS);
62 Align_element * align = dynamic_cast<Align_element*> (common);
63 if (align && align->axis() == Y_AXIS)
65 if (align->threshold_interval_[MIN] !=
66 align->threshold_interval_[MAX])
67 warning (_ ("minVerticalAlign != maxVerticalAlign: interstaff beams/slurs may be broken"));
69 interstaff_f_ = align->threshold_interval_[MIN];
71 Graphical_element const * slur_refpoint = slur_l;
72 while (slur_refpoint->parent_l (Y_AXIS) != common)
73 slur_refpoint = slur_refpoint->parent_l (Y_AXIS);
75 Graphical_element const * note_refpoint = note_column;
76 while (note_refpoint->parent_l (Y_AXIS) != common)
77 note_refpoint = note_refpoint->parent_l (Y_AXIS);
79 int slur_prio =
80 align->get_priority ((Score_element*) dynamic_cast<Score_element const*> (slur_refpoint));
81 int stem_prio =
82 align->get_priority ((Score_element*) dynamic_cast<Score_element const *> (note_refpoint));
85 our staff is lower -> interstaff_f_ *= -1
88 if (slur_prio < stem_prio)
89 interstaff_f_ *= -1;
90 o_[Y_AXIS] += interstaff_f_;