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