]> git.donarmstrong.com Git - lilypond.git/blob - lily/arpeggio.cc
* lily/system.cc (do_derived_mark): don't mark from object_alist_
[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 ())
59     {
60       /*
61         Dumb blonde error
62
63         :-)
64       */
65       programming_error ("no heads for arpeggio found?");
66       return SCM_EOL;
67     }
68
69   SCM ad = me->get_property ("arpeggio-direction");
70   Direction dir = CENTER;
71   if (is_direction (ad))
72     {
73       dir = to_dir (ad);
74     }
75
76   Stencil mol;
77   Font_metric *fm = Font_interface::get_default_font (me);
78   Stencil squiggle = fm->find_by_name ("scripts.arpeggio");
79
80   Stencil arrow;
81   if (dir)
82     {
83       arrow = fm->find_by_name ("scripts.arpeggio.arrow." + to_string (dir));
84       heads[dir] -= dir * arrow.extent (Y_AXIS).length ();
85     }
86
87   for (Real y = heads[LEFT]; y < heads[RIGHT];
88        y += squiggle.extent (Y_AXIS).length ())
89     mol.add_at_edge (Y_AXIS, UP, squiggle, 0.0, 0);
90
91   mol.translate_axis (heads[LEFT], Y_AXIS);
92   if (dir)
93     mol.add_at_edge (Y_AXIS, dir, arrow, 0, 0);
94
95   return mol.smobbed_copy ();
96 }
97
98 /* Draws a vertical bracket to the left of a chord
99    Chris Jackson <chris@fluffhouse.org.uk> */
100
101 MAKE_SCHEME_CALLBACK (Arpeggio, brew_chord_bracket, 1);
102 SCM
103 Arpeggio::brew_chord_bracket (SCM smob)
104 {
105   Grob *me = unsmob_grob (smob);
106
107   Grob *common = me;
108
109   
110   extract_grob_set (me, "stems", stems);
111   for (int i = 0;  i < stems.size(); i++)
112     {
113       Grob *stem = stems[i];
114       common = common->common_refpoint (Staff_symbol_referencer::get_staff_symbol (stem),
115                                         Y_AXIS);
116     }
117
118   Interval heads;
119   Real my_y = me->relative_coordinate (common, Y_AXIS);
120
121   for (int i = 0;  i < stems.size(); i++)
122     {
123       Grob *stem = stems[i];
124       Grob *ss = Staff_symbol_referencer::get_staff_symbol (stem);
125       Interval iv = Stem::head_positions (stem);
126       iv *= Staff_symbol::staff_space (ss) / 2.0;
127       heads.unite (iv + ss->relative_coordinate (common, Y_AXIS) - my_y);
128     }
129
130   Real lt = me->get_layout ()->get_dimension (ly_symbol2scm ("linethickness"));
131   Real sp = 1.5 * Staff_symbol_referencer::staff_space (me);
132   Real dy = heads.length () + sp;
133   Real x = 0.7;
134
135   Stencil mol (Lookup::bracket (Y_AXIS, Interval (0, dy), lt, x, lt));
136   mol.translate_axis (heads[LEFT] - sp / 2.0, Y_AXIS);
137   return mol.smobbed_copy ();
138 }
139
140 /*
141   We have to do a callback, because print () triggers a
142   vertical alignment if it is cross-staff.
143 */
144 MAKE_SCHEME_CALLBACK (Arpeggio, width_callback, 2);
145 SCM
146 Arpeggio::width_callback (SCM smob, SCM axis)
147 {
148   Grob *me = unsmob_grob (smob);
149   (void) axis;
150   
151   assert (scm_to_int (axis) == X_AXIS);
152   Stencil arpeggio = Font_interface::get_default_font (me)->find_by_name ("scripts.arpeggio");
153
154   return ly_interval2scm (arpeggio.extent (X_AXIS));
155 }
156
157 ADD_INTERFACE (Arpeggio, "arpeggio-interface",
158                "Functions and settings for drawing an arpeggio symbol (a wavy line left to noteheads.",
159                "stems arpeggio-direction");
160