]> git.donarmstrong.com Git - lilypond.git/blob - lily/crescendo.cc
d119ca9a04cf818ae9e70b370e11c56517aafd5a
[lilypond.git] / lily / crescendo.cc
1 /*
2   crescendo.cc -- implement Crescendo
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 #include "molecule.hh"
10 #include "crescendo.hh"
11 #include "lookup.hh"
12 #include "dimensions.hh"
13 #include "paper-def.hh"
14 #include "debug.hh"
15 #include "paper-column.hh"
16
17
18 Crescendo::Crescendo (SCM s)
19   : Spanner (s)
20 {
21   set_elt_property ("dynamic-drul", gh_cons (SCM_BOOL_F, SCM_BOOL_F));
22 }
23
24
25
26
27 MAKE_SCHEME_SCORE_ELEMENT_CALLBACKS(Crescendo)
28 Molecule 
29 Crescendo::do_brew_molecule () const
30 {
31   Real absdyn_dim = paper_l ()-> get_var ("crescendo_shorten");
32   Real extra_left =  get_broken_left_end_align ();
33
34   SCM dir = get_elt_property("grow-direction");
35   SCM dyns = get_elt_property ("dynamic-drul");
36
37   if (!isdir_b (dir) || !gh_pair_p (dyns))
38     {
39       Crescendo * me = (Crescendo*)this;
40       me->suicide ();
41       Molecule m;
42       
43       return m;
44     }
45   
46   Direction gd = to_dir (dir);
47
48   bool dynleft= to_boolean (gh_car (dyns));
49   bool dynright = to_boolean (gh_cdr (dyns));
50   
51   if (dynleft)
52     extra_left += absdyn_dim;
53
54   
55
56   Real width = spanner_length()- get_broken_left_end_align ();
57
58   if (dynleft)
59     {
60       width -= absdyn_dim;
61     }
62   if (dynright)
63     {
64       width -= absdyn_dim;
65     }
66
67   if (width < 0)
68     {
69       warning (_ ("crescendo") + " " + _ ("too small"));
70       width = 0;
71     }
72
73   Drul_array<bool> broken;
74   Direction d = LEFT;
75   do
76     {
77       Paper_column* s = dynamic_cast<Paper_column*>(get_bound (d)); // UGH
78       broken[d] = (!s->musical_b ());
79     }
80   while (flip (&d) != LEFT);
81   
82  
83   Molecule m;
84   
85   Real pad = 0;
86   SCM s = get_elt_property ("start-text");
87   if (gh_string_p (s))
88     {
89       Molecule start_text (lookup_l ()->text ("italic",
90                                               ly_scm2string (s),
91                                               paper_l ()));
92       m.add_molecule (start_text);
93
94       pad = paper_l ()->get_var ("interline") / 2;
95
96       width -= start_text.extent (X_AXIS).length ();
97       width -= pad;
98       width = width >? 0;
99     }
100
101   SCM at;
102   s = get_elt_property ("spanner");
103   Real height;
104   if (gh_string_p (s) && ly_scm2string (s) == "dashed-line")
105     {
106       Real thick = paper_l ()->get_var ("crescendo_dash_thickness");
107       Real dash = paper_l ()->get_var ("crescendo_dash");
108       height = thick;
109       at = gh_list (ly_symbol2scm (ly_scm2string (s).ch_C ()),
110                     gh_double2scm (thick),
111                     gh_double2scm (dash),
112                     gh_double2scm (width),
113                     SCM_UNDEFINED);
114     }
115   else
116     {
117       bool continued = broken[Direction (-gd)];
118       height = paper_l()->get_var ("crescendo_height");
119       Real thick = paper_l ()->get_var ("crescendo_thickness");
120       
121       const char* hairpin = (gd < 0)? "decrescendo" :  "crescendo";
122
123       at = gh_list (ly_symbol2scm (hairpin),
124                     gh_double2scm (thick),
125                     gh_double2scm (width),
126                     gh_double2scm (height),
127                     gh_double2scm (continued ? height/2 : 0.0),
128                     SCM_UNDEFINED);
129     }
130   Box b (Interval (0, width), Interval (-2*height, 2*height));
131   Molecule span (b, at);
132
133   m.add_at_edge (X_AXIS, RIGHT, span, pad);
134   m.translate_axis (extra_left, X_AXIS);
135
136   return m;
137 }
138
139