]> git.donarmstrong.com Git - lilypond.git/blob - lily/arpeggio.cc
* lily/grob.cc: remove X-extent-callback / Y-extent-callback.
[lilypond.git] / lily / arpeggio.cc
1 /*
2   arpeggio.cc -- implement Arpeggio
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2000--2005 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "arpeggio.hh"
10
11 #include "output-def.hh"
12 #include "stem.hh"
13 #include "staff-symbol-referencer.hh"
14 #include "staff-symbol.hh"
15 #include "warn.hh"
16 #include "font-interface.hh"
17 #include "lookup.hh"
18 #include "pointer-group-interface.hh"
19
20 MAKE_SCHEME_CALLBACK (Arpeggio, print, 1);
21 SCM
22 Arpeggio::print (SCM smob)
23 {
24   Grob *me = unsmob_grob (smob);
25
26   Grob *common = me;
27
28   extract_grob_set (me, "stems", stems);
29   for (int i = 0; i < stems.size (); i++)
30     {
31       Grob *stem = stems[i];
32       common = common->common_refpoint (Staff_symbol_referencer::get_staff_symbol (stem),
33                                         Y_AXIS);
34     }
35
36   /*
37     TODO:
38
39     Using stems here is not very convenient; should store noteheads
40     instead, and also put them into the support. Now we will mess up
41     in vicinity of a collision.
42
43   */
44   Interval heads;
45   Real my_y = me->relative_coordinate (common, Y_AXIS);
46
47   for (int i = 0; i < stems.size (); i++)
48     {
49       Grob *stem = stems[i];
50       Grob *ss = Staff_symbol_referencer::get_staff_symbol (stem);
51       Interval iv = Stem::head_positions (stem);
52       iv *= Staff_symbol::staff_space (ss) / 2.0;
53
54       heads.unite (iv + ss->relative_coordinate (common, Y_AXIS)
55                    - my_y);
56     }
57
58   if (heads.is_empty () || heads.length () < 0.5)
59     {
60       programming_error ("no heads for arpeggio found?");
61       me->suicide ();
62       return SCM_EOL;
63     }
64
65   SCM ad = me->get_property ("arpeggio-direction");
66   Direction dir = CENTER;
67   if (is_direction (ad))
68     dir = to_dir (ad);
69
70   Stencil mol;
71   Font_metric *fm = Font_interface::get_default_font (me);
72   Stencil squiggle = fm->find_by_name ("scripts.arpeggio");
73
74   Stencil arrow;
75   if (dir)
76     {
77       arrow = fm->find_by_name ("scripts.arpeggio.arrow." + to_string (dir));
78       heads[dir] -= dir * arrow.extent (Y_AXIS).length ();
79     }
80
81   for (Real y = heads[LEFT]; y < heads[RIGHT];
82        y += squiggle.extent (Y_AXIS).length ())
83     mol.add_at_edge (Y_AXIS, UP, squiggle, 0.0, 0);
84
85   mol.translate_axis (heads[LEFT], Y_AXIS);
86   if (dir)
87     mol.add_at_edge (Y_AXIS, dir, arrow, 0, 0);
88
89   return mol.smobbed_copy ();
90 }
91
92 /* Draws a vertical bracket to the left of a chord
93    Chris Jackson <chris@fluffhouse.org.uk> */
94
95 MAKE_SCHEME_CALLBACK (Arpeggio, brew_chord_bracket, 1);
96 SCM
97 Arpeggio::brew_chord_bracket (SCM smob)
98 {
99   Grob *me = unsmob_grob (smob);
100   Grob *common = me;
101
102   extract_grob_set (me, "stems", stems);
103   for (int i = 0; i < stems.size (); i++)
104     {
105       Grob *stem = stems[i];
106       common = common->common_refpoint (Staff_symbol_referencer::get_staff_symbol (stem),
107                                         Y_AXIS);
108     }
109
110   Interval heads;
111   Real my_y = me->relative_coordinate (common, Y_AXIS);
112
113   for (int i = 0; i < stems.size (); i++)
114     {
115       Grob *stem = stems[i];
116       Grob *ss = Staff_symbol_referencer::get_staff_symbol (stem);
117       Interval iv = Stem::head_positions (stem);
118       iv *= Staff_symbol::staff_space (ss) / 2.0;
119       heads.unite (iv + ss->relative_coordinate (common, Y_AXIS) - my_y);
120     }
121
122   Real lt = me->get_layout ()->get_dimension (ly_symbol2scm ("linethickness"));
123   Real sp = 1.5 * Staff_symbol_referencer::staff_space (me);
124   Real dy = heads.length () + sp;
125   Real x = 0.7;
126
127   Stencil mol (Lookup::bracket (Y_AXIS, Interval (0, dy), lt, x, lt));
128   mol.translate_axis (heads[LEFT] - sp / 2.0, Y_AXIS);
129   return mol.smobbed_copy ();
130 }
131
132 /*
133   We have to do a callback, because print () triggers a
134   vertical alignment if it is cross-staff.
135 */
136 MAKE_SCHEME_CALLBACK (Arpeggio, width, 1);
137 SCM
138 Arpeggio::width (SCM smob)
139 {
140   Grob *me = unsmob_grob (smob);
141   Stencil arpeggio = Font_interface::get_default_font (me)->find_by_name ("scripts.arpeggio");
142
143   return ly_interval2scm (arpeggio.extent (X_AXIS));
144 }
145
146 ADD_INTERFACE (Arpeggio, "arpeggio-interface",
147                "Functions and settings for drawing an arpeggio symbol (a wavy line left to noteheads.",
148
149                /* properties */
150                "arpeggio-direction "
151                "stems "
152                );
153