2 ottava-bracket.cc -- implement Ottava_bracket
4 source file of the GNU LilyPond music typesetter
6 (c) 2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
11 #include "text-item.hh"
12 #include "line-spanner.hh"
14 #include "font-interface.hh"
15 #include "dimensions.hh"
16 #include "output-def.hh"
18 #include "paper-column.hh"
19 #include "staff-symbol-referencer.hh"
20 #include "note-column.hh"
21 #include "directional-element-interface.hh"
22 #include "tuplet-bracket.hh"
23 #include "rhythmic-head.hh"
27 DECLARE_SCHEME_CALLBACK (print, (SCM));
28 static bool has_interface (Grob*);
33 TODO: the string for ottava shoudl depend on the available space, ie.
35 Long: 15ma Short: 15ma Empty: 15
40 MAKE_SCHEME_CALLBACK (Ottava_bracket, print, 1);
42 Ottava_bracket::print (SCM smob)
44 Spanner*me = dynamic_cast<Spanner*> (unsmob_grob (smob));
47 Grob *common = me->get_bound (LEFT)->common_refpoint (me->get_bound (RIGHT), X_AXIS);
48 Output_def * layout = me->get_layout ();
50 Drul_array<bool> broken;
54 Item *b = me->get_bound (d);
55 broken[d] = (b->break_status_dir () != CENTER);
57 if (Note_column::has_interface (b))
59 SCM heads = b->get_property ("note-heads");
60 common = common_refpoint_of_list (heads, common, X_AXIS);
61 for (SCM s = heads; scm_is_pair (s); s =scm_cdr (s))
63 Grob * h = unsmob_grob (scm_car (s));
64 Grob * dots = Rhythmic_head::get_dots (h);
66 common = dots->common_refpoint (common, X_AXIS);
70 while (flip (&d) != LEFT);
72 SCM properties = Font_interface::text_font_alist_chain (me);
73 SCM markup = me->get_property ("text");
75 if (Text_interface::markup_p (markup))
76 text = *unsmob_stencil (Text_interface::interpret_markup (layout->self_scm (), properties, markup));
79 Drul_array<Real> shorten = robust_scm2interval (me->get_property ("shorten-pair"),
84 TODO: we should check if there are ledgers, and modify length of
89 Item *b = me->get_bound (d);
92 if (Note_column::has_interface (b))
94 for (SCM s = b->get_property ("note-heads"); scm_is_pair (s); s =scm_cdr (s))
96 Grob * h = unsmob_grob (scm_car (s));
97 ext.unite (h->extent (common, X_AXIS));
98 Grob * dots = Rhythmic_head::get_dots (h);
100 if (dots && d == RIGHT)
102 ext.unite (dots->extent (common, X_AXIS));
109 ext = robust_relative_extent (b, common, X_AXIS);
114 span_points[d] = b->extent (common, X_AXIS)[RIGHT];
119 span_points[d] = ext[d];
121 while (flip (&d) != LEFT);
125 0.3 is ~ italic correction.
127 Real text_size = text.extent (X_AXIS).is_empty ()
128 ? 0.0 : text.extent (X_AXIS)[RIGHT] + 0.3;
130 span_points[LEFT] = span_points[LEFT]
131 <? (span_points[RIGHT] - text_size
132 - robust_scm2double (me->get_property ("minimum-length"), -1.0));
134 Interval bracket_span_points = span_points;
135 bracket_span_points[LEFT] += text_size;
137 Drul_array<Real> edge_height = robust_scm2interval (me->get_property ("edge-height"),
138 Interval (1.0, 1.0));
141 Drul_array<Real> flare = robust_scm2interval (me->get_property ("bracket-flare"),
146 edge_height[LEFT] = 0.0;
147 edge_height[RIGHT] *= - get_grob_direction (me);
149 edge_height[RIGHT] = 0.0;
153 if (!bracket_span_points.is_empty () && bracket_span_points.length () > 0.001)
154 b = Tuplet_bracket::make_bracket (me,
155 Y_AXIS, Offset (bracket_span_points.length (), 0),
161 The vertical lines should not take space, for the following scenario:
169 Just a small amount, yes. In tight situations, it is even
170 possible to center the `8' directly below the note, dropping the
171 ottava line completely...
175 b = Stencil (Box (b.extent (X_AXIS),
179 b.translate_axis (bracket_span_points[LEFT], X_AXIS);
180 text.translate_axis (span_points[LEFT], X_AXIS);
181 text.align_to (Y_AXIS, CENTER);
182 b.add_stencil (text);
184 b.translate_axis (- me->relative_coordinate (common, X_AXIS), X_AXIS);
186 return b.smobbed_copy ();
190 ADD_INTERFACE (Ottava_bracket, "ottava-bracket-interface",
192 "edge-height bracket-flare shorten-pair minimum-length");