]> git.donarmstrong.com Git - lilypond.git/blob - lily/lookup.cc
release: 0.1.1
[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     mtor << "Lookup: " << texsetting << " {\n";
52     symtables_->print();
53     mtor << "}\n";
54     #endif
55 }
56
57 Symbol
58 Lookup::text(String style, String text, int dir) const
59 {
60     Array<String> a;
61  
62     a.push(text);
63     Symbol tsym =  (*symtables_)("style")->lookup(style);
64     a[0] = substitute_args(tsym.tex,a);
65
66     Symbol 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 Symbol
75 Lookup::ball(int j) const
76 {
77     if (j > 4)
78         j = 4;
79
80     Symtable * st = (*symtables_)("balls");
81     return st->lookup(String(j));
82 }
83
84 Symbol
85 Lookup::rest(int j, bool o) const
86 {
87     return (*symtables_)("rests")->lookup(String(j) + (o ? "o" : "") );
88 }
89
90 Symbol
91 Lookup::fill(Box b) const
92 {
93     Symbol s( (*symtables_)("param")->lookup("fill"));
94     s.dim = b;
95     return s;
96 }
97
98 Symbol
99 Lookup::accidental(int j) const
100 {
101     return (*symtables_)("accidentals")->lookup(String(j));
102 }
103
104
105 Symbol
106 Lookup::bar(String s, Real h) const
107 {
108     Array<String> a;
109     a.push(print_dimen( h));
110     Symbol 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 Symbol
117 Lookup::script(String s) const
118 {
119     return (*symtables_)("scripts")->lookup(s);
120 }
121
122 Symbol
123 Lookup::dynamic(String s) const
124 {
125     return (*symtables_)("dynamics")->lookup(s);
126 }
127
128 Symbol
129 Lookup::clef(String s) const
130 {
131     return (*symtables_)("clefs")->lookup(s);
132 }
133  
134 Symbol
135 Lookup::dots(int j) const
136 {
137     if (j>3) {
138         j = 3;
139         warning("max 3 dots");  // todo
140     }
141     return (*symtables_)("dots")->lookup(j);
142 }
143
144 Symbol
145 Lookup::flag(int j) const
146 {
147     return (*symtables_)("flags")->lookup(j);
148 }
149
150 Symbol
151 Lookup::streepjes(int i) const
152 {
153     assert(i);
154     
155     int arg;
156     String idx;
157     
158     if (i < 0) {
159         idx = "botlines";
160         arg = -i;
161     } else {
162         arg = i;
163         idx = "toplines";
164     }
165     Symbol ret = (*symtables_)("streepjes")->lookup(idx);
166     
167     Array<String> a;
168     a.push(arg);
169     ret.tex = substitute_args(ret.tex, a);
170
171     return ret;
172 }
173
174 Symbol
175 Lookup::hairpin(Real &wid, bool decresc) const
176 {
177     int idx = int(rint(wid / 6 PT));
178     if(!idx) idx ++;
179     wid = idx*6 PT;
180     String idxstr = (decresc)? "decrescendosym" : "crescendosym";
181     Symbol ret=(*symtables_)("param")->lookup(idxstr);
182        
183     Array<String> a;
184     a.push(idx);
185     ret.tex = substitute_args(ret.tex, a);
186     ret.dim.x = Interval(0,wid);
187     return ret;
188 }
189
190 Symbol
191 Lookup::linestaff(int lines, Real wid) const
192 {
193     Real internote_f = paper_l_ ->internote_f();
194     Symbol s;
195     s.dim.x = Interval(0,wid);
196     Real dy = (lines >0) ? (lines-1)*internote_f : 0;
197     s.dim.y = Interval(0,dy);
198
199     Array<String> a;
200     a.push(lines);
201     a.push(print_dimen(wid));
202
203     s.tex = (*symtables_)("param")->lookup("linestaf").tex;
204     s.tex = substitute_args(s.tex, a);
205
206     return s;
207 }
208
209
210 Symbol
211 Lookup::meter(Array<Scalar> a) const
212 {
213     Symbol s;
214     s.dim.x = Interval( 0 PT, 10 PT);
215     s.dim.y = Interval(0, 20 PT);       // todo
216     String src = (*symtables_)("param")->lookup("meter").tex;
217     s.tex = substitute_args(src,a);
218     return s;    
219 }
220
221
222 Symbol
223 Lookup::stem(Real y1,Real y2) const
224 {
225     if (y1 > y2) {
226         Real t = y1;
227         y1 = y2;
228         y2 = t;
229     }
230     Symbol s;
231     
232     s.dim.x = Interval(0,0);
233     s.dim.y = Interval(y1,y2);
234     
235     Array<String> a;
236     a.push(print_dimen(y1));
237     a.push(print_dimen(y2));
238         
239     String src = (*symtables_)("param")->lookup("stem").tex;
240     s.tex = substitute_args(src,a);
241     return s;
242 }
243
244 /*
245   should be handled via TeX code and Lookup::bar()
246  */
247 Symbol
248 Lookup::vbrace(Real &y) const
249 {
250     if (y < 2* 20 PT) {
251         warning ( "piano brace too small (" + print_dimen(y)+ ")");
252         y = 2*20 PT;
253     }
254     if (y > 67 * 2 PT) {
255         warning ( "piano brace too big (" + print_dimen(y)+ ")");       
256         y = 67 *2 PT;
257     }
258     
259     int idx = int(rint((y/2.0 - 20 ) + 148));
260     
261     Symbol s = (*symtables_)("param")->lookup("brace");
262     {
263         Array<String> a;
264         a.push(idx);
265         s.tex = substitute_args(s.tex,a);
266         s.dim.y = Interval(0,y);
267     }
268     {
269         Array<String> a;
270         a.push(print_dimen( y/2 ));
271         a.push(print_dimen(0));
272         a.push(s.tex);
273         s.tex = substitute_args("\\placebox{%}{%}{%}", a);
274     }
275
276         
277     return s;
278 }