]> git.donarmstrong.com Git - lilypond.git/blob - lily/crescendo.cc
patch::: 1.3.115.jcn1
[lilypond.git] / lily / crescendo.cc
1 /*
2   crescendo.cc -- implement Hairpin
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 (Hairpin, brew_molecule, 1);
19
20 SCM
21 Hairpin::brew_molecule (SCM smob) 
22 {
23   Grob *me= unsmob_grob (smob);
24   Spanner *span = dynamic_cast<Spanner*>(me);
25
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_grob_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   Real padding = gh_scm2double (me->get_grob_property ("padding"));
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   Drul_array<Real> extra_off;
51   Direction d = LEFT;
52   do
53     {
54       Item *b = span->get_bound (d);
55       broken[d] = b->break_status_dir () != CENTER;
56
57       if (!broken [d])
58         {
59
60           Interval e =b->extent (b, X_AXIS);
61           Real r = 0.0;
62           if (!e.empty_b ())
63             r = e[-d] + padding;
64           width += d * r;
65           extra_off[d] = r;
66         }
67     }
68   while (flip (&d) != LEFT);
69   
70   bool continued = broken[Direction (-grow_dir)];
71   Real height = gh_scm2double (me->get_grob_property ("height"));
72   Real thick = line * gh_scm2double (me->get_grob_property ("thickness"));
73   
74   const char* type = (grow_dir < 0) ? "decrescendo" :  "crescendo";
75   SCM hairpin = gh_list (ly_symbol2scm (type),
76                     gh_double2scm (thick),
77                     gh_double2scm (width),
78                     gh_double2scm (height),
79                     gh_double2scm (continued ? height/2 : 0.0),
80                     SCM_UNDEFINED);
81
82   Box b (Interval (0, width), Interval (-2*height, 2*height));
83   Molecule mol (b, hairpin);
84   mol.translate_axis (broken_left + extra_off[LEFT], X_AXIS);
85
86   return mol.smobbed_copy ();
87 }
88
89