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