]> git.donarmstrong.com Git - lilypond.git/blob - lily/volta-bracket.cc
7b0fd1341179b4cddc88e5293933debdcb4eb6b6
[lilypond.git] / lily / volta-bracket.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2012 Jan Nieuwenhuizen <janneke@gnu.org>
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 <cstring>
21 using namespace std;
22
23 #include "warn.hh"
24 #include "font-interface.hh"
25 #include "line-interface.hh"
26 #include "paper-column.hh"
27 #include "output-def.hh"
28 #include "text-interface.hh"
29 #include "volta-bracket.hh"
30 #include "pointer-group-interface.hh"
31 #include "side-position-interface.hh"
32 #include "directional-element-interface.hh"
33 #include "lookup.hh"
34 #include "tuplet-bracket.hh"
35
36 /*
37   this is too complicated. Yet another version of side-positioning,
38   badly implemented.
39
40   --
41
42   * Should look for system_start_delim to find left edge of staff.
43   */
44
45 MAKE_SCHEME_CALLBACK (Volta_bracket_interface, print, 1);
46 SCM
47 Volta_bracket_interface::print (SCM smob)
48 {
49   Spanner *me = unsmob_spanner (smob);
50   Spanner *orig_span = dynamic_cast<Spanner *> (me->original ());
51   bool broken_first_bracket = orig_span && (orig_span->broken_intos_[0]
52                                             == (Spanner *)me);
53
54   Output_def *layout = me->layout ();
55
56   Item *bound = dynamic_cast<Spanner *> (me)->get_bound (LEFT);
57
58   /*
59     If the volta bracket appears after a line-break, make
60     it start after the prefatory matter.
61   */
62   Real left = 0.;
63   if (bound->break_status_dir () == RIGHT)
64     {
65       Paper_column *pc = bound->get_column ();
66       left = pc->break_align_width (pc, ly_symbol2scm ("break-alignment"))[RIGHT]
67              // For some reason, break_align_width is relative to
68              // the x-parent of the column.
69              - bound->relative_coordinate (pc->get_parent (X_AXIS), X_AXIS);
70     }
71   else
72     {
73       /*
74         the volta spanner is attached to the bar-line, which is moved
75         to the right. We don't need to compensate for the left edge.
76       */
77     }
78
79   modify_edge_height (me);
80   if (!me->is_live ())
81     return SCM_EOL;
82
83   Drul_array<Real> edge_height = robust_scm2interval (me->get_property ("edge-height"),
84                                                       Interval (1.0, 1.0));
85   Drul_array<Real> flare = robust_scm2interval (me->get_property ("bracket-flare"),
86                                                 Interval (0, 0));
87   Drul_array<Real> shorten = robust_scm2interval (me->get_property ("shorten-pair"),
88                                                   Interval (0, 0));
89
90   scale_drul (&edge_height, - Real (get_grob_direction (me)));
91
92   Interval empty;
93   Offset start;
94   start[X_AXIS] = me->spanner_length () - left;
95
96   /*
97     ugh, Tuplet_bracket should use Horizontal_bracket, not the other way around.
98   */
99   Stencil total
100     = Tuplet_bracket::make_bracket (me, Y_AXIS, start,
101                                     edge_height, empty, flare, shorten);
102
103   if (!orig_span || broken_first_bracket)
104     {
105       SCM text = me->get_property ("text");
106       SCM properties = me->get_property_alist_chain (SCM_EOL);
107       SCM snum = Text_interface::interpret_markup (layout->self_scm (),
108                                                    properties, text);
109       Stencil num = *unsmob_stencil (snum);
110       num.align_to (Y_AXIS, UP);
111       num.translate_axis (-0.5, Y_AXIS);
112       total.add_at_edge (X_AXIS, LEFT, num, - num.extent (X_AXIS).length ()
113                          - 1.0);
114     }
115
116   total.translate_axis (left, X_AXIS);
117   return total.smobbed_copy ();
118 }
119
120 void
121 Volta_bracket_interface::modify_edge_height (Spanner *me)
122 {
123   Spanner *orig_span = dynamic_cast<Spanner *> (me->original ());
124
125   bool broken_first_bracket = orig_span && (orig_span->broken_intos_[0] == (Spanner *)me);
126   bool broken_last_bracket = orig_span && (orig_span->broken_intos_.back () == (Spanner *)me);
127   bool no_vertical_start = orig_span && !broken_first_bracket;
128   bool no_vertical_end = orig_span && !broken_last_bracket;
129
130   extract_grob_set (me, "bars", bars);
131   Grob *endbar = bars.size () ? bars.back () : 0;
132   SCM glyph = endbar ? endbar->get_property ("glyph-name") : SCM_EOL;
133
134   string str;
135   if (scm_is_string (glyph))
136     str = ly_scm2string (glyph);
137   else
138     str = "|";
139
140   no_vertical_end |= ly_scm2bool (scm_call_1 (ly_lily_module_constant ("volta-bracket::calc-hook-visibility"),
141                                              ly_string2scm (str)));
142
143   if (no_vertical_end || no_vertical_start)
144     {
145       Drul_array<Real> edge_height = robust_scm2interval (me->get_property ("edge-height"),
146                                                           Interval (1.0, 1.0));
147       if (no_vertical_start)
148         edge_height[LEFT] = 0.0;
149
150       if (no_vertical_end)
151         edge_height[RIGHT] = 0.0;
152
153       me->set_property ("edge-height", ly_interval2scm (edge_height));
154     }
155
156   if (broken_last_bracket && no_vertical_end && no_vertical_start
157       && !broken_first_bracket)
158     me->suicide ();
159 }
160
161 void
162 Volta_bracket_interface::add_bar (Grob *me, Item *b)
163 {
164   Pointer_group_interface::add_grob (me, ly_symbol2scm ("bars"), b);
165   add_bound_item (dynamic_cast<Spanner *> (me), b);
166 }
167
168 ADD_INTERFACE (Volta_bracket_interface,
169                "Volta bracket with number.",
170
171                /* properties */
172                "bars "
173                "thickness "
174                "height "
175                "shorten-pair "
176               );
177