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);
167 Lookup::accordion (SCM s, Real staff_space, Font_metric *fm)
170 String sym = ly_scm2string (ly_car (s));
171 String reg = ly_scm2string (ly_car (ly_cdr (s)));
173 if (sym == "Discant")
175 Molecule r = fm->find_by_name ("accordion-accDiscant");
177 if (reg.left_str (1) == "F")
179 Molecule d = fm->find_by_name ("accordion-accDot");
180 d.translate_axis (staff_space * 2.5 PT, Y_AXIS);
182 reg = reg.right_str (reg.length_i ()-1);
185 if (reg.left_str (3) == "EEE")
188 reg = reg.right_str (reg.length_i ()-3);
190 else if (reg.left_str (2) == "EE")
193 reg = reg.right_str (reg.length_i ()-2);
195 else if (reg.left_str (2) == "Eh")
198 reg = reg.right_str (reg.length_i ()-2);
200 else if (reg.left_str (1) == "E")
203 reg = reg.right_str (reg.length_i ()-1);
207 Molecule d = fm->find_by_name ("accordion-accDot");
208 d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
213 Molecule d = fm->find_by_name ("accordion-accDot");
214 d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
215 d.translate_axis (0.8 * staff_space PT, X_AXIS);
220 Molecule d = fm->find_by_name ("accordion-accDot");
221 d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
222 d.translate_axis (-0.8 * staff_space PT, X_AXIS);
225 if (reg.left_str (2) == "SS")
227 Molecule d = fm->find_by_name ("accordion-accDot");
228 d.translate_axis (0.5 * staff_space PT, Y_AXIS);
229 d.translate_axis (0.4 * staff_space PT, X_AXIS);
231 d.translate_axis (-0.8 * staff_space PT, X_AXIS);
233 reg = reg.right_str (reg.length_i ()-2);
235 if (reg.left_str (1) == "S")
237 Molecule d = fm->find_by_name ("accordion-accDot");
238 d.translate_axis (0.5 * staff_space PT, Y_AXIS);
240 reg = reg.right_str (reg.length_i ()-1);
243 else if (sym == "Freebase")
245 Molecule r = fm->find_by_name ("accordion-accFreebase");
247 if (reg.left_str (1) == "F")
249 Molecule d = fm->find_by_name ("accordion-accDot");
250 d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
252 reg = reg.right_str (reg.length_i ()-1);
256 Molecule d = fm->find_by_name ("accordion-accDot");
257 d.translate_axis (staff_space * 0.5 PT, Y_AXIS);
261 else if (sym == "Bayanbase")
263 Molecule r = fm->find_by_name ("accordion-accBayanbase");
265 if (reg.left_str (1) == "T")
267 Molecule d = fm->find_by_name ("accordion-accDot");
268 d.translate_axis (staff_space * 2.5 PT, Y_AXIS);
270 reg = reg.right_str (reg.length_i ()-1);
272 /* include 4' reed just for completeness. You don't want to use this. */
273 if (reg.left_str (1) == "F")
275 Molecule d = fm->find_by_name ("accordion-accDot");
276 d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
278 reg = reg.right_str (reg.length_i ()-1);
280 if (reg.left_str (2) == "EE")
282 Molecule d = fm->find_by_name ("accordion-accDot");
283 d.translate_axis (staff_space * 0.5 PT, Y_AXIS);
284 d.translate_axis (0.4 * staff_space PT, X_AXIS);
286 d.translate_axis (-0.8 * staff_space PT, X_AXIS);
288 reg = reg.right_str (reg.length_i ()-2);
290 if (reg.left_str (1) == "E")
292 Molecule d = fm->find_by_name ("accordion-accDot");
293 d.translate_axis (staff_space * 0.5 PT, Y_AXIS);
295 reg = reg.right_str (reg.length_i ()-1);
298 else if (sym == "Stdbase")
300 Molecule r = fm->find_by_name ("accordion-accStdbase");
302 if (reg.left_str (1) == "T")
304 Molecule d = fm->find_by_name ("accordion-accDot");
305 d.translate_axis (staff_space * 3.5 PT, Y_AXIS);
307 reg = reg.right_str (reg.length_i ()-1);
309 if (reg.left_str (1) == "F")
311 Molecule d = fm->find_by_name ("accordion-accDot");
312 d.translate_axis (staff_space * 2.5 PT, Y_AXIS);
314 reg = reg.right_str (reg.length_i ()-1);
316 if (reg.left_str (1) == "M")
318 Molecule d = fm->find_by_name ("accordion-accDot");
319 d.translate_axis (staff_space * 2 PT, Y_AXIS);
320 d.translate_axis (staff_space PT, X_AXIS);
322 reg = reg.right_str (reg.length_i ()-1);
324 if (reg.left_str (1) == "E")
326 Molecule d = fm->find_by_name ("accordion-accDot");
327 d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
329 reg = reg.right_str (reg.length_i ()-1);
331 if (reg.left_str (1) == "S")
333 Molecule d = fm->find_by_name ("accordion-accDot");
334 d.translate_axis (staff_space * 0.5 PT, Y_AXIS);
336 reg = reg.right_str (reg.length_i ()-1);
339 /* ugh maybe try to use regular font for S.B. and B.B and only use one font
341 else if (sym == "SB")
343 Molecule r = fm->find_by_name ("accordion-accSB");
346 else if (sym == "BB")
348 Molecule r = fm->find_by_name ("accordion-accBB");
351 else if (sym == "OldEE")
353 Molecule r = fm->find_by_name ("accordion-accOldEE");
356 else if (sym == "OldEES")
358 Molecule r = fm->find_by_name ("accordion-accOldEES");
365 TODO: should use slope instead? Angle gives nasty rad <-> degree
369 Lookup::repeat_slash (Real w, Real s, Real t)
371 SCM wid = gh_double2scm (w);
372 SCM sl = gh_double2scm (s);
373 SCM thick = gh_double2scm (t);
374 SCM slashnodot = scm_list_n (ly_symbol2scm ("repeat-slash"),
375 wid, sl, thick, SCM_UNDEFINED);
377 Box b (Interval (0, w + sqrt (sqr(t/s) + sqr (t))),
378 Interval (0, w * s));
380 return Molecule (b, slashnodot); // http://slashnodot.org
386 Lookup::bracket (Axis a, Interval iv, Direction d, Real thick, Real protude)
389 Axis other = Axis((a+1)%2);
391 b[other] = Interval(-1, 1) * thick * 0.5;
393 Molecule m = filledbox (b);
395 b[a] = Interval (iv[UP] - thick, iv[UP]);
396 Interval oi = Interval (-thick/2, thick/2 + protude) ;
399 m.add_molecule (filledbox (b));
400 b[a] = Interval (iv[DOWN], iv[DOWN] +thick);
401 m.add_molecule (filledbox(b));
407 ly_bracket (SCM a, SCM iv, SCM d, SCM t, SCM p)
409 SCM_ASSERT_TYPE(ly_axis_p (a), a, SCM_ARG1, __FUNCTION__, "axis") ;
410 SCM_ASSERT_TYPE(ly_number_pair_p (iv), iv, SCM_ARG1, __FUNCTION__, "number pair") ;
411 SCM_ASSERT_TYPE(ly_dir_p (d), a, SCM_ARG1, __FUNCTION__, "direction") ;
412 SCM_ASSERT_TYPE(gh_number_p (t), a, SCM_ARG1, __FUNCTION__, "number") ;
413 SCM_ASSERT_TYPE(gh_number_p(p), a, SCM_ARG1, __FUNCTION__, "number") ;
416 return Lookup::bracket ((Axis)gh_scm2int (a), ly_scm2interval (iv),
417 (Direction)gh_scm2int (d), gh_scm2double (t), gh_scm2double (p)).smobbed_copy ();
423 scm_c_define_gsubr ("ly-bracket", 5, 0, 0, (Scheme_function_unknown) ly_bracket);
426 ADD_SCM_INIT_FUNC (lookup,lookup_init);