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