lilypond-1.3.18
[lilypond.git] / lily / crescendo.cc
blobecd51f5d5b393e0a69733dfc069b597385a35ad1
1 /*
2 crescendo.cc -- implement Crescendo
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
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 #include "atom.hh"
18 Crescendo::Crescendo ()
20 set_elt_property ("dynamic-drul", gh_cons (SCM_BOOL_F, SCM_BOOL_F));
25 Molecule*
26 Crescendo::do_brew_molecule_p () const
28 Real absdyn_dim = paper_l ()-> get_var ("crescendo_shorten");
29 Real extra_left = get_broken_left_end_align ();
31 SCM dir = get_elt_property("grow-dir");
32 SCM dyns = get_elt_property ("dynamic-drul");
34 if (!isdir_b (dir) || !gh_pair_p (dyns))
36 set_elt_property ("transparent", SCM_BOOL_T);
37 return new Molecule;
40 Direction gd = to_dir (dir);
42 bool dynleft= to_boolean (gh_car (dyns));
43 bool dynright = to_boolean (gh_cdr (dyns));
45 if (dynleft)
46 extra_left += absdyn_dim;
50 Real width = spanner_length()- get_broken_left_end_align ();
52 if (dynleft)
54 width -= absdyn_dim;
56 if (dynright)
58 width -= absdyn_dim;
61 if (width < 0)
63 warning (_ ("crescendo") + " " + _ ("too small"));
64 width = 0;
67 Drul_array<bool> broken;
68 Direction d = LEFT;
69 do {
70 Paper_column* s = dynamic_cast<Paper_column*>(spanned_drul_[d]); // UGH
71 broken[d] = (!s->musical_b ());
72 } while (flip (&d) != LEFT);
75 bool continued = broken[Direction (-gd)];
76 Real height = paper_l()->get_var ("crescendo_height");
77 Real thick = paper_l ()->get_var ("crescendo_thickness");
79 const char* hairpin = (gd < 0)? "decrescendo" : "crescendo";
80 Atom at (gh_list (ly_symbol2scm (hairpin),
81 gh_double2scm (thick),
82 gh_double2scm (width),
83 gh_double2scm (height),
84 gh_double2scm (continued ? height/2 : 0.0),
85 SCM_UNDEFINED));
86 Molecule * m
87 = new Molecule;
89 m->dim_.x () = Interval (0, width);
90 m->dim_.y () = Interval (-2*height, 2*height);
91 m->add_atom (&at);
93 m->translate_axis (extra_left, X_AXIS);
94 return m;