]> git.donarmstrong.com Git - lilypond.git/blob - lily/lookup.cc
release: 0.1.35
[lilypond.git] / lily / lookup.cc
1 /*
2   lookup.cc -- implement simple Lookup methods.
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7
8   TODO
9   This doth suck. We should have PS output, and read spacing info from TFMs
10
11   Glissando, bracket
12
13 */
14
15 #include "lookup.hh"
16 #include "debug.hh"
17 #include "symtable.hh"
18 #include "dimen.hh"
19 #include "tex.hh"
20 #include "scalar.hh"
21 #include "paper-def.hh"
22 #include "main.hh"
23
24 Lookup::Lookup()
25 {
26   paper_l_ = 0;
27   texsetting = "\\unknowntexsetting";
28   symtables_p_ = new Symtables;
29 }
30
31 Lookup::Lookup (Lookup const &s)
32 {
33   paper_l_ = s.paper_l_;
34   texsetting = s.texsetting;
35   symtables_p_ = new Symtables (*s.symtables_p_);
36 }
37 Lookup::~Lookup()
38 {
39   delete symtables_p_;
40 }
41
42 void
43 Lookup::add (String s, Symtable*p)
44 {
45   symtables_p_->add (s, p);
46 }
47
48 void
49 Lookup::print() const
50 {
51 #ifndef NPRINT
52   DOUT << "Lookup: " << texsetting << " {\n";
53   symtables_p_->print();
54   DOUT << "}\n";
55 #endif
56 }
57
58 Atom
59 Lookup::text (String style, String text, int dir) const
60 {
61   Array<String> a;
62
63   a.push (text);
64   Atom tsym =  (*symtables_p_)("style")->lookup (style);
65   a[0] = substitute_args (tsym.tex_,a);
66
67   Atom s = (*symtables_p_)("align")->lookup (dir);
68   s.tex_ = substitute_args (s.tex_,a);
69   s.dim_ = tsym.dim_;
70   return s;
71 }
72
73
74
75 Atom
76 Lookup::ball (int j) const
77 {
78   if (j > 2)
79     j = 2;
80
81   Symtable * st = (*symtables_p_)("balls");
82   return st->lookup (String (j));
83 }
84
85 Atom
86 Lookup::rest (int j, bool o) const
87 {
88   return (*symtables_p_)("rests")->lookup (String (j) + (o ? "o" : ""));
89 }
90
91 Atom
92 Lookup::fill (Box b) const
93 {
94   Atom s ((*symtables_p_)("param")->lookup ("fill"));
95   s.dim_ = b;
96   return s;
97 }
98
99 Atom
100 Lookup::accidental (int j) const
101 {
102   return (*symtables_p_)("accidentals")->lookup (String (j));
103 }
104
105
106 Atom
107 Lookup::bar (String s, Real h) const
108 {
109   Array<String> a;
110   a.push (print_dimen (h));
111   Atom ret=(*symtables_p_)("bars")->lookup (s);
112   ret.tex_ = substitute_args (ret.tex_, a);
113   ret.dim_.y() = Interval (-h/2, h/2);
114   return ret;
115 }
116
117 Atom
118 Lookup::script (String s) const
119 {
120   return (*symtables_p_)("scripts")->lookup (s);
121 }
122
123 Atom
124 Lookup::dynamic (String s) const
125 {
126   return (*symtables_p_)("dynamics")->lookup (s);
127 }
128
129 Atom
130 Lookup::clef (String s) const
131 {
132   return (*symtables_p_)("clefs")->lookup (s);
133 }
134
135 Atom
136 Lookup::dots () const
137 {
138   return (*symtables_p_)("dots")->lookup ("dot");
139 }
140
141 Atom
142 Lookup::flag (int j, Direction d) const
143 {
144   char c = (d == UP) ? 'u' : 'd';
145   return (*symtables_p_)("flags")->lookup (c + String (j));
146 }
147
148 Atom
149 Lookup::streepje (int type) const
150 {
151   if (type > 2)
152     type = 2;
153
154   Symtable * st = (*symtables_p_)("balls");
155   
156   return st->lookup (String (type) + 'l');
157 }
158
159 Atom
160 Lookup::hairpin (Real &wid, bool decresc) const
161 {
162   bool embedded_b = experimental_features_global_b;
163   String embed;
164   Atom ret;  
165   if (embedded_b)
166     {
167       Real height = 2 PT;
168       embed = "\\embeddedps{\n" ;
169       embed += String (wid) + " " 
170         + String (height)
171         + " draw_"  + String(decresc ? "de" : "") + "cresc}\n";
172       ret.tex_ = embed;
173     }
174   else
175     {
176       int idx = int (rint (wid / 6 PT));
177       if (!idx) idx ++;
178       wid = idx*6 PT;
179       String idxstr = (decresc)? "decrescendosym" : "crescendosym";
180       ret=(*symtables_p_)("param")->lookup (idxstr);
181       
182       Array<String> a;
183       a.push (idx);
184       ret.tex_ = substitute_args (ret.tex_, a);
185       
186     }
187   
188   ret.dim_.x() = Interval (0,wid);
189   return ret;
190 }
191
192 Atom
193 Lookup::meter (Array<Scalar> a) const
194 {
195   Atom s((*symtables_p_)("param")->lookup ("meter"));
196   s.tex_ = substitute_args (s.tex_,a);
197   return s;
198 }
199
200
201 Atom
202 Lookup::stem (Real y1,Real y2) const
203 {
204   if (y1 > y2)
205     {
206       Real t = y1;
207       y1 = y2;
208       y2 = t;
209     }
210   Atom s;
211
212   s.dim_.x() = Interval (0,0);
213   s.dim_.y() = Interval (y1,y2);
214
215   Array<String> a;
216   a.push (print_dimen (y1));
217   a.push (print_dimen (y2));
218
219   String src = (*symtables_p_)("param")->lookup ("stem").tex_;
220   s.tex_ = substitute_args (src,a);
221   return s;
222 }
223
224 /*
225   should be handled via Tex_ code and Lookup::bar()
226  */
227 Atom
228 Lookup::vbrace (Real &y) const
229 {
230   Atom brace = (*symtables_p_)("param")->lookup ("brace");
231   Interval ydims = brace.dim_[Y_AXIS];
232   Real min_y = ydims[LEFT];
233   Real max_y = ydims[RIGHT];
234   Real step = 2.0 PT;
235  
236   if (y < min_y)
237     {
238       warning (_("piano brace too small (") + print_dimen (y)+ ")");
239       y = min_y;
240     }
241   if (y > max_y)
242     {
243       warning (_("piano brace too big (") + print_dimen (y)+ ")");
244       y = max_y;
245     }
246
247   
248   int idx = int (rint ((y- min_y)/step)) + 1;
249   
250   {
251     Array<String> a;
252     a.push (idx);
253     brace.tex_ = substitute_args (brace.tex_,a);
254     brace.dim_[Y_AXIS] = Interval (-y/2,y/2);
255   }
256
257   return brace;
258 }