]> git.donarmstrong.com Git - lilypond.git/blob - lily/piano-pedal-bracket.cc
89a97fb4e33102e288512ff3b282d6db634afc7e
[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 #include "axis-group-interface.hh"
25
26 struct Piano_pedal_bracket
27 {
28   DECLARE_SCHEME_CALLBACK (print, (SCM));
29   DECLARE_GROB_INTERFACE ();
30 };
31
32 MAKE_SCHEME_CALLBACK (Piano_pedal_bracket, print, 1);
33 SCM
34 Piano_pedal_bracket::print (SCM smob)
35 {
36   Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (smob));
37   Spanner *orig = dynamic_cast<Spanner *> (me->original ());
38
39   Drul_array<bool> broken (false, false);
40   Drul_array<Real> height = robust_scm2drul
41                             (me->get_property ("edge-height"), Interval (0, 0));
42   Drul_array<Real> shorten = robust_scm2drul
43                              (me->get_property ("shorten-pair"), Interval (0, 0));
44   Drul_array<Real> flare = robust_scm2drul
45                            (me->get_property ("bracket-flare"), Interval (0, 0));
46
47   Grob *common = me->get_bound (LEFT)
48                  ->common_refpoint (me->get_bound (RIGHT), X_AXIS);
49   Grob *textbit = unsmob_grob (me->get_object ("pedal-text"));
50
51   if (textbit)
52     common = common->common_refpoint (textbit, X_AXIS);
53
54   Interval span_points (0, 0);
55   for (LEFT_and_RIGHT (d))
56     {
57       Item *b = me->get_bound (d);
58       broken[d] = b->break_status_dir () != CENTER;
59       if (broken[d])
60         {
61           if (orig
62               && ((d == RIGHT
63                    && me->get_break_index () != orig->broken_intos_.size () - 1)
64                   || (d == LEFT && me->get_break_index ())))
65             height[d] = 0.0;
66           else
67             flare[d] = 0.0;
68
69           span_points[d]
70             = Axis_group_interface::generic_bound_extent (b, common, X_AXIS)[RIGHT];
71         }
72       else
73         span_points[d] = b->relative_coordinate (common, X_AXIS);
74     }
75
76   /* For 'Mixed' style pedals, i.e.  a bracket preceded by text:  Ped._____|
77      need to shorten by the extent of the text grob
78   */
79   if (textbit)
80     {
81       height[LEFT] = 0;
82
83       Real padding = robust_scm2double (me->get_property ("bound-padding"), 0);
84
85       span_points[LEFT] = padding
86                           + robust_relative_extent (textbit, common, X_AXIS)[RIGHT];
87     }
88
89   Stencil m;
90   if (!span_points.is_empty ()
91       && span_points.length () > 0.001)
92     {
93       m = Tuplet_bracket::make_bracket (me, Y_AXIS,
94                                         Offset (span_points.length (), 0),
95                                         height,
96                                         Interval (),
97                                         flare, shorten);
98     }
99   m.translate_axis (span_points[LEFT]
100                     - me->relative_coordinate (common, X_AXIS), X_AXIS);
101   return m.smobbed_copy ();
102 }
103
104 ADD_INTERFACE (Piano_pedal_bracket,
105                "The bracket of the piano pedal.  It can be tuned through"
106                " the regular bracket properties.",
107
108                /* properties */
109                "bound-padding "
110                "edge-height "
111                "shorten-pair "
112                "bracket-flare "
113                "pedal-text "
114               );