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);
49 Lookup::dashed_slur (Bezier b, Real thick, Real dash)
53 for (int i= 4; i -- ;)
55 l = gh_cons (ly_offset2scm (b.control_[i]), l);
58 SCM at = (scm_list_n (ly_symbol2scm ("dashed-slur"),
59 gh_double2scm (thick),
64 Box box (Interval (0,0),Interval (0,0));
65 return Molecule (box, at);
71 return Molecule (b, SCM_EOL);
75 Lookup::filledbox (Box b)
77 SCM at = (scm_list_n (ly_symbol2scm ("filledbox"),
78 gh_double2scm (-b[X_AXIS][LEFT]),
79 gh_double2scm (b[X_AXIS][RIGHT]),
80 gh_double2scm (-b[Y_AXIS][DOWN]),
81 gh_double2scm (b[Y_AXIS][UP]),
84 return Molecule (b,at);
90 * __________________________
93 * | + | |dia | +---|------
95 * |\ _ _ / v \ _ _ /| |
98 * | <------>| | extent
105 * | x | | +---|------
107 * \__|__/______________\__|__/
111 * |<------------------>|
115 Lookup::roundfilledbox (Box b, Real blotdiameter)
117 SCM at = (scm_list_n (ly_symbol2scm ("roundfilledbox"),
118 gh_double2scm (-b[X_AXIS][LEFT]),
119 gh_double2scm (b[X_AXIS][RIGHT]),
120 gh_double2scm (-b[Y_AXIS][DOWN]),
121 gh_double2scm (b[Y_AXIS][UP]),
122 gh_double2scm (blotdiameter),
125 return Molecule (b,at);
129 Lookup::frame (Box b, Real thick)
138 Axis o = Axis ((a+1)%NO_AXES);
141 edges[a] = b[a][d] + 0.5 * thick * Interval (-1, 1);
142 edges[o][DOWN] = b[o][DOWN] - thick/2;
143 edges[o][UP] = b[o][UP] + thick/2;
145 m.add_molecule (filledbox (edges));
147 while (flip (&d) != LEFT);
154 Make a smooth curve along the points
157 Lookup::slur (Bezier curve, Real curvethick, Real linethick)
159 Real alpha = (curve.control_[3] - curve.control_[0]).arg ();
161 Offset perp = curvethick * complex_exp (Offset (0, alpha + M_PI/2)) * 0.5;
163 back.control_[1] += perp;
164 back.control_[2] += perp;
166 curve.control_[1] -= perp;
167 curve.control_[2] -= perp;
172 scontrols[ i ] = ly_offset2scm (back.control_[i]);
174 scontrols[i+4] = ly_offset2scm (curve.control_[i]);
177 Need the weird order b.o. the way PS want its arguments
179 int indices[]= {5, 6, 7, 4, 1, 2, 3, 0};
183 list = gh_cons (scontrols[indices[i]], list);
187 SCM at = (scm_list_n (ly_symbol2scm ("bezier-sandwich"),
189 gh_double2scm (linethick),
191 Box b(curve.extent (X_AXIS),
192 curve.extent (Y_AXIS));
194 b[X_AXIS].unite (back.extent (X_AXIS));
195 b[Y_AXIS].unite (back.extent (Y_AXIS));
197 return Molecule (b, at);
224 Lookup::bezier_sandwich (Bezier top_curve, Bezier bottom_curve)
227 Need the weird order b.o. the way PS want its arguments
230 list = gh_cons (ly_offset2scm (bottom_curve.control_[3]), list);
231 list = gh_cons (ly_offset2scm (bottom_curve.control_[0]), list);
232 list = gh_cons (ly_offset2scm (bottom_curve.control_[1]), list);
233 list = gh_cons (ly_offset2scm (bottom_curve.control_[2]), list);
234 list = gh_cons (ly_offset2scm (top_curve.control_[0]), list);
235 list = gh_cons (ly_offset2scm (top_curve.control_[3]), list);
236 list = gh_cons (ly_offset2scm (top_curve.control_[2]), list);
237 list = gh_cons (ly_offset2scm (top_curve.control_[1]), list);
239 SCM horizontal_bend = scm_list_n (ly_symbol2scm ("bezier-sandwich"),
244 Interval x_extent = top_curve.extent (X_AXIS);
245 x_extent.unite (bottom_curve.extent (X_AXIS));
246 Interval y_extent = top_curve.extent (Y_AXIS);
247 y_extent.unite (bottom_curve.extent (Y_AXIS));
248 Box b (x_extent, y_extent);
250 return Molecule (b, horizontal_bend);
263 * (0,0) x /slope=dy/dx
271 Lookup::horizontal_slope (Real width, Real slope, Real height)
273 SCM width_scm = gh_double2scm (width);
274 SCM slope_scm = gh_double2scm (slope);
275 SCM height_scm = gh_double2scm (height);
276 SCM horizontal_slope = scm_list_n (ly_symbol2scm ("beam"),
277 width_scm, slope_scm,
278 height_scm, SCM_UNDEFINED);
279 Box b (Interval (0, width),
280 Interval (-height/2, height/2 + width*slope));
281 return Molecule (b, horizontal_slope);
288 Lookup::accordion (SCM s, Real staff_space, Font_metric *fm)
291 String sym = ly_scm2string (ly_car (s));
292 String reg = ly_scm2string (ly_car (ly_cdr (s)));
294 if (sym == "Discant")
296 Molecule r = fm->find_by_name ("accordion-accDiscant");
298 if (reg.left_str (1) == "F")
300 Molecule d = fm->find_by_name ("accordion-accDot");
301 d.translate_axis (staff_space * 2.5 PT, Y_AXIS);
303 reg = reg.right_str (reg.length_i ()-1);
306 if (reg.left_str (3) == "EEE")
309 reg = reg.right_str (reg.length_i ()-3);
311 else if (reg.left_str (2) == "EE")
314 reg = reg.right_str (reg.length_i ()-2);
316 else if (reg.left_str (2) == "Eh")
319 reg = reg.right_str (reg.length_i ()-2);
321 else if (reg.left_str (1) == "E")
324 reg = reg.right_str (reg.length_i ()-1);
328 Molecule d = fm->find_by_name ("accordion-accDot");
329 d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
334 Molecule d = fm->find_by_name ("accordion-accDot");
335 d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
336 d.translate_axis (0.8 * staff_space PT, X_AXIS);
341 Molecule d = fm->find_by_name ("accordion-accDot");
342 d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
343 d.translate_axis (-0.8 * staff_space PT, X_AXIS);
346 if (reg.left_str (2) == "SS")
348 Molecule d = fm->find_by_name ("accordion-accDot");
349 d.translate_axis (0.5 * staff_space PT, Y_AXIS);
350 d.translate_axis (0.4 * staff_space PT, X_AXIS);
352 d.translate_axis (-0.8 * staff_space PT, X_AXIS);
354 reg = reg.right_str (reg.length_i ()-2);
356 if (reg.left_str (1) == "S")
358 Molecule d = fm->find_by_name ("accordion-accDot");
359 d.translate_axis (0.5 * staff_space PT, Y_AXIS);
361 reg = reg.right_str (reg.length_i ()-1);
364 else if (sym == "Freebase")
366 Molecule r = fm->find_by_name ("accordion-accFreebase");
368 if (reg.left_str (1) == "F")
370 Molecule d = fm->find_by_name ("accordion-accDot");
371 d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
373 reg = reg.right_str (reg.length_i ()-1);
377 Molecule d = fm->find_by_name ("accordion-accDot");
378 d.translate_axis (staff_space * 0.5 PT, Y_AXIS);
382 else if (sym == "Bayanbase")
384 Molecule r = fm->find_by_name ("accordion-accBayanbase");
386 if (reg.left_str (1) == "T")
388 Molecule d = fm->find_by_name ("accordion-accDot");
389 d.translate_axis (staff_space * 2.5 PT, Y_AXIS);
391 reg = reg.right_str (reg.length_i ()-1);
393 /* include 4' reed just for completeness. You don't want to use this. */
394 if (reg.left_str (1) == "F")
396 Molecule d = fm->find_by_name ("accordion-accDot");
397 d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
399 reg = reg.right_str (reg.length_i ()-1);
401 if (reg.left_str (2) == "EE")
403 Molecule d = fm->find_by_name ("accordion-accDot");
404 d.translate_axis (staff_space * 0.5 PT, Y_AXIS);
405 d.translate_axis (0.4 * staff_space PT, X_AXIS);
407 d.translate_axis (-0.8 * staff_space PT, X_AXIS);
409 reg = reg.right_str (reg.length_i ()-2);
411 if (reg.left_str (1) == "E")
413 Molecule d = fm->find_by_name ("accordion-accDot");
414 d.translate_axis (staff_space * 0.5 PT, Y_AXIS);
416 reg = reg.right_str (reg.length_i ()-1);
419 else if (sym == "Stdbase")
421 Molecule r = fm->find_by_name ("accordion-accStdbase");
423 if (reg.left_str (1) == "T")
425 Molecule d = fm->find_by_name ("accordion-accDot");
426 d.translate_axis (staff_space * 3.5 PT, Y_AXIS);
428 reg = reg.right_str (reg.length_i ()-1);
430 if (reg.left_str (1) == "F")
432 Molecule d = fm->find_by_name ("accordion-accDot");
433 d.translate_axis (staff_space * 2.5 PT, Y_AXIS);
435 reg = reg.right_str (reg.length_i ()-1);
437 if (reg.left_str (1) == "M")
439 Molecule d = fm->find_by_name ("accordion-accDot");
440 d.translate_axis (staff_space * 2 PT, Y_AXIS);
441 d.translate_axis (staff_space PT, X_AXIS);
443 reg = reg.right_str (reg.length_i ()-1);
445 if (reg.left_str (1) == "E")
447 Molecule d = fm->find_by_name ("accordion-accDot");
448 d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
450 reg = reg.right_str (reg.length_i ()-1);
452 if (reg.left_str (1) == "S")
454 Molecule d = fm->find_by_name ("accordion-accDot");
455 d.translate_axis (staff_space * 0.5 PT, Y_AXIS);
457 reg = reg.right_str (reg.length_i ()-1);
460 /* ugh maybe try to use regular font for S.B. and B.B and only use one font
462 else if (sym == "SB")
464 Molecule r = fm->find_by_name ("accordion-accSB");
467 else if (sym == "BB")
469 Molecule r = fm->find_by_name ("accordion-accBB");
472 else if (sym == "OldEE")
474 Molecule r = fm->find_by_name ("accordion-accOldEE");
477 else if (sym == "OldEES")
479 Molecule r = fm->find_by_name ("accordion-accOldEES");
486 Lookup::repeat_slash (Real w, Real s, Real t)
488 SCM wid = gh_double2scm (w);
489 SCM sl = gh_double2scm (s);
490 SCM thick = gh_double2scm (t);
491 SCM slashnodot = scm_list_n (ly_symbol2scm ("repeat-slash"),
492 wid, sl, thick, SCM_UNDEFINED);
494 Box b (Interval (0, w + sqrt (sqr(t/s) + sqr (t))),
495 Interval (0, w * s));
497 return Molecule (b, slashnodot); // http://slashnodot.org
501 Lookup::bracket (Axis a, Interval iv, Direction d, Real thick, Real protude)
504 Axis other = Axis((a+1)%2);
506 b[other] = Interval(-1, 1) * thick * 0.5;
508 Molecule m = filledbox (b);
510 b[a] = Interval (iv[UP] - thick, iv[UP]);
511 Interval oi = Interval (-thick/2, thick/2 + protude) ;
514 m.add_molecule (filledbox (b));
515 b[a] = Interval (iv[DOWN], iv[DOWN] +thick);
516 m.add_molecule (filledbox(b));
522 ly_bracket (SCM a, SCM iv, SCM d, SCM t, SCM p)
524 SCM_ASSERT_TYPE(ly_axis_p (a), a, SCM_ARG1, __FUNCTION__, "axis") ;
525 SCM_ASSERT_TYPE(ly_number_pair_p (iv), iv, SCM_ARG1, __FUNCTION__, "number pair") ;
526 SCM_ASSERT_TYPE(ly_dir_p (d), a, SCM_ARG1, __FUNCTION__, "direction") ;
527 SCM_ASSERT_TYPE(gh_number_p (t), a, SCM_ARG1, __FUNCTION__, "number") ;
528 SCM_ASSERT_TYPE(gh_number_p(p), a, SCM_ARG1, __FUNCTION__, "number") ;
531 return Lookup::bracket ((Axis)gh_scm2int (a), ly_scm2interval (iv),
532 (Direction)gh_scm2int (d), gh_scm2double (t), gh_scm2double (p)).smobbed_copy ();
538 scm_c_define_gsubr ("ly-bracket", 5, 0, 0, (Scheme_function_unknown) ly_bracket);
541 ADD_SCM_INIT_FUNC (lookup,lookup_init);