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