]> git.donarmstrong.com Git - lilypond.git/blob - lily/lookup.cc
release: 0.0.67
[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
22
23 Lookup::Lookup()
24 {
25     texsetting = "\\unknowntexsetting";
26     symtables_ = new Symtables;
27 }
28
29 Lookup::Lookup(Lookup const &s)
30 {
31     texsetting = s.texsetting;
32     symtables_ = new Symtables(*s.symtables_);
33 }
34 Lookup::~Lookup()
35 {
36     delete symtables_;
37 }
38
39 void
40 Lookup::add(String s, Symtable*p)
41 {
42     symtables_->add(s, p);
43 }
44
45 void
46 Lookup::print()const
47 {
48     mtor << "Lookup: " << texsetting << " {\n";
49     symtables_->print();
50     mtor << "}\n";
51 }
52
53 Symbol
54 Lookup::text(String style, String text, int dir) const
55 {
56     Array<String> a;
57  
58     a.push(text);
59     Symbol tsym =  (*symtables_)("style")->lookup(style);
60     a[0] = substitute_args(tsym.tex,a);
61
62     Symbol s = (*symtables_)("align")->lookup(dir);
63     s.tex = substitute_args(s.tex,a);
64     s.dim = tsym.dim;
65     return s;
66 }
67
68
69 Real
70 Lookup::internote_f() const
71 {
72     return ball(4).dim.y.length()/2;
73 }
74
75 Symbol
76 Lookup::ball(int j) const
77 {
78     if (j > 4)
79         j = 4;
80
81     Symtable * st = (*symtables_)("balls");
82     return st->lookup(String(j));
83 }
84
85 Symbol
86 Lookup::rest(int j) const
87 {
88     return (*symtables_)("rests")->lookup(String(j));
89 }
90
91 Symbol
92 Lookup::fill(Box b) const
93 {
94     Symbol s( (*symtables_)("param")->lookup("fill"));
95     s.dim = b;
96     return s;
97 }
98
99 Symbol
100 Lookup::accidental(int j) const
101 {
102     return (*symtables_)("accidentals")->lookup(String(j));
103 }
104
105
106 Symbol
107 Lookup::bar(String s) const
108 {
109     return (*symtables_)("bars")->lookup(s);
110 }
111
112 Symbol
113 Lookup::script(String s) const
114 {
115     return (*symtables_)("scripts")->lookup(s);
116 }
117
118 Symbol
119 Lookup::dynamic(String s) const
120 {
121     return (*symtables_)("dynamics")->lookup(s);
122 }
123
124 Symbol
125 Lookup::clef(String s) const
126 {
127     return (*symtables_)("clefs")->lookup(s);
128 }
129  
130 Symbol
131 Lookup::dots(int j) const
132 {
133     if (j>3) {
134         j = 3;
135         warning("max 3 dots");  // todo
136     }
137     return (*symtables_)("dots")->lookup(j);
138 }
139
140 Symbol
141 Lookup::flag(int j) const
142 {
143     return (*symtables_)("flags")->lookup(j);
144 }
145
146 Symbol
147 Lookup::streepjes(int i) const
148 {
149     assert(i);
150     
151     int arg;
152     String idx;
153     
154     if (i < 0) {
155         idx = "botlines";
156         arg = -i;
157     } else {
158         arg = i;
159         idx = "toplines";
160     }
161     Symbol ret = (*symtables_)("streepjes")->lookup(idx);
162     
163     Array<String> a;
164     a.push(arg);
165     ret.tex = substitute_args(ret.tex, a);
166
167     return ret;
168 }
169
170 Symbol
171 Lookup::hairpin(Real &wid, bool decresc) const
172 {
173     int idx = int(rint(wid / 6 PT));
174     if(!idx) idx ++;
175     wid = idx*6 PT;
176     String idxstr = (decresc)? "decrescendosym" : "crescendosym";
177     Symbol ret=(*symtables_)("param")->lookup(idxstr);
178        
179     Array<String> a;
180     a.push(idx);
181     ret.tex = substitute_args(ret.tex, a);
182     ret.dim.x = Interval(0,wid);
183     return ret;
184 }
185
186 Symbol
187 Lookup::linestaff(int lines, Real wid) const
188 {
189     Symbol s;
190     s.dim.x = Interval(0,wid);
191     Real dy = (lines >0) ? (lines-1)*internote_f()*2 : 0;
192     s.dim.y = Interval(0,dy);
193
194     Array<String> a;
195     a.push(lines);
196     a.push(print_dimen(wid));
197
198     s.tex = (*symtables_)("param")->lookup("linestaf").tex;
199     s.tex = substitute_args(s.tex, a);
200
201     return s;
202 }
203
204
205 Symbol
206 Lookup::meter(Array<Scalar> a) const
207 {
208     Symbol s;
209     s.dim.x = Interval( 0 PT, 10 PT);
210     s.dim.y = Interval(0, 20 PT);       // todo
211     String src = (*symtables_)("param")->lookup("meter").tex;
212     s.tex = substitute_args(src,a);
213     return s;    
214 }
215
216
217 Symbol
218 Lookup::stem(Real y1,Real y2) const
219 {
220     if (y1 > y2) {
221         Real t = y1;
222         y1 = y2;
223         y2 = t;
224     }
225     Symbol s;
226     
227     s.dim.x = Interval(0,0);
228     s.dim.y = Interval(y1,y2);
229     
230     Array<String> a;
231     a.push(print_dimen(y1));
232     a.push(print_dimen(y2));
233         
234     String src = (*symtables_)("param")->lookup("stem").tex;
235     s.tex = substitute_args(src,a);
236     return s;
237 }
238
239 Symbol
240 Lookup::vbrace(Real &y) const
241 {
242     if (y < 2* 20 PT) {
243         warning ( "piano brace too small (" + print_dimen(y)+ ")");
244         y = 2*20 PT;
245     }
246     if (y > 67 * 2 PT) {
247         warning ( "piano brace too big (" + print_dimen(y)+ ")");       
248         y = 67 *2 PT;
249     }
250     
251     int idx = int(rint((y/2.0 - 20 ) + 148));
252     
253     Symbol s = (*symtables_)("param")->lookup("brace");
254     
255     Array<String> a;
256     a.push(idx);
257     s.tex = substitute_args(s.tex,a);
258     s.dim.y = Interval(0,y);
259     return s;
260 }