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