]> git.donarmstrong.com Git - lilypond.git/blob - lily/lookup.cc
release: 0.1.37
[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 = postscript_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       if (wid > 32 * 6 PT)
177         {
178           warning (_("Crescendo too long (") + print_dimen (wid) 
179                    +_( ") shrinking (ugh)"));
180           wid = 32*6 PT;
181         }
182       int idx = int (rint (wid / 6 PT));
183       if (!idx) idx ++;
184       wid = idx*6 PT;
185       String idxstr = (decresc)? "decrescendosym" : "crescendosym";
186       ret=(*symtables_p_)("param")->lookup (idxstr);
187       
188       Array<String> a;
189       a.push (idx);
190       ret.tex_ = substitute_args (ret.tex_, a);
191     }
192   
193   ret.dim_.x() = Interval (0,wid);
194   return ret;
195 }
196
197 Atom
198 Lookup::meter (Array<Scalar> a) const
199 {
200   Atom s((*symtables_p_)("param")->lookup ("meter"));
201   s.tex_ = substitute_args (s.tex_,a);
202   return s;
203 }
204
205
206 Atom
207 Lookup::stem (Real y1,Real y2) const
208 {
209   if (y1 > y2)
210     {
211       Real t = y1;
212       y1 = y2;
213       y2 = t;
214     }
215   Atom s;
216
217   s.dim_.x() = Interval (0,0);
218   s.dim_.y() = Interval (y1,y2);
219
220   Array<String> a;
221   a.push (print_dimen (y1));
222   a.push (print_dimen (y2));
223
224   String src = (*symtables_p_)("param")->lookup ("stem").tex_;
225   s.tex_ = substitute_args (src,a);
226   return s;
227 }
228
229 /*
230   should be handled via Tex_ code and Lookup::bar()
231  */
232 Atom
233 Lookup::vbrace (Real &y) const
234 {
235   Atom brace = (*symtables_p_)("param")->lookup ("brace");
236   Interval ydims = brace.dim_[Y_AXIS];
237   Real min_y = ydims[LEFT];
238   Real max_y = ydims[RIGHT];
239   Real step = 2.0 PT;
240  
241   if (y < min_y)
242     {
243       warning (_("piano brace too small (") + print_dimen (y)+ ")");
244       y = min_y;
245     }
246   if (y > max_y)
247     {
248       warning (_("piano brace too big (") + print_dimen (y)+ ")");
249       y = max_y;
250     }
251
252   
253   int idx = int (rint ((y- min_y)/step)) + 1;
254   
255   {
256     Array<String> a;
257     a.push (idx);
258     brace.tex_ = substitute_args (brace.tex_,a);
259     brace.dim_[Y_AXIS] = Interval (-y/2,y/2);
260   }
261
262   return brace;
263 }