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