]> git.donarmstrong.com Git - lilypond.git/blob - lily/stem-tremolo.cc
release: 1.3.56
[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 MAKE_SCHEME_SCORE_ELEMENT_CALLBACKS(Stem_tremolo)
52 Molecule 
53 Stem_tremolo::do_brew_molecule () const
54 {
55   Stem * stem = stem_l ();
56   Beam * beam = stem->beam_l ();
57   
58   Real dydx;
59   if (beam)
60     {
61       Real dy = 0;
62       SCM s = beam->get_elt_property ("height");
63       if (gh_number_p (s))
64         dy = gh_scm2double (s);
65       Real dx = beam->last_visible_stem ()->relative_coordinate (0, X_AXIS)
66         - beam->first_visible_stem ()->relative_coordinate (0, X_AXIS);
67       dydx = dx ? dy/dx : 0;
68     }
69   else
70     // urg
71     dydx = 0.25;
72
73   Real ss = Staff_symbol_referencer_interface (stem).staff_space ();
74   Real thick = gh_scm2double (get_elt_property ("beam-thickness"));
75   Real width = gh_scm2double (get_elt_property ("beam-width"));
76   width *= ss;
77   thick *= ss;
78   
79   Molecule a (lookup_l ()->beam (dydx, width, thick));
80   a.translate (Offset (-width/2, width / 2 * dydx));
81   
82   int tremolo_flags;
83   SCM s = get_elt_property ("tremolo-flags");
84   if (gh_number_p (s))
85     tremolo_flags = gh_scm2int (s);
86   else
87     // huh?
88     tremolo_flags = 1;
89
90   int mult = beam ? beam->get_multiplicity () : 0;
91   Real interbeam_f = paper_l ()->interbeam_f (mult);
92   Molecule mol; 
93   for (int i = 0; i < tremolo_flags; i++)
94     {
95       Molecule b (a);
96       b.translate_axis (interbeam_f * i, Y_AXIS);
97       mol.add_molecule (b);
98     }
99   if (tremolo_flags)
100     mol.translate_axis (-mol.extent (Y_AXIS).center (), Y_AXIS);
101   if (beam)
102     {
103       // ugh, rather calc from Stem_tremolo_req
104       int beams_i = stem->beam_count(RIGHT) >? stem->beam_count (LEFT);
105       mol.translate (Offset(stem->relative_coordinate (0, X_AXIS) - relative_coordinate (0, X_AXIS),
106                             stem->stem_end_position () * ss / 2 - 
107                             directional_element (beam).get () * beams_i * interbeam_f));
108     }
109   else
110     {  
111       /*
112         Beams should intersect one beamthickness below stem end
113       */
114       Real dy = stem->stem_end_position () * ss / 2;
115       dy -= mol.extent (Y_AXIS).length () / 2 *  stem->get_direction ();
116
117       /*
118         uhg.  Should use relative coords and placement
119       */
120       Real whole_note_correction;
121       if (stem->invisible_b ())
122         whole_note_correction = -stem->get_direction ()
123           * stem->support_head ()->extent (X_AXIS).length () / 2;
124       else
125         whole_note_correction = 0;
126          
127       mol.translate (Offset (stem->relative_coordinate (0, X_AXIS) - relative_coordinate (0, X_AXIS) +
128                              whole_note_correction, dy));
129     }
130   
131   return mol;
132 }
133
134
135 void
136 Stem_tremolo::set_stem (Stem *s)
137 {
138   set_elt_pointer ("stem", s->self_scm_);
139   add_dependency (s);
140 }
141