]> git.donarmstrong.com Git - lilypond.git/blob - lily/arpeggio.cc
patch::: 1.5.7.jcn2
[lilypond.git] / lily / arpeggio.cc
1 /*   
2   arpegggio.cc -- implement Arpeggio
3
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 2000--2001 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
19 bool
20 Arpeggio::has_interface (Grob* me)
21 {
22   return me && me->has_interface (ly_symbol2scm ("arpeggio-interface"));
23 }
24
25 MAKE_SCHEME_CALLBACK (Arpeggio, brew_molecule, 1);
26 SCM 
27 Arpeggio::brew_molecule (SCM smob) 
28 {
29   Grob *me = unsmob_grob (smob);
30   
31   Grob * common = me;
32   for (SCM s = me->get_grob_property ("stems"); gh_pair_p (s); s = gh_cdr (s))
33     {
34       Grob * stem =  unsmob_grob (gh_car (s));
35       common =  common->common_refpoint (Staff_symbol_referencer::staff_symbol_l (stem),
36                                  Y_AXIS);
37     }
38
39   /*
40     TODO:
41     
42     Using stems here is not very convenient; should store noteheads
43     instead, and also put them into the support. Now we will mess up
44     in vicinity of a collision.
45
46   */
47   Interval heads;
48   Real my_y = me->relative_coordinate (common, Y_AXIS);
49       
50   for (SCM s = me->get_grob_property ("stems"); gh_pair_p (s); s = gh_cdr (s))
51     {
52       Grob * stem = unsmob_grob (gh_car (s));
53       Grob * ss = Staff_symbol_referencer::staff_symbol_l (stem);
54       Interval iv =Stem::head_positions (stem);
55       iv *= Staff_symbol::staff_space (ss)/2.0;
56       
57       heads.unite (iv + ss->relative_coordinate (common, Y_AXIS)
58                    - my_y);
59     }
60
61   if (heads.empty_b ())
62     {
63       programming_error ("Huh? Dumb blonde encountered?");
64       /*
65         Nee Valerie, jij bent _niet_ dom. 
66        */
67       return SCM_EOL;
68     }
69   
70   SCM s = me->get_grob_property ("arpeggio-type");
71   String arpegtype = ly_scm2string (scm_symbol_to_string (s));
72   Molecule arpegbottom = ( (arpegtype=="bracket") ? 
73                            Font_interface::get_default_font (me)->find_by_name ("scripts-bracebottom") :
74                            ((arpegtype=="down") ? 
75                             Font_interface::get_default_font (me)->find_by_name ("scripts-arrowdown") :
76                             Font_interface::get_default_font (me)->find_by_name ("scripts-arpeggio"))
77                            );
78   Molecule arpegmiddle = ( (arpegtype=="bracket") ? 
79                            Font_interface::get_default_font (me)->find_by_name ("scripts-braceseg") :
80                            Font_interface::get_default_font (me)->find_by_name ("scripts-arpeggio") );
81   Molecule arpegtop = ( (arpegtype=="bracket") ? 
82                         Font_interface::get_default_font (me)->find_by_name ("scripts-bracetop") :
83                         ((arpegtype=="up") ? 
84                          Font_interface::get_default_font (me)->find_by_name ("scripts-arrowup") :
85                          Font_interface::get_default_font (me)->find_by_name ("scripts-arpeggio"))
86                         );
87   
88   Molecule mol;
89   Real y = heads[LEFT];
90   
91   mol.add_at_edge (Y_AXIS, UP, arpegbottom, 0.0);
92   y+= arpegbottom. extent (Y_AXIS).length ();
93   
94   Grob * stem = unsmob_grob (gh_car ( me->get_grob_property ("stems") ));
95   Grob * ss = Staff_symbol_referencer::staff_symbol_l (stem);
96   
97   while (y < heads[RIGHT]  -  Staff_symbol::staff_space (ss))
98     {
99       mol.add_at_edge (Y_AXIS, UP, arpegmiddle, 0.0);
100       y+= arpegmiddle. extent (Y_AXIS).length ();
101     }
102   mol.add_at_edge (Y_AXIS, UP, arpegtop, 0.0);
103   
104   mol.translate_axis (heads[LEFT], Y_AXIS);
105
106   return mol.smobbed_copy () ;
107 }
108
109 /*
110   We have to do a callback, because brew_molecule () triggers a
111   vertical alignment if it is cross-staff.
112   This callback also adds padding.
113 */
114 MAKE_SCHEME_CALLBACK (Arpeggio, width_callback,2);
115 SCM
116 Arpeggio::width_callback (SCM smob, SCM axis)
117 {
118   Grob * me = unsmob_grob (smob);
119   Axis a = (Axis)gh_scm2int (axis);
120   assert (a == X_AXIS);
121   Molecule arpeggio = Font_interface::get_default_font (me)->find_by_name ("scripts-arpeggio");
122
123   return ly_interval2scm (arpeggio.extent (X_AXIS) * 1.5);
124 }