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