]> git.donarmstrong.com Git - lilypond.git/blob - lily/lookup.cc
* mf/GNUmakefile: always trace pfa fonts.
[lilypond.git] / lily / lookup.cc
1 /*
2   lookup.cc -- implement simple Lookup methods.
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7
8   Jan Nieuwenhuizen <janneke@gnu.org>
9
10   TODO
11       Glissando
12 */
13 #include <math.h>
14 #include <ctype.h>
15
16 #include "warn.hh"
17 #include "dimensions.hh"
18 #include "bezier.hh"
19 #include "string-convert.hh"
20 #include "file-path.hh"
21 #include "main.hh"
22 #include "lily-guile.hh"
23 #include "molecule.hh"
24 #include "lookup.hh"
25 #include "font-metric.hh"
26 #include "interval.hh"
27
28 Molecule
29 Lookup::dot (Offset p, Real radius)
30 {
31   SCM at = (scm_list_n (ly_symbol2scm ("dot"),
32                         gh_double2scm (p[X_AXIS]),
33                         gh_double2scm (p[Y_AXIS]),
34                         gh_double2scm (radius),
35                         SCM_UNDEFINED));
36   Box box;
37   box.add_point (p - Offset (radius, radius));
38   box.add_point (p + Offset (radius, radius));
39   return Molecule (box, at);
40 }
41
42 Molecule 
43 Lookup::beam (Real slope, Real width, Real thick) 
44 {
45   Real height = slope * width; 
46   Real min_y = (0 <? height) - thick/2;
47   Real max_y = (0 >? height) + thick/2;
48
49   
50
51   Box b (Interval (0, width),
52          Interval (min_y, max_y));
53
54   
55   SCM at = scm_list_n (ly_symbol2scm ("beam"),
56                     gh_double2scm (width),
57                     gh_double2scm (slope),
58                     gh_double2scm (thick),
59                     SCM_UNDEFINED);
60   return Molecule (b, at);
61 }
62
63 Molecule
64 Lookup::dashed_slur (Bezier b, Real thick, Real dash)
65 {
66   SCM l = SCM_EOL;
67
68   for (int i= 4; i -- ;)
69     {
70       l = gh_cons (ly_offset2scm (b.control_[i]), l);
71     }
72
73   SCM at = (scm_list_n (ly_symbol2scm ("dashed-slur"),
74                                gh_double2scm (thick), 
75                                gh_double2scm (dash),
76                                ly_quote_scm (l),
77                                SCM_UNDEFINED));
78
79   Box box (Interval (0,0),Interval (0,0));
80   return   Molecule (box, at);
81 }
82
83 Molecule
84 Lookup::line (Real th, Offset from, Offset to)
85 {
86   SCM at = scm_list_n (ly_symbol2scm ("draw-line"),
87                         gh_double2scm (th), 
88                         gh_double2scm (from[X_AXIS]),
89                         gh_double2scm (from[Y_AXIS]),
90                         gh_double2scm (to[X_AXIS]),
91                         gh_double2scm (to[Y_AXIS]),
92                         SCM_UNDEFINED);
93
94   Box box;
95   box.add_point (from);
96   box.add_point (to);
97
98   box[X_AXIS].widen (th/2);
99   box[Y_AXIS].widen (th/2);  
100
101   return Molecule (box, at);
102 }
103
104 Molecule
105 Lookup::dashed_line (Real thick, Offset from, Offset to,
106                      Real dash_period, Real dash_fraction)
107 {
108   dash_fraction = (dash_fraction >? 0) <? 1.0;
109   Real on = dash_fraction * dash_period + thick; 
110   Real off = dash_period - on;
111   
112   SCM at = scm_list_n (ly_symbol2scm ("dashed-line"),
113                         gh_double2scm (thick), 
114                         gh_double2scm (on),
115                         gh_double2scm (off),
116                         gh_double2scm (to[X_AXIS] - from[X_AXIS]),
117                         gh_double2scm (to[Y_AXIS] - from[Y_AXIS]),
118                         SCM_UNDEFINED);
119   
120   Box box;
121   box.add_point (Offset (0,0));
122   box.add_point (to - from);
123
124   box[X_AXIS].widen (thick/2);
125   box[Y_AXIS].widen (thick/2);  
126
127   Molecule m = Molecule (box, at);
128   m.translate (from);
129   return m;
130 }
131
132 Molecule
133 Lookup::horizontal_line (Interval w, Real th)
134 {
135   SCM at = scm_list_n (ly_symbol2scm ("horizontal-line"),
136                        gh_double2scm (w[LEFT]), 
137                        gh_double2scm (w[RIGHT]),
138                        gh_double2scm (th),
139                        SCM_UNDEFINED);
140
141
142   Box box ;
143   box[X_AXIS] = w;
144   box[Y_AXIS] = Interval (-th/2,th/2);
145
146   return Molecule (box, at);
147 }
148
149
150 Molecule
151 Lookup::blank (Box b) 
152 {
153   return Molecule (b, scm_makfrom0str (""));
154 }
155
156 Molecule
157 Lookup::filledbox (Box b) 
158 {
159   SCM  at  = (scm_list_n (ly_symbol2scm ("filledbox"),
160                      gh_double2scm (-b[X_AXIS][LEFT]),
161                      gh_double2scm (b[X_AXIS][RIGHT]),                 
162                      gh_double2scm (-b[Y_AXIS][DOWN]),
163                      gh_double2scm (b[Y_AXIS][UP]),                    
164                      SCM_UNDEFINED));
165
166   return Molecule (b,at);
167 }
168
169 /*
170  * round filled box:
171  *
172  *   __________________________________
173  *  /     \  ^           /     \      ^
174  * |         |blot              |     |
175  * |       | |dia       |       |     |
176  * |         |meter             |     |
177  * |\ _ _ /  v           \ _ _ /|     |
178  * |                            |     |
179  * |                            |     | Box
180  * |                    <------>|     | extent
181  * |                      blot  |     | (Y_AXIS)
182  * |                    diameter|     |
183  * |                            |     |
184  * |  _ _                  _ _  |     |
185  * |/     \              /     \|     |
186  * |                            |     |
187  * |       |            |       |     |
188  * |                            |     |
189  * x\_____/______________\_____/|_____v
190  * |(0,0)                       |
191  * |                            |
192  * |                            |
193  * |<-------------------------->|
194  *       Box extent(X_AXIS)
195  */
196 Molecule
197 Lookup::round_filled_box (Box b, Real blotdiameter)
198 {
199   if (b.x ().length () < blotdiameter)
200     {
201       programming_error (_f ("round filled box horizontal extent smaller than blot; decreasing blot"));
202       blotdiameter = b.x ().length ();
203     }
204   if (b.y ().length () < blotdiameter)
205     {
206       programming_error (_f ("round filled box vertical extent smaller than blot; decreasing blot"));
207       blotdiameter = b.y ().length ();
208     }
209
210   SCM at = (scm_list_n (ly_symbol2scm ("round-filled-box"),
211                         gh_double2scm (-b[X_AXIS][LEFT]),
212                         gh_double2scm (b[X_AXIS][RIGHT]),
213                         gh_double2scm (-b[Y_AXIS][DOWN]),
214                         gh_double2scm (b[Y_AXIS][UP]),
215                         gh_double2scm (blotdiameter),
216                         SCM_UNDEFINED));
217
218   return Molecule (b,at);
219 }
220
221           
222
223 /*
224  * Create Molecule that represents a filled polygon with round edges.
225  *
226  * LIMITATIONS:
227  *
228  * (a) Only outer (convex) edges are rounded.
229  *
230  * (b) This algorithm works as expected only for polygons whose edges
231  * do not intersect.  For example, the polygon ((0, 0), (q, 0), (0,
232  * q), (q, q)) has an intersection at point (q/2, q/2) and therefore
233  * will give a strange result.  Even non-adjacent edges that just
234  * touch each other will in general not work as expected for non-null
235  * blotdiameter.
236  *
237  * (c) Given a polygon ((x0, y0), (x1, y1), ... , (x(n-1), y(n-1))),
238  * if there is a natural number k such that blotdiameter is greater
239  * than the maximum of { | (x(k mod n), y(k mod n)) - (x((k+1) mod n),
240  * y((k+1) mod n)) |, | (x(k mod n), y(k mod n)) - (x((k+2) mod n),
241  * y((k+2) mod n)) |, | (x((k+1) mod n), y((k+1) mod n)) - (x((k+2)
242  * mod n), y((k+2) mod n)) | }, then the outline of the rounded
243  * polygon will exceed the outline of the core polygon.  In other
244  * words: Do not draw rounded polygons that have a leg smaller or
245  * thinner than blotdiameter (or set blotdiameter to a sufficiently
246  * small value -- maybe even 0.0)!
247  *
248  * NOTE: Limitations (b) and (c) arise from the fact that round edges
249  * are made by moulding sharp edges to round ones rather than adding
250  * to a core filled polygon.  For details of these two different
251  * approaches, see the thread upon the ledger lines patch that started
252  * on March 25, 2002 on the devel mailing list.  The below version of
253  * round_filled_polygon() sticks to the moulding model, which the
254  * majority of the list participants finally voted for.  This,
255  * however, results in the above limitations and a much increased
256  * complexity of the algorithm, since it has to compute a shrinked
257  * polygon -- which is not trivial define precisely and unambigously.
258  * With the other approach, one simply could move a circle of size
259  * blotdiameter along all edges of the polygon (which is what the
260  * postscript routine in the backend effectively does, but on the
261  * shrinked polygon). --jr
262  */
263 Molecule
264 Lookup::round_filled_polygon (Array<Offset> points, Real blotdiameter)
265 {
266   /* TODO: Maybe print a warning if one of the above limitations
267      applies to the given polygon.  However, this is quite complicated
268      to check. */
269
270   /* remove consecutive duplicate points */
271   const Real epsilon = 0.01;
272   for (int i = 0; i < points.size ();)
273     {
274       int next_i = (i + 1) % points.size ();
275       Real d = (points[i] - points[next_i]).length ();
276       if (d < epsilon)
277         points.del (next_i);
278       else
279         i++;
280     }
281
282   /* special cases: degenerated polygons */
283   if (points.size () == 0)
284     return Molecule ();
285   if (points.size () == 1)
286     return dot (points[0], 0.5 * blotdiameter);
287   if (points.size () == 2)
288     return line (blotdiameter, points[0], points[1]);
289
290   /* shrink polygon in size by 0.5 * blotdiameter */
291   Array<Offset> shrinked_points;
292   shrinked_points.set_size (points.size ());
293   bool ccw = 1; // true, if three adjacent points are counterclockwise ordered
294   for (int i = 0; i < points.size (); i++)
295     {
296       int i0 = i;
297       int i1 = (i + 1) % points.size ();
298       int i2 = (i + 2) % points.size ();
299       Offset p0 = points[i0];
300       Offset p1 = points[i1];
301       Offset p2 = points[i2];
302       Offset p10 = p0 - p1;
303       Offset p12 = p2 - p1;
304       if (p10.length () != 0.0)
305         { // recompute ccw
306           Real phi = p10.arg ();
307           // rotate (p2 - p0) by (-phi)
308           Offset q = complex_multiply (p2 - p0, complex_exp (Offset (1.0, -phi)));
309
310           if (q[Y_AXIS] > 0)
311             ccw = 1;
312           else if (q[Y_AXIS] < 0)
313             ccw = 0;
314           else {} // keep ccw unchanged
315         }
316       else {} // keep ccw unchanged
317       Offset p10n = (1.0 / p10.length ()) * p10; // normalize length to 1.0
318       Offset p12n = (1.0 / p12.length ()) * p12;
319       Offset p13n = 0.5 * (p10n + p12n);
320       Offset p14n = 0.5 * (p10n - p12n);
321       Offset p13;
322       Real d = p13n.length () * p14n.length (); // distance p3n to line(p1..p0)
323       if (d < epsilon)
324         // special case: p0, p1, p2 are on a single line => build
325         // vector orthogonal to (p2-p0) of length 0.5 blotdiameter
326         {
327           p13[X_AXIS] = p10[Y_AXIS];
328           p13[Y_AXIS] = -p10[X_AXIS];
329           p13 = (0.5 * blotdiameter / p13.length ()) * p13;
330         }
331       else
332         p13 = (0.5 * blotdiameter / d) * p13n;
333       shrinked_points[i1] = p1 + ((ccw) ? p13 : -p13);
334     }
335
336   /* build scm expression and bounding box */
337   SCM shrinked_points_scm = SCM_EOL;
338   Box box;
339   for (int i = 0; i < shrinked_points.size (); i++)
340     {
341       SCM x = gh_double2scm (shrinked_points[i][X_AXIS]);
342       SCM y = gh_double2scm (shrinked_points[i][Y_AXIS]);
343       shrinked_points_scm = gh_cons (x, gh_cons (y, shrinked_points_scm));
344       box.add_point (points[i]);
345     }
346   SCM polygon_scm = scm_list_n (ly_symbol2scm ("polygon"),
347                                 ly_quote_scm (shrinked_points_scm),
348                                 gh_double2scm (blotdiameter),
349                                 SCM_UNDEFINED);
350
351   Molecule polygon = Molecule (box, polygon_scm);
352   shrinked_points.clear ();
353   return polygon;
354 }
355
356 Molecule
357 Lookup::frame (Box b, Real thick)
358 {
359   Molecule m;
360   Direction d = LEFT;
361   for (Axis a = X_AXIS; a < NO_AXES; a = Axis (a + 1))
362     {
363       Axis o = Axis ((a+1)%NO_AXES);
364       do
365         {
366           Box edges;
367           edges[a] = b[a][d] + 0.5 * thick * Interval (-1, 1);
368           edges[o][DOWN] = b[o][DOWN] - thick/2;
369           edges[o][UP] = b[o][UP] + thick/2;      
370           
371           m.add_molecule (filledbox (edges));
372         }
373       while (flip (&d) != LEFT);
374     }
375   return m;
376   
377 }
378
379 /*
380   Make a smooth curve along the points 
381  */
382 Molecule
383 Lookup::slur (Bezier curve, Real curvethick, Real linethick) 
384 {
385   Real alpha = (curve.control_[3] - curve.control_[0]).arg ();
386   Bezier back = curve;
387   Offset perp = curvethick * complex_exp (Offset (0, alpha + M_PI/2)) * 0.5;
388   back.reverse ();
389   back.control_[1] += perp;
390   back.control_[2] += perp;
391
392   curve.control_[1] -= perp;
393   curve.control_[2] -= perp;
394   
395   SCM scontrols[8];
396
397   for (int i=4; i--;)
398     scontrols[ i ] = ly_offset2scm (back.control_[i]);
399   for (int i=4 ; i--;)
400     scontrols[i+4] = ly_offset2scm (curve.control_[i]);
401
402   /*
403     Need the weird order b.o. the way PS want its arguments  
404    */
405   int indices[]= {5, 6, 7, 4, 1, 2, 3, 0};
406   SCM list = SCM_EOL;
407   for (int i= 8; i--;)
408     {
409       list = gh_cons (scontrols[indices[i]], list);
410     }
411   
412   
413   SCM at = (scm_list_n (ly_symbol2scm ("bezier-sandwich"),
414                      ly_quote_scm (list),
415                      gh_double2scm (linethick),
416                      SCM_UNDEFINED));
417   Box b(curve.extent (X_AXIS),
418         curve.extent (Y_AXIS));
419
420   b[X_AXIS].unite (back.extent (X_AXIS));
421   b[Y_AXIS].unite (back.extent (Y_AXIS));
422
423   return Molecule (b, at);
424 }
425
426 /*
427  * Bezier Sandwich:
428  *
429  *                               .|
430  *                        .       |
431  *              top .             |
432  *              . curve           |
433  *          .                     |
434  *       .                        |
435  *     .                          |
436  *    |                           |
437  *    |                          .|
438  *    |                     .
439  *    |         bottom .
440  *    |            . curve
441  *    |         .
442  *    |      .
443  *    |   .
444  *    | .
445  *    |.
446  *    |
447  *
448  */
449 Molecule
450 Lookup::bezier_sandwich (Bezier top_curve, Bezier bottom_curve)
451 {
452   /*
453     Need the weird order b.o. the way PS want its arguments  
454    */
455   SCM list = SCM_EOL;
456   list = gh_cons (ly_offset2scm (bottom_curve.control_[3]), list);
457   list = gh_cons (ly_offset2scm (bottom_curve.control_[0]), list);
458   list = gh_cons (ly_offset2scm (bottom_curve.control_[1]), list);
459   list = gh_cons (ly_offset2scm (bottom_curve.control_[2]), list);
460   list = gh_cons (ly_offset2scm (top_curve.control_[0]), list);
461   list = gh_cons (ly_offset2scm (top_curve.control_[3]), list);
462   list = gh_cons (ly_offset2scm (top_curve.control_[2]), list);
463   list = gh_cons (ly_offset2scm (top_curve.control_[1]), list);
464
465   SCM horizontal_bend = scm_list_n (ly_symbol2scm ("bezier-sandwich"),
466                                     ly_quote_scm (list),
467                                     gh_double2scm (0.0),
468                                     SCM_UNDEFINED);
469
470   Interval x_extent = top_curve.extent (X_AXIS);
471   x_extent.unite (bottom_curve.extent (X_AXIS));
472   Interval y_extent = top_curve.extent (Y_AXIS);
473   y_extent.unite (bottom_curve.extent (Y_AXIS));
474   Box b (x_extent, y_extent);
475
476   return Molecule (b, horizontal_bend);
477 }
478
479 /*
480  * Horizontal Slope:
481  *
482  *            /|   ^
483  *           / |   |
484  *          /  |   | height
485  *         /   |   |
486  *        /    |   v
487  *       |    /
488  *       |   /
489  * (0,0) x  /slope=dy/dx
490  *       | /
491  *       |/
492  *
493  *       <----->
494  *        width
495  */
496 Molecule
497 Lookup::horizontal_slope (Real width, Real slope, Real height)
498 {
499   SCM width_scm = gh_double2scm (width);
500   SCM slope_scm = gh_double2scm (slope);
501   SCM height_scm = gh_double2scm (height);
502   SCM horizontal_slope = scm_list_n (ly_symbol2scm ("beam"),
503                                      width_scm, slope_scm,
504                                      height_scm, SCM_UNDEFINED);
505   Box b (Interval (0, width),
506          Interval (-height/2, height/2 + width*slope));
507   return Molecule (b, horizontal_slope);
508 }
509
510 /*
511   TODO: junk me.
512  */
513 Molecule
514 Lookup::accordion (SCM s, Real staff_space, Font_metric *fm) 
515 {
516   Molecule m;
517   String sym = ly_scm2string (ly_car (s));
518   String reg = ly_scm2string (ly_car (ly_cdr (s)));
519
520   if (sym == "Discant")
521     {
522       Molecule r = fm->find_by_name ("accordion-accDiscant");
523       m.add_molecule (r);
524       if (reg.left_string (1) == "F")
525         {
526           Molecule d = fm->find_by_name ("accordion-accDot");
527           d.translate_axis (staff_space * 2.5 PT, Y_AXIS);
528           m.add_molecule (d);
529           reg = reg.right_string (reg.length ()-1);
530         }
531       int eflag = 0x00;
532       if (reg.left_string (3) == "EEE")
533         {
534           eflag = 0x07;
535           reg = reg.right_string (reg.length ()-3);
536         }
537       else if (reg.left_string (2) == "EE")
538         {
539           eflag = 0x05;
540           reg = reg.right_string (reg.length ()-2);
541         }
542       else if (reg.left_string (2) == "Eh")
543         {
544           eflag = 0x04;
545           reg = reg.right_string (reg.length ()-2);
546         }
547       else if (reg.left_string (1) == "E")
548         {
549           eflag = 0x02;
550           reg = reg.right_string (reg.length ()-1);
551         }
552       if (eflag & 0x02)
553         {
554           Molecule d = fm->find_by_name ("accordion-accDot");
555           d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
556           m.add_molecule (d);
557         }
558       if (eflag & 0x04)
559         {
560           Molecule d = fm->find_by_name ("accordion-accDot");
561           d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
562           d.translate_axis (0.8 * staff_space PT, X_AXIS);
563           m.add_molecule (d);
564         }
565       if (eflag & 0x01)
566         {
567           Molecule d = fm->find_by_name ("accordion-accDot");
568           d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
569           d.translate_axis (-0.8 * staff_space PT, X_AXIS);
570           m.add_molecule (d);
571         }
572       if (reg.left_string (2) == "SS")
573         {
574           Molecule d = fm->find_by_name ("accordion-accDot");
575           d.translate_axis (0.5 * staff_space PT, Y_AXIS);
576           d.translate_axis (0.4 * staff_space PT, X_AXIS);
577           m.add_molecule (d);
578           d.translate_axis (-0.8 * staff_space PT, X_AXIS);
579           m.add_molecule (d);
580           reg = reg.right_string (reg.length ()-2);
581         }
582       if (reg.left_string (1) == "S")
583         {
584           Molecule d = fm->find_by_name ("accordion-accDot");
585           d.translate_axis (0.5 * staff_space PT, Y_AXIS);
586           m.add_molecule (d);
587           reg = reg.right_string (reg.length ()-1);
588         }
589     }
590   else if (sym == "Freebase")
591     {
592       Molecule r = fm->find_by_name ("accordion-accFreebase");
593       m.add_molecule (r);
594       if (reg.left_string (1) == "F")
595         {
596           Molecule d = fm->find_by_name ("accordion-accDot");
597           d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
598           m.add_molecule (d);
599           reg = reg.right_string (reg.length ()-1);
600         }
601       if (reg == "E")
602         {
603           Molecule d = fm->find_by_name ("accordion-accDot");
604           d.translate_axis (staff_space * 0.5 PT, Y_AXIS);
605           m.add_molecule (d);
606         }
607     }
608   else if (sym == "Bayanbase")
609     {
610       Molecule r = fm->find_by_name ("accordion-accBayanbase");
611       m.add_molecule (r);
612       if (reg.left_string (1) == "T")
613         {
614           Molecule d = fm->find_by_name ("accordion-accDot");
615           d.translate_axis (staff_space * 2.5 PT, Y_AXIS);
616           m.add_molecule (d);
617           reg = reg.right_string (reg.length ()-1);
618         }
619       /* include 4' reed just for completeness. You don't want to use this. */
620       if (reg.left_string (1) == "F")
621         {
622           Molecule d = fm->find_by_name ("accordion-accDot");
623           d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
624           m.add_molecule (d);
625           reg = reg.right_string (reg.length ()-1);
626         }
627       if (reg.left_string (2) == "EE")
628         {
629           Molecule d = fm->find_by_name ("accordion-accDot");
630           d.translate_axis (staff_space * 0.5 PT, Y_AXIS);
631           d.translate_axis (0.4 * staff_space PT, X_AXIS);
632           m.add_molecule (d);
633           d.translate_axis (-0.8 * staff_space PT, X_AXIS);
634           m.add_molecule (d);
635           reg = reg.right_string (reg.length ()-2);
636         }
637       if (reg.left_string (1) == "E")
638         {
639           Molecule d = fm->find_by_name ("accordion-accDot");
640           d.translate_axis (staff_space * 0.5 PT, Y_AXIS);
641           m.add_molecule (d);
642           reg = reg.right_string (reg.length ()-1);
643         }
644     }
645   else if (sym == "Stdbase")
646     {
647       Molecule r = fm->find_by_name ("accordion-accStdbase");
648       m.add_molecule (r);
649       if (reg.left_string (1) == "T")
650         {
651           Molecule d = fm->find_by_name ("accordion-accDot");
652           d.translate_axis (staff_space * 3.5 PT, Y_AXIS);
653           m.add_molecule (d);
654           reg = reg.right_string (reg.length ()-1);
655         }
656       if (reg.left_string (1) == "F")
657         {
658           Molecule d = fm->find_by_name ("accordion-accDot");
659           d.translate_axis (staff_space * 2.5 PT, Y_AXIS);
660           m.add_molecule (d);
661           reg = reg.right_string (reg.length ()-1);
662         }
663       if (reg.left_string (1) == "M")
664         {
665           Molecule d = fm->find_by_name ("accordion-accDot");
666           d.translate_axis (staff_space * 2 PT, Y_AXIS);
667           d.translate_axis (staff_space PT, X_AXIS);
668           m.add_molecule (d);
669           reg = reg.right_string (reg.length ()-1);
670         }
671       if (reg.left_string (1) == "E")
672         {
673           Molecule d = fm->find_by_name ("accordion-accDot");
674           d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
675           m.add_molecule (d);
676           reg = reg.right_string (reg.length ()-1);
677         }
678       if (reg.left_string (1) == "S")
679         {
680           Molecule d = fm->find_by_name ("accordion-accDot");
681           d.translate_axis (staff_space * 0.5 PT, Y_AXIS);
682           m.add_molecule (d);
683           reg = reg.right_string (reg.length ()-1);
684         }
685     }
686   /* ugh maybe try to use regular font for S.B. and B.B and only use one font
687      for the rectangle */
688   else if (sym == "SB")
689     {
690       Molecule r = fm->find_by_name ("accordion-accSB");
691       m.add_molecule (r);
692     }
693   else if (sym == "BB")
694     {
695       Molecule r = fm->find_by_name ("accordion-accBB");
696       m.add_molecule (r);
697     }
698   else if (sym == "OldEE")
699     {
700       Molecule r = fm->find_by_name ("accordion-accOldEE");
701       m.add_molecule (r);
702     }
703   else if (sym == "OldEES")
704     {
705       Molecule r = fm->find_by_name ("accordion-accOldEES");
706       m.add_molecule (r);
707     }
708   return m;  
709 }
710
711 Molecule
712 Lookup::repeat_slash (Real w, Real s, Real t)
713 {
714   SCM wid = gh_double2scm (w);
715   SCM sl = gh_double2scm (s);
716   SCM thick = gh_double2scm (t);
717   SCM slashnodot = scm_list_n (ly_symbol2scm ("repeat-slash"),
718                             wid, sl, thick, SCM_UNDEFINED);
719
720   Box b (Interval (0, w + sqrt (sqr(t/s) + sqr (t))),
721          Interval (0, w * s));
722
723   return Molecule (b, slashnodot); //  http://slashnodot.org
724 }
725
726 Molecule
727 Lookup::bracket (Axis a, Interval iv, Real thick, Real protude)
728 {
729   Box b;
730   Axis other = Axis((a+1)%2);
731   b[a] = iv;
732   b[other] = Interval(-1, 1) * thick * 0.5;
733   
734   Molecule m =  filledbox (b);
735
736   b[a] = Interval (iv[UP] - thick, iv[UP]);
737   Interval oi = Interval (-thick/2, thick/2 + fabs (protude)) ;
738   oi *=  sign (protude);
739   b[other] = oi;
740   m.add_molecule (filledbox (b));
741   b[a] = Interval (iv[DOWN], iv[DOWN]  +thick);
742   m.add_molecule (filledbox(b));
743
744   return m;
745 }
746
747 Molecule
748 Lookup::triangle (Interval iv, Real thick, Real protude)
749 {
750   Box b ;
751   b[X_AXIS] = iv;
752   b[Y_AXIS] = Interval (0 <? protude , 0 >? protude);
753
754   SCM s = scm_list_n (ly_symbol2scm ("symmetric-x-triangle"),
755                       gh_double2scm (thick),
756                       gh_double2scm (iv.length()), 
757                       gh_double2scm (protude), SCM_UNDEFINED);
758
759   return Molecule (b, s);
760 }
761
762
763 /*
764   TODO: use rounded boxes.
765  */
766 LY_DEFINE(ly_bracket ,"ly:bracket",
767           4, 0, 0,
768           (SCM a, SCM iv, SCM t, SCM p),
769           "Make a bracket in direction @var{a}. The extent of the bracket is " 
770           "given by @var{iv}. The wings protude by an amount of @var{p}, which "
771           "may be negative. The thickness is given by @var{t}.")
772 {
773   SCM_ASSERT_TYPE(is_axis (a), a, SCM_ARG1, __FUNCTION__, "axis") ;
774   SCM_ASSERT_TYPE(is_number_pair (iv), iv, SCM_ARG2, __FUNCTION__, "number pair") ;
775   SCM_ASSERT_TYPE(gh_number_p (t), a, SCM_ARG3, __FUNCTION__, "number") ;
776   SCM_ASSERT_TYPE(gh_number_p (p), a, SCM_ARG4, __FUNCTION__, "number") ;
777
778
779   return Lookup::bracket ((Axis)gh_scm2int (a), ly_scm2interval (iv),
780                           gh_scm2double (t),
781                           gh_scm2double (p)).smobbed_copy ();
782 }
783
784
785
786 LY_DEFINE(ly_filled_box ,"ly:round-filled-box",
787           3, 0, 0,
788           (SCM xext, SCM yext, SCM blot),
789           "Make a filled-box of dimensions @var{xext}, @var{yext} and roundness @var{blot}.")
790 {
791   SCM_ASSERT_TYPE(is_number_pair (xext), xext, SCM_ARG1, __FUNCTION__, "number pair") ;
792   SCM_ASSERT_TYPE(is_number_pair (yext), yext, SCM_ARG2, __FUNCTION__, "number pair") ;
793   SCM_ASSERT_TYPE(gh_number_p (blot), blot, SCM_ARG3, __FUNCTION__, "number") ;
794
795   return Lookup::round_filled_box (Box (ly_scm2interval (xext), ly_scm2interval (yext)),
796                                    gh_scm2double (blot)).smobbed_copy ();
797 }
798