]> git.donarmstrong.com Git - lilypond.git/blob - lily/crescendo.cc
be54a96e62e0057a377b78697d250dc77144ec3b
[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 "font-interface.hh"
13 #include "dimensions.hh"
14 #include "paper-def.hh"
15 #include "debug.hh"
16 #include "paper-column.hh"
17
18 MAKE_SCHEME_CALLBACK (Crescendo, brew_molecule, 1);
19
20 SCM
21 Crescendo::brew_molecule (SCM smob) 
22 {
23   Score_element *me= unsmob_element (smob);
24   Spanner *span = dynamic_cast<Spanner*>(me);
25   Real staff_space = me->paper_l ()->get_var ("staffspace");
26   Real line = me->paper_l ()->get_var ("stafflinethickness");  
27   
28   Real broken_left =  span->get_broken_left_end_align ();
29
30   SCM s = me->get_elt_property("grow-direction");
31   if (!isdir_b (s))
32     {
33       me->suicide ();
34       return SCM_EOL;
35     }
36   
37   Direction grow_dir = to_dir (s);
38
39   Real width = span->spanner_length ();
40   width -= span->get_broken_left_end_align ();
41
42   if (width < 0)
43     {
44       warning (_ ((grow_dir < 0) ? "decrescendo too small"
45                   : "crescendo too small"));
46       width = 0;
47     }
48
49   Drul_array<bool> broken;
50   Direction d = LEFT;
51   do
52     {
53       Paper_column* s = dynamic_cast<Paper_column*> (span->get_bound (d)); // UGH
54       broken[d] = (!s->musical_b ());
55     }
56   while (flip (&d) != LEFT);
57   
58   bool continued = broken[Direction (-grow_dir)];
59   Real height = staff_space * gh_scm2double (me->get_elt_property ("height"));
60   Real thick = line * gh_scm2double (me->get_elt_property ("thickness"));
61   
62   const char* type = (grow_dir < 0) ? "decrescendo" :  "crescendo";
63   SCM hairpin = gh_list (ly_symbol2scm (type),
64                     gh_double2scm (thick),
65                     gh_double2scm (width),
66                     gh_double2scm (height),
67                     gh_double2scm (continued ? height/2 : 0.0),
68                     SCM_UNDEFINED);
69
70   Box b (Interval (0, width), Interval (-2*height, 2*height));
71   Molecule mol (b, hairpin);
72   mol.translate_axis (broken_left, X_AXIS);
73
74   return mol.create_scheme ();
75 }
76
77