]> git.donarmstrong.com Git - lilypond.git/blob - lily/lookup.cc
release: 0.0.63
[lilypond.git] / lily / lookup.cc
1 /*
2   lookup.cc -- implement simple Lookup methods.
3
4   source file of the 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 Lookup::Lookup()
23 {
24     texsetting = "\\unknowntexsetting";
25     symtables_ = new Symtables;
26 }
27
28 Lookup::Lookup(Lookup const &s)
29 {
30     texsetting = s.texsetting;
31     symtables_ = new Symtables(*s.symtables_);
32 }
33 Lookup::~Lookup()
34 {
35     delete symtables_;
36 }
37
38 void
39 Lookup::add(String s, Symtable*p)
40 {
41     symtables_->add(s, p);
42 }
43
44 void
45 Lookup::print()const
46 {
47     mtor << "Lookup: " << texsetting << " {\n";
48     symtables_->print();
49     mtor << "}\n";
50 }
51
52 Symbol
53 Lookup::text(String style, String text, int dir) const
54 {
55     Array<String> a;
56  
57     a.push(text);
58     Symbol tsym =  (*symtables_)("style")->lookup(style);
59     a[0] = substitute_args(tsym.tex,a);
60
61     Symbol s = (*symtables_)("align")->lookup(dir);
62     s.tex = substitute_args(s.tex,a);
63     s.dim = tsym.dim;
64     return s;
65 }
66
67
68 Real
69 Lookup::internote() const
70 {
71     return ball(4).dim.y.length()/2;
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) const
86 {
87     return (*symtables_)("rests")->lookup(String(j));
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) const
107 {
108     return (*symtables_)("bars")->lookup(s);
109 }
110
111 Symbol
112 Lookup::script(String s) const
113 {
114     return (*symtables_)("scripts")->lookup(s);
115 }
116
117 Symbol
118 Lookup::dynamic(String s) const
119 {
120     return (*symtables_)("dynamics")->lookup(s);
121 }
122
123 Symbol
124 Lookup::clef(String s) const
125 {
126     return (*symtables_)("clefs")->lookup(s);
127 }
128  
129 Symbol
130 Lookup::dots(int j) const
131 {
132     if (j>3)
133         error("max 3 dots");    // todo
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     Symbol s;
187     s.dim.x = Interval(0,wid);
188     Real dy = (lines >0) ? (lines-1)*internote()*2 : 0;
189     s.dim.y = Interval(0,dy);
190
191     Array<String> a;
192     a.push(lines);
193     a.push(print_dimen(wid));
194
195     s.tex = (*symtables_)("param")->lookup("linestaf").tex;
196     s.tex = substitute_args(s.tex, a);
197
198     return s;
199 }
200
201
202 Symbol
203 Lookup::meter(Array<Scalar> a) const
204 {
205     Symbol s;
206     s.dim.x = Interval( 0 PT, 10 PT);
207     s.dim.y = Interval(0, 20 PT);       // todo
208     String src = (*symtables_)("param")->lookup("meter").tex;
209     s.tex = substitute_args(src,a);
210     return s;    
211 }
212
213
214 Symbol
215 Lookup::stem(Real y1,Real y2) const
216 {
217     if (y1 > y2) {
218         Real t = y1;
219         y1 = y2;
220         y2 = t;
221     }
222     Symbol s;
223     
224     s.dim.x = Interval(0,0);
225     s.dim.y = Interval(y1,y2);
226     
227     Array<String> a;
228     a.push(print_dimen(y1));
229     a.push(print_dimen(y2));
230         
231     String src = (*symtables_)("param")->lookup("stem").tex;
232     s.tex = substitute_args(src,a);
233     return s;
234 }