]> git.donarmstrong.com Git - lilypond.git/blob - lily/volta-bracket.cc
7d7100e468086b9472c495b52b5c131088e97452
[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--2005 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
40   /*
41     UGH UGH  dependency tracking.
42   */
43   SCM proc = me->get_property ("after-line-breaking-callback");
44   if (ly_is_procedure (proc))
45     {
46       me->set_property ("after-line-breaking-callback", SCM_EOL);
47       scm_call_1  (proc, me->self_scm ());
48     }
49
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->get_layout ();
55   Real half_space = 0.5;
56
57   Item *bound = dynamic_cast<Spanner *> (me)->get_bound (LEFT);
58
59   /*
60     not a start, but really broken in two
61   */
62   Real left = 0.;
63   if (bound->break_status_dir () == RIGHT)
64     {
65       Paper_column *pc = bound->get_column ();
66       left = pc->extent (pc, X_AXIS)[RIGHT]
67         - bound->relative_coordinate (pc, X_AXIS);
68     }
69   else
70     {
71       /*
72         the volta spanner is attached to the bar-line, which is moved
73         to the right. We don't need to compensate for the left edge.
74       */
75     }
76
77   Drul_array<Real> edge_height = robust_scm2interval (me->get_property ("edge-height"),
78                                                       Interval (1.0, 1.0));
79   Drul_array<Real> flare = robust_scm2interval (me->get_property ("bracket-flare"),
80                                                 Interval (0, 0));
81   Drul_array<Real> shorten = robust_scm2interval (me->get_property ("shorten-pair"),
82                                                   Interval (0, 0));
83
84   scale_drul (&edge_height, - Real (get_grob_direction (me)));
85
86   Interval empty;
87   Offset start;
88   start[X_AXIS] = me->spanner_length () - left - half_space;
89   
90   /*
91     ugh, Tuplet_bracket should use Horizontal_bracket, not the other way around. 
92   */
93   Stencil total
94     = Tuplet_bracket::make_bracket (me, Y_AXIS, start, 
95                                     edge_height, empty, flare, shorten);
96
97   if (!orig_span || broken_first_bracket)
98     {
99       SCM text = me->get_property ("text");
100       SCM properties = me->get_property_alist_chain (SCM_EOL);
101       SCM snum = Text_interface::interpret_markup (layout->self_scm (),
102                                                    properties, text);
103       Stencil num = *unsmob_stencil (snum);
104       num.align_to (Y_AXIS, UP);
105       num.translate_axis (-0.5, Y_AXIS);
106       total.add_at_edge (X_AXIS, LEFT, num, - num.extent (X_AXIS).length ()
107                          - 1.0, 0);
108     }
109   
110   total.translate_axis (left, X_AXIS);
111   return total.smobbed_copy ();
112 }
113
114
115 MAKE_SCHEME_CALLBACK(Volta_bracket_interface,after_line_breaking, 1);
116 SCM
117 Volta_bracket_interface::after_line_breaking (SCM smob)
118 {
119   Spanner *me = unsmob_spanner (smob);
120   Spanner *orig_span = dynamic_cast<Spanner *> (me->original_);
121  
122   bool broken_first_bracket = orig_span && (orig_span->broken_intos_[0] == (Spanner *)me);
123
124   bool broken_last_bracket = orig_span && (orig_span->broken_intos_.top () == (Spanner *)me);
125
126   bool no_vertical_start = orig_span && !broken_first_bracket;
127   bool no_vertical_end = orig_span && !broken_last_bracket;
128
129   extract_grob_set (me, "bars", bars);
130   Grob *endbar = bars.size () ? bars.top () : 0;
131   SCM glyph = endbar ? endbar->get_property ("glyph") : SCM_EOL;
132
133   String str;
134   if (scm_is_string (glyph))
135     str = ly_scm2string (glyph);
136   else
137     str = "|";
138
139   no_vertical_end
140     |= (str != ":|"
141         && str != "|:"
142         && str != "|."
143         && str != ":|:"
144         && str != ".|");
145
146   if (no_vertical_end || no_vertical_start)
147     {
148       Drul_array<Real> edge_height = robust_scm2interval (me->get_property ("edge-height"),
149                                                           Interval (1.0, 1.0));
150       if (no_vertical_start)
151         edge_height[LEFT] = 0.0;
152
153       if (no_vertical_end)
154         edge_height[RIGHT] = 0.0;
155
156       me->set_property ("edge-height", ly_interval2scm (edge_height));
157     }
158   
159   return SCM_UNSPECIFIED;
160 }
161
162 void
163 Volta_bracket_interface::add_bar (Grob *me, Item *b)
164 {
165   Pointer_group_interface::add_grob (me, ly_symbol2scm ("bars"), b);
166   Side_position_interface::add_support (me, b);
167   add_bound_item (dynamic_cast<Spanner *> (me), b);
168 }
169
170 void
171 Volta_bracket_interface::add_column (Grob *me, Grob *c)
172 {
173   Side_position_interface::add_support (me, c);
174 }
175
176 ADD_INTERFACE (Volta_bracket_interface, "volta-bracket-interface",
177                "Volta bracket with number",
178
179                /* properties */
180                "bars "
181                "thickness "
182                "height");
183