Fixes Issue 1504, allowing feather beam line breaking.
[lilypond/patrick.git] / lily / piano-pedal-bracket.cc
blob40ebbaef7df5a7b638286cff96f2b10a8c654086
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2003--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
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.
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.
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/>.
20 #include "stencil.hh"
21 #include "spanner.hh"
22 #include "item.hh"
23 #include "tuplet-bracket.hh"
25 struct Piano_pedal_bracket
27 DECLARE_SCHEME_CALLBACK (print, (SCM));
28 DECLARE_GROB_INTERFACE ();
31 MAKE_SCHEME_CALLBACK (Piano_pedal_bracket, print, 1);
32 SCM
33 Piano_pedal_bracket::print (SCM smob)
35 Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (smob));
36 Spanner *orig = dynamic_cast<Spanner *> (me->original ());
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));
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"));
50 if (textbit)
51 common = common->common_refpoint (textbit, X_AXIS);
53 Interval span_points (0, 0);
54 Direction d = LEFT;
57 Item *b = me->get_bound (d);
58 broken[d] = b->break_status_dir () != CENTER;
59 if (broken[d])
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;
70 Interval ext = robust_relative_extent (b, common, X_AXIS);
71 span_points[d] = ext [broken[d] ? RIGHT : LEFT];
73 while (flip (&d) != LEFT);
75 /* For 'Mixed' style pedals, i.e. a bracket preceded by text: Ped._____|
76 need to shorten by the extent of the text grob
78 if (textbit)
80 height[LEFT] = 0;
82 Real padding = robust_scm2double (me->get_property ("bound-padding"), 0);
84 span_points[LEFT] = padding
85 + robust_relative_extent (textbit, common, X_AXIS)[RIGHT];
88 Stencil m;
89 if (!span_points.is_empty ()
90 && span_points.length () > 0.001)
92 m = Tuplet_bracket::make_bracket (me, Y_AXIS,
93 Offset (span_points.length (), 0),
94 height,
95 Interval (),
96 flare, shorten);
98 m.translate_axis (span_points[LEFT]
99 - me->relative_coordinate (common, X_AXIS), X_AXIS);
100 return m.smobbed_copy ();
103 ADD_INTERFACE (Piano_pedal_bracket,
104 "The bracket of the piano pedal. It can be tuned through"
105 " the regular bracket properties.",
107 /* properties */
108 "bound-padding "
109 "edge-height "
110 "shorten-pair "
111 "bracket-flare "
112 "pedal-text "