]> git.donarmstrong.com Git - lilypond.git/blob - lily/piano-pedal-bracket.cc
Web-ja: update introduction
[lilypond.git] / lily / piano-pedal-bracket.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2003--2015 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 "bracket.hh"
24 #include "axis-group-interface.hh"
25
26 struct Piano_pedal_bracket
27 {
28   DECLARE_SCHEME_CALLBACK (print, (SCM));
29 };
30
31 MAKE_SCHEME_CALLBACK (Piano_pedal_bracket, print, 1);
32 SCM
33 Piano_pedal_bracket::print (SCM smob)
34 {
35   Spanner *me = unsmob<Spanner> (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]
69             = Axis_group_interface::generic_bound_extent (b, common, X_AXIS)[RIGHT];
70         }
71       else
72         span_points[d] = b->relative_coordinate (common, X_AXIS);
73     }
74
75   /* For 'Mixed' style pedals, i.e.  a bracket preceded by text:  Ped._____|
76      need to shorten by the extent of the text grob
77   */
78   if (textbit)
79     {
80       height[LEFT] = 0;
81
82       Real padding = robust_scm2double (me->get_property ("bound-padding"), 0);
83
84       span_points[LEFT] = padding
85                           + robust_relative_extent (textbit, common, X_AXIS)[RIGHT];
86     }
87
88   Stencil m;
89   if (!span_points.is_empty ()
90       && span_points.length () > 0.001)
91     {
92       m = Bracket::make_bracket (
93         me, Y_AXIS, Offset (span_points.length (), 0), height,
94         Interval (), flare, shorten);
95     }
96   m.translate_axis (span_points[LEFT]
97                     - me->relative_coordinate (common, X_AXIS), X_AXIS);
98   return m.smobbed_copy ();
99 }
100
101 ADD_INTERFACE (Piano_pedal_bracket,
102                "The bracket of the piano pedal.  It can be tuned through"
103                " the regular bracket properties.",
104
105                /* properties */
106                "bound-padding "
107                "edge-height "
108                "shorten-pair "
109                "bracket-flare "
110                "pedal-text "
111               );