]> git.donarmstrong.com Git - lilypond.git/blob - lily/tex-beam.cc
patch::: 0.1.37.jcn2: biem pats
[lilypond.git] / lily / tex-beam.cc
1 /*
2   tex-beam.cc -- implement Lookup::{beam_element, beam, rule_symbol}
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1996,1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 /*
10   Code to generate beams for TeX
11   */
12
13 #include <math.h>
14 #include "atom.hh"
15 #include "molecule.hh"
16 #include "tex.hh"
17 #include "symtable.hh"
18 #include "dimen.hh"
19 #include "debug.hh"
20 #include "lookup.hh"
21 #include "misc.hh"
22
23 Atom
24 Lookup::beam_element (int sidx, int widx, Real slope) const
25 {
26   String name = String("slope");
27   Atom bs=(*symtables_p_)("beamslopes")->lookup (name);
28
29   Array<String> args;
30   args.push (sidx);
31   args.push (widx);
32   bs.tex_ = substitute_args (bs.tex_,args);
33   int w = 2 << widx;
34   Real width = w PT;
35   bs.dim_.x() = Interval (0,width);
36   bs.dim_.y() = Interval (0,width*slope);
37   return bs;
38 }
39
40
41 Atom
42 Lookup::rule_symbol (Real height, Real width) const
43 {
44   Atom bs=(*symtables_p_)("beamslopes")->lookup ("horizontal");
45   Array<String> args;
46   args.push (print_dimen (height));
47   args.push (print_dimen (width));
48   bs.tex_ = substitute_args (bs.tex_,args);
49   bs.dim_.x() = Interval (0,width);
50   bs.dim_.y() = Interval (0,height);
51   return bs;
52 }
53
54 Atom
55 Lookup::beam (Real &slope, Real width) const
56 {
57   const Real MAX_SLOPE = 0.6;
58   const Real SLOPES = 20.0;
59   int sidx = 0;
60   if (abs (slope) > MAX_SLOPE)
61     {
62       WARN << _("beam too steep (") << slope << ")\n";
63       slope = sign (slope) * MAX_SLOPE;
64     }
65
66   sidx = int (rint (slope / MAX_SLOPE *  SLOPES));
67   slope = MAX_SLOPE * sidx / SLOPES;
68
69   Interval xdims = (*symtables_p_)("beamslopes")->lookup ("slope").dim_[X_AXIS];
70   Real min_wid = xdims[LEFT];
71   Real max_wid = xdims[RIGHT];
72   assert(max_wid > 0);
73   int widths = intlog2 (int (max_wid/min_wid)) + 1;
74
75   if (width < min_wid)
76     {
77       WARN<<_("Beam too narrow. (") << print_dimen (width) <<")\n";
78       width = min_wid;
79     }
80
81   Real elemwidth = max_wid;
82
83   int widx  =widths - 1;
84   Molecule m;
85   while (elemwidth > width)
86     {
87       widx --;
88       elemwidth /= 2.0;
89     }
90   Real overlap = elemwidth/4;
91   Real last_x = width - elemwidth;
92   Real x = overlap;
93   Atom elem (beam_element (sidx * widths, widx, slope));
94   m.add (elem);
95   while (x < last_x)
96     {
97       Atom a(elem);
98       a.translate (Offset (x-overlap, (x-overlap)*slope));
99       m.add (a);
100       x += elemwidth - overlap;
101     }
102   Atom a(elem);
103   a.translate (Offset (last_x, (last_x) * slope));
104   m.add (a);
105
106   Atom ret;
107   ret.tex_ = m.TeX_string();
108   ret.dim_.y() = Interval (0,width*slope);
109   ret.dim_.x() = Interval (0,width);
110
111   return ret;
112 }