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