2 lookup.cc -- implement simple Lookup methods.
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 Jan Nieuwenhuizen <janneke@gnu.org>
17 #include "dimensions.hh"
19 #include "string-convert.hh"
20 #include "file-path.hh"
22 #include "lily-guile.hh"
23 #include "molecule.hh"
25 #include "font-metric.hh"
28 Lookup::beam (Real slope
, Real width
, Real thick
)
30 Real height
= slope
* width
;
31 Real min_y
= (0 <? height
) - thick
/2;
32 Real max_y
= (0 >? height
) + thick
/2;
36 Box
b (Interval (0, width
),
37 Interval (min_y
, max_y
));
40 SCM at
= gh_list (ly_symbol2scm ("beam"),
41 gh_double2scm (width
),
42 gh_double2scm (slope
),
43 gh_double2scm (thick
),
45 return Molecule (b
, at
);
51 Lookup::dashed_slur (Bezier b
, Real thick
, Real dash
)
55 for (int i
= 4; i
-- ;)
57 l
= gh_cons (ly_offset2scm (b
.control_
[i
]), l
);
60 SCM at
= (gh_list (ly_symbol2scm ("dashed-slur"),
61 gh_double2scm (thick
),
66 Box
box (Interval (0,0),Interval (0,0));
67 return Molecule (box
, at
);
76 return Molecule (b
, SCM_EOL
);
81 Lookup::filledbox (Box b
)
83 SCM at
= (gh_list (ly_symbol2scm ("filledbox"),
84 gh_double2scm (-b
[X_AXIS
][LEFT
]),
85 gh_double2scm (b
[X_AXIS
][RIGHT
]),
86 gh_double2scm (-b
[Y_AXIS
][DOWN
]),
87 gh_double2scm (b
[Y_AXIS
][UP
]),
90 return Molecule (b
,at
);
94 Lookup::frame (Box b
, Real thick
)
103 Axis o
= Axis ((a
+1)%NO_AXES
);
106 edges
[a
] = b
[a
][d
] + 0.5 * thick
* Interval (-1, 1);
107 edges
[o
][DOWN
] = b
[o
][DOWN
] - thick
/2;
108 edges
[o
][UP
] = b
[o
][UP
] + thick
/2;
111 m
.add_molecule (filledbox (edges
));
113 while (flip (&d
) != LEFT
);
121 Make a smooth curve along the points
124 Lookup::slur (Bezier curve
, Real curvethick
, Real linethick
)
126 Real alpha
= (curve
.control_
[3] - curve
.control_
[0]).arg ();
130 back
.control_
[1] += curvethick
* complex_exp (Offset (0, alpha
+ M_PI
/2));
131 back
.control_
[2] += curvethick
* complex_exp (Offset (0, alpha
+ M_PI
/2));
136 scontrols
[ i
] = ly_offset2scm (back
.control_
[i
]);
138 scontrols
[i
+4] = ly_offset2scm (curve
.control_
[i
]);
141 Need the weird order b.o. the way PS want its arguments
143 int indices
[]= {5, 6, 7, 4, 1, 2, 3, 0};
147 list
= gh_cons (scontrols
[indices
[i
]], list
);
151 SCM at
= (gh_list (ly_symbol2scm ("bezier-sandwich"),
153 gh_double2scm (linethick
),
156 Box
b (curve
.extent (X_AXIS
), curve
.extent (Y_AXIS
));
157 return Molecule (b
, at
);
161 Lookup::accordion (SCM s
, Real staff_space
, Font_metric
*fm
)
164 String sym
= ly_scm2string (gh_car (s
));
165 String reg
= ly_scm2string (gh_car (gh_cdr (s
)));
167 if (sym
== "Discant")
169 Molecule r
= fm
->find_by_name ("accordion-accDiscant");
171 if (reg
.left_str (1) == "F")
173 Molecule d
= fm
->find_by_name ("accordion-accDot");
174 d
.translate_axis (staff_space
* 2.5 PT
, Y_AXIS
);
176 reg
= reg
.right_str (reg
.length_i ()-1);
179 if (reg
.left_str (3) == "EEE")
182 reg
= reg
.right_str (reg
.length_i ()-3);
184 else if (reg
.left_str (2) == "EE")
187 reg
= reg
.right_str (reg
.length_i ()-2);
189 else if (reg
.left_str (2) == "Eh")
192 reg
= reg
.right_str (reg
.length_i ()-2);
194 else if (reg
.left_str (1) == "E")
197 reg
= reg
.right_str (reg
.length_i ()-1);
201 Molecule d
= fm
->find_by_name ("accordion-accDot");
202 d
.translate_axis (staff_space
* 1.5 PT
, Y_AXIS
);
207 Molecule d
= fm
->find_by_name ("accordion-accDot");
208 d
.translate_axis (staff_space
* 1.5 PT
, Y_AXIS
);
209 d
.translate_axis (0.8 * staff_space PT
, X_AXIS
);
214 Molecule d
= fm
->find_by_name ("accordion-accDot");
215 d
.translate_axis (staff_space
* 1.5 PT
, Y_AXIS
);
216 d
.translate_axis (-0.8 * staff_space PT
, X_AXIS
);
219 if (reg
.left_str (2) == "SS")
221 Molecule d
= fm
->find_by_name ("accordion-accDot");
222 d
.translate_axis (0.5 * staff_space PT
, Y_AXIS
);
223 d
.translate_axis (0.4 * staff_space PT
, X_AXIS
);
225 d
.translate_axis (-0.8 * staff_space PT
, X_AXIS
);
227 reg
= reg
.right_str (reg
.length_i ()-2);
229 if (reg
.left_str (1) == "S")
231 Molecule d
= fm
->find_by_name ("accordion-accDot");
232 d
.translate_axis (0.5 * staff_space PT
, Y_AXIS
);
234 reg
= reg
.right_str (reg
.length_i ()-1);
237 else if (sym
== "Freebase")
239 Molecule r
= fm
->find_by_name ("accordion-accFreebase");
241 if (reg
.left_str (1) == "F")
243 Molecule d
= fm
->find_by_name ("accordion-accDot");
244 d
.translate_axis (staff_space
* 1.5 PT
, Y_AXIS
);
246 reg
= reg
.right_str (reg
.length_i ()-1);
250 Molecule d
= fm
->find_by_name ("accordion-accDot");
251 d
.translate_axis (staff_space
* 0.5 PT
, Y_AXIS
);
255 else if (sym
== "Bayanbase")
257 Molecule r
= fm
->find_by_name ("accordion-accBayanbase");
259 if (reg
.left_str (1) == "T")
261 Molecule d
= fm
->find_by_name ("accordion-accDot");
262 d
.translate_axis (staff_space
* 2.5 PT
, Y_AXIS
);
264 reg
= reg
.right_str (reg
.length_i ()-1);
266 /* include 4' reed just for completeness. You don't want to use this. */
267 if (reg
.left_str (1) == "F")
269 Molecule d
= fm
->find_by_name ("accordion-accDot");
270 d
.translate_axis (staff_space
* 1.5 PT
, Y_AXIS
);
272 reg
= reg
.right_str (reg
.length_i ()-1);
274 if (reg
.left_str (2) == "EE")
276 Molecule d
= fm
->find_by_name ("accordion-accDot");
277 d
.translate_axis (staff_space
* 0.5 PT
, Y_AXIS
);
278 d
.translate_axis (0.4 * staff_space PT
, X_AXIS
);
280 d
.translate_axis (-0.8 * staff_space PT
, X_AXIS
);
282 reg
= reg
.right_str (reg
.length_i ()-2);
284 if (reg
.left_str (1) == "E")
286 Molecule d
= fm
->find_by_name ("accordion-accDot");
287 d
.translate_axis (staff_space
* 0.5 PT
, Y_AXIS
);
289 reg
= reg
.right_str (reg
.length_i ()-1);
292 else if (sym
== "Stdbase")
294 Molecule r
= fm
->find_by_name ("accordion-accStdbase");
296 if (reg
.left_str (1) == "T")
298 Molecule d
= fm
->find_by_name ("accordion-accDot");
299 d
.translate_axis (staff_space
* 3.5 PT
, Y_AXIS
);
301 reg
= reg
.right_str (reg
.length_i ()-1);
303 if (reg
.left_str (1) == "F")
305 Molecule d
= fm
->find_by_name ("accordion-accDot");
306 d
.translate_axis (staff_space
* 2.5 PT
, Y_AXIS
);
308 reg
= reg
.right_str (reg
.length_i ()-1);
310 if (reg
.left_str (1) == "M")
312 Molecule d
= fm
->find_by_name ("accordion-accDot");
313 d
.translate_axis (staff_space
* 2 PT
, Y_AXIS
);
314 d
.translate_axis (staff_space PT
, X_AXIS
);
316 reg
= reg
.right_str (reg
.length_i ()-1);
318 if (reg
.left_str (1) == "E")
320 Molecule d
= fm
->find_by_name ("accordion-accDot");
321 d
.translate_axis (staff_space
* 1.5 PT
, Y_AXIS
);
323 reg
= reg
.right_str (reg
.length_i ()-1);
325 if (reg
.left_str (1) == "S")
327 Molecule d
= fm
->find_by_name ("accordion-accDot");
328 d
.translate_axis (staff_space
* 0.5 PT
, Y_AXIS
);
330 reg
= reg
.right_str (reg
.length_i ()-1);
333 /* ugh maybe try to use regular font for S.B. and B.B and only use one font
335 else if (sym
== "SB")
337 Molecule r
= fm
->find_by_name ("accordion-accSB");
340 else if (sym
== "BB")
342 Molecule r
= fm
->find_by_name ("accordion-accBB");
345 else if (sym
== "OldEE")
347 Molecule r
= fm
->find_by_name ("accordion-accOldEE");
350 else if (sym
== "OldEES")
352 Molecule r
= fm
->find_by_name ("accordion-accOldEES");
359 TODO: should use slope instead? Angle gives nasty rad <-> degree
363 Lookup::repeat_slash (Real w
, Real s
, Real t
)
365 SCM wid
= gh_double2scm (w
);
366 SCM sl
= gh_double2scm (s
);
367 SCM thick
= gh_double2scm (t
);
368 SCM slashnodot
= gh_list (ly_symbol2scm ("repeat-slash"),
369 wid
, sl
, thick
, SCM_UNDEFINED
);
371 Box
b (Interval (0, w
+ sqrt (sqr(t
/s
) + sqr (t
))),
372 Interval (0, w
* s
));
374 return Molecule (b
, slashnodot
);