2 lookup.cc -- implement simple Lookup methods.
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2002 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 = scm_list_n (ly_symbol2scm ("beam"),
41 gh_double2scm (width),
42 gh_double2scm (slope),
43 gh_double2scm (thick),
45 return Molecule (b, at);
50 Lookup::dashed_slur (Bezier b, Real thick, Real dash)
54 for (int i= 4; i -- ;)
56 l = gh_cons (ly_offset2scm (b.control_[i]), l);
59 SCM at = (scm_list_n (ly_symbol2scm ("dashed-slur"),
60 gh_double2scm (thick),
65 Box box (Interval (0,0),Interval (0,0));
66 return Molecule (box, at);
72 return Molecule (b, SCM_EOL);
77 Lookup::filledbox (Box b)
79 SCM at = (scm_list_n (ly_symbol2scm ("filledbox"),
80 gh_double2scm (-b[X_AXIS][LEFT]),
81 gh_double2scm (b[X_AXIS][RIGHT]),
82 gh_double2scm (-b[Y_AXIS][DOWN]),
83 gh_double2scm (b[Y_AXIS][UP]),
86 return Molecule (b,at);
91 Lookup::frame (Box b, Real thick)
100 Axis o = Axis ((a+1)%NO_AXES);
103 edges[a] = b[a][d] + 0.5 * thick * Interval (-1, 1);
104 edges[o][DOWN] = b[o][DOWN] - thick/2;
105 edges[o][UP] = b[o][UP] + thick/2;
107 m.add_molecule (filledbox (edges));
109 while (flip (&d) != LEFT);
117 Make a smooth curve along the points
120 Lookup::slur (Bezier curve, Real curvethick, Real linethick)
122 Real alpha = (curve.control_[3] - curve.control_[0]).arg ();
124 Offset perp = curvethick * complex_exp (Offset (0, alpha + M_PI/2)) * 0.5;
126 back.control_[1] += perp;
127 back.control_[2] += perp;
129 curve.control_[1] -= perp;
130 curve.control_[2] -= perp;
135 scontrols[ i ] = ly_offset2scm (back.control_[i]);
137 scontrols[i+4] = ly_offset2scm (curve.control_[i]);
140 Need the weird order b.o. the way PS want its arguments
142 int indices[]= {5, 6, 7, 4, 1, 2, 3, 0};
146 list = gh_cons (scontrols[indices[i]], list);
150 SCM at = (scm_list_n (ly_symbol2scm ("bezier-sandwich"),
152 gh_double2scm (linethick),
154 Box b(curve.extent (X_AXIS),
155 curve.extent (Y_AXIS));
157 b[X_AXIS].unite (back.extent (X_AXIS));
158 b[Y_AXIS].unite (back.extent (Y_AXIS));
160 return Molecule (b, at);
187 Lookup::bezier_sandwich (Bezier top_curve, Bezier bottom_curve)
190 Need the weird order b.o. the way PS want its arguments
193 list = gh_cons (ly_offset2scm (bottom_curve.control_[3]), list);
194 list = gh_cons (ly_offset2scm (bottom_curve.control_[0]), list);
195 list = gh_cons (ly_offset2scm (bottom_curve.control_[1]), list);
196 list = gh_cons (ly_offset2scm (bottom_curve.control_[2]), list);
197 list = gh_cons (ly_offset2scm (top_curve.control_[0]), list);
198 list = gh_cons (ly_offset2scm (top_curve.control_[3]), list);
199 list = gh_cons (ly_offset2scm (top_curve.control_[2]), list);
200 list = gh_cons (ly_offset2scm (top_curve.control_[1]), list);
202 SCM horizontal_bend = scm_list_n (ly_symbol2scm ("bezier-sandwich"),
207 Interval x_extent = top_curve.extent (X_AXIS);
208 x_extent.unite (bottom_curve.extent (X_AXIS));
209 Interval y_extent = top_curve.extent (Y_AXIS);
210 y_extent.unite (bottom_curve.extent (Y_AXIS));
211 Box b (x_extent, y_extent);
213 return Molecule (b, horizontal_bend);
226 * (0,0) x /slope=dy/dx
234 Lookup::horizontal_slope (Real width, Real slope, Real height)
236 SCM width_scm = gh_double2scm (width);
237 SCM slope_scm = gh_double2scm (slope);
238 SCM height_scm = gh_double2scm (height);
239 SCM horizontal_slope = scm_list_n (ly_symbol2scm ("beam"),
240 width_scm, slope_scm,
241 height_scm, SCM_UNDEFINED);
242 Box b (Interval (0, width),
243 Interval (-height/2, height/2 + width*slope));
244 return Molecule (b, horizontal_slope);
251 Lookup::accordion (SCM s, Real staff_space, Font_metric *fm)
254 String sym = ly_scm2string (ly_car (s));
255 String reg = ly_scm2string (ly_car (ly_cdr (s)));
257 if (sym == "Discant")
259 Molecule r = fm->find_by_name ("accordion-accDiscant");
261 if (reg.left_str (1) == "F")
263 Molecule d = fm->find_by_name ("accordion-accDot");
264 d.translate_axis (staff_space * 2.5 PT, Y_AXIS);
266 reg = reg.right_str (reg.length_i ()-1);
269 if (reg.left_str (3) == "EEE")
272 reg = reg.right_str (reg.length_i ()-3);
274 else if (reg.left_str (2) == "EE")
277 reg = reg.right_str (reg.length_i ()-2);
279 else if (reg.left_str (2) == "Eh")
282 reg = reg.right_str (reg.length_i ()-2);
284 else if (reg.left_str (1) == "E")
287 reg = reg.right_str (reg.length_i ()-1);
291 Molecule d = fm->find_by_name ("accordion-accDot");
292 d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
297 Molecule d = fm->find_by_name ("accordion-accDot");
298 d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
299 d.translate_axis (0.8 * staff_space PT, X_AXIS);
304 Molecule d = fm->find_by_name ("accordion-accDot");
305 d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
306 d.translate_axis (-0.8 * staff_space PT, X_AXIS);
309 if (reg.left_str (2) == "SS")
311 Molecule d = fm->find_by_name ("accordion-accDot");
312 d.translate_axis (0.5 * staff_space PT, Y_AXIS);
313 d.translate_axis (0.4 * staff_space PT, X_AXIS);
315 d.translate_axis (-0.8 * staff_space PT, X_AXIS);
317 reg = reg.right_str (reg.length_i ()-2);
319 if (reg.left_str (1) == "S")
321 Molecule d = fm->find_by_name ("accordion-accDot");
322 d.translate_axis (0.5 * staff_space PT, Y_AXIS);
324 reg = reg.right_str (reg.length_i ()-1);
327 else if (sym == "Freebase")
329 Molecule r = fm->find_by_name ("accordion-accFreebase");
331 if (reg.left_str (1) == "F")
333 Molecule d = fm->find_by_name ("accordion-accDot");
334 d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
336 reg = reg.right_str (reg.length_i ()-1);
340 Molecule d = fm->find_by_name ("accordion-accDot");
341 d.translate_axis (staff_space * 0.5 PT, Y_AXIS);
345 else if (sym == "Bayanbase")
347 Molecule r = fm->find_by_name ("accordion-accBayanbase");
349 if (reg.left_str (1) == "T")
351 Molecule d = fm->find_by_name ("accordion-accDot");
352 d.translate_axis (staff_space * 2.5 PT, Y_AXIS);
354 reg = reg.right_str (reg.length_i ()-1);
356 /* include 4' reed just for completeness. You don't want to use this. */
357 if (reg.left_str (1) == "F")
359 Molecule d = fm->find_by_name ("accordion-accDot");
360 d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
362 reg = reg.right_str (reg.length_i ()-1);
364 if (reg.left_str (2) == "EE")
366 Molecule d = fm->find_by_name ("accordion-accDot");
367 d.translate_axis (staff_space * 0.5 PT, Y_AXIS);
368 d.translate_axis (0.4 * staff_space PT, X_AXIS);
370 d.translate_axis (-0.8 * staff_space PT, X_AXIS);
372 reg = reg.right_str (reg.length_i ()-2);
374 if (reg.left_str (1) == "E")
376 Molecule d = fm->find_by_name ("accordion-accDot");
377 d.translate_axis (staff_space * 0.5 PT, Y_AXIS);
379 reg = reg.right_str (reg.length_i ()-1);
382 else if (sym == "Stdbase")
384 Molecule r = fm->find_by_name ("accordion-accStdbase");
386 if (reg.left_str (1) == "T")
388 Molecule d = fm->find_by_name ("accordion-accDot");
389 d.translate_axis (staff_space * 3.5 PT, Y_AXIS);
391 reg = reg.right_str (reg.length_i ()-1);
393 if (reg.left_str (1) == "F")
395 Molecule d = fm->find_by_name ("accordion-accDot");
396 d.translate_axis (staff_space * 2.5 PT, Y_AXIS);
398 reg = reg.right_str (reg.length_i ()-1);
400 if (reg.left_str (1) == "M")
402 Molecule d = fm->find_by_name ("accordion-accDot");
403 d.translate_axis (staff_space * 2 PT, Y_AXIS);
404 d.translate_axis (staff_space PT, X_AXIS);
406 reg = reg.right_str (reg.length_i ()-1);
408 if (reg.left_str (1) == "E")
410 Molecule d = fm->find_by_name ("accordion-accDot");
411 d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
413 reg = reg.right_str (reg.length_i ()-1);
415 if (reg.left_str (1) == "S")
417 Molecule d = fm->find_by_name ("accordion-accDot");
418 d.translate_axis (staff_space * 0.5 PT, Y_AXIS);
420 reg = reg.right_str (reg.length_i ()-1);
423 /* ugh maybe try to use regular font for S.B. and B.B and only use one font
425 else if (sym == "SB")
427 Molecule r = fm->find_by_name ("accordion-accSB");
430 else if (sym == "BB")
432 Molecule r = fm->find_by_name ("accordion-accBB");
435 else if (sym == "OldEE")
437 Molecule r = fm->find_by_name ("accordion-accOldEE");
440 else if (sym == "OldEES")
442 Molecule r = fm->find_by_name ("accordion-accOldEES");
449 Lookup::repeat_slash (Real w, Real s, Real t)
451 SCM wid = gh_double2scm (w);
452 SCM sl = gh_double2scm (s);
453 SCM thick = gh_double2scm (t);
454 SCM slashnodot = scm_list_n (ly_symbol2scm ("repeat-slash"),
455 wid, sl, thick, SCM_UNDEFINED);
457 Box b (Interval (0, w + sqrt (sqr(t/s) + sqr (t))),
458 Interval (0, w * s));
460 return Molecule (b, slashnodot); // http://slashnodot.org
466 Lookup::bracket (Axis a, Interval iv, Direction d, Real thick, Real protude)
469 Axis other = Axis((a+1)%2);
471 b[other] = Interval(-1, 1) * thick * 0.5;
473 Molecule m = filledbox (b);
475 b[a] = Interval (iv[UP] - thick, iv[UP]);
476 Interval oi = Interval (-thick/2, thick/2 + protude) ;
479 m.add_molecule (filledbox (b));
480 b[a] = Interval (iv[DOWN], iv[DOWN] +thick);
481 m.add_molecule (filledbox(b));
487 ly_bracket (SCM a, SCM iv, SCM d, SCM t, SCM p)
489 SCM_ASSERT_TYPE(ly_axis_p (a), a, SCM_ARG1, __FUNCTION__, "axis") ;
490 SCM_ASSERT_TYPE(ly_number_pair_p (iv), iv, SCM_ARG1, __FUNCTION__, "number pair") ;
491 SCM_ASSERT_TYPE(ly_dir_p (d), a, SCM_ARG1, __FUNCTION__, "direction") ;
492 SCM_ASSERT_TYPE(gh_number_p (t), a, SCM_ARG1, __FUNCTION__, "number") ;
493 SCM_ASSERT_TYPE(gh_number_p(p), a, SCM_ARG1, __FUNCTION__, "number") ;
496 return Lookup::bracket ((Axis)gh_scm2int (a), ly_scm2interval (iv),
497 (Direction)gh_scm2int (d), gh_scm2double (t), gh_scm2double (p)).smobbed_copy ();
503 scm_c_define_gsubr ("ly-bracket", 5, 0, 0, (Scheme_function_unknown) ly_bracket);
506 ADD_SCM_INIT_FUNC (lookup,lookup_init);