]> git.donarmstrong.com Git - lilypond.git/blob - lily/stem-tremolo.cc
patch::: 1.3.11.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 #include "dimension-cache.hh"
18 #include "staff-symbol-referencer.hh"
19
20
21 Stem_tremolo::Stem_tremolo ()
22 {
23   set_elt_property ("stem", SCM_EOL);
24   abbrev_flags_i_ = 1;
25 }
26
27 void
28 Stem_tremolo::do_print () const
29 {
30   DEBUG_OUT << "abbrev_flags_i_ " << abbrev_flags_i_;
31 }
32
33 Stem *
34 Stem_tremolo::stem_l ()const
35 {
36   SCM s =   get_elt_property ("stem");
37
38   return dynamic_cast<Stem*> (  unsmob_element (s));
39 }
40
41 Interval
42 Stem_tremolo::dim_callback (Dimension_cache const *c) 
43 {
44   Stem_tremolo * s = dynamic_cast<Stem_tremolo*> (c->element_l ());
45   Real space = Staff_symbol_referencer_interface (s->stem_l ())
46     .staff_line_leading_f ();
47   return Interval (-space, space);
48 }
49
50
51 Molecule*
52 Stem_tremolo::do_brew_molecule_p () const
53 {
54   Stem * st = stem_l ();
55   int mult =0;
56   if (Beam * b = st->beam_l ())
57     {
58       mult = b->multiplicity_i ();
59     }
60   
61   Real interbeam_f = paper_l ()->interbeam_f (mult);
62   Real w  = gh_scm2double (get_elt_property ("beam-width"));
63   Real space = Staff_symbol_referencer_interface (st).staff_line_leading_f ();
64   Real internote_f = space / 2;
65   Real beam_f = gh_scm2double (get_elt_property ("beam-thickness"));
66
67   int beams_i = 0;
68   Real slope_f = 0.25;
69
70   if (st && st->beam_l ()) {
71     slope_f = st->beam_l ()->slope_f_;
72     // ugh, rather calc from Stem_tremolo_req
73     beams_i = st->beam_count (RIGHT) >? st->beam_count (LEFT);
74   } 
75
76   Molecule a (lookup_l ()->beam (slope_f, 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           dy += st->stem_end_f ();
111           beams->translate (Offset(st->hpos_f () - hpos_f ()+
112                                    whole_note_correction, dy));
113         }
114
115       /*
116         there used to be half a page of code that was long commented out.
117         Removed in 1.1.35
118        */
119     }
120   
121   return beams;
122 }
123
124
125 void
126 Stem_tremolo::set_stem (Stem *s)
127 {
128   set_elt_property ("stem", s->self_scm_);
129   add_dependency (s);
130 }
131