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