]> git.donarmstrong.com Git - lilypond.git/blob - src/lookup.cc
release: 0.0.17
[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 /****************/
32
33 Real
34 Lookup::internote()
35 {
36     return ball(4).dim.y.length()/2;
37 }
38
39 Symbol
40 Lookup::ball(int j)
41 {
42     if (j > 4)
43         j = 4;
44
45     Symtable * st = (*symtables_)("balls");
46     return st->lookup(String(j));
47 }
48
49 Symbol
50 Lookup::rest(int j)
51 {
52     return (*symtables_)("rests")->lookup(String(j));
53 }
54 Symbol
55 Lookup::fill(Box b)
56 {
57     Symbol s( (*symtables_)("param")->lookup("fill"));
58     s.dim = b;
59     return s;
60 }
61 Symbol
62 Lookup::accidental(int j)
63 {
64     return (*symtables_)("accidentals")->lookup(String(j));
65 }
66
67
68 Symbol
69 Lookup::bar(String s)
70 {
71     return (*symtables_)("bars")->lookup(s);
72 }
73
74 Symbol
75 Lookup::clef(String s)
76 {
77     return (*symtables_)("clefs")->lookup(s);
78 }
79  
80 Symbol
81 Lookup::dots(int j)
82 {
83     if (j>3)
84         error("max 3 dots");
85     return (*symtables_)("dots")->lookup(j);
86 }
87
88 Symbol
89 Lookup::flag(int j)
90 {
91     return (*symtables_)("flags")->lookup(j);
92 }
93
94 Symbol
95 Lookup::streepjes(int i)
96 {
97     assert(i);
98     
99     int arg;
100     String idx;
101     
102     if (i < 0) {
103         idx = "botlines";
104         arg = -i;
105     } else {
106         arg = i;
107         idx = "toplines";
108     }
109     Symbol ret = (*symtables_)("streepjes")->lookup(idx);
110     
111     svec<String> a;
112     a.add(arg);
113     ret.tex = substitute_args(ret.tex, a);
114
115     return ret;
116 }
117
118
119
120 Symbol
121 Lookup::linestaff(int lines, Real wid) 
122 {
123     Symbol s;
124     s.dim.x = Interval(0,wid);
125     Real dy=(lines-1)*internote()*2;
126     s.dim.y = Interval(0,dy);
127
128     svec<String> a;
129     a.add(lines);
130     a.add(print_dimen(wid));
131
132     s.tex = (*symtables_)("param")->lookup("linestaf").tex;
133     s.tex = substitute_args(s.tex, a);
134     
135     return s;
136 }
137
138
139 Symbol
140 Lookup::meter(svec<Scalar> a)
141 {
142     Symbol s;
143     s.dim.x = Interval( convert_dimen(0,"pt"),
144                         convert_dimen(10,"pt"));
145     s.dim.y = Interval(0, convert_dimen(20,"pt") );     // todo
146     String src = (*symtables_)("param")->lookup("meter").tex;
147     s.tex = substitute_args(src,a);
148     return s;    
149 }
150
151
152 Symbol
153 Lookup::stem(Real y1,Real y2)
154 {
155     assert(y1 <= y2);
156     Symbol s;
157     
158     s.dim.x = Interval(0,0);
159     s.dim.y = Interval(y1,y2);
160     
161     svec<String> a;
162     a.add(print_dimen(y1));
163     a.add(print_dimen(y2));
164         
165     String src = (*symtables_)("param")->lookup("stem").tex;
166     s.tex = substitute_args(src,a);
167     return s;
168 }