]> git.donarmstrong.com Git - lilypond.git/blob - lily/lookup.cc
release: 0.1.39
[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, 
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 #include "main.hh"
23
24 Lookup::Lookup()
25 {
26   paper_l_ = 0;
27   texsetting = "\\unknowntexsetting";
28   symtables_p_ = new Symtables;
29 }
30
31 Lookup::Lookup (Lookup const &s)
32 {
33   paper_l_ = s.paper_l_;
34   texsetting = s.texsetting;
35   symtables_p_ = new Symtables (*s.symtables_p_);
36 }
37 Lookup::~Lookup()
38 {
39   delete symtables_p_;
40 }
41
42 void
43 Lookup::add (String s, Symtable*p)
44 {
45   symtables_p_->add (s, p);
46 }
47
48 void
49 Lookup::print() const
50 {
51 #ifndef NPRINT
52   DOUT << "Lookup: " << texsetting << " {\n";
53   symtables_p_->print();
54   DOUT << "}\n";
55 #endif
56 }
57
58 Atom
59 Lookup::text (String style, String text, int dir) const
60 {
61   Array<String> a;
62
63   a.push (text);
64   Atom tsym =  (*symtables_p_)("style")->lookup (style);
65   a[0] = substitute_args (tsym.tex_,a);
66
67   Atom s = (*symtables_p_)("align")->lookup (dir);
68   s.tex_ = substitute_args (s.tex_,a);
69   s.dim_ = tsym.dim_;
70   return s;
71 }
72
73
74
75 Atom
76 Lookup::ball (int j) const
77 {
78   if (j > 2)
79     j = 2;
80
81   Symtable * st = (*symtables_p_)("balls");
82   return st->lookup (String (j));
83 }
84
85 Atom
86 Lookup::rest (int j, bool o) const
87 {
88   return (*symtables_p_)("rests")->lookup (String (j) + (o ? "o" : ""));
89 }
90
91 Atom
92 Lookup::fill (Box b) const
93 {
94   Atom s ((*symtables_p_)("param")->lookup ("fill"));
95   s.dim_ = b;
96   return s;
97 }
98
99 Atom
100 Lookup::accidental (int j) const
101 {
102   return (*symtables_p_)("accidentals")->lookup (String (j));
103 }
104
105
106 Atom
107 Lookup::bar (String s, Real h) const
108 {
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;
115 }
116
117 Atom
118 Lookup::script (String s) const
119 {
120   return (*symtables_p_)("scripts")->lookup (s);
121 }
122
123 Atom
124 Lookup::dynamic (String s) const
125 {
126   return (*symtables_p_)("dynamics")->lookup (s);
127 }
128
129 Atom
130 Lookup::clef (String s) const
131 {
132   return (*symtables_p_)("clefs")->lookup (s);
133 }
134
135 Atom
136 Lookup::dots () const
137 {
138   return (*symtables_p_)("dots")->lookup ("dot");
139 }
140
141 Atom
142 Lookup::flag (int j, Direction d) const
143 {
144   char c = (d == UP) ? 'u' : 'd';
145   return (*symtables_p_)("flags")->lookup (c + String (j));
146 }
147
148 Atom
149 Lookup::streepje (int type) const
150 {
151   if (type > 2)
152     type = 2;
153
154   Symtable * st = (*symtables_p_)("balls");
155   
156   return st->lookup (String (type) + 'l');
157 }
158
159 Atom
160 Lookup::hairpin (Real &wid, bool decresc, bool continued) const
161 {
162   bool embedded_b = postscript_global_b;
163   String embed;
164   Atom ret;  
165   if (embedded_b)
166     {
167       Real height = 2 PT;
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;
174     }
175   else
176     {
177       if (wid > 32 * 6 PT)
178         {
179           warning (_("Crescendo too long (") + print_dimen (wid) 
180                    +_( ") shrinking (ugh)"));
181           wid = 32*6 PT;
182         }
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);
188       
189       Array<String> a;
190       a.push (idx);
191       ret.tex_ = substitute_args (ret.tex_, a);
192     }
193   
194   ret.dim_.x() = Interval (0,wid);
195   // ret.translate_axis (-ret.dim_[Y_AXIS][DOWN], Y_AXIS);
196   return ret;
197 }
198
199 Atom
200 Lookup::meter (Array<Scalar> a) const
201 {
202   Atom s((*symtables_p_)("param")->lookup ("meter"));
203   s.tex_ = substitute_args (s.tex_,a);
204   return s;
205 }
206
207
208 Atom
209 Lookup::stem (Real y1,Real y2) const
210 {
211   if (y1 > y2)
212     {
213       Real t = y1;
214       y1 = y2;
215       y2 = t;
216     }
217   Atom s;
218
219   s.dim_.x() = Interval (0,0);
220   s.dim_.y() = Interval (y1,y2);
221
222   Array<String> a;
223   a.push (print_dimen (y1));
224   a.push (print_dimen (y2));
225
226   String src = (*symtables_p_)("param")->lookup ("stem").tex_;
227   s.tex_ = substitute_args (src,a);
228   return s;
229 }
230
231 /*
232   should be handled via Tex_ code and Lookup::bar()
233  */
234 Atom
235 Lookup::vbrace (Real &y) const
236 {
237   Atom brace = (*symtables_p_)("param")->lookup ("brace");
238   Interval ydims = brace.dim_[Y_AXIS];
239   Real min_y = ydims[LEFT];
240   Real max_y = ydims[RIGHT];
241   Real step = 1.0 PT;
242  
243   if (y < min_y)
244     {
245       warning (_("piano brace too small (") + print_dimen (y)+ ")");
246       y = min_y;
247     }
248   if (y > max_y)
249     {
250       warning (_("piano brace too big (") + print_dimen (y)+ ")");
251       y = max_y;
252     }
253
254   
255   int idx = int (rint ((y- min_y)/step)) + 1;
256   
257   {
258     Array<String> a;
259     a.push (idx);
260     brace.tex_ = substitute_args (brace.tex_,a);
261     brace.dim_[Y_AXIS] = Interval (-y/2,y/2);
262   }
263
264   return brace;
265 }