lilypond-0.1.57
[lilypond.git] / lily / lookup.cc
blob1ee100caa92dd2ea6c9d2bbefed756c604f7e465
1 /*
2 lookup.cc -- implement simple Lookup methods.
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
8 TODO
9 This doth suck. We should have PS output, and read spacing info from TFMs
11 Glissando,
15 #include "lookup.hh"
16 #include "debug.hh"
17 #include "symtable.hh"
18 #include "dimen.hh"
19 #include "tex.hh"
20 #include "scalar.hh"
21 #include "paper-def.hh"
22 #include "main.hh"
24 Lookup::Lookup()
26 paper_l_ = 0;
27 texsetting = "\\unknowntexsetting";
28 symtables_p_ = new Symtables;
31 Lookup::Lookup (Lookup const &s)
33 paper_l_ = s.paper_l_;
34 texsetting = s.texsetting;
35 symtables_p_ = new Symtables (*s.symtables_p_);
37 Lookup::~Lookup()
39 delete symtables_p_;
42 void
43 Lookup::add (String s, Symtable*p)
45 symtables_p_->add (s, p);
48 void
49 Lookup::print() const
51 #ifndef NPRINT
52 DOUT << "Lookup: " << texsetting << " {\n";
53 symtables_p_->print();
54 DOUT << "}\n";
55 #endif
58 Atom
59 Lookup::text (String style, String text, int dir) const
61 Array<String> a;
63 a.push (text);
64 Atom tsym = (*symtables_p_)("style")->lookup (style);
65 a[0] = substitute_args (tsym.tex_,a);
67 Atom s = (*symtables_p_)("align")->lookup (dir);
68 s.tex_ = substitute_args (s.tex_,a);
69 s.dim_ = tsym.dim_;
70 return s;
75 Atom
76 Lookup::ball (int j) const
78 if (j > 2)
79 j = 2;
81 Symtable * st = (*symtables_p_)("balls");
82 return st->lookup (String (j));
85 Atom
86 Lookup::rest (int j, bool o) const
88 return (*symtables_p_)("rests")->lookup (String (j) + (o ? "o" : ""));
91 Atom
92 Lookup::fill (Box b) const
94 Atom s ((*symtables_p_)("param")->lookup ("fill"));
95 s.dim_ = b;
96 return s;
99 Atom
100 Lookup::accidental (int j) const
102 return (*symtables_p_)("accidentals")->lookup (String (j));
106 Atom
107 Lookup::bar (String s, Real h) const
109 Array<String> a;
110 a.push (print_dimen (h));
111 Atom ret=(*symtables_p_)("bars")->lookup (s);
112 ret.tex_ = substitute_args (ret.tex_, a);
113 ret.dim_.y() = Interval (-h/2, h/2);
114 return ret;
117 Atom
118 Lookup::script (String s) const
120 return (*symtables_p_)("scripts")->lookup (s);
123 Atom
124 Lookup::dynamic (String s) const
126 return (*symtables_p_)("dynamics")->lookup (s);
129 Atom
130 Lookup::clef (String s) const
132 return (*symtables_p_)("clefs")->lookup (s);
135 Atom
136 Lookup::dots () const
138 return (*symtables_p_)("dots")->lookup ("dot");
141 Atom
142 Lookup::flag (int j, Direction d) const
144 char c = (d == UP) ? 'u' : 'd';
145 return (*symtables_p_)("flags")->lookup (c + String (j));
148 Atom
149 Lookup::streepje (int type) const
151 if (type > 2)
152 type = 2;
154 Symtable * st = (*symtables_p_)("balls");
156 return st->lookup (String (type) + 'l');
159 Atom
160 Lookup::hairpin (Real &wid, bool decresc, bool continued) const
162 bool embedded_b = postscript_global_b;
163 String embed;
164 Atom ret;
165 Real height = paper_l_->get_var ("barsize") / 6;
166 if (embedded_b)
168 embed = "\\embeddedps{\n" ;
169 embed += String (wid) + " "
170 + String (height) + " "
171 + String (continued ? height/2 : 0) +
172 + " draw_" + String(decresc ? "de" : "") + "cresc}\n";
173 ret.tex_ = embed;
175 else
177 if (wid > 32 * 6 PT)
179 warning (_("Crescendo too long (") + print_dimen (wid)
180 +_( ") shrinking (ugh)"));
181 wid = 32*6 PT;
183 int idx = int (rint (wid / 6 PT));
184 if (!idx) idx ++;
185 wid = idx*6 PT;
186 String idxstr = (decresc)? "decrescendosym" : "crescendosym";
187 ret=(*symtables_p_)("param")->lookup (idxstr);
189 Array<String> a;
190 a.push (idx);
191 ret.tex_ = substitute_args (ret.tex_, a);
194 ret.dim_.x () = Interval (0,wid);
195 ret.dim_.y () = Interval (-2*height,2*height);
196 // ret.translate_axis (ret.dim_[Y_AXIS][DOWN], Y_AXIS);
197 return ret;
200 Atom
201 Lookup::meter (Array<Scalar> a) const
203 Atom s((*symtables_p_)("param")->lookup ("meter"));
204 s.tex_ = substitute_args (s.tex_,a);
205 return s;
209 Atom
210 Lookup::stem (Real y1,Real y2) const
212 if (y1 > y2)
214 Real t = y1;
215 y1 = y2;
216 y2 = t;
218 Atom s;
220 s.dim_.x() = Interval (0,0);
221 s.dim_.y() = Interval (y1,y2);
223 Array<String> a;
224 a.push (print_dimen (y1));
225 a.push (print_dimen (y2));
227 String src = (*symtables_p_)("param")->lookup ("stem").tex_;
228 s.tex_ = substitute_args (src,a);
229 return s;
233 should be handled via Tex_ code and Lookup::bar()
235 Atom
236 Lookup::vbrace (Real &y) const
238 Atom brace = (*symtables_p_)("param")->lookup ("brace");
239 Interval ydims = brace.dim_[Y_AXIS];
240 Real min_y = ydims[LEFT];
241 Real max_y = ydims[RIGHT];
242 Real step = 1.0 PT;
244 if (y < min_y)
246 warning (_("piano brace too small (") + print_dimen (y)+ ")");
247 y = min_y;
249 if (y > max_y)
251 warning (_("piano brace too big (") + print_dimen (y)+ ")");
252 y = max_y;
256 int idx = int (rint ((y- min_y)/step)) + 1;
259 Array<String> a;
260 a.push (idx);
261 brace.tex_ = substitute_args (brace.tex_,a);
262 brace.dim_[Y_AXIS] = Interval (-y/2,y/2);
265 return brace;
268 Atom
269 Lookup::vbracket (Real &y) const
271 Atom bracket = (*symtables_p_)("param")->lookup ("bracket");
272 Interval ydims = bracket.dim_[Y_AXIS];
273 Real min_y = ydims[LEFT];
274 Real max_y = ydims[RIGHT];
275 Real step = 1.0 PT;
277 if (y < min_y)
279 warning (_("bracket too small (") + print_dimen (y)+ ")");
280 y = min_y;
282 if (y > max_y)
284 warning (_("bracket too big (") + print_dimen (y)+ ")");
285 y = max_y;
289 int idx = int (rint ((y- min_y)/step)) + 1;
292 Array<String> a;
293 a.push (idx);
294 bracket.tex_ = substitute_args (bracket.tex_,a);
295 bracket.dim_[Y_AXIS] = Interval (-y/2,y/2);
298 return bracket;