]> git.donarmstrong.com Git - lilypond.git/blob - lily/ottava-bracket.cc
apply Julian's patch to fix install-info warnings
[lilypond.git] / lily / ottava-bracket.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2004--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 "text-interface.hh"
21 #include "spanner.hh"
22 #include "font-interface.hh"
23 #include "dimensions.hh"
24 #include "output-def.hh"
25 #include "warn.hh"
26 #include "paper-column.hh"
27 #include "staff-symbol-referencer.hh"
28 #include "note-column.hh"
29 #include "directional-element-interface.hh"
30 #include "tuplet-bracket.hh"
31 #include "rhythmic-head.hh"
32 #include "pointer-group-interface.hh"
33
34 struct Ottava_bracket
35 {
36   DECLARE_SCHEME_CALLBACK (print, (SCM));
37   DECLARE_GROB_INTERFACE ();
38 };
39
40 /*
41   TODO: the string for ottava shoudl depend on the available space, ie.
42
43   Long: 15ma        Short: 15ma    Empty: 15
44   8va                8va            8
45   8va bassa          8ba            8
46 */
47 MAKE_SCHEME_CALLBACK (Ottava_bracket, print, 1);
48 SCM
49 Ottava_bracket::print (SCM smob)
50 {
51   Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (smob));
52   Interval span_points;
53
54   Grob *common = me->get_bound (LEFT)->common_refpoint (me->get_bound (RIGHT), X_AXIS);
55   Output_def *layout = me->layout ();
56
57   Drul_array<bool> broken;
58   Direction d = LEFT;
59   do
60     {
61       Item *b = me->get_bound (d);
62       broken[d] = (b->break_status_dir () != CENTER);
63
64       if (Note_column::has_interface (b))
65         {
66           extract_grob_set (b, "note-heads", heads);
67           common = common_refpoint_of_array (heads, common, X_AXIS);
68           for (vsize i = 0; i < heads.size (); i++)
69             {
70               Grob *h = heads[i];
71               Grob *dots = Rhythmic_head::get_dots (h);
72               if (dots)
73                 common = dots->common_refpoint (common, X_AXIS);
74             }
75         }
76     }
77   while (flip (&d) != LEFT);
78
79   SCM properties = Font_interface::text_font_alist_chain (me);
80   SCM markup = me->get_property ("text");
81   Stencil text;
82   if (Text_interface::is_markup (markup))
83     text = *unsmob_stencil (Text_interface::interpret_markup (layout->self_scm (),
84                                                               properties, markup));
85
86   Drul_array<Real> shorten = robust_scm2interval (me->get_property ("shorten-pair"),
87                                                   Interval (0, 0));
88
89   /*
90     TODO: we should check if there are ledgers, and modify length of
91     the spanner to that.
92   */
93   do
94     {
95       Item *b = me->get_bound (d);
96
97       Interval ext;
98       if (Note_column::has_interface (b))
99         {
100           extract_grob_set (b, "note-heads", heads);
101           for (vsize i = 0; i < heads.size (); i++)
102             {
103               Grob *h = heads[i];
104               ext.unite (h->extent (common, X_AXIS));
105               Grob *dots = Rhythmic_head::get_dots (h);
106
107               if (dots && d == RIGHT)
108                 ext.unite (dots->extent (common, X_AXIS));
109             }
110         }
111
112       if (ext.is_empty ())
113         ext = robust_relative_extent (b, common, X_AXIS);
114
115       if (broken[d])
116         {
117           span_points[d] = b->extent (common, X_AXIS)[RIGHT];
118           shorten[d] = 0.;
119         }
120
121       else
122         span_points[d] = ext[d];
123     }
124   while (flip (&d) != LEFT);
125
126   /*
127     0.3 is ~ italic correction.
128   */
129   Real text_size = text.extent (X_AXIS).is_empty ()
130     ? 0.0 : text.extent (X_AXIS)[RIGHT] + 0.3;
131
132   span_points[LEFT]
133     = min (span_points[LEFT],
134            (span_points[RIGHT] - text_size
135             - robust_scm2double (me->get_property ("minimum-length"), -1.0)));
136
137   Interval bracket_span_points = span_points;
138   bracket_span_points[LEFT] += text_size;
139
140   Drul_array<Real> edge_height = robust_scm2interval (me->get_property ("edge-height"),
141                                                       Interval (1.0, 1.0));
142
143   Drul_array<Real> flare = robust_scm2interval (me->get_property ("bracket-flare"),
144                                                 Interval (0, 0));
145
146   do
147     {
148       edge_height[d] *= -get_grob_direction (me);
149       if (broken[d])
150         edge_height[d] = 0.0;
151     }
152   while (flip(&d) != LEFT);
153
154   Stencil b;
155   Interval empty;
156   if (!bracket_span_points.is_empty () && bracket_span_points.length () > 0.001)
157     b = Tuplet_bracket::make_bracket (me,
158                                       Y_AXIS, Offset (bracket_span_points.length (), 0),
159                                       edge_height,
160                                       empty,
161                                       flare, shorten);
162
163   /*
164     The vertical lines should not take space, for the following scenario:
165
166     8 -----+
167     o  |
168     |
169     |
170
171
172     Just a small amount, yes.  In tight situations, it is even
173     possible to center the `8' directly below the note, dropping the
174     ottava line completely...
175
176   */
177
178   b = Stencil (Box (b.extent (X_AXIS),
179                     Interval (0.1, 0.1)),
180                b.expr ());
181
182   b.translate_axis (bracket_span_points[LEFT], X_AXIS);
183   text.translate_axis (span_points[LEFT], X_AXIS);
184   text.align_to (Y_AXIS, CENTER);
185   b.add_stencil (text);
186
187   b.translate_axis (- me->relative_coordinate (common, X_AXIS), X_AXIS);
188
189   return b.smobbed_copy ();
190 }
191
192 ADD_INTERFACE (Ottava_bracket,
193                "An ottava bracket.",
194
195                /* properties */
196                "edge-height "
197                "bracket-flare "
198                "shorten-pair "
199                "minimum-length "
200                );
201