]> git.donarmstrong.com Git - lilypond.git/blob - lily/volta-bracket.cc
(class Grob): move pscore, dim_cache_,
[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   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   Drul_array<Real> edge_height = robust_scm2interval (me->get_property ("edge-height"),
67                                                       Interval (1.0, 1.0));
68   Drul_array<Real> flare = robust_scm2interval (me->get_property ("bracket-flare"),
69                                                 Interval (0, 0));
70   Drul_array<Real> shorten = robust_scm2interval (me->get_property ("shorten-pair"),
71                                                   Interval (0, 0));
72
73   scale_drul (&edge_height, - Real (get_grob_direction (me)));
74
75   Interval empty;
76   Offset start;
77   start[X_AXIS] = me->spanner_length () - left - half_space;
78   
79   /*
80     ugh, Tuplet_bracket should use Horizontal_bracket, not the other way around. 
81   */
82   Stencil total
83     = Tuplet_bracket::make_bracket (me, Y_AXIS, start, 
84                                     edge_height, empty, flare, shorten);
85
86   if (!orig_span || broken_first_bracket)
87     {
88       SCM text = me->get_property ("text");
89       SCM properties = me->get_property_alist_chain (SCM_EOL);
90       SCM snum = Text_interface::interpret_markup (layout->self_scm (),
91                                                    properties, text);
92       Stencil num = *unsmob_stencil (snum);
93       num.align_to (Y_AXIS, UP);
94       num.translate_axis (-0.5, Y_AXIS);
95       total.add_at_edge (X_AXIS, LEFT, num, - num.extent (X_AXIS).length ()
96                          - 1.0, 0);
97     }
98   
99   total.translate_axis (left, X_AXIS);
100   return total.smobbed_copy ();
101 }
102
103
104 MAKE_SCHEME_CALLBACK(Volta_bracket_interface,after_line_breaking, 1);
105 SCM
106 Volta_bracket_interface::after_line_breaking (SCM smob)
107 {
108   Spanner *me = unsmob_spanner (smob);
109   Spanner *orig_span = dynamic_cast<Spanner *> (me->original ());
110  
111   bool broken_first_bracket = orig_span && (orig_span->broken_intos_[0] == (Spanner *)me);
112
113   bool broken_last_bracket = orig_span && (orig_span->broken_intos_.top () == (Spanner *)me);
114
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.top () : 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   return SCM_UNSPECIFIED;
149 }
150
151 void
152 Volta_bracket_interface::add_bar (Grob *me, Item *b)
153 {
154   Pointer_group_interface::add_grob (me, ly_symbol2scm ("bars"), b);
155   Side_position_interface::add_support (me, b);
156   add_bound_item (dynamic_cast<Spanner *> (me), b);
157 }
158
159 void
160 Volta_bracket_interface::add_column (Grob *me, Grob *c)
161 {
162   Side_position_interface::add_support (me, c);
163 }
164
165 ADD_INTERFACE (Volta_bracket_interface, "volta-bracket-interface",
166                "Volta bracket with number",
167
168                /* properties */
169                "bars "
170                "thickness "
171                "height");
172