Workaround for broken MusicXML files (percussion clef in MuseScore)
[lilypond.git] / lily / horizontal-bracket.cc
blobc5594359a1a5415ba6b374c862dadc1f79ed9a64
1 /*
2 horizontal-bracket.cc -- implement Horizontal_bracket
4 source file of the GNU LilyPond music typesetter
6 (c) 2002--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "horizontal-bracket.hh"
11 #include "lookup.hh"
12 #include "side-position-interface.hh"
13 #include "pointer-group-interface.hh"
14 #include "directional-element-interface.hh"
15 #include "output-def.hh"
16 #include "staff-symbol-referencer.hh"
17 #include "tuplet-bracket.hh"
18 #include "axis-group-interface.hh"
19 #include "spanner.hh"
20 #include "item.hh"
23 Stencil
24 Horizontal_bracket::make_bracket (Grob *me,
25 Real length,
26 Axis a, Direction dir)
28 Drul_array<Real> edge_height = robust_scm2interval (me->get_property ("edge-height"),
29 Interval (1.0, 1.0));
30 Drul_array<Real> flare = robust_scm2interval (me->get_property ("bracket-flare"),
31 Interval (0, 0));
32 Drul_array<Real> shorten = robust_scm2interval (me->get_property ("shorten-pair"),
33 Interval (0, 0));
36 // Make sure that it points in the correct direction:
37 scale_drul (&edge_height, Real (-dir));
39 Interval empty;
40 Offset start;
41 start[a] = length;
43 Drul_array<bool> connect_to_other =
44 robust_scm2booldrul (me->get_property ("connect-to-neighbor"),
45 Drul_array<bool> (false, false));
47 Direction d = LEFT;
50 if (connect_to_other[d])
52 edge_height[d] = 0.0;
53 flare[d] = 0.0;
54 shorten[d] = 0.0;
57 while (flip (&d) != LEFT);
60 ugh, Tuplet_bracket should use Horizontal_bracket, not the other way around.
62 return Tuplet_bracket::make_bracket (me, other_axis (a), start,
63 edge_height, empty, flare, shorten);
67 Stencil
68 Horizontal_bracket::make_enclosing_bracket (Grob *me, Grob *refpoint,
69 vector<Grob*> grobs,
70 Axis a, Direction dir)
72 Grob *common = common_refpoint_of_array (grobs, refpoint, a);
73 Interval ext = Axis_group_interface::relative_group_extent (grobs, common, a);
75 if (ext.is_empty ())
77 me->programming_error ("Can't enclose empty extents with bracket");
78 return Stencil ();
80 else
82 Stencil b = make_bracket (me, ext.length (), a, dir);
83 b.translate_axis (ext[LEFT] - refpoint->relative_coordinate (common, a), a);
85 return b;
90 TODO:
92 Support texts on the brackets?
94 MAKE_SCHEME_CALLBACK (Horizontal_bracket, print, 1);
95 SCM
96 Horizontal_bracket::print (SCM smob)
98 Spanner *me = unsmob_spanner (smob);
99 extract_grob_set (me, "columns", gs);
101 vector<Grob*> enclosed = gs;
102 if (!gs.size ())
104 me->suicide ();
105 return SCM_EOL;
108 Direction d = LEFT;
111 Item *b = me->get_bound (d);
112 if (b->break_status_dir ())
113 enclosed.push_back (b);
115 while (flip (&d) != LEFT);
117 Stencil b = make_enclosing_bracket (me, me, enclosed, X_AXIS, get_grob_direction (me));
118 return b.smobbed_copy ();
121 ADD_INTERFACE (Horizontal_bracket,
122 "A horizontal bracket encompassing notes.",
124 /* properties */
125 "bracket-flare "
126 "columns "
127 "edge-height "
128 "shorten-pair "
129 "connect-to-neighbor "