lilypond-0.0.32
[lilypond.git] / src / lookup.cc
bloba87454e2d15ad10c60e9fa4c06d6d9598e12bee0
1 #include "lookup.hh"
2 #include "debug.hh"
3 #include "symtable.hh"
4 #include "dimen.hh"
5 #include "tex.hh"
6 #include "scalar.hh"
8 Lookup::Lookup()
10 texsetting = "\\unknowntexsetting";
11 symtables_ = new Symtables;
14 Lookup::Lookup(Lookup const &s)
16 texsetting = s.texsetting;
17 symtables_ = new Symtables(*s.symtables_);
19 Lookup::~Lookup()
21 delete symtables_;
24 void
25 Lookup::add(String s, Symtable*p)
27 symtables_->add(s, p);
30 Symbol
31 Lookup::text(String style, String text, int dir)
33 Array<String> a;
35 a.push(text);
36 Symbol tsym = (*symtables_)("style")->lookup(style);
37 a[0] = substitute_args(tsym.tex,a);
39 Symbol s = (*symtables_)("align")->lookup(dir);
40 s.tex = substitute_args(s.tex,a);
41 s.dim.y = tsym.dim.y;
42 return s;
45 /* *************** */
47 Real
48 Lookup::internote()
50 return ball(4).dim.y.length()/2;
53 Symbol
54 Lookup::ball(int j)
56 if (j > 4)
57 j = 4;
59 Symtable * st = (*symtables_)("balls");
60 return st->lookup(String(j));
63 Symbol
64 Lookup::rest(int j)
66 return (*symtables_)("rests")->lookup(String(j));
69 Symbol
70 Lookup::fill(Box b)
72 Symbol s( (*symtables_)("param")->lookup("fill"));
73 s.dim = b;
74 return s;
77 Symbol
78 Lookup::accidental(int j)
80 return (*symtables_)("accidentals")->lookup(String(j));
84 Symbol
85 Lookup::bar(String s)
87 return (*symtables_)("bars")->lookup(s);
90 Symbol
91 Lookup::script(String s)
93 return (*symtables_)("scripts")->lookup(s);
96 Symbol
97 Lookup::clef(String s)
99 return (*symtables_)("clefs")->lookup(s);
102 Symbol
103 Lookup::dots(int j)
105 if (j>3)
106 error("max 3 dots"); // todo
107 return (*symtables_)("dots")->lookup(j);
110 Symbol
111 Lookup::flag(int j)
113 return (*symtables_)("flags")->lookup(j);
116 Symbol
117 Lookup::streepjes(int i)
119 assert(i);
121 int arg;
122 String idx;
124 if (i < 0) {
125 idx = "botlines";
126 arg = -i;
127 } else {
128 arg = i;
129 idx = "toplines";
131 Symbol ret = (*symtables_)("streepjes")->lookup(idx);
133 Array<String> a;
134 a.push(arg);
135 ret.tex = substitute_args(ret.tex, a);
137 return ret;
140 Symbol
141 Lookup::hairpin(Real &wid, bool decresc)
143 int idx = int(rint(wid / 6 PT));
144 if(!idx) idx ++;
145 wid = idx*6 PT;
146 String idxstr = (decresc)? "decrescendosym" : "crescendosym";
147 Symbol ret=(*symtables_)("param")->lookup(idxstr);
149 Array<String> a;
150 a.push(idx);
151 ret.tex = substitute_args(ret.tex, a);
152 ret.dim.x = Interval(0,wid);
153 return ret;
156 Symbol
157 Lookup::linestaff(int lines, Real wid)
159 Symbol s;
160 s.dim.x = Interval(0,wid);
161 Real dy = (lines >0) ? (lines-1)*internote()*2 : 0;
162 s.dim.y = Interval(0,dy);
164 Array<String> a;
165 a.push(lines);
166 a.push(print_dimen(wid));
168 s.tex = (*symtables_)("param")->lookup("linestaf").tex;
169 s.tex = substitute_args(s.tex, a);
171 return s;
175 Symbol
176 Lookup::meter(Array<Scalar> a)
178 Symbol s;
179 s.dim.x = Interval( 0 PT, 10 PT);
180 s.dim.y = Interval(0, 20 PT); // todo
181 String src = (*symtables_)("param")->lookup("meter").tex;
182 s.tex = substitute_args(src,a);
183 return s;
187 Symbol
188 Lookup::stem(Real y1,Real y2)
190 if (y1 > y2) {
191 Real t = y1;
192 y1 = y2;
193 y2 = t;
195 Symbol s;
197 s.dim.x = Interval(0,0);
198 s.dim.y = Interval(y1,y2);
200 Array<String> a;
201 a.push(print_dimen(y1));
202 a.push(print_dimen(y2));
204 String src = (*symtables_)("param")->lookup("stem").tex;
205 s.tex = substitute_args(src,a);
206 return s;