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