2 ottava-bracket.cc -- implement Ottava_bracket
4 source file of the GNU LilyPond music typesetter
6 (c) 2004--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #include "text-interface.hh"
11 #include "font-interface.hh"
12 #include "dimensions.hh"
13 #include "output-def.hh"
15 #include "paper-column.hh"
16 #include "staff-symbol-referencer.hh"
17 #include "note-column.hh"
18 #include "directional-element-interface.hh"
19 #include "tuplet-bracket.hh"
20 #include "rhythmic-head.hh"
21 #include "pointer-group-interface.hh"
25 DECLARE_SCHEME_CALLBACK (print
, (SCM
));
26 DECLARE_GROB_INTERFACE ();
30 TODO: the string for ottava shoudl depend on the available space, ie.
32 Long: 15ma Short: 15ma Empty: 15
36 MAKE_SCHEME_CALLBACK (Ottava_bracket
, print
, 1);
38 Ottava_bracket::print (SCM smob
)
40 Spanner
*me
= dynamic_cast<Spanner
*> (unsmob_grob (smob
));
43 Grob
*common
= me
->get_bound (LEFT
)->common_refpoint (me
->get_bound (RIGHT
), X_AXIS
);
44 Output_def
*layout
= me
->layout ();
46 Drul_array
<bool> broken
;
50 Item
*b
= me
->get_bound (d
);
51 broken
[d
] = (b
->break_status_dir () != CENTER
);
53 if (Note_column::has_interface (b
))
55 extract_grob_set (b
, "note-heads", heads
);
56 common
= common_refpoint_of_array (heads
, common
, X_AXIS
);
57 for (vsize i
= 0; i
< heads
.size (); i
++)
60 Grob
*dots
= Rhythmic_head::get_dots (h
);
62 common
= dots
->common_refpoint (common
, X_AXIS
);
66 while (flip (&d
) != LEFT
);
68 SCM properties
= Font_interface::text_font_alist_chain (me
);
69 SCM markup
= me
->get_property ("text");
71 if (Text_interface::is_markup (markup
))
72 text
= *unsmob_stencil (Text_interface::interpret_markup (layout
->self_scm (),
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 (vsize 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
)
97 ext
.unite (dots
->extent (common
, X_AXIS
));
102 ext
= robust_relative_extent (b
, common
, X_AXIS
);
106 span_points
[d
] = b
->extent (common
, X_AXIS
)[RIGHT
];
111 span_points
[d
] = ext
[d
];
113 while (flip (&d
) != LEFT
);
116 0.3 is ~ italic correction.
118 Real text_size
= text
.extent (X_AXIS
).is_empty ()
119 ? 0.0 : text
.extent (X_AXIS
)[RIGHT
] + 0.3;
122 = min (span_points
[LEFT
],
123 (span_points
[RIGHT
] - text_size
124 - robust_scm2double (me
->get_property ("minimum-length"), -1.0)));
126 Interval bracket_span_points
= span_points
;
127 bracket_span_points
[LEFT
] += text_size
;
129 Drul_array
<Real
> edge_height
= robust_scm2interval (me
->get_property ("edge-height"),
130 Interval (1.0, 1.0));
132 Drul_array
<Real
> flare
= robust_scm2interval (me
->get_property ("bracket-flare"),
137 edge_height
[d
] *= -get_grob_direction (me
);
139 edge_height
[d
] = 0.0;
141 while (flip(&d
) != LEFT
);
145 if (!bracket_span_points
.is_empty () && bracket_span_points
.length () > 0.001)
146 b
= Tuplet_bracket::make_bracket (me
,
147 Y_AXIS
, Offset (bracket_span_points
.length (), 0),
153 The vertical lines should not take space, for the following scenario:
161 Just a small amount, yes. In tight situations, it is even
162 possible to center the `8' directly below the note, dropping the
163 ottava line completely...
167 b
= Stencil (Box (b
.extent (X_AXIS
),
168 Interval (0.1, 0.1)),
171 b
.translate_axis (bracket_span_points
[LEFT
], X_AXIS
);
172 text
.translate_axis (span_points
[LEFT
], X_AXIS
);
173 text
.align_to (Y_AXIS
, CENTER
);
174 b
.add_stencil (text
);
176 b
.translate_axis (- me
->relative_coordinate (common
, X_AXIS
), X_AXIS
);
178 return b
.smobbed_copy ();
181 ADD_INTERFACE (Ottava_bracket
,
182 "An ottava bracket.",