]> git.donarmstrong.com Git - lilypond.git/blob - lily/crescendo.cc
release: 1.3.14
[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--1999 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 #include "atom.hh"
17
18 Crescendo::Crescendo ()
19 {
20   grow_dir_ =0;
21   dyn_b_drul_[LEFT] = dyn_b_drul_[RIGHT] =false;
22 }
23
24
25
26 Molecule*
27 Crescendo::do_brew_molecule_p () const
28 {
29   Real absdyn_dim = paper_l ()-> get_var ("crescendo_shorten");
30   Real extra_left =  get_broken_left_end_align ();
31
32   if (dyn_b_drul_[LEFT])
33     extra_left += absdyn_dim;
34
35   
36
37   Real width = spanner_length()- get_broken_left_end_align ();
38
39   if (dyn_b_drul_[LEFT])
40     {
41       width -= absdyn_dim;
42     }
43   if (dyn_b_drul_[RIGHT])
44     {
45       width -= absdyn_dim;
46     }
47
48   if (width < 0)
49     {
50       warning (_ ("crescendo") + " " + _ ("too small"));
51       width = 0;
52     }
53
54   Drul_array<bool> broken;
55   Direction d = LEFT;
56   do {
57     Paper_column* s = dynamic_cast<Paper_column*>(spanned_drul_[d]); // UGH
58     broken[d] = (!s->musical_b ());
59   } while (flip (&d) != LEFT);
60   
61
62   bool continued = broken[Direction (-grow_dir_)];
63   Real height = paper_l()->get_var ("crescendo_height");
64   Real thick = paper_l ()->get_var ("crescendo_thickness");
65
66   const char* hairpin = (grow_dir_ < 0)? "decrescendo" :  "crescendo";
67   Atom at  (gh_list (ly_symbol2scm (hairpin),
68                      gh_double2scm (thick),
69                      gh_double2scm (width),
70                      gh_double2scm (height),
71                      gh_double2scm (continued ? height/2 : 0.0),
72                      SCM_UNDEFINED));
73   Molecule * m
74     = new Molecule;
75   
76   m->dim_.x () = Interval (0, width);
77   m->dim_.y () = Interval (-2*height, 2*height);
78   m->add_atom (&at);
79   
80   m->translate_axis (extra_left, X_AXIS);
81   return m;
82 }
83
84