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