]> git.donarmstrong.com Git - lilypond.git/blob - lily/arpeggio.cc
''
[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--2002 Jan Nieuwenhuizen <janneke@gnu.org>
7  */
8
9 #include "molecule.hh"
10 #include "paper-def.hh"
11 #include "arpeggio.hh"
12 #include "grob.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
20 bool
21 Arpeggio::has_interface (Grob* me)
22 {
23   return me && me->has_interface (ly_symbol2scm ("arpeggio-interface"));
24 }
25
26 MAKE_SCHEME_CALLBACK (Arpeggio, brew_molecule, 1);
27 SCM 
28 Arpeggio::brew_molecule (SCM smob) 
29 {
30   Grob *me = unsmob_grob (smob);
31   
32   Grob * common = me;
33   for (SCM s = me->get_grob_property ("stems"); gh_pair_p (s); s = ly_cdr (s))
34     {
35       Grob * stem =  unsmob_grob (ly_car (s));
36       common =  common->common_refpoint (Staff_symbol_referencer::staff_symbol_l (stem),
37                                  Y_AXIS);
38     }
39
40   /*
41     TODO:
42     
43     Using stems here is not very convenient; should store noteheads
44     instead, and also put them into the support. Now we will mess up
45     in vicinity of a collision.
46
47   */
48   Interval heads;
49   Real my_y = me->relative_coordinate (common, Y_AXIS);
50       
51   for (SCM s = me->get_grob_property ("stems"); gh_pair_p (s); s = ly_cdr (s))
52     {
53       Grob * stem = unsmob_grob (ly_car (s));
54       Grob * ss = Staff_symbol_referencer::staff_symbol_l (stem);
55       Interval iv =Stem::head_positions (stem);
56       iv *= Staff_symbol::staff_space (ss)/2.0;
57       
58       heads.unite (iv + ss->relative_coordinate (common, Y_AXIS)
59                    - my_y);
60     }
61
62   if (heads.empty_b ())
63     {
64       programming_error ("Huh? Dumb blonde encountered?");
65       /*
66         Nee Valerie, jij bent _niet_ dom. 
67        */
68       return SCM_EOL;
69     }
70
71   Direction dir = CENTER;
72   if (ly_dir_p (me->get_grob_property ("arpeggio-direction")))
73     {
74       dir = to_dir (me->get_grob_property ("arpeggio-direction"));
75     }
76   
77   Molecule mol;
78   Font_metric *fm =Font_interface::get_default_font (me);
79   Molecule squiggle = fm->find_by_name ("scripts-arpeggio");
80
81   Real arrow_space = (dir) ? Staff_symbol_referencer::staff_space (me)  : 0.0;
82   
83   Real y = heads[LEFT];
84   while (y < heads[RIGHT] - arrow_space)
85     {
86       mol.add_at_edge (Y_AXIS, UP,squiggle, 0.0);
87       y+= squiggle. extent (Y_AXIS).length ();
88     }
89   mol.translate_axis (heads[LEFT], Y_AXIS);
90   if (dir)
91     mol.add_at_edge (Y_AXIS, dir,
92                      fm->find_by_name ("scripts-arpeggio-arrow-" + to_str (dir)), 0.0);
93   
94   return mol.smobbed_copy () ;
95 }
96
97 /* Draws a vertical bracket to the left of a chord 
98    Chris Jackson <chris@fluffhouse.org.uk> */
99
100 MAKE_SCHEME_CALLBACK (Arpeggio, brew_chord_bracket, 1);
101 SCM 
102 Arpeggio::brew_chord_bracket (SCM smob) 
103 {
104   Grob *me = unsmob_grob (smob);
105   
106   Grob * common = me;
107   for (SCM s = me->get_grob_property ("stems"); gh_pair_p (s); s = ly_cdr (s))
108     {
109       Grob * stem =  unsmob_grob (ly_car (s));
110       common =  common->common_refpoint (Staff_symbol_referencer::staff_symbol_l (stem),
111                                  Y_AXIS);
112     }
113
114   Interval heads;
115   Real my_y = me->relative_coordinate (common, Y_AXIS);
116       
117   for (SCM s = me->get_grob_property ("stems"); gh_pair_p (s); s = ly_cdr (s))
118     {
119       Grob * stem = unsmob_grob (ly_car (s));
120       Grob * ss = Staff_symbol_referencer::staff_symbol_l (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->paper_l ()->get_var ("linethickness");
127   Real sp = 1.5 * Staff_symbol_referencer::staff_space (me);
128   Real dy = heads.length() + sp;
129   Real x = 0.7;
130
131   Molecule l1     = Lookup::line (lt, Offset(0, 0),  Offset (0, dy));
132   Molecule bottom = Lookup::line (lt, Offset(0, 0),  Offset (x, 0));
133   Molecule top    = Lookup::line (lt, Offset(0, dy), Offset (x, dy));
134   Molecule mol;
135   mol.add_molecule (l1);
136   mol.add_molecule (bottom);
137   mol.add_molecule (top);
138   mol.translate_axis (heads[LEFT] - sp/2.0, Y_AXIS);
139   return mol.smobbed_copy();
140 }
141
142
143 /*
144   We have to do a callback, because brew_molecule () triggers a
145   vertical alignment if it is cross-staff.
146   This callback also adds padding.
147 */
148 MAKE_SCHEME_CALLBACK (Arpeggio, width_callback,2);
149 SCM
150 Arpeggio::width_callback (SCM smob, SCM axis)
151 {
152   Grob * me = unsmob_grob (smob);
153   Axis a = (Axis)gh_scm2int (axis);
154   assert (a == X_AXIS);
155   Molecule arpeggio = Font_interface::get_default_font (me)->find_by_name ("scripts-arpeggio");
156
157   return ly_interval2scm (arpeggio.extent (X_AXIS) * 1.5);
158 }
159
160
161 ADD_INTERFACE (Arpeggio, "arpeggio-interface",
162   "Functions and settings for drawing an arpeggio symbol (a wavy line left to noteheads.",
163   "stems arpeggio-direction");
164