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