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>
9 #include "text-interface.hh"
10 #include "line-spanner.hh"
12 #include "font-interface.hh"
13 #include "dimensions.hh"
14 #include "output-def.hh"
16 #include "paper-column.hh"
17 #include "staff-symbol-referencer.hh"
18 #include "note-column.hh"
19 #include "directional-element-interface.hh"
20 #include "tuplet-bracket.hh"
21 #include "rhythmic-head.hh"
22 #include "pointer-group-interface.hh"
26 DECLARE_SCHEME_CALLBACK (print, (SCM));
27 static bool has_interface (Grob *);
31 TODO: the string for ottava shoudl depend on the available space, ie.
33 Long: 15ma Short: 15ma Empty: 15
37 MAKE_SCHEME_CALLBACK (Ottava_bracket, print, 1);
39 Ottava_bracket::print (SCM smob)
41 Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (smob));
44 Grob *common = me->get_bound (LEFT)->common_refpoint (me->get_bound (RIGHT), X_AXIS);
45 Output_def *layout = me->get_layout ();
47 Drul_array<bool> broken;
51 Item *b = me->get_bound (d);
52 broken[d] = (b->break_status_dir () != CENTER);
54 if (Note_column::has_interface (b))
56 extract_grob_set (b, "note-heads", heads);
57 common = common_refpoint_of_array (heads, common, X_AXIS);
58 for (int i = 0; i < heads.size (); i++)
61 Grob *dots = Rhythmic_head::get_dots (h);
63 common = dots->common_refpoint (common, X_AXIS);
67 while (flip (&d) != LEFT);
69 SCM properties = Font_interface::text_font_alist_chain (me);
70 SCM markup = me->get_property ("text");
72 if (Text_interface::markup_p (markup))
73 text = *unsmob_stencil (Text_interface::interpret_markup (layout->self_scm (), properties, markup));
75 Drul_array<Real> shorten = robust_scm2interval (me->get_property ("shorten-pair"),
79 TODO: we should check if there are ledgers, and modify length of
84 Item *b = me->get_bound (d);
87 if (Note_column::has_interface (b))
89 extract_grob_set (b, "note-heads", heads);
90 for (int i = 0; i < heads.size (); i++)
93 ext.unite (h->extent (common, X_AXIS));
94 Grob *dots = Rhythmic_head::get_dots (h);
96 if (dots && d == RIGHT)
98 ext.unite (dots->extent (common, X_AXIS));
105 ext = robust_relative_extent (b, common, X_AXIS);
110 span_points[d] = b->extent (common, X_AXIS)[RIGHT];
115 span_points[d] = ext[d];
117 while (flip (&d) != LEFT);
120 0.3 is ~ italic correction.
122 Real text_size = text.extent (X_AXIS).is_empty ()
123 ? 0.0 : text.extent (X_AXIS)[RIGHT] + 0.3;
126 min (span_points[LEFT],
127 (span_points[RIGHT] - text_size
128 - robust_scm2double (me->get_property ("minimum-length"), -1.0)));
130 Interval bracket_span_points = span_points;
131 bracket_span_points[LEFT] += text_size;
133 Drul_array<Real> edge_height = robust_scm2interval (me->get_property ("edge-height"),
134 Interval (1.0, 1.0));
136 Drul_array<Real> flare = robust_scm2interval (me->get_property ("bracket-flare"),
139 edge_height[LEFT] = 0.0;
140 edge_height[RIGHT] *= -get_grob_direction (me);
142 edge_height[RIGHT] = 0.0;
146 if (!bracket_span_points.is_empty () && bracket_span_points.length () > 0.001)
147 b = Tuplet_bracket::make_bracket (me,
148 Y_AXIS, Offset (bracket_span_points.length (), 0),
154 The vertical lines should not take space, for the following scenario:
162 Just a small amount, yes. In tight situations, it is even
163 possible to center the `8' directly below the note, dropping the
164 ottava line completely...
168 b = Stencil (Box (b.extent (X_AXIS),
169 Interval (0.1, 0.1)),
172 b.translate_axis (bracket_span_points[LEFT], X_AXIS);
173 text.translate_axis (span_points[LEFT], X_AXIS);
174 text.align_to (Y_AXIS, CENTER);
175 b.add_stencil (text);
177 b.translate_axis (- me->relative_coordinate (common, X_AXIS), X_AXIS);
179 return b.smobbed_copy ();
182 ADD_INTERFACE (Ottava_bracket, "ottava-bracket-interface",
184 "edge-height bracket-flare shorten-pair minimum-length");