]> git.donarmstrong.com Git - lilypond.git/blob - lily/stem-info.cc
4a9e06e05ed3f910e5a074ba0a357139203467cd
[lilypond.git] / lily / stem-info.cc
1 /*
2   stem-info.cc -- implement Stem_info
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1999 Jan Nieuwenhuizen <janneke@gnu.org>
7
8 */
9
10 #include "proto.hh"
11 #include "misc.hh"
12 #include "cross-staff.hh"
13
14 #include "stem.hh"
15 #include "paper-def.hh"
16 #include "lookup.hh"
17 #include "stem-info.hh"
18 #include "beam.hh"
19
20
21 Stem_info::Stem_info ()
22 {
23 }
24
25
26 /*
27   FIXME: y dims should not be in internote.
28  */
29 Stem_info::Stem_info (Stem*s, int mult)
30 {
31   mult_i_ =mult;
32   stem_l_ = s;
33   x_ = stem_l_->hpos_f ();
34   dir_ = stem_l_->dir_;
35   SCM bd = stem_l_->remove_elt_property (beam_dir_scm_sym);
36   
37   beam_dir_ = gh_scm2int (SCM_CDR(bd));
38   interstaff_f_ = 0;
39
40   Paper_def* paper_l = stem_l_->paper_l ();
41   Real internote_f = stem_l_->staff_line_leading_f ()/2;
42   Real interbeam_f = paper_l->interbeam_f (mult_i_);
43   Real beam_f = paper_l->get_realvar (beam_thickness_scm_sym);;
44          
45
46   // strangely enough, dim(chord_start_f) == pt (and not internote!)
47   idealy_f_ = stem_l_->chord_start_f () / internote_f;
48
49   // calculate using dim(y) == pt
50   idealy_f_ *= internote_f;
51
52   // for simplicity, we calculate as if dir == UP
53   idealy_f_ *= beam_dir_;
54
55   bool grace_b = stem_l_->get_elt_property (grace_scm_sym) != SCM_BOOL_F;
56
57   int stem_max = (int)rint(paper_l->get_var ("stem_max"));
58   String type_str = grace_b ? "grace_" : "";
59   Real min_stem_f = paper_l->get_var (type_str + "minimum_stem_length"
60                                       + to_str (mult_i_ <? stem_max)) * internote_f;
61   Real stem_f = paper_l->get_var (type_str + "stem_length"
62                                   + to_str (mult_i_ <? stem_max))* internote_f;
63
64   if (!beam_dir_ || (beam_dir_ == dir_))
65     /* normal beamed stem */
66     {
67       if (mult_i_)
68         {
69           idealy_f_ += beam_f;
70           idealy_f_ += (mult_i_ - 1) * interbeam_f;
71         }
72       miny_f_ = idealy_f_;
73       maxy_f_ = INT_MAX;
74
75       idealy_f_ += stem_f;
76       miny_f_ += min_stem_f;
77
78       /*
79         lowest beam of (UP) beam must never be lower than second staffline
80
81         Hmm, reference (Wanske?)
82
83         Although this (additional) rule is probably correct,
84         I expect that highest beam (UP) should also never be lower
85         than middle staffline, just as normal stems.
86         
87       */
88       if (!grace_b)
89         {
90           //highest beam of (UP) beam must never be lower than middle staffline
91           miny_f_ = miny_f_ >? 0;
92           //lowest beam of (UP) beam must never be lower than second staffline
93           miny_f_ = miny_f_ >? (- 2 * internote_f - beam_f
94                                 + (mult_i_ > 0) * beam_f + interbeam_f * (mult_i_ - 1));
95         }
96     }
97   else
98     /* knee */
99     {
100       idealy_f_ -= beam_f;
101       maxy_f_ = idealy_f_;
102       miny_f_ = -INT_MAX;
103
104       idealy_f_ -= stem_f;
105       maxy_f_ -= min_stem_f;
106     }
107
108   // set dim(y) == internote
109   idealy_f_ /= internote_f;
110   miny_f_ /= internote_f;
111   maxy_f_ /= internote_f;
112
113   idealy_f_ = maxy_f_ <? idealy_f_;
114   idealy_f_ = miny_f_ >? idealy_f_;
115
116   // interstaff beam
117   Beam* beam_l = stem_l_->beam_l_;
118   
119   Real is = calc_interstaff_dist (stem_l_, beam_l);
120   idealy_f_ += is* beam_dir_;
121   miny_f_ += is * beam_dir_;
122   maxy_f_ += is * beam_dir_;
123 }
124