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