* lily/text-spanner.cc (brew_molecule): use bracket-flare
[lilypond.git] / lily / piano-pedal-bracket.cc
blob1289dd90579f2afae76599a042a98d159c5ae8c7
1 /*
2 piano-pedal-bracket.cc -- implement Piano_pedal_bracket
4 source file of the GNU LilyPond music typesetter
6 (c) 2003 Han-Wen Nienhuys <hanwen@xs4all.nl>
8 based on smouldering remains by
10 Chris Jackson <chris@fluffhouse.org.uk>
14 /*
15 Piano pedal brackets are a special case of a text spanner.
16 Pedal up-down (restart) indicated by the angled right and left edges
17 of consecutive pedals touching exactly to form an __/\__
23 TODO: this should be moved somewhere else (?).
25 Perhaps make separate function for pedal-bracket.
27 #include "molecule.hh"
28 #include "spanner.hh"
29 #include "item.hh"
30 #include "paper-def.hh"
32 struct Piano_pedal_bracket
34 DECLARE_SCHEME_CALLBACK(after_line_breaking,(SCM));
35 static bool has_interface (Grob*);
38 ADD_INTERFACE (Piano_pedal_bracket,"piano-pedal-bracket-interface",
39 "",
40 "pedal-text");
42 MAKE_SCHEME_CALLBACK(Piano_pedal_bracket,after_line_breaking,1);
43 SCM
44 Piano_pedal_bracket::after_line_breaking (SCM smob)
46 Spanner *me = dynamic_cast<Spanner*> (unsmob_grob (smob));
48 Drul_array<bool> broken;
49 Drul_array<Real> height(0,0), shorten(0,0);
51 SCM eh = me->get_grob_property ("edge-height");
52 SCM sp = me->get_grob_property ("shorten-pair");
54 Direction d = LEFT;
58 Item *b = me->get_bound (d);
59 broken[d] = b->break_status_dir () != CENTER;
61 if (!broken[d] && (ly_number_pair_p (eh)))
62 height[d] += gh_scm2double (index_get_cell (eh, d));
63 if (ly_number_pair_p (sp))
64 shorten[d] += gh_scm2double (index_get_cell (sp, d));
66 while (flip (&d) != LEFT);
68 /* For 'Mixed' style pedals, i.e. a bracket preceded by text: Ped._____|
69 need to shorten by the extent of the text grob
72 Urg. - why not hang bracket between text items? --hwn
74 if (Grob *textbit = unsmob_grob (me->get_grob_property("pedal-text")))
76 height[LEFT] = 0;
77 SCM pa = me->get_grob_property ("if-text-padding"); // UGH.
78 Real padding =0.;
79 if (gh_number_p (pa))
80 padding = gh_scm2double (pa);
82 shorten[LEFT] += padding + textbit->extent (textbit, X_AXIS)[RIGHT];
85 if (broken[LEFT])
87 shorten[LEFT] -= me->get_broken_left_end_align () ;
90 // Also shorten so that it ends just before the spanned note.
91 Grob *rb = me->get_bound (RIGHT);
92 shorten[RIGHT] += rb->extent (rb, X_AXIS)[RIGHT];
94 me->set_grob_property ("edge-height", ly_interval2scm (height));
95 me->set_grob_property ("shorten-pair", ly_interval2scm (shorten));
97 return SCM_UNSPECIFIED;