]> git.donarmstrong.com Git - lilypond.git/blob - lily/hairpin.cc
patch::: 1.3.116.jcn3
[lilypond.git] / lily / hairpin.cc
1 /*
2   hairpin.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 "hairpin.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 *spanner = dynamic_cast<Spanner*>(me);
25
26   Real line = me->paper_l ()->get_var ("stafflinethickness");  
27   
28   SCM s = me->get_grob_property("grow-direction");
29   if (!isdir_b (s))
30     {
31       me->suicide ();
32       return SCM_EOL;
33     }
34   
35   Direction grow_dir = to_dir (s);
36
37
38   /* Ugh, must be same as Text_spanner::brew_molecule.  */  
39   Real padding = gh_scm2double (me->get_grob_property ("if-text-padding"));
40   Real broken_left =  spanner->get_broken_left_end_align ();
41   Real width = spanner->spanner_length ();
42   width -= broken_left;
43
44   Drul_array<bool> broken;
45   Drul_array<Real> extra_off;
46   Direction d = LEFT;
47   do
48     {
49       Item *b = spanner->get_bound (d);
50       broken[d] = b->break_status_dir () != CENTER;
51
52       if (!broken [d])
53         {
54
55           Interval e =b->extent (b, X_AXIS);
56           Real r = 0.0;
57           if (!e.empty_b ())
58             r = e[-d] + padding;
59           width += d * r;
60           extra_off[d] = r;
61         }
62     }
63   while (flip (&d) != LEFT);
64
65   // FIXME: ecs tells us
66   width += gh_scm2double (me->get_grob_property ("width-correct"));
67   /* /Ugh */
68   
69   if (width < 0)
70     {
71       warning (_ ((grow_dir < 0) ? "decrescendo too small"
72                   : "crescendo too small"));
73       width = 0;
74     }
75
76   bool continued = broken[Direction (-grow_dir)];
77   Real height = gh_scm2double (me->get_grob_property ("height"));
78   Real thick = line * gh_scm2double (me->get_grob_property ("thickness"));
79   
80   const char* type = (grow_dir < 0) ? "decrescendo" :  "crescendo";
81   SCM hairpin = gh_list (ly_symbol2scm (type),
82                     gh_double2scm (thick),
83                     gh_double2scm (width),
84                     gh_double2scm (height),
85                     gh_double2scm (continued ? height/2 : 0.0),
86                     SCM_UNDEFINED);
87
88   Box b (Interval (0, width), Interval (-2*height, 2*height));
89   Molecule mol (b, hairpin);
90   mol.translate_axis (broken_left + extra_off[LEFT], X_AXIS);
91
92   return mol.smobbed_copy ();
93 }
94
95