]> git.donarmstrong.com Git - lilypond.git/blob - lily/stem-tremolo.cc
700a491854e5410cff2a20177f142a08cb7cb6f7
[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->get_multiplicity ();
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 dydx = 0.25;
69   
70   if (st && st->beam_l ())
71     {
72       Real dy = 0;
73       SCM s = st->beam_l ()->get_elt_property ("height");
74       if (s != SCM_UNDEFINED)
75         dy = gh_scm2double (s);
76       Real dx = st->beam_l ()->last_visible_stem ()->hpos_f ()
77         - st->beam_l ()->first_visible_stem ()->hpos_f ();
78       dydx = dy/dx;
79   
80       // ugh, rather calc from Stem_tremolo_req
81       beams_i = st->beam_count(RIGHT) >? st->beam_count (LEFT);
82     } 
83
84   Molecule a (lookup_l ()->beam (dydx, w, beam_f));
85   a.translate (Offset (-w/2, w / 2 * dydx));
86   
87
88   Molecule *beams= new Molecule; 
89   for (int i = 0; i < abbrev_flags_i_; i++)
90     {
91       Molecule b (a);
92       b.translate_axis (interbeam_f * i, Y_AXIS);
93       beams->add_molecule (b);
94     }
95   beams->translate_axis (-beams->extent ()[Y_AXIS].center (), Y_AXIS);
96
97   if (st)
98     { 
99       if (st->beam_l ())
100         {
101           beams->translate (Offset(st->hpos_f () - hpos_f (),
102             st->stem_end_f () * internote_f - 
103             st->beam_l ()->get_direction () * beams_i * interbeam_f));
104         }
105       else
106         {  
107           /*
108             Beams should intersect one beamthickness below staff end
109            */
110           Real dy = - beams->extent ()[Y_AXIS].length () / 2 * st->get_direction ();
111
112           /*
113             uhg.  Should use relative coords and placement
114           */
115           Real whole_note_correction = (st && st->invisible_b( ))
116             ? -st->get_direction () * st->note_delta_f ()/2
117             : 0.0;
118
119           dy += st->stem_end_f ();
120           beams->translate (Offset(st->hpos_f () - hpos_f ()+
121                                    whole_note_correction, dy));
122         }
123
124       /*
125         there used to be half a page of code that was long commented out.
126         Removed in 1.1.35
127        */
128     }
129   
130   return beams;
131 }
132
133
134 void
135 Stem_tremolo::set_stem (Stem *s)
136 {
137   set_elt_property ("stem", s->self_scm_);
138   add_dependency (s);
139 }
140