]> git.donarmstrong.com Git - lilypond.git/blob - lily/lookup.cc
release: 0.0.39-1
[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)
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()
64 {
65     return ball(4).dim.y.length()/2;
66 }
67
68 Symbol
69 Lookup::ball(int j)
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)
80 {
81     return (*symtables_)("rests")->lookup(String(j));
82 }
83
84 Symbol
85 Lookup::fill(Box b)
86 {
87     Symbol s( (*symtables_)("param")->lookup("fill"));
88     s.dim = b;
89     return s;
90 }
91
92 Symbol
93 Lookup::accidental(int j)
94 {
95     return (*symtables_)("accidentals")->lookup(String(j));
96 }
97
98
99 Symbol
100 Lookup::bar(String s)
101 {
102     return (*symtables_)("bars")->lookup(s);
103 }
104
105 Symbol
106 Lookup::script(String s)
107 {
108     return (*symtables_)("scripts")->lookup(s);
109 }
110
111 Symbol
112 Lookup::clef(String s)
113 {
114     return (*symtables_)("clefs")->lookup(s);
115 }
116  
117 Symbol
118 Lookup::dots(int j)
119 {
120     if (j>3)
121         error("max 3 dots");    // todo
122     return (*symtables_)("dots")->lookup(j);
123 }
124
125 Symbol
126 Lookup::flag(int j)
127 {
128     return (*symtables_)("flags")->lookup(j);
129 }
130
131 Symbol
132 Lookup::streepjes(int i)
133 {
134     assert(i);
135     
136     int arg;
137     String idx;
138     
139     if (i < 0) {
140         idx = "botlines";
141         arg = -i;
142     } else {
143         arg = i;
144         idx = "toplines";
145     }
146     Symbol ret = (*symtables_)("streepjes")->lookup(idx);
147     
148     Array<String> a;
149     a.push(arg);
150     ret.tex = substitute_args(ret.tex, a);
151
152     return ret;
153 }
154
155 Symbol
156 Lookup::hairpin(Real &wid, bool decresc)
157 {
158     int idx = int(rint(wid / 6 PT));
159     if(!idx) idx ++;
160     wid = idx*6 PT;
161     String idxstr = (decresc)? "decrescendosym" : "crescendosym";
162     Symbol ret=(*symtables_)("param")->lookup(idxstr);
163        
164     Array<String> a;
165     a.push(idx);
166     ret.tex = substitute_args(ret.tex, a);
167     ret.dim.x = Interval(0,wid);
168     return ret;
169 }
170
171 Symbol
172 Lookup::linestaff(int lines, Real wid) 
173 {
174     Symbol s;
175     s.dim.x = Interval(0,wid);
176     Real dy = (lines >0) ? (lines-1)*internote()*2 : 0;
177     s.dim.y = Interval(0,dy);
178
179     Array<String> a;
180     a.push(lines);
181     a.push(print_dimen(wid));
182
183     s.tex = (*symtables_)("param")->lookup("linestaf").tex;
184     s.tex = substitute_args(s.tex, a);
185
186     return s;
187 }
188
189
190 Symbol
191 Lookup::meter(Array<Scalar> a)
192 {
193     Symbol s;
194     s.dim.x = Interval( 0 PT, 10 PT);
195     s.dim.y = Interval(0, 20 PT);       // todo
196     String src = (*symtables_)("param")->lookup("meter").tex;
197     s.tex = substitute_args(src,a);
198     return s;    
199 }
200
201
202 Symbol
203 Lookup::stem(Real y1,Real y2)
204 {
205     if (y1 > y2) {
206         Real t = y1;
207         y1 = y2;
208         y2 = t;
209     }
210     Symbol s;
211     
212     s.dim.x = Interval(0,0);
213     s.dim.y = Interval(y1,y2);
214     
215     Array<String> a;
216     a.push(print_dimen(y1));
217     a.push(print_dimen(y2));
218         
219     String src = (*symtables_)("param")->lookup("stem").tex;
220     s.tex = substitute_args(src,a);
221     return s;
222 }