]> git.donarmstrong.com Git - lilypond.git/blob - src/lookup.cc
release: 0.0.9
[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
7 void
8 Lookup::parse(Text_db&t)
9 {
10     symtables_->read(t) ;
11 }
12
13 Lookup::Lookup()
14 {
15     symtables_ = new Symtables;
16 }
17
18 Lookup::~Lookup()
19 {
20     delete symtables_;
21 }
22
23 Symbol
24 Lookup::ball(int j)
25 {
26     if (j > 4)
27         j = 4;
28
29     Symtable * st = (*symtables_)("balls");
30     return st->lookup(String(j));
31 }
32
33 Symbol
34 Lookup::rest(int j)
35 {
36     return (*symtables_)("rests")->lookup(String(j));
37 }
38
39
40 Symbol
41 Lookup::bar(String s)
42 {
43     return (*symtables_)("bars")->lookup(s);
44 }
45  Symbol
46 Lookup::dots(int j)
47 {
48     if (j>3)
49         error("max 3 dots");
50     return (*symtables_)("dots")->lookup(j);
51 }
52
53 Symbol
54 Lookup::flag(int j)
55 {
56     return (*symtables_)("flags")->lookup(j);
57 }
58
59 Symbol
60 Lookup::streepjes(int i)
61 {
62     assert(i);
63     
64     int arg;
65     String idx ;
66     if (i<0) {
67         idx = "botlines";
68         arg = -i;
69     }else {
70         arg = i;
71         idx = "toplines";
72     }
73     Symbol ret = (*symtables_)("streepjes")->lookup(idx);
74     
75     svec<String> a;
76     a.add(arg);
77     ret.tex = substitute_args(ret.tex, a);
78
79     return ret;
80 }
81
82 /****************************************************************/
83 // bare bones.
84
85 struct Linestaf_symbol : Parametric_symbol {
86     int lines;
87     Linestaf_symbol(int n, Symtables*s): Parametric_symbol(s) { lines = n;}
88     Symbol eval(svec<String>)const;
89 };
90
91
92 Symbol
93 Linestaf_symbol::eval(svec<String> w)const
94 {
95     Real wid = w[0].fvalue();
96
97     Symbol s;
98     s.dim.x = Interval(0,wid);
99     Real dy=(lines-1)*convert_dimen(5,"pt"); // TODO!
100     s.dim.y = Interval(0,dy);
101     svec<String> a;
102     a.add(lines);
103     a.add(w[0]);
104     s.tex = (*symtables_)("param")->lookup("linestaf").tex;
105     s.tex = substitute_args(s.tex, a);
106     return s;
107 }
108
109 /****************************************************************/
110
111
112 struct Meter_sym:Parametric_symbol {
113
114     Meter_sym(Symtables*s) : Parametric_symbol(s){  }
115     Symbol eval(svec<String> a) const{
116         Symbol s;
117         s.dim.x = Interval( convert_dimen(-5,"pt"),
118                             convert_dimen(5,"pt"));
119         s.dim.y = Interval(0, convert_dimen(10,"pt") ); // todo
120         String src = (*symtables_)("param")->lookup("meter").tex;
121         s.tex = substitute_args(src,a);
122         return s;
123     }
124 };
125 /****************************************************************/
126
127 struct Stem_sym:Parametric_symbol {
128
129     Stem_sym(Symtables*s) : Parametric_symbol(s) {  }
130     Symbol eval(svec<String> a) const {
131         Real y1 = a[0].fvalue();
132         Real y2 = a[1].fvalue();
133         assert(y1 <= y2);
134         Symbol s;
135         s.dim.x = Interval(0,0);
136         s.dim.y = Interval(y1,y2);
137
138         String src = (*symtables_)("param")->lookup("stem").tex;
139         s.tex = substitute_args(src,a);
140         return s;
141     }
142 };
143
144 Parametric_symbol *
145 Lookup::meter(String )
146 {
147     return new Meter_sym(symtables_);
148 }
149
150 Parametric_symbol *
151 Lookup::linestaff(int n)
152 {
153     return new Linestaf_symbol(n,symtables_);
154 }
155
156 Parametric_symbol*
157 Lookup::stem()
158 {
159     return new Stem_sym(symtables_);
160 }