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