]> git.donarmstrong.com Git - lilypond.git/blob - lily/arpeggio.cc
* flower
[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
19 MAKE_SCHEME_CALLBACK (Arpeggio, print, 1);
20 SCM
21 Arpeggio::print (SCM smob)
22 {
23   Grob *me = unsmob_grob (smob);
24
25   Grob *common = me;
26   for (SCM s = me->get_property ("stems"); scm_is_pair (s); s = scm_cdr (s))
27     {
28       Grob *stem = unsmob_grob (scm_car (s));
29       common = common->common_refpoint (Staff_symbol_referencer::get_staff_symbol (stem),
30                                         Y_AXIS);
31     }
32
33   /*
34     TODO:
35
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.
39
40   */
41   Interval heads;
42   Real my_y = me->relative_coordinate (common, Y_AXIS);
43
44   for (SCM s = me->get_property ("stems"); scm_is_pair (s); s = scm_cdr (s))
45     {
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;
50
51       heads.unite (iv + ss->relative_coordinate (common, Y_AXIS)
52                    - my_y);
53     }
54
55   if (heads.is_empty ())
56     {
57       /*
58         Dumb blonde error
59
60         :-)
61       */
62       programming_error ("Huh, no heads for arpeggio found.");
63       return SCM_EOL;
64     }
65
66   SCM ad = me->get_property ("arpeggio-direction");
67   Direction dir = CENTER;
68   if (is_direction (ad))
69     {
70       dir = to_dir (ad);
71     }
72
73   Stencil mol;
74   Font_metric *fm = Font_interface::get_default_font (me);
75   Stencil squiggle = fm->find_by_name ("scripts.arpeggio");
76
77   Stencil arrow;
78   if (dir)
79     {
80       arrow = fm->find_by_name ("scripts.arpeggio.arrow." + to_string (dir));
81       heads[dir] -= dir * arrow.extent (Y_AXIS).length ();
82     }
83
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);
87
88   mol.translate_axis (heads[LEFT], Y_AXIS);
89   if (dir)
90     mol.add_at_edge (Y_AXIS, dir, arrow, 0, 0);
91
92   return mol.smobbed_copy ();
93 }
94
95 /* Draws a vertical bracket to the left of a chord
96    Chris Jackson <chris@fluffhouse.org.uk> */
97
98 MAKE_SCHEME_CALLBACK (Arpeggio, brew_chord_bracket, 1);
99 SCM
100 Arpeggio::brew_chord_bracket (SCM smob)
101 {
102   Grob *me = unsmob_grob (smob);
103
104   Grob *common = me;
105   for (SCM s = me->get_property ("stems"); scm_is_pair (s); s = scm_cdr (s))
106     {
107       Grob *stem = unsmob_grob (scm_car (s));
108       common = common->common_refpoint (Staff_symbol_referencer::get_staff_symbol (stem),
109                                         Y_AXIS);
110     }
111
112   Interval heads;
113   Real my_y = me->relative_coordinate (common, Y_AXIS);
114
115   for (SCM s = me->get_property ("stems"); scm_is_pair (s); s = scm_cdr (s))
116     {
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);
122     }
123
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;
127   Real x = 0.7;
128
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 ();
132 }
133
134 /*
135   We have to do a callback, because print () triggers a
136   vertical alignment if it is cross-staff.
137 */
138 MAKE_SCHEME_CALLBACK (Arpeggio, width_callback, 2);
139 SCM
140 Arpeggio::width_callback (SCM smob, SCM axis)
141 {
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");
146
147   return ly_interval2scm (arpeggio.extent (X_AXIS));
148 }
149
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");
153