]> git.donarmstrong.com Git - lilypond.git/blob - lily/piano-pedal-bracket.cc
Run `make grand-replace'.
[lilypond.git] / lily / piano-pedal-bracket.cc
1 /*
2   piano-pedal-bracket.cc -- implement  Piano_pedal_bracket
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2003--2008 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "stencil.hh"
10 #include "spanner.hh"
11 #include "item.hh"
12 #include "tuplet-bracket.hh"
13
14 struct Piano_pedal_bracket
15 {
16   DECLARE_SCHEME_CALLBACK (print, (SCM));
17   DECLARE_GROB_INTERFACE ();
18 };
19
20 MAKE_SCHEME_CALLBACK (Piano_pedal_bracket, print, 1);
21 SCM
22 Piano_pedal_bracket::print (SCM smob)
23 {
24   Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (smob));
25   Spanner *orig = dynamic_cast<Spanner *> (me->original ());
26
27   Drul_array<bool> broken (false, false);
28   Drul_array<Real> height = robust_scm2drul
29     (me->get_property ("edge-height"), Interval (0, 0));
30   Drul_array<Real> shorten = robust_scm2drul
31     (me->get_property ("shorten-pair"), Interval (0, 0));
32   Drul_array<Real> flare = robust_scm2drul
33     (me->get_property ("bracket-flare"), Interval (0, 0));
34
35   Grob *common = me->get_bound (LEFT)
36     ->common_refpoint (me->get_bound (RIGHT), X_AXIS);
37   Grob *textbit = unsmob_grob (me->get_object ("pedal-text"));
38
39   if (textbit)
40     common = common->common_refpoint (textbit, X_AXIS);
41
42   Interval span_points (0, 0);
43   Direction d = LEFT;
44   do
45     {
46       Item *b = me->get_bound (d);
47       broken[d] = b->break_status_dir () != CENTER;
48       if (broken[d])
49         {
50           if (orig
51               && ((d == RIGHT
52                    && me->get_break_index () != orig->broken_intos_.size () - 1)
53                   || (d == LEFT && me->get_break_index ())))
54             height[d] = 0.0;
55           else
56             flare[d] = 0.0;
57         }
58
59       Interval ext = robust_relative_extent (b, common, X_AXIS);
60       span_points[d] = ext [broken[d] ? RIGHT : LEFT];
61     }
62   while (flip (&d) != LEFT);
63
64   /* For 'Mixed' style pedals, i.e.  a bracket preceded by text:  Ped._____|
65      need to shorten by the extent of the text grob
66   */
67   if (textbit)
68     {
69       height[LEFT] = 0;
70
71       Real padding = robust_scm2double (me->get_property ("bound-padding"), 0);
72
73       span_points[LEFT] = padding
74         + robust_relative_extent (textbit, common, X_AXIS)[RIGHT];
75     }
76
77   Stencil m;
78   if (!span_points.is_empty ()
79       && span_points.length () > 0.001)
80     {
81       m = Tuplet_bracket::make_bracket (me, Y_AXIS,
82                                         Offset (span_points.length (), 0),
83                                         height,
84                                         Interval (),
85                                         flare, shorten);
86     }
87   m.translate_axis (span_points[LEFT]
88                     - me->relative_coordinate (common, X_AXIS), X_AXIS);
89   return m.smobbed_copy ();
90 }
91
92 ADD_INTERFACE (Piano_pedal_bracket,
93                "The bracket of the piano pedal.  It can be tuned through"
94                " the regular bracket properties.",
95
96                /* properties */
97                "bound-padding "
98                "edge-height "
99                "shorten-pair "
100                "bracket-flare "
101                "pedal-text "
102                );