2 ottava-bracket.cc -- implement Ottava_bracket
4 source file of the GNU LilyPond music typesetter
6 (c) 2004--2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
10 #include "text-item.hh"
11 #include "line-spanner.hh"
13 #include "font-interface.hh"
14 #include "dimensions.hh"
15 #include "output-def.hh"
17 #include "paper-column.hh"
18 #include "staff-symbol-referencer.hh"
19 #include "note-column.hh"
20 #include "directional-element-interface.hh"
21 #include "tuplet-bracket.hh"
22 #include "rhythmic-head.hh"
26 DECLARE_SCHEME_CALLBACK (print, (SCM));
27 static bool has_interface (Grob*);
32 TODO: the string for ottava shoudl depend on the available space, ie.
34 Long: 15ma Short: 15ma Empty: 15
39 MAKE_SCHEME_CALLBACK (Ottava_bracket, print, 1);
41 Ottava_bracket::print (SCM smob)
43 Spanner*me = dynamic_cast<Spanner*> (unsmob_grob (smob));
46 Grob *common = me->get_bound (LEFT)->common_refpoint (me->get_bound (RIGHT), X_AXIS);
47 Output_def * layout = me->get_layout ();
49 Drul_array<bool> broken;
53 Item *b = me->get_bound (d);
54 broken[d] = (b->break_status_dir () != CENTER);
56 if (Note_column::has_interface (b))
58 SCM heads = b->get_property ("note-heads");
59 common = common_refpoint_of_list (heads, common, X_AXIS);
60 for (SCM s = heads; scm_is_pair (s); s = scm_cdr (s))
62 Grob * h = unsmob_grob (scm_car (s));
63 Grob * dots = Rhythmic_head::get_dots (h);
65 common = dots->common_refpoint (common, X_AXIS);
69 while (flip (&d) != LEFT);
71 SCM properties = Font_interface::text_font_alist_chain (me);
72 SCM markup = me->get_property ("text");
74 if (Text_interface::markup_p (markup))
75 text = *unsmob_stencil (Text_interface::interpret_markup (layout->self_scm (), properties, markup));
78 Drul_array<Real> shorten = robust_scm2interval (me->get_property ("shorten-pair"),
83 TODO: we should check if there are ledgers, and modify length of
88 Item *b = me->get_bound (d);
91 if (Note_column::has_interface (b))
93 for (SCM s = b->get_property ("note-heads"); scm_is_pair (s); s = scm_cdr (s))
95 Grob * h = unsmob_grob (scm_car (s));
96 ext.unite (h->extent (common, X_AXIS));
97 Grob * dots = Rhythmic_head::get_dots (h);
99 if (dots && d == RIGHT)
101 ext.unite (dots->extent (common, X_AXIS));
108 ext = robust_relative_extent (b, common, X_AXIS);
113 span_points[d] = b->extent (common, X_AXIS)[RIGHT];
118 span_points[d] = ext[d];
120 while (flip (&d) != LEFT);
124 0.3 is ~ italic correction.
126 Real text_size = text.extent (X_AXIS).is_empty ()
127 ? 0.0 : text.extent (X_AXIS)[RIGHT] + 0.3;
129 span_points[LEFT] = span_points[LEFT]
130 <? (span_points[RIGHT] - text_size
131 - robust_scm2double (me->get_property ("minimum-length"), -1.0));
133 Interval bracket_span_points = span_points;
134 bracket_span_points[LEFT] += text_size;
136 Drul_array<Real> edge_height = robust_scm2interval (me->get_property ("edge-height"),
137 Interval (1.0, 1.0));
140 Drul_array<Real> flare = robust_scm2interval (me->get_property ("bracket-flare"),
145 edge_height[LEFT] = 0.0;
146 edge_height[RIGHT] *= - get_grob_direction (me);
148 edge_height[RIGHT] = 0.0;
152 if (!bracket_span_points.is_empty () && bracket_span_points.length () > 0.001)
153 b = Tuplet_bracket::make_bracket (me,
154 Y_AXIS, Offset (bracket_span_points.length (), 0),
160 The vertical lines should not take space, for the following scenario:
168 Just a small amount, yes. In tight situations, it is even
169 possible to center the `8' directly below the note, dropping the
170 ottava line completely...
174 b = Stencil (Box (b.extent (X_AXIS),
175 Interval (0.1, 0.1)),
178 b.translate_axis (bracket_span_points[LEFT], X_AXIS);
179 text.translate_axis (span_points[LEFT], X_AXIS);
180 text.align_to (Y_AXIS, CENTER);
181 b.add_stencil (text);
183 b.translate_axis (- me->relative_coordinate (common, X_AXIS), X_AXIS);
185 return b.smobbed_copy ();
189 ADD_INTERFACE (Ottava_bracket, "ottava-bracket-interface",
191 "edge-height bracket-flare shorten-pair minimum-length");