]> git.donarmstrong.com Git - lilypond.git/blob - lily/piano-pedal-bracket.cc
Merge branch 'Paco' into staging
[lilypond.git] / lily / piano-pedal-bracket.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2003--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "stencil.hh"
21 #include "spanner.hh"
22 #include "item.hh"
23 #include "tuplet-bracket.hh"
24
25 struct Piano_pedal_bracket
26 {
27   DECLARE_SCHEME_CALLBACK (print, (SCM));
28   DECLARE_GROB_INTERFACE ();
29 };
30
31 MAKE_SCHEME_CALLBACK (Piano_pedal_bracket, print, 1);
32 SCM
33 Piano_pedal_bracket::print (SCM smob)
34 {
35   Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (smob));
36   Spanner *orig = dynamic_cast<Spanner *> (me->original ());
37
38   Drul_array<bool> broken (false, false);
39   Drul_array<Real> height = robust_scm2drul
40                             (me->get_property ("edge-height"), Interval (0, 0));
41   Drul_array<Real> shorten = robust_scm2drul
42                              (me->get_property ("shorten-pair"), Interval (0, 0));
43   Drul_array<Real> flare = robust_scm2drul
44                            (me->get_property ("bracket-flare"), Interval (0, 0));
45
46   Grob *common = me->get_bound (LEFT)
47                  ->common_refpoint (me->get_bound (RIGHT), X_AXIS);
48   Grob *textbit = unsmob_grob (me->get_object ("pedal-text"));
49
50   if (textbit)
51     common = common->common_refpoint (textbit, X_AXIS);
52
53   Interval span_points (0, 0);
54   for (LEFT_and_RIGHT (d))
55     {
56       Item *b = me->get_bound (d);
57       broken[d] = b->break_status_dir () != CENTER;
58       if (broken[d])
59         {
60           if (orig
61               && ((d == RIGHT
62                    && me->get_break_index () != orig->broken_intos_.size () - 1)
63                   || (d == LEFT && me->get_break_index ())))
64             height[d] = 0.0;
65           else
66             flare[d] = 0.0;
67
68           span_points[d] = robust_relative_extent (b, common, X_AXIS)[RIGHT];
69         }
70       else
71         span_points[d] = b->relative_coordinate (common, X_AXIS);
72     }
73
74   /* For 'Mixed' style pedals, i.e.  a bracket preceded by text:  Ped._____|
75      need to shorten by the extent of the text grob
76   */
77   if (textbit)
78     {
79       height[LEFT] = 0;
80
81       Real padding = robust_scm2double (me->get_property ("bound-padding"), 0);
82
83       span_points[LEFT] = padding
84                           + robust_relative_extent (textbit, common, X_AXIS)[RIGHT];
85     }
86
87   Stencil m;
88   if (!span_points.is_empty ()
89       && span_points.length () > 0.001)
90     {
91       m = Tuplet_bracket::make_bracket (me, Y_AXIS,
92                                         Offset (span_points.length (), 0),
93                                         height,
94                                         Interval (),
95                                         flare, shorten);
96     }
97   m.translate_axis (span_points[LEFT]
98                     - me->relative_coordinate (common, X_AXIS), X_AXIS);
99   return m.smobbed_copy ();
100 }
101
102 ADD_INTERFACE (Piano_pedal_bracket,
103                "The bracket of the piano pedal.  It can be tuned through"
104                " the regular bracket properties.",
105
106                /* properties */
107                "bound-padding "
108                "edge-height "
109                "shorten-pair "
110                "bracket-flare "
111                "pedal-text "
112               );