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