]> git.donarmstrong.com Git - lilypond.git/blob - lily/stem-tremolo.cc
patch::: 1.3.1.hwn1
[lilypond.git] / lily / stem-tremolo.cc
1 /*   
2   abbrev.cc --  implement Stem_tremolo
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "stem-tremolo.hh"
11 #include "debug.hh"
12 #include "beam.hh"
13 #include "paper-def.hh"
14 #include "lookup.hh"
15 #include "stem.hh"
16 #include "offset.hh"
17
18 Stem_tremolo::Stem_tremolo ()
19 {
20   stem_l_ = 0;
21   abbrev_flags_i_ = 1;
22 }
23
24 void
25 Stem_tremolo::do_print () const
26 {
27   DEBUG_OUT << "abbrev_flags_i_ " << abbrev_flags_i_;
28 }
29
30 Interval
31 Stem_tremolo::do_width () const
32 {
33   Real space = stem_l_->staff_line_leading_f ();
34   return Interval (-space, space);
35 }
36
37 void
38 Stem_tremolo::do_pre_processing ()
39 {
40 }
41
42 Molecule*
43 Stem_tremolo::do_brew_molecule_p () const
44 {
45   int mult =0;
46   if (Beam * b = stem_l_->beam_l_)
47     {
48       Stem_info i = b->get_stem_info (stem_l_);
49       mult = i.mult_i_;
50     }
51   
52   Real interbeam_f = paper_l ()->interbeam_f (mult);
53   Real w = 1.5 * lookup_l ()->notehead (2, "").dim_[X_AXIS].length ();
54   Real space = stem_l_->staff_line_leading_f ();
55   Real internote_f = space/2;
56   
57   Real beam_f = paper_l ()->get_var ("beam_thickness");
58
59   int beams_i = 0;
60   Real slope_f = internote_f / 4 / internote_f; // HUH?
61
62   if (stem_l_ && stem_l_->beam_l_) {
63     slope_f = stem_l_->beam_l_->slope_f_;
64     // ugh, rather calc from Stem_tremolo_req
65     beams_i = stem_l_->beams_i_drul_[RIGHT] >? stem_l_->beams_i_drul_[LEFT];
66   } 
67   Real sl = slope_f * internote_f;
68
69   Molecule a (lookup_l ()->beam (sl, w, beam_f));
70   a.translate (Offset (-w/2, w / 2 * slope_f));
71
72   Molecule *beams= new Molecule; 
73   for (int i = 0; i < abbrev_flags_i_; i++)
74     {
75       Molecule b (a);
76       b.translate_axis (interbeam_f * i, Y_AXIS);
77       beams->add_molecule (b);
78     }
79   beams->translate_axis (-beams->extent ()[Y_AXIS].center (), Y_AXIS);
80
81   if (stem_l_)
82     { 
83       if (stem_l_->beam_l_)
84         {
85           beams->translate (Offset(stem_l_->hpos_f () - hpos_f (),
86             stem_l_->stem_end_f () * internote_f - 
87             stem_l_->beam_l_->dir_ * beams_i * interbeam_f));
88         }
89       else
90         {  
91           /*
92             Beams should intersect one beamthickness below staff end
93            */
94           Real dy = - beams->extent ()[Y_AXIS].length () / 2 * stem_l_->dir_;
95
96           /*
97             uhg.  Should use relative coords and placement
98           */
99           Real whole_note_correction = (stem_l_ && stem_l_->invisible_b( ))
100             ? -stem_l_->get_dir () * stem_l_->note_delta_f ()/2
101             : 0.0;
102
103           /*
104             UGH. Internote fudging.
105            */
106           dy /= internote_f;
107           dy += stem_l_->stem_end_f ();
108           dy *= internote_f;
109           beams->translate (Offset(stem_l_->hpos_f () - hpos_f ()+
110                                    whole_note_correction, dy));
111         }
112
113       /*
114         there used to be half a page of code that was long commented out.
115         Removed in 1.1.35
116        */
117     }
118   
119   return beams;
120 }
121
122 void
123 Stem_tremolo::do_substitute_element_pointer (Score_element*o, Score_element*n)
124 {
125   if (stem_l_ == o)
126     stem_l_ = dynamic_cast<Stem*> (n);
127 }
128
129
130 void
131 Stem_tremolo::set_stem (Stem *s)
132 {
133   stem_l_ = s;
134   add_dependency (s);
135 }
136