~ubuntu-branches/ubuntu/precise/lilypond/precise

« back to all changes in this revision

Viewing changes to lily/lookup.cc

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Bushnell, BSG
  • Date: 2006-12-19 10:18:12 UTC
  • mfrom: (3.1.4 feisty)
  • Revision ID: james.westby@ubuntu.com-20061219101812-7awtjkp0i393wxty
Tags: 2.8.7-3
scripts/midi2ly.py: When setting DATADIR, find Lilypond python files
in the @TOPLEVEL_VERSION@ directory, not 'current'.  Patch thanks to
Chris Lamb (chris@chris-lamb.co.uk).  (Closes: #400550)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
  source file of the GNU LilyPond music typesetter
5
5
 
6
 
  (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 
6
  (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7
7
 
8
8
  Jan Nieuwenhuizen <janneke@gnu.org>
9
9
*/
10
 
#include <math.h>
11
 
#include <ctype.h>
 
10
 
 
11
#include "lookup.hh"
 
12
 
 
13
#include <cmath>
 
14
#include <cctype>
 
15
using namespace std;
12
16
 
13
17
#include "line-interface.hh"
14
18
#include "warn.hh"
18
22
#include "file-path.hh"
19
23
#include "main.hh"
20
24
#include "lily-guile.hh"
21
 
#include "stencil.hh"
22
 
#include "lookup.hh"
23
25
#include "font-metric.hh"
24
 
#include "interval.hh"
25
26
 
26
27
Stencil
27
28
Lookup::dot (Offset p, Real radius)
28
29
{
29
30
  SCM at = (scm_list_n (ly_symbol2scm ("dot"),
30
 
                        gh_double2scm (p[X_AXIS]),
31
 
                        gh_double2scm (p[Y_AXIS]),
32
 
                        gh_double2scm (radius),
 
31
                        scm_from_double (p[X_AXIS]),
 
32
                        scm_from_double (p[Y_AXIS]),
 
33
                        scm_from_double (radius),
33
34
                        SCM_UNDEFINED));
34
35
  Box box;
35
36
  box.add_point (p - Offset (radius, radius));
37
38
  return Stencil (box, at);
38
39
}
39
40
 
40
 
 
41
 
 
42
 
/*
43
 
 * Horizontal Slope:
44
 
 *
45
 
 *            /|   ^
46
 
 *           / |   |
47
 
 *          /  |   | height
48
 
 *         /   |   |
49
 
 *        /    |   v
50
 
 *       |    /
51
 
 *       |   /
52
 
 * (0,0) x  /slope=dy/dx
53
 
 *       | /
54
 
 *       |/
55
 
 *
56
 
 *       <----->
57
 
 *        width
58
 
 */
59
 
Stencil 
60
 
Lookup::beam (Real slope, Real width, Real thick, Real blot) 
 
41
Stencil
 
42
Lookup::beam (Real slope, Real width, Real thick, Real blot)
61
43
{
62
 
  Real height = slope * width; 
63
 
  Real min_y = (0 <? height) - thick/2;
64
 
  Real max_y = (0 >? height) + thick/2;
65
 
 
66
 
  Box b (Interval (0, width),
67
 
         Interval (min_y, max_y));
68
 
  
69
 
  SCM at = scm_list_n (ly_symbol2scm ("beam"),
70
 
                    gh_double2scm (width),
71
 
                    gh_double2scm (slope),
72
 
                    gh_double2scm (thick),
73
 
                    gh_double2scm (blot),
74
 
                    SCM_UNDEFINED);
75
 
  return Stencil (b, at);
 
44
  Box b;
 
45
 
 
46
  Offset p;
 
47
 
 
48
  p = Offset (0, thick / 2);
 
49
  b.add_point (p);
 
50
  p += Offset (1, -1) * (blot / 2);
 
51
 
 
52
  SCM points = SCM_EOL;
 
53
 
 
54
  points = scm_cons (scm_from_double (p[X_AXIS]),
 
55
                     scm_cons (scm_from_double (p[Y_AXIS]),
 
56
                               points));
 
57
 
 
58
  p = Offset (0, -thick / 2);
 
59
  b.add_point (p);
 
60
  p += Offset (1, 1) * (blot / 2);
 
61
 
 
62
  points = scm_cons (scm_from_double (p[X_AXIS]),
 
63
                     scm_cons (scm_from_double (p[Y_AXIS]),
 
64
                               points));
 
65
 
 
66
  p = Offset (width, width * slope - thick / 2);
 
67
  b.add_point (p);
 
68
  p += Offset (-1, 1) * (blot / 2);
 
69
 
 
70
  points = scm_cons (scm_from_double (p[X_AXIS]),
 
71
                     scm_cons (scm_from_double (p[Y_AXIS]),
 
72
                               points));
 
73
 
 
74
  p = Offset (width, width * slope + thick / 2);
 
75
  b.add_point (p);
 
76
  p += Offset (-1, -1) * (blot / 2);
 
77
 
 
78
  points = scm_cons (scm_from_double (p[X_AXIS]),
 
79
                     scm_cons (scm_from_double (p[Y_AXIS]),
 
80
                               points));
 
81
 
 
82
  SCM expr = scm_list_n (ly_symbol2scm ("polygon"),
 
83
                         ly_quote_scm (points),
 
84
                         scm_from_double (blot),
 
85
                         SCM_BOOL_T,
 
86
                         SCM_UNDEFINED);
 
87
 
 
88
  return Stencil (b, expr);
76
89
}
77
90
 
78
91
Stencil
79
 
Lookup::dashed_slur (Bezier b, Real thick, Real dash)
 
92
Lookup::dashed_slur (Bezier b, Real thick, Real dash_period, Real dash_fraction)
80
93
{
81
94
  SCM l = SCM_EOL;
82
95
 
83
 
  for (int i= 4; i -- ;)
84
 
    {
85
 
      l = gh_cons (ly_offset2scm (b.control_[i]), l);
86
 
    }
 
96
  Real on = dash_fraction * dash_period;
 
97
  Real off = dash_period - on;
 
98
 
 
99
  for (int i = 4; i--;)
 
100
    l = scm_cons (ly_offset2scm (b.control_[i]), l);
87
101
 
88
102
  SCM at = (scm_list_n (ly_symbol2scm ("dashed-slur"),
89
 
                               gh_double2scm (thick), 
90
 
                               gh_double2scm (dash),
91
 
                               ly_quote_scm (l),
92
 
                               SCM_UNDEFINED));
 
103
                        scm_from_double (thick),
 
104
                        scm_from_double (on),
 
105
                        scm_from_double (off),
 
106
                        ly_quote_scm (l),
 
107
                        SCM_UNDEFINED));
93
108
 
94
 
  Box box (Interval (0,0),Interval (0,0));
95
 
  return   Stencil (box, at);
 
109
  Box box (Interval (0, 0), Interval (0, 0));
 
110
  return Stencil (box, at);
96
111
}
97
112
 
98
 
 
99
 
 
100
113
Stencil
101
114
Lookup::horizontal_line (Interval w, Real th)
102
115
{
103
 
  SCM at = scm_list_n (ly_symbol2scm ("horizontal-line"),
104
 
                       gh_double2scm (w[LEFT]), 
105
 
                       gh_double2scm (w[RIGHT]),
106
 
                       gh_double2scm (th),
 
116
  SCM at = scm_list_n (ly_symbol2scm ("draw-line"),
 
117
                       scm_from_double (th),
 
118
                       scm_from_double (w[LEFT]),
 
119
                       scm_from_double (0),
 
120
                       scm_from_double (w[RIGHT]),
 
121
                       scm_from_double (0),
107
122
                       SCM_UNDEFINED);
108
123
 
109
 
 
110
 
  Box box ;
 
124
  Box box;
111
125
  box[X_AXIS] = w;
112
 
  box[Y_AXIS] = Interval (-th/2,th/2);
 
126
  box[Y_AXIS] = Interval (-th / 2, th / 2);
113
127
 
114
128
  return Stencil (box, at);
115
129
}
116
130
 
117
 
 
118
131
Stencil
119
 
Lookup::blank (Box b) 
 
132
Lookup::blank (Box b)
120
133
{
121
134
  return Stencil (b, scm_makfrom0str (""));
122
135
}
123
136
 
124
137
Stencil
125
 
Lookup::filled_box (Box b) 
 
138
Lookup::filled_box (Box b)
126
139
{
127
 
  SCM  at  = (scm_list_n (ly_symbol2scm ("filledbox"),
128
 
                     gh_double2scm (-b[X_AXIS][LEFT]),
129
 
                     gh_double2scm (b[X_AXIS][RIGHT]),                 
130
 
                     gh_double2scm (-b[Y_AXIS][DOWN]),
131
 
                     gh_double2scm (b[Y_AXIS][UP]),                    
132
 
                     SCM_UNDEFINED));
133
 
 
134
 
  return Stencil (b,at);
 
140
  return round_filled_box (b, 0.0);
135
141
}
136
142
 
137
143
/*
155
161
 * |       |            |       |     |
156
162
 * |                            |     |
157
163
 * x\_____/______________\_____/|_____v
158
 
 * |(0,0)                       |
 
164
 * |(0, 0)                       |
159
165
 * |                            |
160
166
 * |                            |
161
167
 * |<-------------------------->|
165
171
Lookup::round_filled_box (Box b, Real blotdiameter)
166
172
{
167
173
  if (b.x ().length () < blotdiameter)
168
 
    {
169
 
      programming_error (_f ("round filled box horizontal extent smaller than blot; decreasing blot"));
170
 
      blotdiameter = b.x ().length ();
171
 
    }
 
174
    blotdiameter = b.x ().length ();
172
175
  if (b.y ().length () < blotdiameter)
173
 
    {
174
 
      programming_error (_f ("round filled box vertical extent smaller than blot; decreasing blot"));
175
 
      blotdiameter = b.y ().length ();
176
 
    }
 
176
    blotdiameter = b.y ().length ();
177
177
 
178
178
  SCM at = (scm_list_n (ly_symbol2scm ("round-filled-box"),
179
 
                        gh_double2scm (-b[X_AXIS][LEFT]),
180
 
                        gh_double2scm (b[X_AXIS][RIGHT]),
181
 
                        gh_double2scm (-b[Y_AXIS][DOWN]),
182
 
                        gh_double2scm (b[Y_AXIS][UP]),
183
 
                        gh_double2scm (blotdiameter),
 
179
                        scm_from_double (-b[X_AXIS][LEFT]),
 
180
                        scm_from_double (b[X_AXIS][RIGHT]),
 
181
                        scm_from_double (-b[Y_AXIS][DOWN]),
 
182
                        scm_from_double (b[Y_AXIS][UP]),
 
183
                        scm_from_double (blotdiameter),
184
184
                        SCM_UNDEFINED));
185
185
 
186
 
  return Stencil (b,at);
 
186
  return Stencil (b, at);
187
187
}
188
188
 
189
 
          
190
 
 
191
189
/*
192
190
 * Create Stencil that represents a filled polygon with round edges.
193
191
 *
229
227
 * shrinked polygon). --jr
230
228
 */
231
229
Stencil
232
 
Lookup::round_filled_polygon (Array<Offset> points, Real blotdiameter)
 
230
Lookup::round_filled_polygon (vector<Offset> const &points,
 
231
                              Real blotdiameter)
233
232
{
234
233
  /* TODO: Maybe print a warning if one of the above limitations
235
234
     applies to the given polygon.  However, this is quite complicated
236
235
     to check. */
237
236
 
 
237
  const Real epsilon = 0.01;
 
238
 
 
239
#ifndef NDEBUG
238
240
  /* remove consecutive duplicate points */
239
 
  const Real epsilon = 0.01;
240
 
  for (int i = 0; i < points.size ();)
 
241
  for (vsize i = 0; i < points.size (); i++)
241
242
    {
242
243
      int next_i = (i + 1) % points.size ();
243
244
      Real d = (points[i] - points[next_i]).length ();
244
245
      if (d < epsilon)
245
 
        points.del (next_i);
246
 
      else
247
 
        i++;
 
246
        programming_error ("Polygon should not have duplicate points");
248
247
    }
 
248
#endif
249
249
 
250
250
  /* special cases: degenerated polygons */
251
251
  if (points.size () == 0)
256
256
    return Line_interface::make_line (blotdiameter, points[0], points[1]);
257
257
 
258
258
  /* shrink polygon in size by 0.5 * blotdiameter */
259
 
  Array<Offset> shrinked_points;
260
 
  shrinked_points.set_size (points.size ());
 
259
  vector<Offset> shrunk_points;
 
260
  shrunk_points.resize (points.size ());
261
261
  bool ccw = 1; // true, if three adjacent points are counterclockwise ordered
262
 
  for (int i = 0; i < points.size (); i++)
 
262
  for (vsize i = 0; i < points.size (); i++)
263
263
    {
264
264
      int i0 = i;
265
265
      int i1 = (i + 1) % points.size ();
298
298
        }
299
299
      else
300
300
        p13 = (0.5 * blotdiameter / d) * p13n;
301
 
      shrinked_points[i1] = p1 + ((ccw) ? p13 : -p13);
 
301
      shrunk_points[i1] = p1 + ((ccw) ? p13 : -p13);
302
302
    }
303
303
 
304
304
  /* build scm expression and bounding box */
305
 
  SCM shrinked_points_scm = SCM_EOL;
 
305
  SCM shrunk_points_scm = SCM_EOL;
306
306
  Box box;
307
 
  for (int i = 0; i < shrinked_points.size (); i++)
 
307
  for (vsize i = 0; i < shrunk_points.size (); i++)
308
308
    {
309
 
      SCM x = gh_double2scm (shrinked_points[i][X_AXIS]);
310
 
      SCM y = gh_double2scm (shrinked_points[i][Y_AXIS]);
311
 
      shrinked_points_scm = gh_cons (x, gh_cons (y, shrinked_points_scm));
 
309
      SCM x = scm_from_double (shrunk_points[i][X_AXIS]);
 
310
      SCM y = scm_from_double (shrunk_points[i][Y_AXIS]);
 
311
      shrunk_points_scm = scm_cons (x, scm_cons (y, shrunk_points_scm));
312
312
      box.add_point (points[i]);
313
313
    }
314
314
  SCM polygon_scm = scm_list_n (ly_symbol2scm ("polygon"),
315
 
                                ly_quote_scm (shrinked_points_scm),
316
 
                                gh_double2scm (blotdiameter),
 
315
                                ly_quote_scm (shrunk_points_scm),
 
316
                                scm_from_double (blotdiameter),
 
317
                                SCM_BOOL_T,
317
318
                                SCM_UNDEFINED);
318
319
 
319
320
  Stencil polygon = Stencil (box, polygon_scm);
320
 
  shrinked_points.clear ();
 
321
  shrunk_points.clear ();
321
322
  return polygon;
322
323
}
323
324
 
324
 
 
325
325
/*
326
326
  TODO: deprecate?
327
 
 */
 
327
*/
328
328
Stencil
329
329
Lookup::frame (Box b, Real thick, Real blot)
330
330
{
332
332
  Direction d = LEFT;
333
333
  for (Axis a = X_AXIS; a < NO_AXES; a = Axis (a + 1))
334
334
    {
335
 
      Axis o = Axis ((a+1)%NO_AXES);
 
335
      Axis o = Axis ((a + 1)%NO_AXES);
336
336
      do
337
337
        {
338
338
          Box edges;
339
339
          edges[a] = b[a][d] + 0.5 * thick * Interval (-1, 1);
340
 
          edges[o][DOWN] = b[o][DOWN] - thick/2;
341
 
          edges[o][UP] = b[o][UP] + thick/2;      
342
 
          
 
340
          edges[o][DOWN] = b[o][DOWN] - thick / 2;
 
341
          edges[o][UP] = b[o][UP] + thick / 2;
 
342
 
343
343
          m.add_stencil (round_filled_box (edges, blot));
344
344
        }
345
345
      while (flip (&d) != LEFT);
348
348
}
349
349
 
350
350
/*
351
 
  Make a smooth curve along the points 
352
 
 */
 
351
  Make a smooth curve along the points
 
352
*/
353
353
Stencil
354
 
Lookup::slur (Bezier curve, Real curvethick, Real linethick) 
 
354
Lookup::slur (Bezier curve, Real curvethick, Real linethick)
355
355
{
356
356
  Real alpha = (curve.control_[3] - curve.control_[0]).arg ();
357
357
  Bezier back = curve;
358
 
  Offset perp = curvethick * complex_exp (Offset (0, alpha + M_PI/2)) * 0.5;
 
358
  Offset perp = curvethick * complex_exp (Offset (0, alpha + M_PI / 2)) * 0.5;
359
359
  back.reverse ();
360
360
  back.control_[1] += perp;
361
361
  back.control_[2] += perp;
362
362
 
363
363
  curve.control_[1] -= perp;
364
364
  curve.control_[2] -= perp;
365
 
  
 
365
 
366
366
  SCM scontrols[8];
367
367
 
368
 
  for (int i=4; i--;)
369
 
    scontrols[ i ] = ly_offset2scm (back.control_[i]);
370
 
  for (int i=4 ; i--;)
371
 
    scontrols[i+4] = ly_offset2scm (curve.control_[i]);
 
368
  for (int i = 0; i < 4; i++)
 
369
    scontrols[i] = ly_offset2scm (back.control_[i]);
 
370
  for (int i = 0; i < 4; i++)
 
371
    scontrols[i + 4] = ly_offset2scm (curve.control_[i]);
372
372
 
373
373
  /*
374
 
    Need the weird order b.o. the way PS want its arguments  
375
 
   */
376
 
  int indices[]= {5, 6, 7, 4, 1, 2, 3, 0};
 
374
    Need the weird order b.o. the way PS want its arguments
 
375
  */
 
376
  int indices[] = {5, 6, 7, 4, 1, 2, 3, 0};
377
377
  SCM list = SCM_EOL;
378
 
  for (int i= 8; i--;)
379
 
    {
380
 
      list = gh_cons (scontrols[indices[i]], list);
381
 
    }
382
 
  
383
 
  
 
378
  for (int i = 8; i--;)
 
379
    list = scm_cons (scontrols[indices[i]], list);
 
380
 
384
381
  SCM at = (scm_list_n (ly_symbol2scm ("bezier-sandwich"),
385
 
                     ly_quote_scm (list),
386
 
                     gh_double2scm (linethick),
387
 
                     SCM_UNDEFINED));
 
382
                        ly_quote_scm (list),
 
383
                        scm_from_double (linethick),
 
384
                        SCM_UNDEFINED));
388
385
  Box b (curve.extent (X_AXIS),
389
 
        curve.extent (Y_AXIS));
 
386
         curve.extent (Y_AXIS));
