2 arpeggio.cc -- implement Arpeggio
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2005 Jan Nieuwenhuizen <janneke@gnu.org>
11 #include "output-def.hh"
13 #include "staff-symbol-referencer.hh"
14 #include "staff-symbol.hh"
16 #include "font-interface.hh"
19 MAKE_SCHEME_CALLBACK (Arpeggio, print, 1);
21 Arpeggio::print (SCM smob)
23 Grob *me = unsmob_grob (smob);
26 for (SCM s = me->get_property ("stems"); scm_is_pair (s); s = scm_cdr (s))
28 Grob *stem = unsmob_grob (scm_car (s));
29 common = common->common_refpoint (Staff_symbol_referencer::get_staff_symbol (stem),
36 Using stems here is not very convenient; should store noteheads
37 instead, and also put them into the support. Now we will mess up
38 in vicinity of a collision.
42 Real my_y = me->relative_coordinate (common, Y_AXIS);
44 for (SCM s = me->get_property ("stems"); scm_is_pair (s); s = scm_cdr (s))
46 Grob *stem = unsmob_grob (scm_car (s));
47 Grob *ss = Staff_symbol_referencer::get_staff_symbol (stem);
48 Interval iv = Stem::head_positions (stem);
49 iv *= Staff_symbol::staff_space (ss) / 2.0;
51 heads.unite (iv + ss->relative_coordinate (common, Y_AXIS)
55 if (heads.is_empty ())
62 programming_error ("Huh, no heads for arpeggio found.");
66 SCM ad = me->get_property ("arpeggio-direction");
67 Direction dir = CENTER;
68 if (is_direction (ad))
74 Font_metric *fm = Font_interface::get_default_font (me);
75 Stencil squiggle = fm->find_by_name ("scripts.arpeggio");
80 arrow = fm->find_by_name ("scripts.arpeggio.arrow." + to_string (dir));
81 heads[dir] -= dir * arrow.extent (Y_AXIS).length ();
84 for (Real y = heads[LEFT]; y < heads[RIGHT];
85 y += squiggle.extent (Y_AXIS).length ())
86 mol.add_at_edge (Y_AXIS, UP, squiggle, 0.0, 0);
88 mol.translate_axis (heads[LEFT], Y_AXIS);
90 mol.add_at_edge (Y_AXIS, dir, arrow, 0, 0);
92 return mol.smobbed_copy ();
95 /* Draws a vertical bracket to the left of a chord
96 Chris Jackson <chris@fluffhouse.org.uk> */
98 MAKE_SCHEME_CALLBACK (Arpeggio, brew_chord_bracket, 1);
100 Arpeggio::brew_chord_bracket (SCM smob)
102 Grob *me = unsmob_grob (smob);
105 for (SCM s = me->get_property ("stems"); scm_is_pair (s); s = scm_cdr (s))
107 Grob *stem = unsmob_grob (scm_car (s));
108 common = common->common_refpoint (Staff_symbol_referencer::get_staff_symbol (stem),
113 Real my_y = me->relative_coordinate (common, Y_AXIS);
115 for (SCM s = me->get_property ("stems"); scm_is_pair (s); s = scm_cdr (s))
117 Grob *stem = unsmob_grob (scm_car (s));
118 Grob *ss = Staff_symbol_referencer::get_staff_symbol (stem);
119 Interval iv = Stem::head_positions (stem);
120 iv *= Staff_symbol::staff_space (ss) / 2.0;
121 heads.unite (iv + ss->relative_coordinate (common, Y_AXIS) - my_y);
124 Real lt = me->get_layout ()->get_dimension (ly_symbol2scm ("linethickness"));
125 Real sp = 1.5 * Staff_symbol_referencer::staff_space (me);
126 Real dy = heads.length () + sp;
129 Stencil mol (Lookup::bracket (Y_AXIS, Interval (0, dy), lt, x, lt));
130 mol.translate_axis (heads[LEFT] - sp / 2.0, Y_AXIS);
131 return mol.smobbed_copy ();
135 We have to do a callback, because print () triggers a
136 vertical alignment if it is cross-staff.
138 MAKE_SCHEME_CALLBACK (Arpeggio, width_callback, 2);
140 Arpeggio::width_callback (SCM smob, SCM axis)
142 Grob *me = unsmob_grob (smob);
143 Axis a = (Axis)scm_to_int (axis);
144 assert (a == X_AXIS);
145 Stencil arpeggio = Font_interface::get_default_font (me)->find_by_name ("scripts.arpeggio");
147 return ly_interval2scm (arpeggio.extent (X_AXIS));
150 ADD_INTERFACE (Arpeggio, "arpeggio-interface",
151 "Functions and settings for drawing an arpeggio symbol (a wavy line left to noteheads.",
152 "stems arpeggio-direction");