lilypond-0.0.40
[lilypond.git] / lily / lookup.cc
blobede8af08554d3a796b994453e5f96f1b4d70741a
1 /*
2 lookup.cc -- implement simple Lookup methods.
4 source file of the LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
9 #include "lookup.hh"
10 #include "debug.hh"
11 #include "symtable.hh"
12 #include "dimen.hh"
13 #include "tex.hh"
14 #include "scalar.hh"
16 Lookup::Lookup()
18 texsetting = "\\unknowntexsetting";
19 symtables_ = new Symtables;
22 Lookup::Lookup(Lookup const &s)
24 texsetting = s.texsetting;
25 symtables_ = new Symtables(*s.symtables_);
27 Lookup::~Lookup()
29 delete symtables_;
32 void
33 Lookup::add(String s, Symtable*p)
35 symtables_->add(s, p);
38 void
39 Lookup::print()const
41 mtor << "Lookup: " << texsetting << " {\n";
42 symtables_->print();
43 mtor << "}\n";
46 Symbol
47 Lookup::text(String style, String text, int dir) const
49 Array<String> a;
51 a.push(text);
52 Symbol tsym = (*symtables_)("style")->lookup(style);
53 a[0] = substitute_args(tsym.tex,a);
55 Symbol s = (*symtables_)("align")->lookup(dir);
56 s.tex = substitute_args(s.tex,a);
57 s.dim.y = tsym.dim.y;
58 return s;
62 Real
63 Lookup::internote() const
65 return ball(4).dim.y.length()/2;
68 Symbol
69 Lookup::ball(int j) const
71 if (j > 4)
72 j = 4;
74 Symtable * st = (*symtables_)("balls");
75 return st->lookup(String(j));
78 Symbol
79 Lookup::rest(int j) const
81 return (*symtables_)("rests")->lookup(String(j));
84 Symbol
85 Lookup::fill(Box b) const
87 Symbol s( (*symtables_)("param")->lookup("fill"));
88 s.dim = b;
89 return s;
92 Symbol
93 Lookup::accidental(int j) const
95 return (*symtables_)("accidentals")->lookup(String(j));
99 Symbol
100 Lookup::bar(String s) const
102 return (*symtables_)("bars")->lookup(s);
105 Symbol
106 Lookup::script(String s) const
108 return (*symtables_)("scripts")->lookup(s);
111 Symbol
112 Lookup::dynamic(String s) const
114 return (*symtables_)("dynamics")->lookup(s);
117 Symbol
118 Lookup::clef(String s) const
120 return (*symtables_)("clefs")->lookup(s);
123 Symbol
124 Lookup::dots(int j) const
126 if (j>3)
127 error("max 3 dots"); // todo
128 return (*symtables_)("dots")->lookup(j);
131 Symbol
132 Lookup::flag(int j) const
134 return (*symtables_)("flags")->lookup(j);
137 Symbol
138 Lookup::streepjes(int i) const
140 assert(i);
142 int arg;
143 String idx;
145 if (i < 0) {
146 idx = "botlines";
147 arg = -i;
148 } else {
149 arg = i;
150 idx = "toplines";
152 Symbol ret = (*symtables_)("streepjes")->lookup(idx);
154 Array<String> a;
155 a.push(arg);
156 ret.tex = substitute_args(ret.tex, a);
158 return ret;
161 Symbol
162 Lookup::hairpin(Real &wid, bool decresc) const
164 int idx = int(rint(wid / 6 PT));
165 if(!idx) idx ++;
166 wid = idx*6 PT;
167 String idxstr = (decresc)? "decrescendosym" : "crescendosym";
168 Symbol ret=(*symtables_)("param")->lookup(idxstr);
170 Array<String> a;
171 a.push(idx);
172 ret.tex = substitute_args(ret.tex, a);
173 ret.dim.x = Interval(0,wid);
174 return ret;
177 Symbol
178 Lookup::linestaff(int lines, Real wid) const
180 Symbol s;
181 s.dim.x = Interval(0,wid);
182 Real dy = (lines >0) ? (lines-1)*internote()*2 : 0;
183 s.dim.y = Interval(0,dy);
185 Array<String> a;
186 a.push(lines);
187 a.push(print_dimen(wid));
189 s.tex = (*symtables_)("param")->lookup("linestaf").tex;
190 s.tex = substitute_args(s.tex, a);
192 return s;
196 Symbol
197 Lookup::meter(Array<Scalar> a) const
199 Symbol s;
200 s.dim.x = Interval( 0 PT, 10 PT);
201 s.dim.y = Interval(0, 20 PT); // todo
202 String src = (*symtables_)("param")->lookup("meter").tex;
203 s.tex = substitute_args(src,a);
204 return s;
208 Symbol
209 Lookup::stem(Real y1,Real y2) const
211 if (y1 > y2) {
212 Real t = y1;
213 y1 = y2;
214 y2 = t;
216 Symbol s;
218 s.dim.x = Interval(0,0);
219 s.dim.y = Interval(y1,y2);
221 Array<String> a;
222 a.push(print_dimen(y1));
223 a.push(print_dimen(y2));
225 String src = (*symtables_)("param")->lookup("stem").tex;
226 s.tex = substitute_args(src,a);
227 return s;