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