lilypond-1.1.44
[lilypond.git] / lily / encompass-info.cc
blob0271eba2976f803a761ba851d9e68f1e81c9bf4c
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 */
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 ()
23 assert (0);
26 Encompass_info::Encompass_info (Note_column const* note, Direction dir, Slur const* slur_l)
28 interstaff_f_ = 0;
30 Paper_def* paper = note->paper_l ();
32 // UGH
33 Real notewidth = paper->note_width () * 0.8;
36 Stem* stem_l = note->stem_l_;
37 if (!stem_l)
39 warning ("Slur over rest?");
40 o_[X_AXIS] = note->hpos_f ();
41 return;
44 Real internote = stem_l-> staff_line_leading_f ()/2.;
46 /*
47 set o_[X_AXIS] to middle of notehead or on the exact position of stem,
48 according to slur direction
50 o_[X_AXIS] = stem_l->hpos_f ();
53 stem_l->dir == dir
54 ________
55 | | / \
56 x| x| |x |x
57 \________/ | |
61 if (stem_l->dir_ != dir)
62 o_[X_AXIS] -= 0.5 * notewidth * stem_l->dir_;
64 o_[Y_AXIS] = stem_l->extent (Y_AXIS)[dir];
66 leave a gap: slur mustn't touch head/stem
68 o_[Y_AXIS] += 2.5 * internote * dir;
70 if (stem_l->dir_ != dir)
71 o_[Y_AXIS] += 1.0 * internote * dir;
74 Dimension_cache *common = stem_l->common_group (slur_l, Y_AXIS);
75 Align_element * align = dynamic_cast<Align_element*> (common->element_l ());
76 if (align && align->axis() == Y_AXIS)
78 if (align->threshold_interval_[MIN] !=
79 align->threshold_interval_[MAX])
80 warning (_ ("minVerticalAlign != maxVerticalAlign: interstaff beams/slurs may be broken"));
82 interstaff_f_ = align->threshold_interval_[MIN];
84 Dimension_cache * slur_refpoint = slur_l->dim_cache_[Y_AXIS];
85 Dimension_cache * note_refpoint = note->dim_cache_[Y_AXIS];
87 while (slur_refpoint->parent_l_ != common)
88 slur_refpoint = slur_refpoint->parent_l_;
89 while (note_refpoint->parent_l_ != common)
90 note_refpoint = note_refpoint->parent_l_;
93 int slur_prio =
94 align->get_priority (dynamic_cast<Score_element*> (slur_refpoint->element_l ()));
95 int stem_prio =
96 align->get_priority (dynamic_cast<Score_element*> (note_refpoint->element_l ()));
99 our staff is lower -> interstaff_f_ *= -1
102 if (slur_prio < stem_prio)
103 interstaff_f_ *= -1;
104 o_[Y_AXIS] += interstaff_f_;