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