]> git.donarmstrong.com Git - lilypond.git/blob - lily/horizontal-bracket.cc
Merge branch 'master' into lilypond/translation
[lilypond.git] / lily / horizontal-bracket.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2002--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
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.
10
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.
15
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/>.
18 */
19
20 #include "horizontal-bracket.hh"
21
22 #include "lookup.hh"
23 #include "side-position-interface.hh"
24 #include "pointer-group-interface.hh"
25 #include "directional-element-interface.hh"
26 #include "output-def.hh"
27 #include "staff-symbol-referencer.hh"
28 #include "tuplet-bracket.hh"
29 #include "axis-group-interface.hh"
30 #include "spanner.hh"
31 #include "item.hh"
32
33 Stencil
34 Horizontal_bracket::make_bracket (Grob *me,
35                                   Real length,
36                                   Axis a, Direction dir)
37 {
38   Drul_array<Real> edge_height = robust_scm2interval (me->get_property ("edge-height"),
39                                                       Interval (1.0, 1.0));
40   Drul_array<Real> flare = robust_scm2interval (me->get_property ("bracket-flare"),
41                                                 Interval (0, 0));
42   Drul_array<Real> shorten = robust_scm2interval (me->get_property ("shorten-pair"),
43                                                   Interval (0, 0));
44
45   // Make sure that it points in the correct direction:
46   scale_drul (&edge_height, Real (-dir));
47
48   Interval empty;
49   Offset start;
50   start[a] = length;
51
52   Drul_array<bool> connect_to_other
53     = robust_scm2booldrul (me->get_property ("connect-to-neighbor"),
54                            Drul_array<bool> (false, false));
55
56   Direction d = LEFT;
57   do
58     {
59       if (connect_to_other[d])
60         {
61           edge_height[d] = 0.0;
62           flare[d] = 0.0;
63           shorten[d] = 0.0;
64         }
65     }
66   while (flip (&d) != LEFT);
67
68   /*
69     ugh, Tuplet_bracket should use Horizontal_bracket, not the other way around.
70   */
71   return Tuplet_bracket::make_bracket (me, other_axis (a), start,
72                                        edge_height, empty, flare, shorten);
73 }
74
75 Stencil
76 Horizontal_bracket::make_enclosing_bracket (Grob *me, Grob *refpoint,
77                                             vector<Grob *> grobs,
78                                             Axis a, Direction dir)
79 {
80   Grob *common = common_refpoint_of_array (grobs, refpoint, a);
81   Interval ext = Axis_group_interface::relative_group_extent (grobs, common, a);
82
83   if (ext.is_empty ())
84     {
85       me->programming_error ("Can't enclose empty extents with bracket");
86       return Stencil ();
87     }
88   else
89     {
90       Stencil b = make_bracket (me, ext.length (), a, dir);
91       b.translate_axis (ext[LEFT] - refpoint->relative_coordinate (common, a), a);
92
93       return b;
94     }
95 }
96
97 /*
98   TODO:
99
100   Support texts on the brackets?
101 */
102 MAKE_SCHEME_CALLBACK (Horizontal_bracket, print, 1);
103 SCM
104 Horizontal_bracket::print (SCM smob)
105 {
106   Spanner *me = unsmob_spanner (smob);
107   extract_grob_set (me, "columns", gs);
108
109   vector<Grob *> enclosed = gs;
110   if (!gs.size ())
111     {
112       me->suicide ();
113       return SCM_EOL;
114     }
115
116   Direction d = LEFT;
117   do
118     {
119       Item *b = me->get_bound (d);
120       if (b->break_status_dir ())
121         enclosed.push_back (b);
122     }
123   while (flip (&d) != LEFT);
124
125   Stencil b = make_enclosing_bracket (me, me, enclosed, X_AXIS, get_grob_direction (me));
126   return b.smobbed_copy ();
127 }
128
129 ADD_INTERFACE (Horizontal_bracket,
130                "A horizontal bracket encompassing notes.",
131
132                /* properties */
133                "bracket-flare "
134                "columns "
135                "edge-height "
136                "shorten-pair "
137                "connect-to-neighbor "
138               );
139