]> git.donarmstrong.com Git - lilypond.git/blob - lily/stem-tremolo.cc
release: 1.3.55
[lilypond.git] / lily / stem-tremolo.cc
1 /*   
2   stem-tremolo.cc --  implement Stem_tremolo
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c)  1997--2000 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 #include "directional-element-interface.hh"
20
21 /*
22   TODO:
23     lengthen stem if necessary
24  */
25
26 Stem_tremolo::Stem_tremolo (SCM s)
27   : Item (s)
28 {
29   set_elt_pointer ("stem", SCM_EOL);
30 }
31
32
33 Stem *
34 Stem_tremolo::stem_l ()const
35 {
36   SCM s =   get_elt_pointer ("stem");
37
38   return dynamic_cast<Stem*> (  unsmob_element (s));
39 }
40
41 Interval
42 Stem_tremolo::dim_callback (Score_element * se, Axis )
43 {
44   Stem_tremolo * s = dynamic_cast<Stem_tremolo*> (se);
45   Real space = Staff_symbol_referencer_interface (s->stem_l ())
46     .staff_space ();
47   return Interval (-space, space);
48 }
49
50
51 Molecule 
52 Stem_tremolo::do_brew_molecule () const
53 {
54   Stem * stem = stem_l ();
55   Beam * beam = stem->beam_l ();
56   
57   Real dydx;
58   if (beam)
59     {
60       Real dy = 0;
61       SCM s = beam->get_elt_property ("height");
62       if (gh_number_p (s))
63         dy = gh_scm2double (s);
64       Real dx = beam->last_visible_stem ()->relative_coordinate (0, X_AXIS)
65         - beam->first_visible_stem ()->relative_coordinate (0, X_AXIS);
66       dydx = dx ? dy/dx : 0;
67     }
68   else
69     // urg
70     dydx = 0.25;
71
72   Real ss = Staff_symbol_referencer_interface (stem).staff_space ();
73   Real thick = gh_scm2double (get_elt_property ("beam-thickness"));
74   Real width = gh_scm2double (get_elt_property ("beam-width"));
75   width *= ss;
76   thick *= ss;
77   
78   Molecule a (lookup_l ()->beam (dydx, width, thick));
79   a.translate (Offset (-width/2, width / 2 * dydx));
80   
81   int tremolo_flags;
82   SCM s = get_elt_property ("tremolo-flags");
83   if (gh_number_p (s))
84     tremolo_flags = gh_scm2int (s);
85   else
86     // huh?
87     tremolo_flags = 1;
88
89   int mult = beam ? beam->get_multiplicity () : 0;
90   Real interbeam_f = paper_l ()->interbeam_f (mult);
91   Molecule mol; 
92   for (int i = 0; i < tremolo_flags; i++)
93     {
94       Molecule b (a);
95       b.translate_axis (interbeam_f * i, Y_AXIS);
96       mol.add_molecule (b);
97     }
98   if (tremolo_flags)
99     mol.translate_axis (-mol.extent (Y_AXIS).center (), Y_AXIS);
100   if (beam)
101     {
102       // ugh, rather calc from Stem_tremolo_req
103       int beams_i = stem->beam_count(RIGHT) >? stem->beam_count (LEFT);
104       mol.translate (Offset(stem->relative_coordinate (0, X_AXIS) - relative_coordinate (0, X_AXIS),
105                             stem->stem_end_position () * ss / 2 - 
106                             directional_element (beam).get () * beams_i * interbeam_f));
107     }
108   else
109     {  
110       /*
111         Beams should intersect one beamthickness below stem end
112       */
113       Real dy = stem->stem_end_position () * ss / 2;
114       dy -= mol.extent (Y_AXIS).length () / 2 *  stem->get_direction ();
115
116       /*
117         uhg.  Should use relative coords and placement
118       */
119       Real whole_note_correction;
120       if (stem->invisible_b ())
121         whole_note_correction = -stem->get_direction ()
122           * stem->support_head ()->extent (X_AXIS).length () / 2;
123       else
124         whole_note_correction = 0;
125          
126       mol.translate (Offset (stem->relative_coordinate (0, X_AXIS) - relative_coordinate (0, X_AXIS) +
127                              whole_note_correction, dy));
128     }
129   
130   return mol;
131 }
132
133
134 void
135 Stem_tremolo::set_stem (Stem *s)
136 {
137   set_elt_pointer ("stem", s->self_scm_);
138   add_dependency (s);
139 }
140