]> git.donarmstrong.com Git - lilypond.git/blob - lily/stem-tremolo.cc
release: 1.3.10
[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 #include "dimension-cache.hh"
18
19 Stem_tremolo::Stem_tremolo ()
20 {
21   set_elt_property ("stem", SCM_EOL);
22   abbrev_flags_i_ = 1;
23 }
24
25 void
26 Stem_tremolo::do_print () const
27 {
28   DEBUG_OUT << "abbrev_flags_i_ " << abbrev_flags_i_;
29 }
30
31 Stem *
32 Stem_tremolo::stem_l ()const
33 {
34   SCM s =   get_elt_property ("stem");
35
36   return dynamic_cast<Stem*> (  unsmob_element (s));
37 }
38
39 Interval
40 Stem_tremolo::dim_callback (Dimension_cache const *c) 
41 {
42   Stem_tremolo * s = dynamic_cast<Stem_tremolo*> (c->element_l ());
43   Real space = s->stem_l ()->staff_line_leading_f ();
44   return Interval (-space, space);
45 }
46
47
48 Molecule*
49 Stem_tremolo::do_brew_molecule_p () const
50 {
51   Stem * st = stem_l ();
52   int mult =0;
53   if (Beam * b = st->beam_l ())
54     {
55       Stem_info i = b->get_stem_info (st);
56       mult = i.mult_i_;
57     }
58   
59   Real interbeam_f = paper_l ()->interbeam_f (mult);
60   Real w  = gh_scm2double (get_elt_property ("beam-width"));
61   Real space = st->staff_line_leading_f ();
62   Real internote_f = space/2;
63   
64   Real beam_f = gh_scm2double (get_elt_property ("beam-thickness"));
65
66   int beams_i = 0;
67   Real slope_f = internote_f / 4 / internote_f; // HUH?
68
69   if (st && st->beam_l ()) {
70     slope_f = st->beam_l ()->slope_f_;
71     // ugh, rather calc from Stem_tremolo_req
72     beams_i = st->beams_i_drul_[RIGHT] >? st->beams_i_drul_[LEFT];
73   } 
74   Real sl = slope_f * internote_f;
75
76   Molecule a (lookup_l ()->beam (sl, w, beam_f));
77   a.translate (Offset (-w/2, w / 2 * slope_f));
78
79   Molecule *beams= new Molecule; 
80   for (int i = 0; i < abbrev_flags_i_; i++)
81     {
82       Molecule b (a);
83       b.translate_axis (interbeam_f * i, Y_AXIS);
84       beams->add_molecule (b);
85     }
86   beams->translate_axis (-beams->extent ()[Y_AXIS].center (), Y_AXIS);
87
88   if (st)
89     { 
90       if (st->beam_l ())
91         {
92           beams->translate (Offset(st->hpos_f () - hpos_f (),
93             st->stem_end_f () * internote_f - 
94             st->beam_l ()->get_direction () * beams_i * interbeam_f));
95         }
96       else
97         {  
98           /*
99             Beams should intersect one beamthickness below staff end
100            */
101           Real dy = - beams->extent ()[Y_AXIS].length () / 2 * st->get_direction ();
102
103           /*
104             uhg.  Should use relative coords and placement
105           */
106           Real whole_note_correction = (st && st->invisible_b( ))
107             ? -st->get_direction () * st->note_delta_f ()/2
108             : 0.0;
109
110           /*
111             UGH. Internote fudging.
112            */
113           dy /= internote_f;
114           dy += st->stem_end_f ();
115           dy *= internote_f;
116           beams->translate (Offset(st->hpos_f () - hpos_f ()+
117                                    whole_note_correction, dy));
118         }
119
120       /*
121         there used to be half a page of code that was long commented out.
122         Removed in 1.1.35
123        */
124     }
125   
126   return beams;
127 }
128
129
130 void
131 Stem_tremolo::set_stem (Stem *s)
132 {
133   set_elt_property ("stem", s->self_scm_);
134   add_dependency (s);
135 }
136