]> git.donarmstrong.com Git - lilypond.git/blob - lily/piano-pedal-bracket.cc
cleanup. Separate into internal
[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--2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
7
8 */
9
10 #include "molecule.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   
28   Drul_array<bool> broken (false,false);
29   Drul_array<Real> height = robust_scm2drul
30     (me->get_grob_property ("edge-height"), Interval (0,0));
31   Drul_array<Real> shorten = robust_scm2drul
32     (me->get_grob_property ("shorten-pair"), Interval (0,0));
33   Drul_array<Real> flare = robust_scm2drul
34     (me->get_grob_property ("bracket-flare"), Interval (0,0));
35
36   Grob *common = me->get_bound (LEFT)
37     ->common_refpoint (me->get_bound (RIGHT), X_AXIS);
38   Grob *textbit = unsmob_grob (me->get_grob_property("pedal-text"));
39
40   if (textbit)
41     common = common->common_refpoint (textbit, X_AXIS);
42
43   Interval span_points (0,0);
44   Direction d = LEFT;
45   do
46     {
47       Item *b = me->get_bound (d);
48       broken[d] = b->break_status_dir () != CENTER;
49       if (broken[d])
50         height[d] = 0.0;
51
52       Interval ext   = b->extent (common,  X_AXIS);
53       span_points[d] = ext [broken[d] ?  RIGHT : LEFT];
54     }
55   while (flip (&d) != LEFT);
56
57   
58   /* For 'Mixed' style pedals, i.e.  a bracket preceded by text:  Ped._____|
59    need to shorten by the extent of the text grob
60   */
61   if (textbit)
62     {
63       height[LEFT] = 0;
64       
65       Real padding = robust_scm2double (me->get_grob_property ("if-text-padding"), 0);
66       
67       span_points[LEFT] = padding
68         + textbit->extent (common, X_AXIS)[RIGHT];
69     }
70   
71
72   Molecule m ;
73   if (!span_points.is_empty () &&
74       span_points.length () > 0.001)
75     {
76       m = Tuplet_bracket::make_bracket (me, Y_AXIS,
77                                         Offset (span_points.length (), 0),
78                                         height,
79                                         0.0,
80                                         flare, shorten);
81     }
82   m.translate_axis (span_points[LEFT]
83                     - me->relative_coordinate (common, X_AXIS), X_AXIS);
84   return m.smobbed_copy ();
85 }
86
87
88
89 ADD_INTERFACE (Piano_pedal_bracket,"piano-pedal-bracket-interface",
90                "The bracket of the piano pedal.  It can be tuned through the regular bracket properties (bracket-flare, edge-height, shorten-pair).",
91                "edge-height shorten-pair bracket-flare pedal-text");