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