390
387
 
391
388
  b[X_AXIS].unite (back.extent (X_AXIS));
392
389
  b[Y_AXIS].unite (back.extent (Y_AXIS));
421
418
Lookup::bezier_sandwich (Bezier top_curve, Bezier bottom_curve)
422
419
{
423
420
  /*
424
 
    Need the weird order b.o. the way PS want its arguments  
425
 
   */
 
421
    Need the weird order b.o. the way PS want its arguments
 
422
  */
426
423
  SCM list = SCM_EOL;
427
 
  list = gh_cons (ly_offset2scm (bottom_curve.control_[3]), list);
428
 
  list = gh_cons (ly_offset2scm (bottom_curve.control_[0]), list);
429
 
  list = gh_cons (ly_offset2scm (bottom_curve.control_[1]), list);
430
 
  list = gh_cons (ly_offset2scm (bottom_curve.control_[2]), list);
431
 
  list = gh_cons (ly_offset2scm (top_curve.control_[0]), list);
432
 
  list = gh_cons (ly_offset2scm (top_curve.control_[3]), list);
433
 
  list = gh_cons (ly_offset2scm (top_curve.control_[2]), list);
434
 
  list = gh_cons (ly_offset2scm (top_curve.control_[1]), list);
 
424
  list = scm_cons (ly_offset2scm (bottom_curve.control_[3]), list);
 
425
  list = scm_cons (ly_offset2scm (bottom_curve.control_[0]), list);
 
426
  list = scm_cons (ly_offset2scm (bottom_curve.control_[1]), list);
 
427
  list = scm_cons (ly_offset2scm (bottom_curve.control_[2]), list);
 
428
  list = scm_cons (ly_offset2scm (top_curve.control_[0]), list);
 
429
  list = scm_cons (ly_offset2scm (top_curve.control_[3]), list);
 
430
  list = scm_cons (ly_offset2scm (top_curve.control_[2]), list);
 
431
  list = scm_cons (ly_offset2scm (top_curve.control_[1]), list);
435
432
 
436
433
  SCM horizontal_bend = scm_list_n (ly_symbol2scm ("bezier-sandwich"),
437
434
                                    ly_quote_scm (list),
438
 
                                    gh_double2scm (0.0),
 
435
                                    scm_from_double (0.0),
439
436
                                    SCM_UNDEFINED);
440
437
 
441
438
  Interval x_extent = top_curve.extent (X_AXIS);
449
446
 
450
447
/*
451
448
  TODO: junk me.
452
 
 */
 
449
*/
453
450
Stencil
454
 
Lookup::accordion (SCM s, Real staff_space, Font_metric *fm) 
 
451
Lookup::accordion (SCM s, Real staff_space, Font_metric *fm)
455
452
{
456
453
  Stencil m;
457
 
  String sym = ly_scm2string (ly_car (s));
458
 
  String reg = ly_scm2string (ly_car (ly_cdr (s)));
 
454
  string sym = ly_scm2string (scm_car (s));
 
455
  string reg = ly_scm2string (scm_car (scm_cdr (s)));
459
456
 
460
457
  if (sym == "Discant")
461
458
    {
462
 
      Stencil r = fm->find_by_name ("accordion-accDiscant");
 
459
      Stencil r = fm->find_by_name ("accordion.accDiscant");
463
460
      m.add_stencil (r);
464
 
      if (reg.left_string (1) == "F")
 
461
      if (reg.substr (0, 1) == "F")
465
462
        {
466
 
          Stencil d = fm->find_by_name ("accordion-accDot");
 
463
          Stencil d = fm->find_by_name ("accordion.accDot");
467
464
          d.translate_axis (staff_space * 2.5 PT, Y_AXIS);
468
465
          m.add_stencil (d);
469
 
          reg = reg.right_string (reg.length ()-1);
 
466
          reg = reg.substr (1);
470
467
        }
471
468
      int eflag = 0x00;
472
 
      if (reg.left_string (3) == "EEE")
 
469
      if (reg.substr (0, 3) == "EEE")
473
470
        {
474
471
          eflag = 0x07;
475
 
          reg = reg.right_string (reg.length ()-3);
 
472
          reg = reg.substr (3);
476
473
        }
477
 
      else if (reg.left_string (2) == "EE")
 
474
      else if (reg.substr (0, 2) == "EE")
478
475
        {
479
476
          eflag = 0x05;
480
 
          reg = reg.right_string (reg.length ()-2);
 
477
          reg = reg.substr (2);
481
478
        }
482
 
      else if (reg.left_string (2) == "Eh")
 
479
      else if (reg.substr (0, 2) == "Eh")
483
480
        {
484
481
          eflag = 0x04;
485
 
          reg = reg.right_string (reg.length ()-2);
 
482
          reg = reg.substr (2);
486
483
        }
487
 
      else if (reg.left_string (1) == "E")
 
484
      else if (reg.substr (0, 1) == "E")
488
485
        {
489
486
          eflag = 0x02;
490
 
          reg = reg.right_string (reg.length ()-1);
 
487
          reg = reg.substr (1);
491
488
        }
492
489
      if (eflag & 0x02)
493
490
        {
494
 
          Stencil d = fm->find_by_name ("accordion-accDot");
 
491
          Stencil d = fm->find_by_name ("accordion.accDot");
495
492
          d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
496
493
          m.add_stencil (d);
497
494
        }
498
495
      if (eflag & 0x04)
499
496
        {
500
 
          Stencil d = fm->find_by_name ("accordion-accDot");
 
497
          Stencil d = fm->find_by_name ("accordion.accDot");
501
498
          d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
502
499
          d.translate_axis (0.8 * staff_space PT, X_AXIS);
503
500
          m.add_stencil (d);
504
501
        }
505
502
      if (eflag & 0x01)
506
503
        {
507
 
          Stencil d = fm->find_by_name ("accordion-accDot");
 
504
          Stencil d = fm->find_by_name ("accordion.accDot");
508
505
          d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
509
506
          d.translate_axis (-0.8 * staff_space PT, X_AXIS);
510
507
          m.add_stencil (d);
511
508
        }
512
 
      if (reg.left_string (2) == "SS")
 
509
      if (reg.substr (0, 2) == "SS")
513
510
        {
514
 
          Stencil d = fm->find_by_name ("accordion-accDot");
 
511
          Stencil d = fm->find_by_name ("accordion.accDot");
515
512
          d.translate_axis (0.5 * staff_space PT, Y_AXIS);
516
513
          d.translate_axis (0.4 * staff_space PT, X_AXIS);
517
514
          m.add_stencil (d);
518
515
          d.translate_axis (-0.8 * staff_space PT, X_AXIS);
519
516
          m.add_stencil (d);
520
 
          reg = reg.right_string (reg.length ()-2);
 
517
          reg = reg.substr (2);
521
518
        }
522
 
      if (reg.left_string (1) == "S")
 
519
      if (reg.substr (0, 1) == "S")
523
520
        {
524
 
          Stencil d = fm->find_by_name ("accordion-accDot");
 
521
          Stencil d = fm->find_by_name ("accordion.accDot");
525
522
          d.translate_axis (0.5 * staff_space PT, Y_AXIS);
526
523
          m.add_stencil (d);
527
 
          reg = reg.right_string (reg.length ()-1);
 
524
          reg = reg.substr (1);
528
525
        }
529
526
    }
530
527
  else if (sym == "Freebase")
531
528
    {
532
 
      Stencil r = fm->find_by_name ("accordion-accFreebase");
 
529
      Stencil r = fm->find_by_name ("accordion.accFreebase");
533
530
      m.add_stencil (r);
534
 
      if (reg.left_string (1) == "F")
 
531
      if (reg.substr (0, 1) == "F")
535
532
        {
536
 
          Stencil d = fm->find_by_name ("accordion-accDot");
 
533
          Stencil d = fm->find_by_name ("accordion.accDot");
537
534
          d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
538
535
          m.add_stencil (d);
539
 
          reg = reg.right_string (reg.length ()-1);
 
536
          reg = reg.substr (1);
540
537
        }
541
538
      if (reg == "E")
542
539
        {
543
 
          Stencil d = fm->find_by_name ("accordion-accDot");
 
540
          Stencil d = fm->find_by_name ("accordion.accDot");
544
541
          d.translate_axis (staff_space * 0.5 PT, Y_AXIS);
545
542
          m.add_stencil (d);
546
543
        }
547
544
    }
548
545
  else if (sym == "Bayanbase")
549
546
    {
550
 
      Stencil r = fm->find_by_name ("accordion-accBayanbase");
 
547
      Stencil r = fm->find_by_name ("accordion.accBayanbase");
551
548
      m.add_stencil (r);
552
 
      if (reg.left_string (1) == "T")
 
549
      if (reg.substr (0, 1) == "T")
553
550
        {
554
 
          Stencil d = fm->find_by_name ("accordion-accDot");
 
551
          Stencil d = fm->find_by_name ("accordion.accDot");
555
552
          d.translate_axis (staff_space * 2.5 PT, Y_AXIS);
556
553
          m.add_stencil (d);
557
 
          reg = reg.right_string (reg.length ()-1);
 
554
          reg = reg.substr (1);
558
555
        }
559
556
      /* include 4' reed just for completeness. You don't want to use this. */
560
 
      if (reg.left_string (1) == "F")
 
557
      if (reg.substr (0, 1) == "F")
561
558
        {
562
 
          Stencil d = fm->find_by_name ("accordion-accDot");
 
559
          Stencil d = fm->find_by_name ("accordion.accDot");
563
560
          d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
564
561
          m.add_stencil (d);
565
 
          reg = reg.right_string (reg.length ()-1);
 
562
          reg = reg.substr (1);
566
563
        }
567
 
      if (reg.left_string (2) == "EE")
 
564
      if (reg.substr (0, 2) == "EE")
568
565
        {
569
 
          Stencil d = fm->find_by_name ("accordion-accDot");
 
566
          Stencil d = fm->find_by_name ("accordion.accDot");
570
567
          d.translate_axis (staff_space * 0.5 PT, Y_AXIS);
571
568
          d.translate_axis (0.4 * staff_space PT, X_AXIS);
572
569
          m.add_stencil (d);
573
570
          d.translate_axis (-0.8 * staff_space PT, X_AXIS);
574
571
          m.add_stencil (d);
575
 
          reg = reg.right_string (reg.length ()-2);
 
572
          reg = reg.substr (2);
576
573
        }
577
 
      if (reg.left_string (1) == "E")
 
574
      if (reg.substr (0, 1) == "E")
578
575
        {
579
 
          Stencil d = fm->find_by_name ("accordion-accDot");
 
576
          Stencil d = fm->find_by_name ("accordion.accDot");
580
577
          d.translate_axis (staff_space * 0.5 PT, Y_AXIS);
581
578
          m.add_stencil (d);
582
 
          reg = reg.right_string (reg.length ()-1);
 
579
          reg = reg.substr (1);
583
580
        }
584
581
    }
585
582
  else if (sym == "Stdbase")
586
583
    {
587
 
      Stencil r = fm->find_by_name ("accordion-accStdbase");
 
584
      Stencil r = fm->find_by_name ("accordion.accStdbase");
588
585
      m.add_stencil (r);
589
 
      if (reg.left_string (1) == "T")
 
586
      if (reg.substr (0, 1) == "T")
590
587
        {
591
 
          Stencil d = fm->find_by_name ("accordion-accDot");
 
588
          Stencil d = fm->find_by_name ("accordion.accDot");
592
589
          d.translate_axis (staff_space * 3.5 PT, Y_AXIS);
593
590
          m.add_stencil (d);
594
 
          reg = reg.right_string (reg.length ()-1);
 
591
          reg = reg.substr (1);
595
592
        }
596
 
      if (reg.left_string (1) == "F")
 
593
      if (reg.substr (0, 1) == "F")
597
594
        {
598
 
          Stencil d = fm->find_by_name ("accordion-accDot");
 
595
          Stencil d = fm->find_by_name ("accordion.accDot");
599
596
          d.translate_axis (staff_space * 2.5 PT, Y_AXIS);
600
597
          m.add_stencil (d);
601
 
          reg = reg.right_string (reg.length ()-1);
 
598
          reg = reg.substr (1);
602
599
        }
603
 
      if (reg.left_string (1) == "M")
 
600
      if (reg.substr (0, 1) == "M")
604
601
        {
605
 
          Stencil d = fm->find_by_name ("accordion-accDot");
 
602
          Stencil d = fm->find_by_name ("accordion.accDot");
606
603
          d.translate_axis (staff_space * 2 PT, Y_AXIS);
607
604
          d.translate_axis (staff_space PT, X_AXIS);
608
605
          m.add_stencil (d);
609
 
          reg = reg.right_string (reg.length ()-1);
 
606
          reg = reg.substr (1);
610
607
        }
611
 
      if (reg.left_string (1) == "E")
 
608
      if (reg.substr (0, 1) == "E")
612
609
        {
613
 
          Stencil d = fm->find_by_name ("accordion-accDot");
 
610
          Stencil d = fm->find_by_name ("accordion.accDot");
614
611
          d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
615
612
          m.add_stencil (d);
616
 
          reg = reg.right_string (reg.length ()-1);
 
613
          reg = reg.substr (1);
617
614
        }
618
 
      if (reg.left_string (1) == "S")
 
615
      if (reg.substr (0, 1) == "S")
619
616
        {
620
 
          Stencil d = fm->find_by_name ("accordion-accDot");
 
617
          Stencil d = fm->find_by_name ("accordion.accDot");
621
618
          d.translate_axis (staff_space * 0.5 PT, Y_AXIS);
622
619
          m.add_stencil (d);
623
 
          reg = reg.right_string (reg.length ()-1);
 
620
          reg = reg.substr (1);
624
621
        }
625
622
    }
626
623
  /* ugh maybe try to use regular font for S.B. and B.B and only use one font
627
624
     for the rectangle */
628
625
  else if (sym == "SB")
629
626
    {
630
 
      Stencil r = fm->find_by_name ("accordion-accSB");
 
627
      Stencil r = fm->find_by_name ("accordion.accSB");
631
628
      m.add_stencil (r);
632
629
    }
633
630
  else if (sym == "BB")
634
631
    {
635
 
      Stencil r = fm->find_by_name ("accordion-accBB");
 
632
      Stencil r = fm->find_by_name ("accordion.accBB");
636
633
      m.add_stencil (r);
637
634
    }
638
635
  else if (sym == "OldEE")
639
636
    {
640
 
      Stencil r = fm->find_by_name ("accordion-accOldEE");
 
637
      Stencil r = fm->find_by_name ("accordion.accOldEE");
641
638
      m.add_stencil (r);
642
639
    }
643
640
  else if (sym == "OldEES")
644
641
    {
645
 
      Stencil r = fm->find_by_name ("accordion-accOldEES");
 
642
      Stencil r = fm->find_by_name ("accordion.accOldEES");
646
643
      m.add_stencil (r);
647
644
    }
648
 
  return m;  
 
645
  return m;
649
646
}
650
647
 
651
648
Stencil
652
649
Lookup::repeat_slash (Real w, Real s, Real t)
653
650
{
654
 
  SCM wid = gh_double2scm (w);
655
 
  SCM sl = gh_double2scm (s);
656
 
  SCM thick = gh_double2scm (t);
 
651
#if 0 /*  TODO */
 
652
  vector<Offset> points;
 
653
  Real blotdiameter = 0.0;
 
654
 
 
655
  Offset p1 (0, 0);
 
656
  Offset p2 (w, w * s);
 
657
 
 
658
  return Lookup::round_filled_polygon (points, blotdiameter);
 
659
#endif
 
660
 
 
661
  SCM wid = scm_from_double (w);
 
662
  SCM sl = scm_from_double (s);
 
663
  SCM thick = scm_from_double (t);
657
664
  SCM slashnodot = scm_list_n (ly_symbol2scm ("repeat-slash"),
658
 
                            wid, sl, thick, SCM_UNDEFINED);
 
665
                               wid, sl, thick, SCM_UNDEFINED);
659
666
 
660
 
  Box b (Interval (0, w + sqrt (sqr (t/s) + sqr (t))),
 
667
  Box b (Interval (0, w + sqrt (sqr (t / s) + sqr (t))),
661
668
         Interval (0, w * s));
662
669
 
663
670
  return Stencil (b, slashnodot); //  http://slashnodot.org
664
671
}
665
672
 
666
 
 
667
673
Stencil
668
674
Lookup::bracket (Axis a, Interval iv, Real thick, Real protude, Real blot)
669
675
{
670
676
  Box b;
671
 
  Axis other = Axis ((a+1)%2);
 
677
  Axis other = Axis ((a + 1)%2);
672
678
  b[a] = iv;
673
679
  b[other] = Interval (-1, 1) * thick * 0.5;
674
 
  
675
 
  Stencil m =  round_filled_box (b, blot);
 
680
 
 
681
  Stencil m = round_filled_box (b, blot);
676
682
 
677
683
  b[a] = Interval (iv[UP] - thick, iv[UP]);
678
 
  Interval oi = Interval (-thick/2, thick/2 + fabs (protude)) ;
679
 
  oi *=  sign (protude);
 
684
  Interval oi = Interval (-thick / 2, thick / 2 + fabs (protude));
 
685
  oi *= sign (protude);
680
686
  b[other] = oi;
681
687
  m.add_stencil (round_filled_box (b, blot));
682
 
  b[a] = Interval (iv[DOWN], iv[DOWN]  +thick);
683
 
  m.add_stencil (round_filled_box (b,blot));
 
688
  b[a] = Interval (iv[DOWN], iv[DOWN] + thick);
 
689
  m.add_stencil (round_filled_box (b, blot));
684
690
 
685
691
  return m;
686
692
}
688
694
Stencil
689
695
Lookup::triangle (Interval iv, Real thick, Real protude)
690
696
{
691
 
  Box b ;
692
 
  b[X_AXIS] = iv;
693
 
  b[Y_AXIS] = Interval (0 <? protude , 0 >? protude);
694
 
 
695
 
  SCM s = scm_list_n (ly_symbol2scm ("symmetric-x-triangle"),
696
 
                      gh_double2scm (thick),
697
 
                      gh_double2scm (iv.length ()), 
698
 
                      gh_double2scm (protude), SCM_UNDEFINED);
699
 
 
700
 
  return Stencil (b, s);
701
 
}
702
 
 
703
 
 
704
 
LY_DEFINE (ly_bracket ,"ly:bracket",
705
 
          4, 0, 0,
706
 
          (SCM a, SCM iv, SCM t, SCM p),
707
 
          "Make a bracket in direction @var{a}. The extent of the bracket is " 
708
 
          "given by @var{iv}. The wings protude by an amount of @var{p}, which "
709
 
          "may be negative. The thickness is given by @var{t}.")
710
 
{
711
 
  SCM_ASSERT_TYPE (is_axis (a), a, SCM_ARG1, __FUNCTION__, "axis") ;
712
 
  SCM_ASSERT_TYPE (is_number_pair (iv), iv, SCM_ARG2, __FUNCTION__, "number pair") ;
713
 
  SCM_ASSERT_TYPE (gh_number_p (t), a, SCM_ARG3, __FUNCTION__, "number") ;
714
 
  SCM_ASSERT_TYPE (gh_number_p (p), a, SCM_ARG4, __FUNCTION__, "number") ;
715
 
 
716
 
 
717
 
  return Lookup::bracket ((Axis)gh_scm2int (a), ly_scm2interval (iv),
718
 
                          gh_scm2double (t),
719
 
                          gh_scm2double (p),
720
 
                          0.95 * gh_scm2double (t)).smobbed_copy ();
721
 
}
722
 
 
723
 
 
724
 
 
725
 
LY_DEFINE (ly_filled_box ,"ly:round-filled-box",
726
 
          3, 0, 0,
727
 
          (SCM xext, SCM yext, SCM blot),
728
 
          "Make a @code{Stencil} "
729
 
          "that prints a black box of dimensions @var{xext}, "
730
 
          "@var{yext} and roundness @var{blot}."
731
 
          )
732
 
{
733
 
  SCM_ASSERT_TYPE (is_number_pair (xext), xext, SCM_ARG1, __FUNCTION__, "number pair") ;
734
 
  SCM_ASSERT_TYPE (is_number_pair (yext), yext, SCM_ARG2, __FUNCTION__, "number pair") ;
735
 
  SCM_ASSERT_TYPE (gh_number_p (blot), blot, SCM_ARG3, __FUNCTION__, "number") ;
736
 
 
737
 
  return Lookup::round_filled_box (Box (ly_scm2interval (xext), ly_scm2interval (yext)),
738
 
                                   gh_scm2double (blot)).smobbed_copy ();
 
697
  Box b;
 
698
  b[X_AXIS] = Interval (0, iv.length ());
 
699
  b[Y_AXIS] = Interval (min (0., protude), max (0.0, protude));
 
700
 
 
701
  Offset z1 (iv[LEFT], 0);
 
702
  Offset z2 (iv[RIGHT], 0);
 
703
  Offset z3 ((z1 + z2)[X_AXIS] / 2, protude);
 
704
 
 
705
  /*
 
706
    TODO: move Triangle to Line_interface ?
 
707
  */
 
708
  Stencil tri = Line_interface::make_line (thick, z1, z2);
 
709
  tri.add_stencil (Line_interface::make_line (thick, z2, z3));
 
710
  tri.add_stencil (Line_interface::make_line (thick, z3, z1));
 
711
 
 
712
  return tri;
739
713
}
740
714