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