]> git.donarmstrong.com Git - lilypond.git/blob - lily/stem-info.cc
patch::: 1.1.18.jcn4: vixje
[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--1998 Jan Nieuwenhuizen <janneke@gnu.org>
7
8 */
9
10 #include "proto.hh"
11 #include "misc.hh"
12 #include "debug.hh"
13 #include "atom.hh"
14 #include "stem.hh"
15 #include "paper-def.hh"
16 #include "lookup.hh"
17 #include "stem-info.hh"
18
19 Stem_info::Stem_info ()
20 {
21 }
22
23 Stem_info::Stem_info (Stem const *s)
24 {
25   x_ = s->hpos_f ();
26   dir_ = s->dir_;
27   beam_dir_ = s->beam_dir_;
28   mult_i_ = s->mult_i_;
29
30   /*
31     [TODO]
32     make this runtime
33
34     Breitkopf + H\"artel:
35     miny_f_ = interline + #beams * interbeam
36     ideal8 = 2 * interline + interbeam
37     ideal16,32,64,128 = 1.5 * interline + #beams * interbeam
38
39     * B\"arenreiter:
40     miny_f_ = interline + #beams * interbeam
41     ideal8,16 = 2 interline + #beams * interbeam
42     ideal32,64,128 = 1.5 interline + #beams * interbeam
43        
44     */
45
46   Real internote_f = s->paper ()->internote_f ();
47   Real interbeam_f = s->paper ()->interbeam_f (mult_i_);
48   Real beam_f = s->paper ()->beam_thickness_f ();
49          
50
51   {
52       static int i = 1;
53       DOUT << "******" << i++ << "******\n" 
54            << "begin_f: " << s->stem_begin_f () * dir_ 
55            << "\nchord_f/i: " << s->chord_start_f () * dir_ / internote_f << '\n';
56   }
57
58   /*
59     For simplicity, we'll assume dir = UP and correct if 
60     dir = DOWN afterwards.
61    */
62   idealy_f_ = s->chord_start_f () * beam_dir_ / internote_f;
63   idealy_f_ *= internote_f;
64
65   Real break_i = (int)rint (s->paper ()->get_var ("beam_multiple_break"));
66   Real min_stem1_f = s->paper ()->get_var ("beam_minimum_stem1");
67   Real min_stem2_f = s->paper ()->get_var ("beam_minimum_stem2");
68   Real ideal_stem1_f = s->paper ()->get_var ("beam_ideal_stem1");
69   Real ideal_stem2_f = s->paper ()->get_var ("beam_ideal_stem2");
70   Real shorten_f = s->paper ()->get_var ("forced_stem_shorten");
71
72   if (!beam_dir_ || (beam_dir_ == dir_))
73     {
74       idealy_f_ += interbeam_f * mult_i_;
75       miny_f_ = idealy_f_;
76       maxy_f_ = INT_MAX;
77
78       if (mult_i_ < break_i)
79         {
80           idealy_f_ += ideal_stem1_f;
81           miny_f_ += min_stem1_f;
82         }
83       else
84         {
85           idealy_f_ += ideal_stem2_f;
86           miny_f_ += min_stem2_f;
87         }
88
89       /*
90         stems in unnatural (forced) direction are shortened
91         central line is never 'forced'
92        */
93       if (((int)s->chord_start_f ()) && (s->dir_ != s->get_default_dir ()))
94         {
95           idealy_f_ -= shorten_f;
96           miny_f_ = miny_f_ <? idealy_f_ + internote_f;
97         }
98
99       // lowest beam of (UP) beam must never be lower than second staffline
100       miny_f_ = miny_f_ >? (- 2 * internote_f - beam_f
101         + (mult_i_ > 0) * beam_f + interbeam_f * (mult_i_ - 1));
102     }
103   else
104     {
105       idealy_f_ -= beam_f;
106       maxy_f_ = idealy_f_;
107       miny_f_ = -INT_MAX;
108
109       // B"arenreiter
110       if (mult_i_ < break_i)
111         {
112           idealy_f_ -= ideal_stem1_f;
113           maxy_f_ -= min_stem1_f;
114         }
115       else
116         {
117           idealy_f_ -= ideal_stem2_f;
118           maxy_f_ -= min_stem2_f;
119         }
120     }
121
122
123   idealy_f_ /= internote_f;
124   miny_f_ /= internote_f;
125   maxy_f_ /= internote_f;
126
127   DOUT << "dir_: " << dir_ << '\n';
128   DOUT << "mult_i_: " << mult_i_ << '\n';
129   DOUT << "idealy_f_: " << idealy_f_ << '\n';
130   DOUT << "miny_f_: " << miny_f_ << '\n';
131   DOUT << "maxy_f_: " << maxy_f_ << '\n';
132
133   idealy_f_ = maxy_f_ <? idealy_f_;
134   idealy_f_ = miny_f_ >? idealy_f_;
135 }
136