]> git.donarmstrong.com Git - lilypond.git/blob - lily/lookup.cc
release: 0.0.40
[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
9 #include "lookup.hh"
10 #include "debug.hh"
11 #include "symtable.hh"
12 #include "dimen.hh"
13 #include "tex.hh"
14 #include "scalar.hh"
15
16 Lookup::Lookup()
17 {
18     texsetting = "\\unknowntexsetting";
19     symtables_ = new Symtables;
20 }
21
22 Lookup::Lookup(Lookup const &s)
23 {
24     texsetting = s.texsetting;
25     symtables_ = new Symtables(*s.symtables_);
26 }
27 Lookup::~Lookup()
28 {
29     delete symtables_;
30 }
31
32 void
33 Lookup::add(String s, Symtable*p)
34 {
35     symtables_->add(s, p);
36 }
37
38 void
39 Lookup::print()const
40 {
41     mtor << "Lookup: " << texsetting << " {\n";
42     symtables_->print();
43     mtor << "}\n";
44 }
45
46 Symbol
47 Lookup::text(String style, String text, int dir) const
48 {
49     Array<String> a;
50  
51     a.push(text);
52     Symbol tsym =  (*symtables_)("style")->lookup(style);
53     a[0] = substitute_args(tsym.tex,a);
54
55     Symbol s = (*symtables_)("align")->lookup(dir);
56     s.tex = substitute_args(s.tex,a);
57     s.dim.y = tsym.dim.y;
58     return s;
59 }
60
61
62 Real
63 Lookup::internote() const
64 {
65     return ball(4).dim.y.length()/2;
66 }
67
68 Symbol
69 Lookup::ball(int j) const
70 {
71     if (j > 4)
72         j = 4;
73
74     Symtable * st = (*symtables_)("balls");
75     return st->lookup(String(j));
76 }
77
78 Symbol
79 Lookup::rest(int j) const
80 {
81     return (*symtables_)("rests")->lookup(String(j));
82 }
83
84 Symbol
85 Lookup::fill(Box b) const
86 {
87     Symbol s( (*symtables_)("param")->lookup("fill"));
88     s.dim = b;
89     return s;
90 }
91
92 Symbol
93 Lookup::accidental(int j) const
94 {
95     return (*symtables_)("accidentals")->lookup(String(j));
96 }
97
98
99 Symbol
100 Lookup::bar(String s) const
101 {
102     return (*symtables_)("bars")->lookup(s);
103 }
104
105 Symbol
106 Lookup::script(String s) const
107 {
108     return (*symtables_)("scripts")->lookup(s);
109 }
110
111 Symbol
112 Lookup::dynamic(String s) const
113 {
114     return (*symtables_)("dynamics")->lookup(s);
115 }
116
117 Symbol
118 Lookup::clef(String s) const
119 {
120     return (*symtables_)("clefs")->lookup(s);
121 }
122  
123 Symbol
124 Lookup::dots(int j) const
125 {
126     if (j>3)
127         error("max 3 dots");    // todo
128     return (*symtables_)("dots")->lookup(j);
129 }
130
131 Symbol
132 Lookup::flag(int j) const
133 {
134     return (*symtables_)("flags")->lookup(j);
135 }
136
137 Symbol
138 Lookup::streepjes(int i) const
139 {
140     assert(i);
141     
142     int arg;
143     String idx;
144     
145     if (i < 0) {
146         idx = "botlines";
147         arg = -i;
148     } else {
149         arg = i;
150         idx = "toplines";
151     }
152     Symbol ret = (*symtables_)("streepjes")->lookup(idx);
153     
154     Array<String> a;
155     a.push(arg);
156     ret.tex = substitute_args(ret.tex, a);
157
158     return ret;
159 }
160
161 Symbol
162 Lookup::hairpin(Real &wid, bool decresc) const
163 {
164     int idx = int(rint(wid / 6 PT));
165     if(!idx) idx ++;
166     wid = idx*6 PT;
167     String idxstr = (decresc)? "decrescendosym" : "crescendosym";
168     Symbol ret=(*symtables_)("param")->lookup(idxstr);
169        
170     Array<String> a;
171     a.push(idx);
172     ret.tex = substitute_args(ret.tex, a);
173     ret.dim.x = Interval(0,wid);
174     return ret;
175 }
176
177 Symbol
178 Lookup::linestaff(int lines, Real wid) const
179 {
180     Symbol s;
181     s.dim.x = Interval(0,wid);
182     Real dy = (lines >0) ? (lines-1)*internote()*2 : 0;
183     s.dim.y = Interval(0,dy);
184
185     Array<String> a;
186     a.push(lines);
187     a.push(print_dimen(wid));
188
189     s.tex = (*symtables_)("param")->lookup("linestaf").tex;
190     s.tex = substitute_args(s.tex, a);
191
192     return s;
193 }
194
195
196 Symbol
197 Lookup::meter(Array<Scalar> a) const
198 {
199     Symbol s;
200     s.dim.x = Interval( 0 PT, 10 PT);
201     s.dim.y = Interval(0, 20 PT);       // todo
202     String src = (*symtables_)("param")->lookup("meter").tex;
203     s.tex = substitute_args(src,a);
204     return s;    
205 }
206
207
208 Symbol
209 Lookup::stem(Real y1,Real y2) const
210 {
211     if (y1 > y2) {
212         Real t = y1;
213         y1 = y2;
214         y2 = t;
215     }
216     Symbol s;
217     
218     s.dim.x = Interval(0,0);
219     s.dim.y = Interval(y1,y2);
220     
221     Array<String> a;
222     a.push(print_dimen(y1));
223     a.push(print_dimen(y2));
224         
225     String src = (*symtables_)("param")->lookup("stem").tex;
226     s.tex = substitute_args(src,a);
227     return s;
228 }