2 hairpin.cc -- implement Hairpin
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
11 #include "dimensions.hh"
12 #include "international.hh"
13 #include "line-interface.hh"
14 #include "output-def.hh"
15 #include "paper-column.hh"
16 #include "pointer-group-interface.hh"
18 #include "staff-symbol-referencer.hh"
19 #include "text-interface.hh"
20 #include "note-column.hh"
23 MAKE_SCHEME_CALLBACK (Hairpin
, height
, 1);
25 Hairpin::height (SCM smob
)
27 return Grob::stencil_height (smob
);
30 MAKE_SCHEME_CALLBACK (Hairpin
, pure_height
, 3);
32 Hairpin::pure_height (SCM smob
, SCM
, SCM
)
34 Grob
*me
= unsmob_grob (smob
);
35 Real height
= robust_scm2double (me
->get_property ("height"), 0.0)
36 * Staff_symbol_referencer::staff_space (me
);
38 Real thickness
= robust_scm2double (me
->get_property ("thickness"), 1)
39 * Staff_symbol_referencer::line_thickness (me
);
41 height
+= thickness
/ 2;
42 return ly_interval2scm (Interval (-height
, height
));
45 MAKE_SCHEME_CALLBACK (Hairpin
, print
, 1);
47 Hairpin::print (SCM smob
)
49 Spanner
*me
= unsmob_spanner (smob
);
51 SCM s
= me
->get_property ("grow-direction");
52 if (!is_direction (s
))
58 Direction grow_dir
= to_dir (s
);
59 Real padding
= robust_scm2double (me
->get_property ("bound-padding"), 0.5);
61 Drul_array
<bool> broken
;
62 Drul_array
<Item
*> bounds
;
66 bounds
[d
] = me
->get_bound (d
);
67 broken
[d
] = bounds
[d
]->break_status_dir () != CENTER
;
69 while (flip (&d
) != LEFT
);
71 broken
[RIGHT
] = broken
[RIGHT
] && me
->broken_neighbor (RIGHT
);
72 broken
[RIGHT
] = broken
[RIGHT
] && me
->broken_neighbor (RIGHT
)->is_live ();
76 Spanner
*next
= me
->broken_neighbor (RIGHT
);
77 Stencil
*s
= next
->get_stencil ();
78 if (!s
|| s
->is_empty ())
79 broken
[RIGHT
] = false;
82 Grob
*common
= bounds
[LEFT
]->common_refpoint (bounds
[RIGHT
], X_AXIS
);
83 Drul_array
<Real
> x_points
;
86 Use the height and thickness of the hairpin when making a circled tip
88 bool circled_tip
= ly_scm2bool (me
->get_property ("circled-tip"));
89 Real height
= robust_scm2double (me
->get_property ("height"), 0.2) *
90 Staff_symbol_referencer::staff_space (me
);
92 FIXME: 0.525 is still just a guess...
94 Real rad
= height
* 0.525;
97 thick
= robust_scm2double (me
->get_property ("thickness"), 1.0)
98 * Staff_symbol_referencer::line_thickness (me
);
103 x_points
[d
] = b
->relative_coordinate (common
, X_AXIS
);
107 x_points
[d
] = b
->extent (common
, X_AXIS
)[RIGHT
];
111 if (Text_interface::has_interface (b
))
113 Interval e
= b
->extent (common
, X_AXIS
);
115 x_points
[d
] = e
[-d
] - d
* padding
;
119 bool neighbor_found
= false;
120 extract_grob_set (me
, "adjacent-hairpins", pins
);
121 for (vsize i
= 0; i
< pins
.size (); i
++)
124 FIXME: this will fuck up in case of polyphonic
125 notes in other voices. Need to look at note-columns
126 in the current staff/voice.
129 Spanner
*pin
= dynamic_cast<Spanner
*> (pins
[i
]);
131 && (pin
->get_bound (LEFT
)->get_column () == b
->get_column ()
132 || pin
->get_bound (RIGHT
)->get_column () == b
->get_column ()))
133 neighbor_found
= true;
136 Interval e
= robust_relative_extent (b
, common
, X_AXIS
);
140 Handle back-to-back hairpins with a circle in the middle
142 if (circled_tip
&& (grow_dir
!= d
))
143 x_points
[d
] = e
.center () + d
* (rad
- thick
/ 2.0);
145 If we're hung on a paper column, that means we're not
146 adjacent to a text-dynamic, and we may move closer. We
147 make the padding a little smaller, here.
150 x_points
[d
] = e
.center () - d
* padding
/ 3;
154 if (Note_column::has_interface (b
)
155 && Note_column::has_rests (b
))
160 Item
*bound
= me
->get_bound (d
);
161 if (bound
->is_non_musical (bound
))
162 x_points
[d
] -= d
* padding
;
167 while (flip (&d
) != LEFT
);
169 Real width
= x_points
[RIGHT
] - x_points
[LEFT
];
172 me
->warning (_ ((grow_dir
< 0) ? "decrescendo too small"
173 : "crescendo too small"));
177 bool continued
= broken
[Direction (-grow_dir
)];
184 endh
= continued
? height
/ 2 : 0.0;
188 starth
= continued
? height
/ 2 : 0.0;
193 should do relative to staff-symbol staff-space?
199 Compensate for size of circle
201 Direction tip_dir
= -grow_dir
;
202 if (circled_tip
&& !broken
[tip_dir
])
206 else if (grow_dir
< 0)
209 mol
= Line_interface::line (me
, Offset (x
, starth
), Offset (width
, endh
));
210 mol
.add_stencil (Line_interface::line (me
,
212 Offset (width
, -endh
)));
215 Support al/del niente notation by putting a circle at the
216 tip of the (de)crescendo.
220 Box
extent (Interval (-rad
, rad
), Interval (-rad
, rad
));
222 /* Hmmm, perhaps we should have a Lookup::circle () method? */
223 Stencil
circle (extent
,
224 scm_list_4 (ly_symbol2scm ("circle"),
225 scm_from_double (rad
),
226 scm_from_double (thick
),
230 don't add another circle the hairpin is broken
232 if (!broken
[tip_dir
])
233 mol
.add_at_edge (X_AXIS
, tip_dir
, Stencil (circle
), 0);
236 mol
.translate_axis (x_points
[LEFT
]
237 - bounds
[LEFT
]->relative_coordinate (common
, X_AXIS
),
239 return mol
.smobbed_copy ();
242 ADD_INTERFACE (Hairpin
,
243 "A hairpin crescendo or decrescendo.",