]> git.donarmstrong.com Git - lilypond.git/blob - lily/lookup.cc
release: 0.1.28
[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_p_ = new Symtables;
28 }
29
30 Lookup::Lookup (Lookup const &s)
31 {
32   paper_l_ = s.paper_l_;
33   texsetting = s.texsetting;
34   symtables_p_ = new Symtables (*s.symtables_p_);
35 }
36 Lookup::~Lookup()
37 {
38   delete symtables_p_;
39 }
40
41 void
42 Lookup::add (String s, Symtable*p)
43 {
44   symtables_p_->add (s, p);
45 }
46
47 void
48 Lookup::print() const
49 {
50 #ifndef NPRINT
51   DOUT << "Lookup: " << texsetting << " {\n";
52   symtables_p_->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_p_)("style")->lookup (style);
64   a[0] = substitute_args (tsym.tex_,a);
65
66   Atom s = (*symtables_p_)("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_p_)("balls");
81   return st->lookup (String (j));
82 }
83
84 Atom
85 Lookup::rest (int j, bool o) const
86 {
87   return (*symtables_p_)("rests")->lookup (String (j) + (o ? "o" : ""));
88 }
89
90 Atom
91 Lookup::fill (Box b) const
92 {
93   Atom s ((*symtables_p_)("param")->lookup ("fill"));
94   s.dim_ = b;
95   return s;
96 }
97
98 Atom
99 Lookup::accidental (int j) const
100 {
101   return (*symtables_p_)("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_p_)("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_p_)("scripts")->lookup (s);
120 }
121
122 Atom
123 Lookup::dynamic (String s) const
124 {
125   return (*symtables_p_)("dynamics")->lookup (s);
126 }
127
128 Atom
129 Lookup::clef (String s) const
130 {
131   return (*symtables_p_)("clefs")->lookup (s);
132 }
133
134 Atom
135 Lookup::dots () const
136 {
137   return (*symtables_p_)("dots")->lookup ("dot");
138 }
139
140 Atom
141 Lookup::flag (int j, Direction d) const
142 {
143   char c = (d == UP) ? 'u' : 'd';
144   return (*symtables_p_)("flags")->lookup (c + String (j));
145 }
146
147 Atom
148 Lookup::streepje (int type) const
149 {
150   if (type > 2)
151     type = 2;
152
153   Symtable * st = (*symtables_p_)("balls");
154   
155   return st->lookup (String (type) + 'l');
156 }
157
158 Atom
159 Lookup::hairpin (Real &wid, bool decresc) const
160 {
161   int idx = int (rint (wid / 6 PT));
162   if (!idx) idx ++;
163   wid = idx*6 PT;
164   String idxstr = (decresc)? "decrescendosym" : "crescendosym";
165   Atom ret=(*symtables_p_)("param")->lookup (idxstr);
166
167   Array<String> a;
168   a.push (idx);
169   ret.tex_ = substitute_args (ret.tex_, a);
170   ret.dim_.x() = Interval (0,wid);
171   return ret;
172 }
173
174 Atom
175 Lookup::meter (Array<Scalar> a) const
176 {
177   Atom s((*symtables_p_)("param")->lookup ("meter"));
178   s.tex_ = substitute_args (s.tex_,a);
179   return s;
180 }
181
182
183 Atom
184 Lookup::stem (Real y1,Real y2) const
185 {
186   if (y1 > y2)
187     {
188       Real t = y1;
189       y1 = y2;
190       y2 = t;
191     }
192   Atom s;
193
194   s.dim_.x() = Interval (0,0);
195   s.dim_.y() = Interval (y1,y2);
196
197   Array<String> a;
198   a.push (print_dimen (y1));
199   a.push (print_dimen (y2));
200
201   String src = (*symtables_p_)("param")->lookup ("stem").tex_;
202   s.tex_ = substitute_args (src,a);
203   return s;
204 }
205
206 /*
207   should be handled via Tex_ code and Lookup::bar()
208  */
209 Atom
210 Lookup::vbrace (Real &y) const
211 {
212   if (y < 2* 20 PT)
213     {
214       warning (_("piano brace too small (") + print_dimen (y)+ ")");
215       y = 2*20 PT;
216     }
217   if (y > 67 * 2 PT)
218     {
219       warning (_("piano brace too big (") + print_dimen (y)+ ")");
220       y = 67 *2 PT;
221     }
222
223   int idx = int (rint ((y/2.0 - 20) + 148));
224
225   Atom s = (*symtables_p_)("param")->lookup ("brace");
226   {
227     Array<String> a;
228     a.push (idx);
229     s.tex_ = substitute_args (s.tex_,a);
230     s.dim_.y() = Interval (0,y);
231   }
232   {
233     Array<String> a;
234     a.push (print_dimen (y/2));
235     a.push (print_dimen (0));
236     a.push (s.tex_);
237     s.tex_ = substitute_args ("\\placebox{%}{%}{%}", a);
238   }
239
240
241   return s;
242 }