]> git.donarmstrong.com Git - lilypond.git/blob - src/lookup.cc
release: 0.0.21
[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     svec<String> a;
35  
36     a.add(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 Symbol
70 Lookup::fill(Box b)
71 {
72     Symbol s( (*symtables_)("param")->lookup("fill"));
73     s.dim = b;
74     return s;
75 }
76 Symbol
77 Lookup::accidental(int j)
78 {
79     return (*symtables_)("accidentals")->lookup(String(j));
80 }
81
82
83 Symbol
84 Lookup::bar(String s)
85 {
86     return (*symtables_)("bars")->lookup(s);
87 }
88
89 Symbol
90 Lookup::script(String s)
91 {
92     return (*symtables_)("scripts")->lookup(s);
93 }
94
95 Symbol
96 Lookup::clef(String s)
97 {
98     return (*symtables_)("clefs")->lookup(s);
99 }
100  
101 Symbol
102 Lookup::dots(int j)
103 {
104     if (j>3)
105         error("max 3 dots");
106     return (*symtables_)("dots")->lookup(j);
107 }
108
109 Symbol
110 Lookup::flag(int j)
111 {
112     return (*symtables_)("flags")->lookup(j);
113 }
114
115 Symbol
116 Lookup::streepjes(int i)
117 {
118     assert(i);
119     
120     int arg;
121     String idx;
122     
123     if (i < 0) {
124         idx = "botlines";
125         arg = -i;
126     } else {
127         arg = i;
128         idx = "toplines";
129     }
130     Symbol ret = (*symtables_)("streepjes")->lookup(idx);
131     
132     svec<String> a;
133     a.add(arg);
134     ret.tex = substitute_args(ret.tex, a);
135
136     return ret;
137 }
138
139
140
141 Symbol
142 Lookup::linestaff(int lines, Real wid) 
143 {
144     Symbol s;
145     s.dim.x = Interval(0,wid);
146     Real dy=(lines-1)*internote()*2;
147     s.dim.y = Interval(0,dy);
148
149     svec<String> a;
150     a.add(lines);
151     a.add(print_dimen(wid));
152
153     s.tex = (*symtables_)("param")->lookup("linestaf").tex;
154     s.tex = substitute_args(s.tex, a);
155     
156     return s;
157 }
158
159
160 Symbol
161 Lookup::meter(svec<Scalar> a)
162 {
163     Symbol s;
164     s.dim.x = Interval( convert_dimen(0,"pt"),
165                         convert_dimen(10,"pt"));
166     s.dim.y = Interval(0, convert_dimen(20,"pt") );     // todo
167     String src = (*symtables_)("param")->lookup("meter").tex;
168     s.tex = substitute_args(src,a);
169     return s;    
170 }
171
172
173 Symbol
174 Lookup::stem(Real y1,Real y2)
175 {
176     assert(y1 <= y2);
177     Symbol s;
178     
179     s.dim.x = Interval(0,0);
180     s.dim.y = Interval(y1,y2);
181     
182     svec<String> a;
183     a.add(print_dimen(y1));
184     a.add(print_dimen(y2));
185         
186     String src = (*symtables_)("param")->lookup("stem").tex;
187     s.tex = substitute_args(src,a);
188     return s;
189 }