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