]> git.donarmstrong.com Git - lilypond.git/blob - lily/lookup.cc
790ab2d34adf285e1464b4b1e6d601bacc864ab5
[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, Real h) const
105 {
106     Array<String> a;
107     a.push(print_dimen( h));
108     Symbol ret=(*symtables_)("bars")->lookup(s);;
109     ret.tex = substitute_args(ret.tex, a);
110     ret.dim.y = Interval( 0, h);
111     return ret;
112 }
113
114 Symbol
115 Lookup::script(String s) const
116 {
117     return (*symtables_)("scripts")->lookup(s);
118 }
119
120 Symbol
121 Lookup::dynamic(String s) const
122 {
123     return (*symtables_)("dynamics")->lookup(s);
124 }
125
126 Symbol
127 Lookup::clef(String s) const
128 {
129     return (*symtables_)("clefs")->lookup(s);
130 }
131  
132 Symbol
133 Lookup::dots(int j) const
134 {
135     if (j>3) {
136         j = 3;
137         warning("max 3 dots");  // todo
138     }
139     return (*symtables_)("dots")->lookup(j);
140 }
141
142 Symbol
143 Lookup::flag(int j) const
144 {
145     return (*symtables_)("flags")->lookup(j);
146 }
147
148 Symbol
149 Lookup::streepjes(int i) const
150 {
151     assert(i);
152     
153     int arg;
154     String idx;
155     
156     if (i < 0) {
157         idx = "botlines";
158         arg = -i;
159     } else {
160         arg = i;
161         idx = "toplines";
162     }
163     Symbol ret = (*symtables_)("streepjes")->lookup(idx);
164     
165     Array<String> a;
166     a.push(arg);
167     ret.tex = substitute_args(ret.tex, a);
168
169     return ret;
170 }
171
172 Symbol
173 Lookup::hairpin(Real &wid, bool decresc) const
174 {
175     int idx = int(rint(wid / 6 PT));
176     if(!idx) idx ++;
177     wid = idx*6 PT;
178     String idxstr = (decresc)? "decrescendosym" : "crescendosym";
179     Symbol ret=(*symtables_)("param")->lookup(idxstr);
180        
181     Array<String> a;
182     a.push(idx);
183     ret.tex = substitute_args(ret.tex, a);
184     ret.dim.x = Interval(0,wid);
185     return ret;
186 }
187
188 Symbol
189 Lookup::linestaff(int lines, Real wid) const
190 {
191     Real internote_f = paper_l_ ->internote_f();
192     Symbol s;
193     s.dim.x = Interval(0,wid);
194     Real dy = (lines >0) ? (lines-1)*internote_f : 0;
195     s.dim.y = Interval(0,dy);
196
197     Array<String> a;
198     a.push(lines);
199     a.push(print_dimen(wid));
200
201     s.tex = (*symtables_)("param")->lookup("linestaf").tex;
202     s.tex = substitute_args(s.tex, a);
203
204     return s;
205 }
206
207
208 Symbol
209 Lookup::meter(Array<Scalar> a) const
210 {
211     Symbol s;
212     s.dim.x = Interval( 0 PT, 10 PT);
213     s.dim.y = Interval(0, 20 PT);       // todo
214     String src = (*symtables_)("param")->lookup("meter").tex;
215     s.tex = substitute_args(src,a);
216     return s;    
217 }
218
219
220 Symbol
221 Lookup::stem(Real y1,Real y2) const
222 {
223     if (y1 > y2) {
224         Real t = y1;
225         y1 = y2;
226         y2 = t;
227     }
228     Symbol s;
229     
230     s.dim.x = Interval(0,0);
231     s.dim.y = Interval(y1,y2);
232     
233     Array<String> a;
234     a.push(print_dimen(y1));
235     a.push(print_dimen(y2));
236         
237     String src = (*symtables_)("param")->lookup("stem").tex;
238     s.tex = substitute_args(src,a);
239     return s;
240 }
241
242 Symbol
243 Lookup::vbrace( Real &y ) const
244 {
245     if ( y < 2 * 20 PT ) {
246         warning( "staff brace too small (" + print_dimen( y ) + ")" );
247         y = 2 * 20 PT;
248     }
249     if ( y > 2 * 67 PT ) {
250         warning( "staff brace too big (" + print_dimen( y ) + ")" );
251         y = 2 * 67 PT;
252     }
253     
254     int idx = int( rint( y/2.0 - 20 ) );
255     
256     Symbol s = (*symtables_)("param")->lookup("brace");
257     
258     Array<String> a;
259     a.push(idx);
260     s.tex = substitute_args(s.tex,a);
261     s.dim.y = Interval(0,y);
262     return s;
263 }