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