]> git.donarmstrong.com Git - lilypond.git/blob - lily/stem-info.cc
release: 1.1.51
[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 "debug.hh"
13
14 #include "align-element.hh"
15 #include "stem.hh"
16 #include "paper-def.hh"
17 #include "lookup.hh"
18 #include "stem-info.hh"
19 #include "beam.hh"
20 #include "staff-symbol.hh"
21
22 Stem_info::Stem_info ()
23 {
24 }
25 /*
26   FIXME: y dims should not be in internote.
27  */
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->beam_thickness_f ();
44          
45   {
46       static int i = 1;
47       DOUT << "******" << i++ << "******\n" 
48            << "begin_f: " << stem_l_->stem_begin_f () * dir_ 
49            << "\nchord_f/i: " << stem_l_->chord_start_f () * dir_ / internote_f << '\n';
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   int stem_max = (int)rint(paper_l->get_var ("stem_max"));
62   Real min_stem_f = paper_l->get_var (String ("minimum_stem_length")
63                                      + to_str (mult_i_ <? stem_max));
64   Real stem_f = paper_l->get_var (String ("stem_length")
65                                  + to_str (mult_i_ <? stem_max))* internote_f;
66
67   if (!beam_dir_ || (beam_dir_ == dir_))
68     /* normal beamed stem */
69     {
70       if (mult_i_)
71         {
72           idealy_f_ += beam_f;
73           idealy_f_ += (mult_i_ - 1) * interbeam_f;
74         }
75       miny_f_ = idealy_f_;
76       maxy_f_ = INT_MAX;
77
78       idealy_f_ += stem_f;
79       miny_f_ += min_stem_f;
80
81       // lowest beam of (UP) beam must never be lower than second staffline
82       miny_f_ = miny_f_ >? (- 2 * internote_f - beam_f
83         + (mult_i_ > 0) * beam_f + interbeam_f * (mult_i_ - 1));
84     }
85   else
86     /* knee */
87     {
88       idealy_f_ -= beam_f;
89       // idealy_f_ -= (mult_i_ - 1) * interbeam_f;
90       // idealy_f_ += (mult_i_ - stem_l_->flag_i_ >? 0) * interbeam_f;
91       maxy_f_ = idealy_f_;
92       miny_f_ = -INT_MAX;
93
94       idealy_f_ -= stem_f;
95       maxy_f_ -= min_stem_f;
96     }
97
98   // set dim(y) == internote
99   idealy_f_ /= internote_f;
100   miny_f_ /= internote_f;
101   maxy_f_ /= internote_f;
102
103   DOUT << "dir_: " << dir_ << '\n';
104   DOUT << "mult_i_: " << mult_i_ << '\n';
105   DOUT << "idealy_f_: " << idealy_f_ << '\n';
106   DOUT << "miny_f_: " << miny_f_ << '\n';
107   DOUT << "maxy_f_: " << maxy_f_ << '\n';
108
109   idealy_f_ = maxy_f_ <? idealy_f_;
110   idealy_f_ = miny_f_ >? idealy_f_;
111
112   // interstaff beam
113   Beam* beam_l = stem_l_->beam_l_;
114   
115   Dimension_cache *common = stem_l_->common_group (beam_l, Y_AXIS);
116   Align_element * align = dynamic_cast<Align_element*> (common->element_l ());
117   if (align && align->axis() == Y_AXIS)
118     {
119       if (align->threshold_interval_[MIN] != 
120           align->threshold_interval_[MAX])
121         warning (_ ("minVerticalAlign != maxVerticalAlign: interstaff beams/slurs may be broken"));
122
123       interstaff_f_ = align->threshold_interval_[MIN] / internote_f;
124
125       Dimension_cache * beam_refpoint = beam_l->dim_cache_[Y_AXIS];
126       Dimension_cache * stem_refpoint = stem_l_->dim_cache_[Y_AXIS];
127
128       while (beam_refpoint->parent_l_ != common)
129         beam_refpoint = beam_refpoint->parent_l_;
130       while (stem_refpoint->parent_l_ != common)
131         stem_refpoint = stem_refpoint->parent_l_;
132
133
134       int beam_prio =
135         align->get_priority (dynamic_cast<Score_element*> (beam_refpoint->element_l ()));
136       int stem_prio =
137         align->get_priority (dynamic_cast<Score_element*> (stem_refpoint->element_l ()));
138
139       /*
140         our staff is lower -> interstaff_f_ *= -1
141        */
142       if (beam_prio < stem_prio)
143         interstaff_f_ *= -1;
144       
145       idealy_f_ += interstaff_f_ * beam_dir_;
146       miny_f_ += interstaff_f_ * beam_dir_;
147       maxy_f_ += interstaff_f_ * beam_dir_;
148     }
149 }
150