]> git.donarmstrong.com Git - lilypond.git/blob - lily/volta-bracket.cc
* lily/volta-bracket.cc (modify_edge_height): change from
[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--2006 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   scale_drul (&edge_height, - Real (get_grob_direction (me)));
78
79   Interval empty;
80   Offset start;
81   start[X_AXIS] = me->spanner_length () - left - half_space;
82   
83   /*
84     ugh, Tuplet_bracket should use Horizontal_bracket, not the other way around. 
85   */
86   Stencil total
87     = Tuplet_bracket::make_bracket (me, Y_AXIS, start, 
88                                     edge_height, empty, flare, shorten);
89
90   if (!orig_span || broken_first_bracket)
91     {
92       SCM text = me->get_property ("text");
93       SCM properties = me->get_property_alist_chain (SCM_EOL);
94       SCM snum = Text_interface::interpret_markup (layout->self_scm (),
95                                                    properties, text);
96       Stencil num = *unsmob_stencil (snum);
97       num.align_to (Y_AXIS, UP);
98       num.translate_axis (-0.5, Y_AXIS);
99       total.add_at_edge (X_AXIS, LEFT, num, - num.extent (X_AXIS).length ()
100                          - 1.0, 0);
101     }
102   
103   total.translate_axis (left, X_AXIS);
104   return total.smobbed_copy ();
105 }
106
107
108 void
109 Volta_bracket_interface::modify_edge_height (Spanner *me)
110 {
111   Spanner *orig_span = dynamic_cast<Spanner *> (me->original ());
112  
113   bool broken_first_bracket = orig_span && (orig_span->broken_intos_[0] == (Spanner *)me);
114   bool broken_last_bracket = orig_span && (orig_span->broken_intos_.back () == (Spanner *)me);
115   bool no_vertical_start = orig_span && !broken_first_bracket;
116   bool no_vertical_end = orig_span && !broken_last_bracket;
117
118   extract_grob_set (me, "bars", bars);
119   Grob *endbar = bars.size () ? bars.back () : 0;
120   SCM glyph = endbar ? endbar->get_property ("glyph") : SCM_EOL;
121
122   string str;
123   if (scm_is_string (glyph))
124     str = ly_scm2string (glyph);
125   else
126     str = "|";
127
128   no_vertical_end
129     |= (str != ":|"
130         && str != "|:"
131         && str != "|."
132         && str != ":|:"
133         && str != ".|");
134
135   if (no_vertical_end || no_vertical_start)
136     {
137       Drul_array<Real> edge_height = robust_scm2interval (me->get_property ("edge-height"),
138                                                           Interval (1.0, 1.0));
139       if (no_vertical_start)
140         edge_height[LEFT] = 0.0;
141
142       if (no_vertical_end)
143         edge_height[RIGHT] = 0.0;
144
145       me->set_property ("edge-height", ly_interval2scm (edge_height));
146     }
147
148   if (broken_last_bracket && no_vertical_end && no_vertical_start
149       && !broken_first_bracket)
150     me->suicide ();
151 }
152
153 void
154 Volta_bracket_interface::add_bar (Grob *me, Item *b)
155 {
156   Pointer_group_interface::add_grob (me, ly_symbol2scm ("bars"), b);
157   Side_position_interface::add_support (me, b);
158   add_bound_item (dynamic_cast<Spanner *> (me), b);
159 }
160
161 void
162 Volta_bracket_interface::add_column (Grob *me, Grob *c)
163 {
164   Side_position_interface::add_support (me, c);
165 }
166
167 ADD_INTERFACE (Volta_bracket_interface, "volta-bracket-interface",
168                "Volta bracket with number",
169
170                /* properties */
171                "bars "
172                "thickness "
173                "height");
174