]> git.donarmstrong.com Git - lilypond.git/blob - lily/lookup.cc
release: 0.1.17
[lilypond.git] / lily / lookup.cc
1 /*
2   lookup.cc -- implement simple Lookup methods.
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7
8   TODO
9   This doth suck. We should have PS output, and read spacing info from TFMs
10   
11   Glissando, bracket
12   
13 */
14
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
23 Lookup::Lookup()
24 {
25   paper_l_ = 0;
26   texsetting = "\\unknowntexsetting";
27   symtables_ = new Symtables;
28 }
29
30 Lookup::Lookup (Lookup const &s)
31 {
32   paper_l_ = s.paper_l_;
33   texsetting = s.texsetting;
34   symtables_ = new Symtables (*s.symtables_);
35 }
36 Lookup::~Lookup()
37 {
38   delete symtables_;
39 }
40
41 void
42 Lookup::add (String s, Symtable*p)
43 {
44   symtables_->add (s, p);
45 }
46
47 void
48 Lookup::print() const
49 {
50 #ifndef NPRINT
51   DOUT << "Lookup: " << texsetting << " {\n";
52   symtables_->print();
53   DOUT << "}\n";
54 #endif
55 }
56
57 Atom
58 Lookup::text (String style, String text, int dir) const
59 {
60   Array<String> a;
61  
62   a.push (text);
63   Atom tsym =  (*symtables_)("style")->lookup (style);
64   a[0] = substitute_args (tsym.tex_,a);
65
66   Atom s = (*symtables_)("align")->lookup (dir);
67   s.tex_ = substitute_args (s.tex_,a);
68   s.dim_ = tsym.dim_;
69   return s;
70 }
71
72
73
74 Atom
75 Lookup::ball (int j) const
76 {
77   if (j > 2)
78     j = 2;
79
80   Symtable * st = (*symtables_)("balls");
81   return st->lookup (String (j));
82 }
83
84 Atom
85 Lookup::rest (int j, bool o) const
86 {
87   return (*symtables_)("rests")->lookup (String (j) + (o ? "o" : ""));
88 }
89
90 Atom
91 Lookup::fill (Box b) const
92 {
93   Atom s ((*symtables_)("param")->lookup ("fill"));
94   s.dim_ = b;
95   return s;
96 }
97
98 Atom
99 Lookup::accidental (int j) const
100 {
101   return (*symtables_)("accidentals")->lookup (String (j));
102 }
103
104
105 Atom
106 Lookup::bar (String s, Real h) const
107 {
108   Array<String> a;
109   a.push (print_dimen (h));
110   Atom ret=(*symtables_)("bars")->lookup (s);;
111   ret.tex_ = substitute_args (ret.tex_, a);
112   ret.dim_.y() = Interval (0, h);
113   return ret;
114 }
115
116 Atom
117 Lookup::script (String s) const
118 {
119   return (*symtables_)("scripts")->lookup (s);
120 }
121
122 Atom
123 Lookup::dynamic (String s) const
124 {
125   return (*symtables_)("dynamics")->lookup (s);
126 }
127
128 Atom
129 Lookup::clef (String s) const
130 {
131   return (*symtables_)("clefs")->lookup (s);
132 }
133  
134 Atom
135 Lookup::dots (int j) const
136 {
137   if (j>3) 
138     {
139       j = 3;
140       warning ("max 3 dots");   // todo
141     }
142   return (*symtables_)("dots")->lookup (j);
143 }
144
145 Atom
146 Lookup::flag (int j, Direction d) const
147 {
148   char c = (d == UP) ? 'u' : 'd';
149   return (*symtables_)("flags")->lookup (c + String (j));
150 }
151
152 Atom
153 Lookup::streepjes (int type, int i) const
154 {
155   assert (i);
156   
157   int arg;
158   String idx;
159   
160   if (i < 0) 
161     {
162       idx = "botlines";
163       arg = -i;
164     }
165   else 
166     {
167       arg = i;
168       idx = "toplines";
169     }
170
171   // ugh
172   Real w = ball (type).dim_[X_AXIS].length ();
173
174   Atom ret = (*symtables_)("streepjes")->lookup (idx);
175   
176   Array<String> a;
177   a.push (String (w) + "pt");
178   a.push (arg);
179   ret.tex_ = substitute_args (ret.tex_, a);
180
181   return ret;
182 }
183
184 Atom
185 Lookup::hairpin (Real &wid, bool decresc) const
186 {
187   int idx = int (rint (wid / 6 PT));
188   if (!idx) idx ++;
189   wid = idx*6 PT;
190   String idxstr = (decresc)? "decrescendosym" : "crescendosym";
191   Atom ret=(*symtables_)("param")->lookup (idxstr);
192      
193   Array<String> a;
194   a.push (idx);
195   ret.tex_ = substitute_args (ret.tex_, a);
196   ret.dim_.x() = Interval (0,wid);
197   return ret;
198 }
199
200 Atom
201 Lookup::linestaff (int lines, Real wid) const
202 {
203   Real internote_f = paper_l_ ->internote_f();
204   Atom s;
205   Real dy = (lines >0) ? (lines-1)*internote_f : 0;
206   s.dim_ = Box (Interval (0,wid), Interval (0,dy));
207
208   Array<String> a;
209   a.push (lines);
210   a.push (print_dimen (wid));
211
212   s.tex_ = (*symtables_)("param")->lookup ("linestaf").tex_;
213   s.tex_ = substitute_args (s.tex_, a);
214
215   return s;
216 }
217
218
219 Atom
220 Lookup::meter (Array<Scalar> a) const
221 {
222   Atom s;
223   s.dim_.x() = Interval (0 PT, 10 PT);
224   s.dim_.y() = Interval (0, 20 PT);     // todo
225   String src = (*symtables_)("param")->lookup ("meter").tex_;
226   s.tex_ = substitute_args (src,a);
227   return s;    
228 }
229
230
231 Atom
232 Lookup::stem (Real y1,Real y2) const
233 {
234   if (y1 > y2) 
235     {
236       Real t = y1;
237       y1 = y2;
238       y2 = t;
239     }
240   Atom s;
241   
242   s.dim_.x() = Interval (0,0);
243   s.dim_.y() = Interval (y1,y2);
244   
245   Array<String> a;
246   a.push (print_dimen (y1));
247   a.push (print_dimen (y2));
248         
249   String src = (*symtables_)("param")->lookup ("stem").tex_;
250   s.tex_ = substitute_args (src,a);
251   return s;
252 }
253
254 /*
255   should be handled via Tex_ code and Lookup::bar()
256  */
257 Atom
258 Lookup::vbrace (Real &y) const
259 {
260   if (y < 2* 20 PT) 
261     {
262       warning ("piano brace too small (" + print_dimen (y)+ ")");
263       y = 2*20 PT;
264     }
265   if (y > 67 * 2 PT) 
266     {
267       warning ("piano brace too big (" + print_dimen (y)+ ")"); 
268       y = 67 *2 PT;
269     }
270   
271   int idx = int (rint ((y/2.0 - 20) + 148));
272   
273   Atom s = (*symtables_)("param")->lookup ("brace");
274   {
275     Array<String> a;
276     a.push (idx);
277     s.tex_ = substitute_args (s.tex_,a);
278     s.dim_.y() = Interval (0,y);
279   }
280   {
281     Array<String> a;
282     a.push (print_dimen (y/2));
283     a.push (print_dimen (0));
284     a.push (s.tex_);
285     s.tex_ = substitute_args ("\\placebox{%}{%}{%}", a);
286   }
287
288         
289   return s;
290 }