]> git.donarmstrong.com Git - lilypond.git/blob - lily/hairpin.cc
* buildscripts/analyse-cxx-log.py: new file. Read compile log to
[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--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "hairpin.hh"
10 #include "staff-symbol-referencer.hh"
11 #include "line-interface.hh"
12 #include "spanner.hh"
13 #include "font-interface.hh"
14 #include "dimensions.hh"
15 #include "output-def.hh"
16 #include "warn.hh"
17 #include "paper-column.hh"
18 #include "lookup.hh"
19 #include "text-interface.hh"
20 #include "pointer-group-interface.hh"
21
22 MAKE_SCHEME_CALLBACK (Hairpin, after_line_breaking, 1);
23 SCM
24 Hairpin::after_line_breaking (SCM smob)
25 {
26   Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (smob));
27
28   Drul_array<bool> broken;
29   Drul_array<Item *> bounds;
30   Direction d = LEFT;
31   do
32     {
33       bounds[d] = me->get_bound (d);
34       broken[d] = bounds[d]->break_status_dir () != CENTER;
35     }
36   while (flip (&d) != LEFT);
37
38   if (broken[LEFT]
39       && ly_is_equal (bounds[RIGHT]->get_column ()->get_property ("when"),
40                       bounds[LEFT]->get_property ("when")))
41     me->suicide ();
42   return SCM_UNSPECIFIED;
43 }
44
45 MAKE_SCHEME_CALLBACK (Hairpin, print, 1);
46
47 SCM
48 Hairpin::print (SCM smob)
49 {
50   Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (smob));
51
52   SCM s = me->get_property ("grow-direction");
53   if (!is_direction (s))
54     {
55       me->suicide ();
56       return SCM_EOL;
57     }
58
59   Direction grow_dir = to_dir (s);
60   Real padding = robust_scm2double (me->get_property ("bound-padding"), 0.5);
61
62   Drul_array<bool> broken;
63   Drul_array<Item *> bounds;
64   Direction d = LEFT;
65   do
66     {
67       bounds[d] = me->get_bound (d);
68       broken[d] = bounds[d]->break_status_dir () != CENTER;
69     }
70   while (flip (&d) != LEFT);
71
72   Grob *common = bounds[LEFT]->common_refpoint (bounds[RIGHT], X_AXIS);
73   Drul_array<Real> x_points;
74
75   do
76     {
77       Item *b = bounds[d];
78       x_points[d] = b->relative_coordinate (common, X_AXIS);
79       if (broken [d])
80         {
81           if (d == LEFT)
82             x_points[d] = b->extent (common, X_AXIS)[RIGHT];
83         }
84       else
85         {
86           if (Text_interface::has_interface (b))
87             {
88               Interval e = b->extent (common, X_AXIS);
89               if (!e.is_empty ())
90                 x_points[d] = e[-d] - d * padding;
91             }
92           else
93             {
94               bool neighbor_found = false;
95               extract_grob_set (me, "adjacent-hairpins", pins);
96               for (int i = 0; i < pins.size (); i++)
97                 {
98                   /*
99                     FIXME: this will fuck up in case of polyphonic
100                     notes in other voices. Need to look at note-columns
101                     in the current staff/voice.
102                   */
103
104                   Spanner *pin = dynamic_cast<Spanner *> (pins[i]);
105                   if (pin
106                       && (pin->get_bound (LEFT)->get_column () == b->get_column ()
107                           || pin->get_bound (RIGHT)->get_column () == b->get_column ()))
108                     neighbor_found = true;
109                 }
110
111               /*
112                 If we're hung on a paper column, that means we're not
113                 adjacent to a text-dynamic, and we may move closer. We
114                 make the padding a little smaller, here.
115               */
116               Interval e = robust_relative_extent (b, common, X_AXIS);
117               x_points[d]
118                 = neighbor_found ? e.center () - d * padding / 3 : e[d];
119             }
120         }
121     }
122   while (flip (&d) != LEFT);
123
124   Real width = x_points[RIGHT] - x_points[LEFT];
125   if (width < 0)
126     {
127       me->warning (_ ((grow_dir < 0) ? "decrescendo too small"
128                       : "crescendo too small"));
129       width = 0;
130     }
131
132   bool continued = broken[Direction (-grow_dir)];
133   Real height = robust_scm2double (me->get_property ("height"), 0.2) *
134     Staff_symbol_referencer::staff_space (me);
135
136   Real starth, endh;
137   if (grow_dir < 0)
138     {
139       starth = height;
140       endh = continued ? height / 2 : 0.0;
141     }
142   else
143     {
144       starth = continued ? height / 2 : 0.0;
145       endh = height;
146     }
147
148   /*
149     should do relative to staff-symbol staff-space?
150   */
151
152   Stencil mol;
153   mol = Line_interface::line (me, Offset (0, starth), Offset (width, endh));
154   mol.add_stencil (Line_interface::line (me,
155                                          Offset (0, -starth),
156                                          Offset (width, -endh)));
157
158   mol.translate_axis (x_points[LEFT]
159                       - bounds[LEFT]->relative_coordinate (common, X_AXIS),
160                       X_AXIS);
161   return mol.smobbed_copy ();
162 }
163
164 ADD_INTERFACE (Hairpin, "hairpin-interface",
165                "A hairpin crescendo/decrescendo.",
166                "adjacent-hairpins "
167                "bound-padding "
168                "grow-direction "
169                "height "
170                );
171