2 hairpin.cc -- implement Hairpin
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
12 #include "font-interface.hh"
13 #include "dimensions.hh"
14 #include "paper-def.hh"
16 #include "paper-column.hh"
19 MAKE_SCHEME_CALLBACK (Hairpin
, brew_molecule
, 1);
22 Hairpin::brew_molecule (SCM smob
)
24 Grob
*me
= unsmob_grob (smob
);
25 Spanner
*spanner
= dynamic_cast<Spanner
*> (me
);
27 Real line
= me
->get_paper ()->get_var ("linethickness");
29 SCM s
= me
->get_grob_property ("grow-direction");
36 Direction grow_dir
= to_dir (s
);
39 /* Ugh, must be same as Text_spanner::brew_molecule. */
42 Ugh. property name is not general.
44 Real padding
= gh_scm2double (me
->get_grob_property ("if-text-padding"));
46 Drul_array
<bool> broken
;
47 Drul_array
<Item
*> bounds
;
51 bounds
[d
] =spanner
->get_bound (d
);
52 broken
[d
] = bounds
[d
]->break_status_dir () != CENTER
;
54 while (flip (&d
) != LEFT
);
56 Grob
*common
= bounds
[LEFT
]->common_refpoint (bounds
[RIGHT
], X_AXIS
);
57 Drul_array
<Real
> x_points
;
62 x_points
[d
] = b
->relative_coordinate (common
, X_AXIS
);
66 x_points
[d
] = b
->extent (common
,X_AXIS
)[RIGHT
] ;
70 if (dynamic_cast<Paper_column
*> (b
))
73 If we're hung on a paper column, that means we're not
74 adjacent to a text-dynamic, and we may move closer. We
75 make the padding a little smaller, here.
77 Interval e
=b
->extent (common
, X_AXIS
);
79 e
= Interval (0,0) + b
->relative_coordinate (common
, X_AXIS
);
81 x_points
[d
] = e
.center () - d
* padding
/3; // ugh.
85 Interval e
=b
->extent (common
, X_AXIS
);
87 x_points
[d
] = e
[-d
] - d
*padding
;
91 while (flip (&d
) != LEFT
);
94 Real width
= x_points
[RIGHT
] - x_points
[LEFT
];
98 me
->warning (_ ((grow_dir
< 0) ? "decrescendo too small"
99 : "crescendo too small"));
103 bool continued
= broken
[Direction (-grow_dir
)];
104 Real height
= gh_scm2double (me
->get_grob_property ("height"));
105 Real thick
= line
* gh_scm2double (me
->get_grob_property ("thickness"));
111 endh
= continued
? height
/2 : 0.0;
115 starth
= continued
? height
/2 : 0.0;
119 Molecule mol
= Lookup::line (thick
,
121 Offset (width
, endh
));
122 mol
.add_molecule (Lookup::line (thick
,
124 Offset (width
, -endh
)));
126 mol
.translate_axis (x_points
[LEFT
]
127 - bounds
[LEFT
]->relative_coordinate (common
, X_AXIS
),
130 return mol
.smobbed_copy ();
135 ADD_INTERFACE (Hairpin
, "hairpin-interface",
136 "hairpin crescendo.",
137 "grow-direction thickness height if-text-padding");