]> git.donarmstrong.com Git - lilypond.git/blob - lily/stem-info.cc
release: 1.3.0
[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
39   Paper_def* paper_l = stem_l_->paper_l ();
40   Real internote_f = stem_l_->staff_line_leading_f ()/2;
41   Real interbeam_f = paper_l->interbeam_f (mult_i_);
42   Real beam_f = paper_l->get_realvar (beam_thickness_scm_sym);;
43          
44
45   // strangely enough, dim(chord_start_f) == pt (and not internote!)
46   idealy_f_ = stem_l_->chord_start_f () / internote_f;
47
48   // calculate using dim(y) == pt
49   idealy_f_ *= internote_f;
50
51   // for simplicity, we calculate as if dir == UP
52   idealy_f_ *= beam_dir_;
53
54   bool grace_b = stem_l_->get_elt_property (grace_scm_sym) != SCM_BOOL_F;
55   bool no_extend_b = stem_l_->get_elt_property (no_stem_extend_scm_sym) 
56     != SCM_BOOL_F;
57
58   int stem_max = (int)rint(paper_l->get_var ("stem_max"));
59   String type_str = grace_b ? "grace_" : "";
60   Real min_stem_f = paper_l->get_var (type_str + "minimum_stem_length"
61                                       + to_str (mult_i_ <? stem_max)) * internote_f;
62   Real stem_f = paper_l->get_var (type_str + "stem_length"
63                                   + to_str (mult_i_ <? stem_max))* internote_f;
64
65   if (!beam_dir_ || (beam_dir_ == dir_))
66     /* normal beamed stem */
67     {
68       if (mult_i_)
69         {
70           idealy_f_ += beam_f;
71           idealy_f_ += (mult_i_ - 1) * interbeam_f;
72         }
73       miny_f_ = idealy_f_;
74       maxy_f_ = INT_MAX;
75
76       idealy_f_ += stem_f;
77       miny_f_ += min_stem_f;
78
79       /*
80         lowest beam of (UP) beam must never be lower than second staffline
81
82         Hmm, reference (Wanske?)
83
84         Although this (additional) rule is probably correct,
85         I expect that highest beam (UP) should also never be lower
86         than middle staffline, just as normal stems.
87         
88       */
89       if (!grace_b && !no_extend_b)
90         {
91           //highest beam of (UP) beam must never be lower than middle staffline
92           miny_f_ = miny_f_ >? 0;
93           //lowest beam of (UP) beam must never be lower than second staffline
94           miny_f_ = miny_f_ >? (- 2 * internote_f - beam_f
95                                 + (mult_i_ > 0) * beam_f + interbeam_f * (mult_i_ - 1));
96         }
97     }
98   else
99     /* knee */
100     {
101       idealy_f_ -= beam_f;
102       maxy_f_ = idealy_f_;
103       miny_f_ = -INT_MAX;
104
105       idealy_f_ -= stem_f;
106       maxy_f_ -= min_stem_f;
107     }
108
109   // set dim(y) == internote
110   idealy_f_ /= internote_f;
111   miny_f_ /= internote_f;
112   maxy_f_ /= internote_f;
113
114   idealy_f_ = maxy_f_ <? idealy_f_;
115   idealy_f_ = miny_f_ >? idealy_f_;
116
117   // interstaff beam
118   Beam* beam_l = stem_l_->beam_l_;
119   
120   interstaff_f_ = calc_interstaff_dist (stem_l_, beam_l) / internote_f;
121   idealy_f_ += interstaff_f_* beam_dir_;
122   miny_f_   += interstaff_f_ * beam_dir_;
123   maxy_f_   += interstaff_f_ * beam_dir_;
124 }
125